CallWndProc 挂钩未接收所有消息
我正在制作一个像 Displayfusion 这样的小工具,我需要一些钩子来在 Windows 移动/激活/等时接收消息,但是我被卡住了..
我正在使用这个项目作为 CallWndProc 钩子: http://www.codeproject.com/KB/system/WilsonSystemGlobalHooks.aspx
对于几乎所有 Windows,它都工作得很好(x86 和 x64),但是在某些 Windows 上,它似乎无法注入钩子 DLL。目前我在使用 adobe reader X 时遇到问题。没有从该窗口收到任何消息。我觉得这和沙盒有关系吗?有人可以推动我朝正确的方向前进吗?
钩子的初始化代码:
bool InitializeCallWndProcHook(int threadID, HWND destination)
{
if (g_appInstance == NULL)
return false;
if (GetProp(GetDesktopWindow(), "WILSON_HOOK_HWND_CALLWNDPROC") != NULL)
SendNotifyMessage((HWND)GetProp(GetDesktopWindow(), "WILSON_HOOK_HWND_CALLWNDPROC"), RegisterWindowMessage("WILSON_HOOK_CALLWNDPROC_REPLACED"), 0, 0);
SetProp(GetDesktopWindow(), "WILSON_HOOK_HWND_CALLWNDPROC", destination);
hookCallWndProc = SetWindowsHookEx(WH_CALLWNDPROC, (HOOKPROC)CallWndProcHookCallback, g_appInstance, threadID);
return hookCallWndProc != NULL;
}
I am making a little tool like Displayfusion and I need some Hooks to receive messages when Windows move/activate/etc , however I'm stuck..
I am using this project for the CallWndProc hook:
http://www.codeproject.com/KB/system/WilsonSystemGlobalHooks.aspx
For pretty much all windows it works great(x86 and x64), however on some windows it seems to can't inject the hook DLL. Currently I am having problems with adobe reader X. No messages are being received from that window. I think it has something to do with the sandbox? Can somebody give me a push in the right direction?
The initialization code for the hook:
bool InitializeCallWndProcHook(int threadID, HWND destination)
{
if (g_appInstance == NULL)
return false;
if (GetProp(GetDesktopWindow(), "WILSON_HOOK_HWND_CALLWNDPROC") != NULL)
SendNotifyMessage((HWND)GetProp(GetDesktopWindow(), "WILSON_HOOK_HWND_CALLWNDPROC"), RegisterWindowMessage("WILSON_HOOK_CALLWNDPROC_REPLACED"), 0, 0);
SetProp(GetDesktopWindow(), "WILSON_HOOK_HWND_CALLWNDPROC", destination);
hookCallWndProc = SetWindowsHookEx(WH_CALLWNDPROC, (HOOKPROC)CallWndProcHookCallback, g_appInstance, threadID);
return hookCallWndProc != NULL;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯,试试 Spy++ 是否可以捕获消息。如果可以,那么显然安全措施不是问题。然而 Spy++ 却不能,那么这几乎是不可能的。
看看这是否有效:同时使用 WH_CALLWNDPROC 和 WH_GETMESSAGE 挂钩,因为显然,前者仅捕获发送的消息,后者仅捕获发布的消息。
Hmm, try if Spy++ can catch the messages. If it can, then obviously it's not a problem with security measures. It Spy++ can't however, then it's pretty much impossible.
See if this works: Use both WH_CALLWNDPROC and WH_GETMESSAGE hooks, since apparently, the former only catches sent message, and the latter only catches posted messages.
我的应用程序中也有类似的问题。访问以下链接:
windows hooks 的奇怪行为
我的猜测是应用程序中断了通过不调用 CallNextHookEx 方法来过滤函数链。请注意,这仅在您使用 WH_CBT 挂钩时才可能实现。
I have a similar Problem in my application. Visit the following link:
Strange behaviour of windows hooks
My guess ist that an application interrupts the filter function chain by not calling the
CallNextHookEx
method. Note that is this only possible when you are usingWH_CBT
hooks.