Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MFC应用程序中的.NET Activex控件访问冲突_C#_C++_.net_Mfc_Activex - Fatal编程技术网

C# MFC应用程序中的.NET Activex控件访问冲突

C# MFC应用程序中的.NET Activex控件访问冲突,c#,c++,.net,mfc,activex,C#,C++,.net,Mfc,Activex,背景:我在.NET中开发了一个Activex控件,但发现它在使用它的各种应用程序中造成了稳定性问题。我从示例应用程序中找到了一系列步骤,如下所述 我从开发中心网站下载了一个名为“CSActivex”的Activex控件示例(http://code.msdn.microsoft.com/windowsdesktop/CSActiveX-b86194f8) 构建起来相当容易,我只是在VS2010 Express(C#)中加载了该项目,并将其编译成.dll 然后我从VS2008 C++创建了一个示例M

背景:我在.NET中开发了一个Activex控件,但发现它在使用它的各种应用程序中造成了稳定性问题。我从示例应用程序中找到了一系列步骤,如下所述

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

构建起来相当容易,我只是在VS2010 Express(C#)中加载了该项目,并将其编译成.dll

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

我向regasm注册了csactivex.dll,并将其复制到VS IDE文件夹中,这样我就可以在设计时插入Activex控件,然后再插入调试文件夹,这样就可以在运行时找到它

在设计时,我将CSActivex控件插入到“关于”对话框中,它会毫无意外地出现。在构建dll并将其复制到调试文件夹并运行调试会话后,如果我继续导航到“关于”框,在控件的各个位置单击,关闭“关于”对话框并重复几次,我开始在输出日志中看到有关访问冲突的消息,它开始如下所示:

'CSActivexMFC.exe': Loaded 'C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System.Windows.Forms\63406259e94d5c0ff5b79401dfe113ce\System.Windows.Forms.ni.dll'
'CSActivexMFC.exe': Loaded 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorjit.dll'
'CSActivexMFC.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.Windows.GdiPlus_6595b64144ccf1df_1.0.2600.5581_x-ww_dfbc4fc4\GdiPlus.dll'
'CSActivexMFC.exe': Loaded 'C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\Accessibility\11eb4f6606ba01e5128805759121ea6c\Accessibility.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)行 644+0x9字节C msvcr90d.dll!退出(整数代码=2)行412+0xd 字节C CSActivexMFC.exe__tmainCRTStartup()行595 C CSActivexMFC.exe!wwinmincartstartup()行399 C 内核32.dll!7c817077()

我希望有人以前可能遇到过这种情况,我在多台机器(家庭和工作)上遇到过这种情况,至少可以把它缩小到CSActivex没有做它应该做的事情的问题,或者MFC中的问题

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

编辑:

仅仅打开about窗口并反复关闭它最终会导致调试器崩溃(未处理的异常),下面有一个堆栈跟踪,在我看来,被破坏的对象似乎再次被破坏

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()  
看看这是什么第一次机会例外

从博客

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

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

对于没有异常处理的代码,调试器将收到第二次异常通知,并将在出现未处理的异常时停止

通过查看另一个异常,它将告诉您如何在第一次出现异常时停止,以查看是什么导致了异常

这个

看看这是什么第一次机会的例外

从博客

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

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

对于没有异常处理的代码,调试器将收到第二次异常通知,并将在出现未处理的异常时停止

通过查看另一个异常,它将告诉您如何在第一次出现异常时停止,以查看是什么导致了异常

您应该能够从.Net调用旧的东西(使用Interop)。。。但如果可以避免的话,您当然不应该在ActiveX中编写任何新内容。这是MFC的两倍!我是…我的朋友之一