gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 12:07:52 27 4
gpt4 key购买 nike

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

我有一个从开发中心网站下载的示例 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 文件夹并运行调试 session 后,如果我不断导航到“关于”框,单击控件上的各个位置,关闭“关于”对话框并重复几次,我开始在关于访问冲突的输出日志,它开始看起来像这样:

'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() [Frames below may be incorrect and/or missing, no symbols loaded for 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) Line 716 C msvcr90d.dll!_crtExitProcess(int status=2) Line 722 + 0x9 bytes 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()

最佳答案

看看这个MSDN Blog by David Kline关于什么是第一次机会异常(exception)。

来自博客

Does a first chance exception mean there is a problem in my code?

First chance exception messages most often do not mean there is a problem in the code. For applications / components which handle exceptions gracefully, first chance exception messages let the developer know that an exceptional situation was encountered and was handled.

For code without exception handling, the debugger will receive a second chance exception notification and will stop with a unhandled exception.

通过查看另一个 MSDN Blog by David Kline它会告诉您如何在第一次机会异常时停止以查看导致它的原因。

还有这个MSDN Forum Posting

关于c# - MFC 应用程序中的 .NET Activex 控件访问冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11218694/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com