How to Create a global WH_GETMESSAGE HOOK without

2019-06-07 20:03发布

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. :)

3条回答
来,给爷笑一个
2楼-- · 2019-06-07 20:36

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.

查看更多
放我归山
3楼-- · 2019-06-07 20:52

You need a message loop in the calling thread of SetWindowsHookEx

while(GetMessage(&msg, NULL, 0, 0))
{
    TranslateMessage(&msg);
    DispatchMessage(&msg);
}
查看更多
老娘就宠你
4楼-- · 2019-06-07 20:56

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.

查看更多
登录 后发表回答