Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hooking and message sending

Status
Not open for further replies.

tkop

Programmer
Jun 12, 2003
5
IL
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top