MFC应用程序中的ActiveX Activex控件访问冲突

背景:我在.NET中开发了一个ActiveX控件,但发现它在使用它的各种应用程序中导致了稳定性问题。 我设法从示例应用程序中找到一系列步骤,以下列出类似的不稳定性。

我从Dev-Center网站下载了一个示例Activex控件,名为“CSActivex”(http://code.msdn.microsoft.com/windowsdesktop/CSActiveX-b86194f8)

构建起来相当简单,我只是将项目加载到VS2010 Express(C#)中,并将其编译为一个.dll文件

然后我从VS2008 C ++创建了一个示例MFC应用程序来模拟遗留应用程序(它不使用任何.NET)。 目标是具有关于框的基于简单对话框的GUI。

我用regasm注册了csactivex.dll,并将dll复制到了VS IDE文件夹,因此我可以在设计时插入Activex控件,然后插入Debug文件夹,以便在运行时找到它。

在设计时,我将CSActivex控件插入“关于”对话框中,看起来毫不意外。 建立并复制DLL到Debug文件夹并运行调试会话后,如果我不断导航到about框,请单击控件上的各个位置,关闭about对话框并重复几次,然后开始在输出关于访问违规的日志,它开始看起来像这样:

'CSActivexMFC.exe': Loaded 'C:WINDOWSassemblyNativeImages_v2.0.50727_32System.Windows.Forms63406259e94d5c0ff5b79401dfe113ceSystem.Windows.Forms.ni.dll'
'CSActivexMFC.exe': Loaded 'C:WINDOWSMicrosoft.NETFrameworkv2.0.50727mscorjit.dll'
'CSActivexMFC.exe': Loaded 'C:WINDOWSWinSxSx86_Microsoft.Windows.GdiPlus_6595b64144ccf1df_1.0.2600.5581_x-ww_dfbc4fc4GdiPlus.dll'
'CSActivexMFC.exe': Loaded 'C:WINDOWSassemblyNativeImages_v2.0.50727_32Accessibility11eb4f6606ba01e5128805759121ea6cAccessibility.ni.dll'
First-chance exception at 0x00000000 in CSActivexMFC.exe: 0xC0000005: Access violation reading location 0x00000000.
First-chance exception at 0x00000000 in CSActivexMFC.exe: 0xC0000005: Access violation reading location 0x00000000.
First-chance exception at 0x79f4c2f7 in CSActivexMFC.exe: 0xC0000005: Access violation reading location 0x0000000b.
First-chance exception at 0x79f4c2f7 in CSActivexMFC.exe: 0xC0000005: Access violation reading location 0x0000000b.

虽然它不会在调试器中崩溃,但我不禁觉得这不太好,而且我有一种感觉,它可能与其他.NET ActiveX控件的不稳定性有关。 如果我能找出解决这个问题的方法,那么相同的解决方案可能有助于原始控制。

我试图打破例外,但它似乎发生在几个不同的地方。 下面是关闭应用程序时的一个堆栈跟踪:

mscorwks.dll!79f4c2f7()[下面的框架可能不正确和/或丢失,没有为mscorwks.dll加载符号]
mscorwks.dll!79f4c370()mscorwks.dll!79faaa91()
mscorwks.dll!79faa858()mscorwks.dll!79faa9ad()
mscorwks.dll!79faa9d9()mscorwks.dll!7a079480()
mscorwks.dll!7a0798e8()mscorwks.dll!7a043f25()
ole32.dll!77525834()rpcrt4.dll!77e799f4()
rpcrt4.dll!77ef421a()ntdll.dll!7c915239()
ntdll.dll!7c91542b()ntdll.dll!7c91534a()
ntdll.dll!7c915239()ntdll.dll!7c91542b()
ntdll.dll!7c91534a()ntdll.dll!7c915f75()
ntdll.dll!7c9155ed()ntdll.dll!7c915ce9()
ntdll.dll!7c96f07c()ole32.dll!77600c15()
ole32.dll!77600bbf()ole32.dll!7752ad31()
ole32.dll!7752ac56()ole32.dll!7752b771()
ole32.dll!77600e1f()ole32.dll!7752b7ab()
ole32.dll!7752b5e1()ole32.dll!7752b54e()
user32.dll!7e418734()ole32.dll!7752b54e()
ole32.dll!7752b54e()ole32.dll!7752b54e()
ole32.dll!7752b54e()ole32.dll!7752f2d0()
ole32.dll!7752f23e()ole32.dll!77557237()
mscorwks.dll!79f9e14d()mscorwks.dll!79f9e0b4()
mscorwks.dll!79f9e018()mscorwks.dll!79f4c879()
mscorwks.dll!79f3bb76()mscoreei.dll!603cc966()
mscoreei.dll!603d1f25()mscoree.dll!790186ad()

msvcr90d.dll!_crtCorExitProcess(int status = 2)行716 C msvcr90d.dll!_crtExitProcess(int status = 2)行722 + 0x9字节C msvcr90d.dll!doexit(int code = 2,int quick = 0,int retcaller = 0)Line 644 + 0x9 bytes C msvcr90d.dll!exit(int code = 2)Line 412 + 0xd bytes C CSActivexMFC.exe!__ tmainCRTStartup()Line 595 C CSActivexMFC.exe!wWinMainCRTStartup()Line 399 C kernel32.dll!7c817077 ()

我希望以前有人遇到过这种情况,我在多台机器上(家庭和工作中)遇到了这个问题,至少已经缩小到CSActivex没有做的事情或者MFC中的某个问题。

所以我的问题是如何让这些样本在没有访问违规的情况下工作?

编辑:

只要打开窗口并重复关闭它,最终会导致调试器(未处理的异常)崩溃,下面有一个堆栈跟踪,对我来说,它看起来像一个被破坏的对象再次被销毁?

First-chance exception at 0x00400003 in CSActivexMFC.exe: 0xC0000005: Access violation writing location 0x00000000.
First-chance exception at 0x00400003 in CSActivexMFC.exe: 0xC0000005: Access violation writing location 0x00000000.
First-chance exception at 0x003a005c in CSActivexMFC.exe: 0xC0000096: Privileged instruction.
First-chance exception at 0x00460020 in CSActivexMFC.exe: 0xC0000005: Access violation reading location 0x00460020.
First-chance exception at 0x78b6ba1d (mfc90ud.dll) in CSActivexMFC.exe: 0xC0000005: Access violation writing location 0x00000018.
Unhandled exception at 0x78b6ba1d (mfc90ud.dll) in CSActivexMFC.exe: 0xC0000005: Access violation writing location 0x00000018.


    mfc90ud.dll!CDataSourceControl::~CDataSourceControl()  Line 2431 + 0x2d bytes   C++
mfc90ud.dll!CDataSourceControl::`scalar deleting destructor'()  + 0x11 bytes    C++
mfc90ud.dll!COleControlSite::~COleControlSite()  Line 77 + 0x22 bytes   C++
mfc90ud.dll!COleControlSite::`scalar deleting destructor'()  + 0x11 bytes   C++
mfc90ud.dll!COleControlSiteOrWnd::~COleControlSiteOrWnd()  Line 161 + 0x24 bytes    C++
mfc90ud.dll!COleControlSiteOrWnd::`scalar deleting destructor'()  + 0x11 bytes  C++
mfc90ud.dll!COleControlContainer::~COleControlContainer()  Line 199 + 0x1c bytes    C++
mfc90ud.dll!COleControlContainer::`scalar deleting destructor'()  + 0x11 bytes  C++
mfc90ud.dll!CWnd::OnDestroy()  Line 786 + 0x24 bytes    C++
mfc90ud.dll!CWnd::OnWndMsg(unsigned int message=2, unsigned int wParam=0, long lParam=0, long * pResult=0x0012f510)  Line 2042  C++
mfc90ud.dll!CWnd::WindowProc(unsigned int message=2, unsigned int wParam=0, long lParam=0)  Line 1755 + 0x20 bytes  C++
mfc90ud.dll!AfxCallWndProc(CWnd * pWnd=0x0012f88c, HWND__ * hWnd=0x002c04fc, unsigned int nMsg=2, unsigned int wParam=0, long lParam=0)  Line 240 + 0x1c bytes  C++
mfc90ud.dll!AfxWndProc(HWND__ * hWnd=0x002c04fc, unsigned int nMsg=2, unsigned int wParam=0, long lParam=0)  Line 403   C++
mfc90ud.dll!AfxWndProcBase(HWND__ * hWnd=0x002c04fc, unsigned int nMsg=2, unsigned int wParam=0, long lParam=0)  Line 441 + 0x15 bytes  C++
user32.dll!7e418734()   
[Frames below may be incorrect and/or missing, no symbols loaded for user32.dll]    
user32.dll!7e418816()   
mfc90ud.dll!CThreadSlotData::GetThreadValue(int nSlot=6623744)  Line 268    C++
user32.dll!7e428eec()   
ntdll.dll!7c90e473()    
user32.dll!7e42b1a8()   
mfc90ud.dll!CWnd::DestroyWindow()  Line 1007 + 0xd bytes    C++
90909090()  

看看David Kline撰写的这篇MSDN博客:什么是第一次机会例外。

来自博客

第一次机会异常是否意味着我的代码中存在问题?

第一次机会异常消息通常并不意味着代码中存在问题。 对于优雅处理异常的应用程序/组件,第一次机会异常消息让开发人员知道遇到并处理了异常情况。

对于没有异常处理的代码,调试器将收到第二次机会异常通知,并停止处理未处理的异常。

通过查看David Kline的另一个MSDN博客,它会告诉您如何停止第一次机会例外,以查看造成它的原因。

和这个MSDN论坛发帖

链接地址: http://www.djcxy.com/p/95499.html

上一篇: .NET Activex control access violation in MFC application

下一篇: Access violation after catching dll exception