如果在 Visual Studio 2010 调试器下运行,应用程序不会收到广播消息
我们使用注册的 Windows 消息在应用程序实例之间进行通信。我们使用以下调用发送消息:
DWORD dwResult;
::SendMessageTimeout(HWND_BROADCAST, wmRegisteredMessage, 0, 0,
SMTO_ABORTIFHUNG | SMTO_NORMAL,
200,
&dwResult);
只要应用程序不在 Visual Studio 2010 调试器下运行,此机制就可以正常工作。如果是,则不会调用消息处理程序。此外,Spy++ 显示应用程序没有收到消息。
如果应用程序正在运行并且调试器随后附加到进程,则会按预期接收消息。
如果代码更改为:
SendMessage(HWND_BROADCAST, wmRegisteredMessage, 0, 0);
一切都按预期进行。
我尝试了 SendMessageTimeout() 的不同参数,但仍然看到相同的行为。我添加了代码来检查 SendMessageTimeout() 的返回代码,并且它不会返回错误。
有什么想法吗?
We are using registered Windows messages to communicate between instances of our application. We send the message using the following call:
DWORD dwResult;
::SendMessageTimeout(HWND_BROADCAST, wmRegisteredMessage, 0, 0,
SMTO_ABORTIFHUNG | SMTO_NORMAL,
200,
&dwResult);
This mechanism works fine as long as the application is not running under the Visual Studio 2010 debugger. If it is, the message handler does not get called. In addition, Spy++ shows that the application is not being sent the message.
If the application is running and the debugger is then attached to the process, the message is received as expected.
If the code is changed to:
SendMessage(HWND_BROADCAST, wmRegisteredMessage, 0, 0);
Everything works as expected.
I have tried different parameters to SendMessageTimeout() but I still see the same behavior. I added code to check the return code from SendMessageTimeout() and it does not return an error.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
阿杰是对的。这是一个UAC问题。调试器以管理员身份运行,而发送 Windows 消息的应用程序未以管理员身份运行。当我以管理员身份运行此应用程序时,会正确接收消息。有趣的是,SendMessage() 似乎没有强制执行与 SendMessageTimeout() 相同的安全性。
Ajay is correct. It is a UAC problem. The debugger was running as an admin and the application sending the Windows message was not running as an admin. When I run this application as an admin the message is received correctly. The interesting thing is that SendMessage() does not appear to enforce the same security as SendMessageTimeout().