I am trying to create a global WH_GETMESSAGE HOOK without DLL,but I can't success. My OS is Win7 32Bit,This is my some code:
SetWindowsHookEx(WH_GETMESSAGE,GetMsgProc,GetModuleHandle(NULL),0);
Please help me if you have any time. :)
I am trying to create a global WH_GETMESSAGE HOOK without DLL,but I can't success. My OS is Win7 32Bit,This is my some code:
SetWindowsHookEx(WH_GETMESSAGE,GetMsgProc,GetModuleHandle(NULL),0);
Please help me if you have any time. :)
As documented,
hMod [in]
Type: HINSTANCE
A handle to the DLL containing the hook procedure pointed to by the lpfn parameter. The hMod parameter must be set to NULL if the dwThreadId parameter specifies a thread created by the current process and if the hook procedure is within the code associated with the current process.
hMod
must be a handle to a DLL. Not an EXE. This is because the DLL will be loaded into all running processes to be hooked, and its code run straight from within those processes.
You need a message loop in the calling thread of SetWindowsHookEx
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
It's obvious, the last parameter shouldn't be '0', it should be the thread id of the thread you want to call the function in. You can't pass in null for both the last and next to last parameters. Use GetThreadId() to get the id of the current thread, that's most likely what you want to do.
The previous poster's answer was very useful for you, if you would have read it you would have seen the above yourself.