WndProc 中的 64 位异常静默失败 [英] 64bit exceptions in WndProc silently fail

查看:29
本文介绍了WndProc 中的 64 位异常静默失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码在 Windows 7 32 位下运行时会出现硬故障:

The following code will give a hard fail when run under Windows 7 32bit:

void CTestView::OnDraw(CDC* /*pDC*/)
{
    *(int*)0 = 0; // Crash

    CTestDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    if (!pDoc)
        return;

    // TODO: add draw code for native data here
}

但是,如果我在 64 位 Windows 7 上尝试这个,我只会在输出窗口中得到这个:

However, if I try this on Windows 7 64bit, I just get this in the output window:

0x13929384 处的第一次机会异常在 Test.exe 中:0xC0000005:访问违规写入位置 0x00000000.
0x77c6ee42 处的第一次机会异常在 Test.exe 中:0xC0150010:激活上下文被停用对当前线程不活跃执行.

First-chance exception at 0x13929384 in Test.exe: 0xC0000005: Access violation writing location 0x00000000.
First-chance exception at 0x77c6ee42 in Test.exe: 0xC0150010: The activation context being deactivated is not active for the current thread of execution.

这是什么原因?我知道这是一个硬件异常(http://msdn.microsoft.com/en-us/library/aa363082.aspx),但是为什么在 32bit 和 64bit 下运行有区别呢?我该怎么做才能正确处理此类错误?因为它们真的应该被困住和修复,而不是当前发生的事情,Windows 只是继续向应用程序发送消息并让它运行(因此用户和开发人员完全不知道实际发生了任何问题).

What is the reason for this? I know it's a hardware exception (http://msdn.microsoft.com/en-us/library/aa363082.aspx), but why the difference when ran under 32bit and 64bit? And what can I do to correctly handle these kind of errors? Because they should really be trapped and fixed, as opposed to what currently happens which is Windows just carries on pumping messages to the application and let's it run (so the user and the developers are completely unaware any problems have actually occurred).

更新:我们的常规崩溃报告软件使用 SetUnhandledExceptionFilter,但不会在 x64 上调用 WndProc 中的硬件异常.有没有人有这方面的信息或解决方法?

Update: Our regular crash reporting software uses SetUnhandledExceptionFilter but that doesn't get called on x64 for hardware exceptions inside a WndProc. Does anyone have any information on this, or a workaround?

更新 2:我已在 Microsoft Connect 上报告了该问题:
https://connect.microsoft.com/VisualStudio/feedback/details/550944/hardware-exceptions-on-x64-machines-are-silently-caught-in-wndproc-messages

Update2: I've reported the issue at Microsoft Connect:
https://connect.microsoft.com/VisualStudio/feedback/details/550944/hardware-exceptions-on-x64-machines-are-silently-caught-in-wndproc-messages

推荐答案

好的,我收到了微软的回复:

OK, I've received a reply from Microsoft:

你好

感谢报告.我发现了这是一个 Windows 问题,并且有可用的修补程序.请看http://support.microsoft.com/kb/976038一个修复,你可以安装,如果你愿望.

Thanks for the report. I've found out that this is a Windows issue, and there is a hot fix available. Please see http://support.microsoft.com/kb/976038 for a fix that you can install if you wish.

@Skute:注意程序兼容性助手会问一次如果应该允许程序继续执行,然后将始终被允许,因此可能混淆行为的原因你看到了.

@Skute: note that the Program Compatibility Assistant will ask once if the program should be allowed to continue to execute, and after that it will always be allowed, so that may be the cause of the confusing behavior you are seeing.

Pat Brenner Visual C++ 库发展

Pat Brenner Visual C++ Libraries Development

因此,解决方法是确保安装了修补程序,或者使用 __try/__except 块将应用程序中的每个 WndProc 包装起来.

So the workaround is either make sure the hotfix is installed, or wrap each WndProc in your application with a __try / __except block.

这篇关于WndProc 中的 64 位异常静默失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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