Hi,
I have the following in a dll:
//***********************************************
bool WINAPI InstallHook(HWND handle)
{
bool bSuccess = false;
g_hHook = SetWindowsHookEx(WH_KEYBOARD, GetMsgProc, g_hinstDLL, NULL);
hWnd=handle;
return bSuccess;
}
//***********************************************
bool WINAPI RemoveHook(void)
{
bool bSuccess = false;
if(g_hHook != NULL)
{
bSuccess = UnhookWindowsHookEx(g_hHook) ? true : false;
g_hHook = NULL;
}
return bSuccess;
}
//***********************************************
LRESULT WINAPI GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam)
{
// MessageBeep(100);
if ( nCode < 0 )
return CallNextHookEx ( g_hHook, nCode, wParam, lParam ) ;
if (((DWORD)lParam & 0x40000000))
{
SendMessage(hWnd,WM_KEYDOWN,wParam,lParam);
}
else
{
SendMessage(hWnd,WM_KEYUP,wParam,lParam);
}
// Always call the next hook in the chain
return CallNextHookEx(g_hHook, nCode, wParam, lParam);
}
but the messages are not being received by hWnd.
what could be the problem?
Tsvi
I have the following in a dll:
//***********************************************
bool WINAPI InstallHook(HWND handle)
{
bool bSuccess = false;
g_hHook = SetWindowsHookEx(WH_KEYBOARD, GetMsgProc, g_hinstDLL, NULL);
hWnd=handle;
return bSuccess;
}
//***********************************************
bool WINAPI RemoveHook(void)
{
bool bSuccess = false;
if(g_hHook != NULL)
{
bSuccess = UnhookWindowsHookEx(g_hHook) ? true : false;
g_hHook = NULL;
}
return bSuccess;
}
//***********************************************
LRESULT WINAPI GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam)
{
// MessageBeep(100);
if ( nCode < 0 )
return CallNextHookEx ( g_hHook, nCode, wParam, lParam ) ;
if (((DWORD)lParam & 0x40000000))
{
SendMessage(hWnd,WM_KEYDOWN,wParam,lParam);
}
else
{
SendMessage(hWnd,WM_KEYUP,wParam,lParam);
}
// Always call the next hook in the chain
return CallNextHookEx(g_hHook, nCode, wParam, lParam);
}
but the messages are not being received by hWnd.
what could be the problem?
Tsvi