Hi,
I have to port a Windows CE application to Windows XP.
In Windows CE this application runs fine. It contains a lowlevelkeyboardproc that is called when a key is pressed.
The different Windows CE projects are build with several makefile-, sources- & *.def- files.
I built new projects with Visual Studio 2010 and added the *.cpp & *.h files.
Further there has been some Windows CE specific stuff in the code, which I replaced with Windows XP stuff.
Concerning the lowlevelkeyboardproc I changed nothing in the existing Windows CE code.
The lowlevelkeyboardproc stuff is implemented in a service (*.exe) and a DLL.
The service loads the DLL. The DLL is the part that contains the hook function.
1. Inside the service a thread is created. Concerning the lowlevelkeyboardproc the following stuff is done in this thread:
---------------------------------------------------------------------------------------------------------------------------
DWORD WINAPI MyServiceThread (LPVOID lpParameter)
{
HMODULE hinstDLL = LoadLibrary(TEXT("MyHook.dll"));
BOOL_FUNC pInstallHook = (BOOL_FUNC)GetProcAddress(hinstDLL,"InstallHook");
pInstallHook();
MSG msg;
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
BOOL_FUNC pUnInstallHook = (BOOL_FUNC)GetProcAddress(hinstDLL,"UnInstallHook");
pUnInstallHook();
return 0;
}
2. the lowlevelkeyboardproc related stuff in my MyHook.dll is:
---------------------------------------------------------------------------------------------------------------------------
........
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD fdwReason,
LPVOID lpReserved )
{
static HANDLE hFileMap = NULL;
if( DLL_PROCESS_ATTACH == fdwReason )
{
InitializeCriticalSection(&csStatusPos);
EnterCriticalSection(&csStatusPos);
hFileMap = CreateFileMapping((HANDLE)-1, (LPSECURITY_ATTRIBUTES) NULL, PAGE_READWRITE, (DWORD) 0, (DWORD) sizeof(SHARED_MEM_VAR), TEXT("MY_SHARED_MEM_VAR") );
p_my_shared_mem = (PSHARED_MEM_VAR)MapViewOfFile( hFileMap, FILE_MAP_WRITE, (DWORD) 0, (DWORD) 0, (DWORD) sizeof(SHARED_MEM_VAR));
p_my_shared_mem->m_hDllInst = (HINSTANCE) hModule;
p_my_shared_mem->m_MyKeyBoardHookObject = new MyKeyBoardHookClass;
p_my_shared_mem->m_MyKeyBoardHookObject->Init();
....
LeaveCriticalSection(&csStatusPos);
}
if(DLL_PROCESS_DETACH == fdwReason)
{
EnterCriticalSection(&csStatusPos);
delete p_my_shared_mem->m_MyKeyBoardHookObject;
.....
UninstallHook();
UnmapViewOfFile( (LPCVOID) p_my_shared_mem);
CloseHandle(hFileMap);
LeaveCriticalSection(&csStatusPos);
DeleteCriticalSection(&csStatusPos);
}
return TRUE;
}
EXTERN BOOL InstallHook()
{
p_my_shared_mem->m_hMyKeybdHook = SetWindowsHookEx( WH_KEYBOARD_LL,
(HOOKPROC)MyLowLevelKeyboardHook,
p_my_shared_mem->m_hDllInst,
0 );
return ! ( NULL == p_my_shared_mem->m_hMyKeybdHook );
}
EXTERN BOOL UninstallHook()
{
UnhookWindowsHookEx(p_my_shared_mem->m_hMyKeybdHook);
return FALSE;
}
EXTERN HOOKPROC MyLowLevelKeyboardHook(int nCode, WPARAM wParam, LPARAM lParam)
{
........
}
........
1. Can somebody see, why MyLowLevelKeyboardHook is never called in Windows XP, when a key has been pressed?
2. I tried a lot of stuff to get my Hook installed.... I read a lot in the MSDN about Hooks &
especially lowlevelkeyboardproc etc... I searched in old forum threads for a solution. ...
But I wasn't able to fix the problem. My hook still isn't called.
==> Can somebody tell me please all the important points, that are required to
get a own lowlevelkeyboardproc global hook working.
3. Does somebody know a good link(s) to a place(s), that explains everything about this topic?
4. Does somebody know a good link(s) to a place(s), with a good free sample code?
Thanks in advance for all your answers and help.
regards dave