I have an MFC based DLL which is injected into a game process I know nothing about, and I want to hook the keyboard capture to perform my own actions when certain keys are pressed. I'm using other API hooks here and there on the OpenGL libraries in this game without issue, however the keyboard hook appears not to be working.
I'm decalrinig the hook procedure as follows:
_declspec(dllexport) LRESULT CALLBACK KBHookProc(int Code, WPARAM wParam, LPARAM lParam)
if (Code < 0) return(CallNextHookEx(hhook, Code, wParam, lParam));
if (lParam & (1 << 31))
// do something
return(CallNextHookEx(hhook, Code, wParam, lParam));
and in the InitInstance method of my MFC DLL (where I'm successfully hooking other functions using IAT patching) I'm setting up the hook with:
hHook = SetWindowsHookEx(WH_KEYBOARD_LL, KBHookProc, GetModuleHandle("telemreader.dll"), 0);
(telemreader.dll is the name of my DLL being injected).
This returns as successful (GetLastError == 0 and a non-null handle is assigned to hHook), however the function itself is not being called when I press a key in my app.
Can anyone please help me with this?
Cheers in advance, sorry if I'm missing something obvious - have tried all sorts before posting here :)