Win32 消息调度程序捕获异常的问题

发布于 2024-09-29 01:29:12 字数 696 浏览 6 评论 0原文

这是一个非常低级的问题,但也许这里有人有一些见解...

我遇到一个问题,未处理的 SEH 异常(例如访问冲突)似乎是在 Win32 消息调度级别捕获的,而不是终止程序。我找到了以下参考博客,它解释了问题,但仅在 WM_TIMER 消息的上下文中: http://bugswar.blogspot.com/2010/07/why-its-not-crashing.html

我在 Win 2008R2 和“正常”消息上遇到了这个问题(例如:WM_COMMAND 等)。我怀疑Windows可能试图通过屏蔽异常来“提供帮助”,但我希望它出错; “继续并忽略”行为通常会导致应用程序出现问题。我意识到我可以尝试将每个函数包装在 try/catch 中,并使用编译器选项 /EHa 将 SEH 异常转换为 C++ 异常(这本身就是非常令人沮丧和危险的),但这显然不是最佳选择。

根据引用的博客,TIB结构中的AppCompatFlags2中有一个标志(http://en.wikipedia.org/wiki/Win32_Thread_Information_Block),它可能导致Win32处理程序不捕获/丢弃SEH异常,但我没有知道如何设置/启用它。有人对此有任何见解吗?我可以启用 AppCompat 设置来让 Windows 不捕获和忽略异常吗?

This is kinda a very low-level type question, but maybe someone here has some insight...

I'm having an issue where unhandled SEH exceptions (such as Access Violations) are seemingly being caught at the Win32 message dispatch level, rather than terminating the program. I found the following reference blog, which explains the problem, but in the context of WM_TIMER messages only: http://bugswar.blogspot.com/2010/07/why-its-not-crashing.html

I'm experiencing the issue with Win 2008R2, and on "normal" messages (eg: WM_COMMAND, etc.). I suspect it might be Windows trying to "help" by masking exceptions, but I want it to error out; the "continue and ignore" behavior is causing problems with the application in general. I realize I could try to wrap every function in a try/catch, and use the compiler option /EHa to convert SEH exceptions into C++ exceptions (which is itself very discouraged and dangerous), but this is obviously sub-optimal.

According to the referenced blog, there's a flag in the AppCompatFlags2 in the TIB structure (http://en.wikipedia.org/wiki/Win32_Thread_Information_Block) which can cause the Win32 handler to not catch/discard the SEH exception, but I have no idea how to set/enable it. Anyone have any insight on this? Is there an AppCompat setting I can enable to have Windows not catch and ignore exceptions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无力看清 2024-10-06 01:29:12

我认为这是设计使然,但显然考虑得不够仔细。也许是不明智的尝试让某些遗留应用程序“表现良好”。

您可以在 Windows 7 SP1 中覆盖此行为;我在这个 stackoverflow 答案中写了更多相关内容。

I think it's by design, but obviously it was not considered carefully enough. Perhaps ill-advised attempt to make some legacy application "behave".

You can override this behaviour in Windows 7 SP1; I wrote more on this in this stackoverflow answer.

浪荡不羁 2024-10-06 01:29:12

我不知道兼容性设置如何影响这个特定方面,但您可以从资源管理器中 EXE 的“属性”页面中选择多种兼容性模式(至少在 W7 和 Vista 上)。我似乎记得您还可以从清单中请求特定的一项。

I don't know how the compatibility settings affect this particular aspect, but you can choose among several compatibility modes from the Properties page of an EXE in Explorer (on W7 and Vista, at least). I seem to recall that you can also request a specific one from the manifest.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文