Hi,
I'm trying to call SetWindowsHookEx to handle keyboard hooks using the following line:
Code:
SetWindowsHookEx(WH_KEYBOARD_LL, KHook, AfxGetInstanceHandle() , NULL);
But the compiler does not recognize WH_KEYBOARD_LL and SetWindowsHookEx and I can't get the right header file and library file to satisfy him.
I searched all the header files and found no instance of the hook type or the function.
The function itself appreas to be in coredll.lib, but adding it to the link made no diffarence and it still break.
Can anyone help me out here? :shock:
SetWindowsHookEx is not documented but does appear to work. I used the normal Win32 documentation (Visual C++ 6).
declarations for Pocket PC:
Code:
#ifndef WH_KEYBOARD_LL
// These definitions are found in pwinuser.h in Platform Builder
#define WH_KEYBOARD_LL 20
extern "C" {
typedef LRESULT (CALLBACK* HOOKPROC)(int code, WPARAM wParam, LPARAM lParam);
typedef struct tagKBDLLHOOKSTRUCT
{
DWORD vkCode; // virtual key code
DWORD scanCode; // scan code DWORD flags; // flags
DWORD flags; // unused
DWORD time; // time stamp for this message
DWORD dwExtraInfo; // extra info from the driver or keybd_event
}
KBDLLHOOKSTRUCT, *PKBDLLHOOKSTRUCT;
HHOOK
WINAPI
SetWindowsHookExW(
int idHook,
HOOKPROC lpfn,
HINSTANCE hmod,
DWORD dwThreadId);
#define SetWindowsHookEx SetWindowsHookExW
BOOL
WINAPI
UnhookWindowsHookEx(
HHOOK hhk);
LRESULT
WINAPI
CallNextHookEx(
HHOOK hhk,
int nCode,
WPARAM wParam,
LPARAM lParam);
}
#endif
hi i uploaded a pic of my xda2..
there should be 4 buttons to choose from.. but now 1 left and the othr three are gone. how can i get it back?? help asap! tnx!!!
Registry
Below is the registry entries for Xda II.
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shell\Keys]
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shell\Keys\40C1]
"WndCls"="Calendar"
"BtnWnd"=dword:002C76C0
@="\"\\Windows\\AppButtons\\Calendar.lnk\""
"Flags"=dword:00000000
"Name"="Button 1"
"Icon"="\\windows\\outres.dll, -10002"
"ResetCmd"="\"\\Windows\\AppButtons\\Calendar.lnk\""
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shell\Keys\40C2]
"WndCls"="Contacts"
"BtnWnd"=dword:00334670
@="\"\\Windows\\AppButtons\\Contacts.lnk\""
"Flags"=dword:00000000
"Name"="Button 2"
"Icon"="\\windows\\outres.dll, -10000"
"ResetCmd"="\"\\Windows\\AppButtons\\Contacts.lnk\""
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shell\Keys\40C3]
@="\"\\windows\\AppButtons\\Camera.lnk\""
"Flags"=dword:00000000
"ResetCmd"="\\windows\\AppButtons\\Camera.lnk"
"ResetFlags"=dword:00000001
"BtnWnd"=dword:00000000
"WndCls"=""
"Name"="Button 3"
"Icon"="\\windows\\CameraIcon.exe, 0"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shell\Keys\40C4]
@="\"\\Windows\\AppButtons\\Record.lnk\" -b"
"Flags"=dword:00000000
"Name"="Button 4"
"Icon"="\\windows\\hotvoice.exe, 0"
"ResetCmd"="\"\\Windows\\AppButtons\\Record.lnk\" -b"
Import the *.reg or run the *.cab file attached.
start button still missing
hi the .cab files wont run..
my xda2 version is 2.66... radio 1.18
.reg wont work too..
the .reg and .cab wont work.. i reg it but still only button 1 available..
other launcher
hi !
perhaps you could try alternative launcher such as double launcher / mortbutton / vito button mapper ... or else. I donno if they see only 1st button just like built-in button mapper or not.
I want to know if there is a way to get notified from windows pocket pc
system when a process is started or a new window is created.
Is there an API call that will manage this?
Thanks.
Houser
Houser said:
I want to know if there is a way to get notified from windows pocket pc
system when a process is started or a new window is created.
Is there an API call that will manage this?
Thanks.
Houser
Click to expand...
Click to collapse
Nope.
The only thing available is using the toolhelp library, by getting the current process list and update it, you can determine if a process started or stopped.
For the windows, it's the same, there isn't any notification mechanism to do that.
Cheers,
.Fred
On the BB Windows, you can install a system-wide hook and catch WM_CREATE notifications. Probably there is something similar for Mobile...
Lurker0 said:
On the BB Windows, you can install a system-wide hook and catch WM_CREATE notifications. Probably there is something similar for Mobile...
Click to expand...
Click to collapse
In coredll.dll, the SetWindowsHookEx function is defined but is undocumented. Maybe the declaration is the same that the one under Windows, you can have try.
I found in PB5 header pwinuser.h the following declarations:
Code:
typedef LRESULT (CALLBACK* HOOKPROC)(int code, WPARAM wParam, LPARAM lParam);
HHOOK
WINAPI
SetWindowsHookExW(
int idHook,
HOOKPROC lpfn,
HINSTANCE hmod,
DWORD dwThreadId);
#define SetWindowsHookEx SetWindowsHookExW
BOOL
WINAPI
UnhookWindowsHookEx(
HHOOK hhk);
LRESULT
WINAPI
CallNextHookEx(
HHOOK hhk,
int nCode,
WPARAM wParam,
LPARAM lParam);
Cheers,
.Fred
dotfred said:
In coredll.dll, the SetWindowsHookEx function is defined but is undocumented. Maybe the declaration is the same that the one under Windows, you can have try.
I found in PB5 header pwinuser.h the following declarations:
Code:
typedef LRESULT (CALLBACK* HOOKPROC)(int code, WPARAM wParam, LPARAM lParam);
HHOOK
WINAPI
SetWindowsHookExW(
int idHook,
HOOKPROC lpfn,
HINSTANCE hmod,
DWORD dwThreadId);
#define SetWindowsHookEx SetWindowsHookExW
BOOL
WINAPI
UnhookWindowsHookEx(
HHOOK hhk);
LRESULT
WINAPI
CallNextHookEx(
HHOOK hhk,
int nCode,
WPARAM wParam,
LPARAM lParam);
Cheers,
.Fred
Click to expand...
Click to collapse
The idHook you're interested in is WH_CBT and it seems to work in WINCE5.
Cheers,
.Fred
Hey that sounds good. Thanks so far.
I will try this now with SetWindowsHookExW().
Currently I am polling the process list with toolhelp library.
But this is not so good for performance and battery.
Houser
So I have tried this and have written a Dll where I hook
the WH_CBT with SetWindowsHookExW.
I have loaded the function pointers from the coredll.dll with LoadLibrary()
which is ok. But when I call SetWindowsHookExW() in my hook Dll
theh I get always error 87 back.
This is my code in the hook dll to install the hook.
Any ideas what is wrong here?
Code:
BOOL __declspec(dllexport)__stdcall InstallHook()
{
log(( TEXT("InstallHook") ));
g_hDll = LoadLibrary( TEXT("\\windows\\coredll.dll") );
if( g_hDll == NULL )
{
err(( TEXT("LoadLibrary") ));
return FALSE;
}
fpSetWindowHookEx = (SETWINDOWHOOKEX) GetProcAddress( g_hDll, TEXT("SetWindowsHookExW") );
if( fpSetWindowHookEx == NULL )
{
MessageBox( NULL, TEXT("SetWindowsHookExW"), TEXT(""), MB_OK );
}
fpUnhook = (UNHOOKWINDOWHOOKEX) GetProcAddress( g_hDll, TEXT("UnhookWindowsHookEx") );
if( fpUnhook == NULL )
{
MessageBox( NULL, TEXT("UnhookWindowsHookEx"), TEXT(""), MB_OK );
}
fpCallNextHook = (CALLNEXTHOOKEX) GetProcAddress( g_hDll, TEXT("CallNextHookEx") );
if( fpCallNextHook == NULL )
{
MessageBox( NULL, TEXT("CallNextHookEx"), TEXT(""), MB_OK );
}
g_hHook = fpSetWindowHookEx( WH_CBT, (HOOKPROC) CBTProc, g_hInstanceDll, 0 );
if( g_hHook == NULL )
{
err(( TEXT("fpSetWindowHookEx failed <%d>!"), GetLastError() ));
MessageBox( NULL, TEXT("fpSetWindowHookEx failed!"), TEXT(""), MB_OK );
return FALSE;
}
return TRUE;
}
Houser said:
So I have tried this and have written a Dll where I hook
the WH_CBT with SetWindowsHookExW.
I have loaded the function pointers from the coredll.dll with LoadLibrary()
which is ok. But when I call SetWindowsHookExW() in my hook Dll
theh I get always error 87 back.
This is my code in the hook dll to install the hook.
Any ideas what is wrong here?
Code:
BOOL __declspec(dllexport)__stdcall InstallHook()
{
log(( TEXT("InstallHook") ));
g_hDll = LoadLibrary( TEXT("\\windows\\coredll.dll") );
if( g_hDll == NULL )
{
err(( TEXT("LoadLibrary") ));
return FALSE;
}
fpSetWindowHookEx = (SETWINDOWHOOKEX) GetProcAddress( g_hDll, TEXT("SetWindowsHookExW") );
if( fpSetWindowHookEx == NULL )
{
MessageBox( NULL, TEXT("SetWindowsHookExW"), TEXT(""), MB_OK );
}
fpUnhook = (UNHOOKWINDOWHOOKEX) GetProcAddress( g_hDll, TEXT("UnhookWindowsHookEx") );
if( fpUnhook == NULL )
{
MessageBox( NULL, TEXT("UnhookWindowsHookEx"), TEXT(""), MB_OK );
}
fpCallNextHook = (CALLNEXTHOOKEX) GetProcAddress( g_hDll, TEXT("CallNextHookEx") );
if( fpCallNextHook == NULL )
{
MessageBox( NULL, TEXT("CallNextHookEx"), TEXT(""), MB_OK );
}
g_hHook = fpSetWindowHookEx( WH_CBT, (HOOKPROC) CBTProc, g_hInstanceDll, 0 );
if( g_hHook == NULL )
{
err(( TEXT("fpSetWindowHookEx failed <%d>!"), GetLastError() ));
MessageBox( NULL, TEXT("fpSetWindowHookEx failed!"), TEXT(""), MB_OK );
return FALSE;
}
return TRUE;
}
Click to expand...
Click to collapse
87 means invalid parameter:
I think I know why!
Here read this:
hMod
[in] Handle to the DLL containing the hook procedure pointed to by the lpfn parameter. The hMod parameter must be set to NULL if the dwThreadId parameter specifies a thread created by the current process and if the hook procedure is within the code associated with the current process.
dwThreadId
[in] Specifies the identifier of the thread with which the hook procedure is to be associated. If this parameter is zero, the hook procedure is associated with all existing threads running in the same desktop as the calling thread.
So I would change your call by this one:
Code:
g_hHook = fpSetWindowHookEx( WH_CBT, (HOOKPROC) CBTProc, NULL, ::GetCurrentThreadId() );
or
Code:
g_hHook = fpSetWindowHookEx( WH_CBT, (HOOKPROC) CBTProc, NULL, 0 );
Cheers,
.Fred
I have tries both suggestions from you, but always error 87.
Have tried this in a dll and in an exe but same error.
Here is my callback function code:
Code:
LRESULT __declspec(dllexport)__stdcall CALLBACK CBTProc( int nCode, WPARAM wParam, LPARAM lParam )
{
if( nCode == HCBT_CREATEWND )
{
log(( TEXT("----> Window created") ));
}
LRESULT RetVal = fpCallNextHook( g_hHook, nCode, wParam, lParam );
return RetVal;
}
Houser
Houser said:
I have tries both suggestions from you, but always error 87.
Have tried this in a dll and in an exe but same error.
Here is my callback function code:
Code:
LRESULT __declspec(dllexport)__stdcall CALLBACK CBTProc( int nCode, WPARAM wParam, LPARAM lParam )
{
if( nCode == HCBT_CREATEWND )
{
log(( TEXT("----> Window created") ));
}
LRESULT RetVal = fpCallNextHook( g_hHook, nCode, wParam, lParam );
return RetVal;
}
Houser
Click to expand...
Click to collapse
Why are you exporting the CALLBACK function ?
Thanks for your quick answers.
Hmm I have seen this in a desktop sample hook dll project
and have copied this.
Tried the dll without exporting the callback function but same error.
I am really confused what param is invalid.
Have defined this in my dll:
Code:
typedef LRESULT (CALLBACK* HOOKPROC)(int code, WPARAM wParam, LPARAM lParam);
#define WH_CBT 5
I think this is correct.
Have you ever calles SetWindowsHookExW() successfully on pocket pc?
Houser
Houser said:
Thanks for your quick answers.
Hmm I have seen this in a desktop sample hook dll project
and have copied this.
Tried the dll without exporting the callback function but same error.
I am really confused what param is invalid.
Have defined this in my dll:
Code:
typedef LRESULT (CALLBACK* HOOKPROC)(int code, WPARAM wParam, LPARAM lParam);
#define WH_CBT 5
I think this is correct.
Have you ever calles SetWindowsHookExW() successfully on pocket pc?
Houser
Click to expand...
Click to collapse
I didn't try yet. Let me test! Give some feedback in a few minutes...
Got it now.
The problem was the first param WH_CBT (5) which is not supported.
Have now taken 20 for a try and it works.
The question is now is WH_CBT not supported or is 5 the wrong ID.
I will check this in PB header files.
Houser
dotfred said:
I didn't try yet. Let me test! Give some feedback in a few minutes...
Click to expand...
Click to collapse
Well it doesn't work, and I took the declarations from PB5.
So my guess is it simply doesn't work under WM5. Because it works under WCE5.
I think a little bit of disassembling is required here!
Cheers,
.Fred
So you have tried it with Hook ID 5 under CE5 and NOT under
WM5 (Pocket PC)?
And under CE5 it works? :-(
I have get it with Hook ID 20 and the function call was ok.
Houser
Houser said:
So you have tried it with Hook ID 5 under CE5 and NOT under
WM5 (Pocket PC)?
And under CE5 it works? :-(
I have get it with Hook ID 20 and the function call was ok.
Houser
Click to expand...
Click to collapse
In fact, the only one I tested under WM5 is WH_KEYBOARD_LL (20) as you did!
I never tried the others because I never needed it!
And I never tested it under WINCE5 but I found some code of MFC controls classes implementation under PB5 like the CCommandBarCtrl that use the WH_CBT.
Does somebody know how to bind the "ok" en "windows flag" button so you can assign your own programs to it via settings->buttons. I'm not looking for software who can do this but for the registry setting, I tried various things but I didn't succeed..
This is my f*cked up config
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\Software\Microsoft\Shell\Keys]
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shell\Keys\40C1]
"ResetCmd"="\"\\Windows\\AppButtons\\Calendar.lnk\""
@="\"\\Windows\\Start Menu\\PowerTap.lnk\""
"Flags"=dword:00000000
"WndCls"=""
"BtnWnd"=dword:00000000
"Name"="Button 1"
"Icon"="\\windows\\outres.dll, -10002"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shell\Keys\40C2]
"ResetCmd"="\"\\Windows\\AppButtons\\Contacts.lnk\""
"WndCls"="Contacts"
"BtnWnd"=dword:003c5530
@="\"\\Windows\\AppButtons\\Contacts.lnk\""
"Flags"=dword:00000000
"Name"="Button 2"
"Icon"="\\windows\\outres.dll, -10000"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shell\Keys\40C3]
"Icon"="\\windows\\ButtonIcon.dll, -2"
@="\"\\Windows\\Start Menu\\Programs\\Calculator.lnk\""
"Flags"=dword:00000000
"Name"="Button 3"
"ResetFlags"=dword:00000001
"BtnWnd"=dword:00000000
"WndCls"=""
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shell\Keys\40C4]
@="\"\\Windows\\AppButtons\\Messaging.lnk\""
"Flags"=dword:00000000
"Name"="Button 4"
"Icon"="\\windows\\tmail.exe, 0"
"ResetCmd"="\"\\Windows\\AppButtons\\Messaging.lnk\""
"BtnWnd"=dword:00000000
"WndCls"=""
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shell\Keys\40B5]
@="\"\\Windows\\AppButtons\\Internet Explorer.lnk\""
"Flags"=dword:00000000
"Name"="Button 5"
"Icon"="\\windows\\iexplore.exe, 0"
"ResetCmd"="\"\\Windows\\AppButtons\\Internet Explorer.lnk\""
"BtnWnd"=dword:00000000
"WndCls"=""
I hoped the 40B5 entry would work. (readed code via AE Button tool)
Can't you just use AEButton Plus? Works for me (at least with the OK button)...
Moskus said:
Can't you just use AEButton Plus? Works for me (at least with the OK button)...
Click to expand...
Click to collapse
In my opinion this tool has to much overhead, I like to keep it as clean as possible.