This DLL gets injected in to a simple form application using a 'starter app' which uses CreateProccessEXA from Madshi's library (www.madshi.net
). For testing purposes I've set it up to hook the keyboard up and down arrows. Because of this, I'm not sure if I'm setting the hook correctly or not.
Can someone explain to me why this does not work? I thought I had read somewhere that maybe the hook has to be in a loop or something... I don't, the only example I find are very basic and they only seem to be in EXEs, not DLLs. Does that make a difference?
I know that the DLL is getting injected and started because I get the "Attaching" messagebox when my starter app is used and "Detaching" messagebox when I close my form. So the DLL is running in the simple form app Ultimately what I would like to do is hook messages sent to controls with in the form.
Anyways, here's the code. If more explanation is needed, just let me know.
/////////////// THE DLL ///////////////////
LRESULT CALLBACK KeyboardProc(int hCode,WPARAM ww,LPARAM ll)
if (hCode < 0)
// log here info , ww has its HWND
BOOL WINAPI DllMain( HANDLE hModule,
if (reason == DLL_PROCESS_ATTACH)
MessageBox(0,"Attaching", "Debug", 0);
HINSTANCE hDll = GetModuleHandle(NULL);
hH = SetWindowsHookEx(WH_KEYBOA
else if (reason == DLL_PROCESS_DETACH)
MessageBox(0,"Detaching", "Debug", 0);
//////////// THE STARTER APP /////////////
int _tmain(int argc, _TCHAR* argv)
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );