How to Create a global WH_GETMESSAGE HOOK without DLL

早过忘川 提交于 2019-12-08 04:07:12

问题


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


回答1:


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.




回答2:


You need a message loop in the calling thread of SetWindowsHookEx

while(GetMessage(&msg, NULL, 0, 0))
{
    TranslateMessage(&msg);
    DispatchMessage(&msg);
}



回答3:


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.



来源:https://stackoverflow.com/questions/6406337/how-to-create-a-global-wh-getmessage-hook-without-dll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!