CreateEx 导致未处理的异常 正在停用的激活上下文不是最近激活的激活上下文
itsAnalysisDataTable.CreateEx( WS_EX_CLIENTEDGE, AfxRegisterWndClass( CS_DBLCLKS, LoadCursor( NULL, IDC_ARROW ), (HBRUSH)::GetStockObject( NULL_BRUSH ), NULL ), "AnalysiysTable", WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_TABSTOP, dialogItemRect, this, IDC_ANALYSIS_DATA_TABLE );
这条线费了我两天的功夫,没有解决。 itsAnalysisDataTable 是一个自定义 Windows 控件,以 CWnd 作为其祖父。该控件已成功用于其他步骤,我们的代码没有出现问题。 这是一个CPropertyPage。
我遇到的问题是线路导致(并且每次都会这样做) MyProduct (x64).exe 中 0x76f7fd5c 处出现未处理的异常:0xC015000F:正在停用的激活上下文不是最近激活的激活上下文。
32 位也会出现该异常。我使用的是 Windows 7 x64、VS 2008。
我已经尝试过:
- 在调试器中启用 win32 异常中断。没有发生异常(除了第一次机会异常,这些异常在我们的代码中有很多并且没有任何影响)
- 重新编译整个项目
- 调试异常控件的 OnCreate 处理程序。
调用堆栈:
ntdll.dll!0000000076f7fd5c()
[Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll]
kernel32.dll!0000000076df42d3()
mfc90d.dll!AfxDeactivateActCtx(unsigned long dwFlags=0, unsigned __int64 ulCookie=2077018657900210161) Line 260 + 0x19 bytes C++
观察:
- 如果我跳过 WS_CHILD 标志,则不会发生异常,但控件上也不会调用 OnCreate!
- 如果我忽略异常并继续,应用程序可以正常工作,控件也可以正常工作。
- 在应用程序初始化期间调用 AfxSetAmbientActCtx(FALSE) 可抑制异常。但我认为这是一个黑客行为,除非我能证明它是合理的。
itsAnalysisDataTable.CreateEx( WS_EX_CLIENTEDGE, AfxRegisterWndClass( CS_DBLCLKS, LoadCursor( NULL, IDC_ARROW ), (HBRUSH)::GetStockObject( NULL_BRUSH ), NULL ), "AnalysiysTable", WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_TABSTOP, dialogItemRect, this, IDC_ANALYSIS_DATA_TABLE );
This line has cost me two days of effort with no solution. itsAnalysisDataTable is a custom windows control having CWnd as its grand grand grand parent. The control has been successfully used in other paces without issues in our code. this is a CPropertyPage.
The problem I have is the line causes (and it does it every time) an
Unhandled exception at 0x76f7fd5c in MyProduct (x64).exe: 0xC015000F: The activation context being deactivated is not the most recently activated one.
The exception occurs in 32-bit as well. I'm on Windows 7 x64, VS 2008.
What I have already tried:
- Enabling break on win32 exceptions in the debugger. No exception occurs (except first chance exceptions of which there are a lot in our code and have no effect)
- Recompiling the whole project
- Debugging the OnCreate handler for the control for exceptions.
Call Stack:
ntdll.dll!0000000076f7fd5c()
[Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll]
kernel32.dll!0000000076df42d3()
mfc90d.dll!AfxDeactivateActCtx(unsigned long dwFlags=0, unsigned __int64 ulCookie=2077018657900210161) Line 260 + 0x19 bytes C++
Observations:
- If I skip the WS_CHILD flag the exception does not happen, but OnCreate is also not called on the control!
- If I ignore the exception and continue, the application works fine, the control also works fine.
- Calling AfxSetAmbientActCtx(FALSE) during app init suppresses the exception. But I think this is a hack, unless I can justify it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在遇到了很多这些问题之后,我发现追踪根本问题的简单方法是转到“调试”->“调试”。异常并启用所有抛出的异常。然后你会发现还有一些其他异常正在触发,被默默地捕获,但弄乱了激活上下文。一旦修复了第一个异常,激活上下文异常就不会发生。
After hitting a lot of these, I've found the simple way to track down the root issue is to go to Debug -> Exceptions and enable ALL Thrown exceptions. Then you'll find there is some other exception that is firing, being silently caught, BUT messing up the activation context. Once you fix the first exception, the activation context exception won't happen.
事实证明,我的问题是由于违规控制类中的未初始化成员造成的。在构造函数中初始化变量解决了这个问题。所以我不必求助于 AfxSetAmbientActCtx(FALSE)
Turns out mine was due to an uninitialized member in the offending control class. Initializing the variable in the constructor fixed the issue. So I did not have to resort to AfxSetAmbientActCtx(FALSE)
讨论MS Connect“MFC 默认异常处理导致激活上下文出现问题” 可能会帮助您证明该黑客行为是 Microsoft 的解决方法建议。
The discussion on MS Connect 'MFC default exception handling causes problems with activation context' might help you justify the hack being a workaround suggestion from Microsoft.
有同样的问题。
就我而言,我正在从路径读取文件,并且不小心删除了该文件。将文件放回去解决了问题。
Had the same problem.
In my case i was reading a file from a path and I accidentally deleted that file. Putting the file back solved the issue.
托管 IE 和多个 ActiveX 控件的程序发生了一些神秘的崩溃。
事实证明,早期除以零(由 AX 控件之一)最终导致了此异常以及随后的访问冲突。
Had some mysterious crashes in a program that hosted IE along with several ActiveX controls.
Turns out an earlier division by zero (by one of the AX controls) eventually caused this exception and a subsequent Access Violation as well.