setwindowshookex returns null
I want to use setwindowshookex for hooking a dll into one of my own applications. setwindowshookex returns null setting error code 87 (invalid parameter), which I believe is the threadid parameter. This is a cut down version of my code to show what im trying to do.
the hook variable is set to null at this point, however LoadLibrary and GetProcAddress all work correctly. Also CreateProcess works ok as I can see the application load and the procInfo.dwThreadId is none 0
memset(&startInfo, 0, sizeof(startInfo));
memset(&procInfo, 0, sizeof(procInfo));
startInfo.cb = sizeof(startInfo);
CreateProcess( "c:/myapp.exe", NULL, NULL, NULL, false, DETACHED_PROCESS, 0, 0,
&startInfo, &procInfo ) ;
HINSTANCE dll = LoadLibrary(TEXT("c:/mydll.dll")) ;
if (dll == NULL) return false ;
DllHookProc hookProc = (DllHookProc)GetProcAddress(dll,"HookProc");
if (hookProc == NULL) return false ; // will also free dll.
HHOOK hook = SetWindowsHookEx( WH_CALLWNDPROC,(HOOKPROC)hookProc,
dll, procInfo.dwThreadId );
Any ideas what i am doing incorrectly?
Thanks for any help