在Vista x64上使用dwThreadId = 0的SetWindowsHookEx自动挂钩 [英] SetWindowsHookEx with dwThreadId=0 on Vista x64 to hook automatically

查看:212
本文介绍了在Vista x64上使用dwThreadId = 0的SetWindowsHookEx自动挂钩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SetWindowsHookEx 的文档指出应该有单独的hookmodules和进程来加载64位32位进程的钩子。它没有说明当dwThreadId设置为0以自动挂钩所有线程时会发生什么。 Windows是否只挂钩所有xx位线程,还是挂钩所有线程,为YY位进程留下非功能挂钩?
当我使用64位进程调用SetWindowsHookEx时,所有32位进程都不再响应。当我手动enumarate窗口并将正确的钩子附加到每个窗口的线程时,它工作正常。这表明后者是后者。
但是文档要求hook dll具有不同的名称,这表明windows会对它们做一些特殊操作并自动只挂钩到具有相同类型的线程。

哪种假设是对的,是否自动挂钩不再在64位下工作或者我做错了什么?

这是我用来挂钩的代码:


 

 HMODULE hookDll = LoadLibrary(_T(" F:\\ project) \\\Debug\\zrh64.dll")); 
HOOKPROC hookProc =(HOOKPROC)GetProcAddress(hookDll," myMouseProc");
SetWindowsHookEx(WH_MOUSE,hookProc,hookDll,0);


解决方案

我在这里有更多详细信息:


http://social.msdn.microsoft.com/Forums/en-US/windowssdk/thread/e71f690a-00de-4032-95e2-21660e2235f6


但总而言之,当您在混合位数环境中安装全局挂钩时,挂钩事件有时会被分派到*挂钩应用程序*。 如果您的应用程序是32位,并且您安装了一个全局挂钩,您的挂钩将在32位应用程序内运行,
但64位应用程序将等待挂钩应用程序(32位)来处理该事件。  ;如果32位应用程序没有抽取消息,那么所有64位GUI进程最终都会被您的挂钩阻止。 完全反向
也是正确的(64位进程挂钩32位应用程序)。


谢谢,


Dan


The documentation fo SetWindowsHookEx states that there should be seperate hookmodules and processes to load the hooks for 64-bit en 32-bit processes. What it doesn't state is what happens when dwThreadId is set to 0 to hook to all threads automatically. Will Windows only hook to all xx-bit threads or will it hook to all threads, leaving non functional hooks for YY-bit processes?.
When I call SetWindowsHookEx with a 64-bit process all 32-bit processes cease to respond. When I manually enumarate windows and attach the correct hook to each window's thread it works fine. This suggests sugests the latter.
But the documentation demands the hook dll's to have different names which suggests that windows will do something special with them and automatically hook only to threads that have the same type.

Which assumption is right, does hooking automatically no longer work under 64-bit or am I doing something wrong?

This is the code I use to hook:

HMODULE hookDll = LoadLibrary(_T("F:\\project\\Debug\\zrh64.dll"));
HOOKPROC hookProc = (HOOKPROC)GetProcAddress(hookDll,"myMouseProc");
SetWindowsHookEx(WH_MOUSE, hookProc, hookDll, 0);

解决方案

I have more detail in a reponse here:

http://social.msdn.microsoft.com/Forums/en-US/windowssdk/thread/e71f690a-00de-4032-95e2-21660e2235f6

But to sum it up, when you install a global hook in a mixed bitness environment, the hook events will sometimes be dispatched to the *hooking application*.  If your app is 32 bit, and you install a global hook, your hook will run inside of 32 bit applications, but 64 bit applications will wait for the hooking application (which is 32 bit) to process the event.  If the 32 bit application is not pumping messages, then all 64 bit GUI processes will eventually become blocked by your hook.  The complete inverse is true as well (64 bit process hooking 32 bit applications).

Thanks,

Dan


这篇关于在Vista x64上使用dwThreadId = 0的SetWindowsHookEx自动挂钩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆