In my KeyboardProc in my dll, how can I obtain the handle returned to the hook by SetWindowsHookEx so that I can call CallNextHookEx?
Printable View
In my KeyboardProc in my dll, how can I obtain the handle returned to the hook by SetWindowsHookEx so that I can call CallNextHookEx?
It's passed to your hook function. Read the MSDN.
Oops. My bad. Hook handle is return by SetWindowsHookEx.
Eg.
where the init call is:Code:LRESULT __stdcall LowLevelKeyboardProc (DWORD code, WPARAM wparam, LPARAM lparam)
{
if (code == HC_ACTION) /* A key was pressed */
{
KBDLLHOOKSTRUCT *hookstruct = (KBDLLHOOKSTRUCT *)lparam;
/* Send key to our main program */
PostMessage (hWnd, WM_U_HOOKMSG, (hookstruct->vkCode << 16) + hookstruct->scanCode, hookstruct->flags);
}
/* Otherwise pass it down... */
return (CallNextHookEx (hookHandle, code, wparam, lparam));
}
Code:hookHandle = SetWindowsHookEx (WH_KEYBOARD_LL, (HOOKPROC)&LowLevelKeyboardProc, HInstance, 0);
Yeah, my problem was that the proc function was assigned in a dll, separate from the actual hook call. I just ended up using a startup function.