.Net ActiveX控件不允许MFC/ATL容器正确关闭 [英] .Net ActiveX control does not allow MFC/ATL container to shutdown properly

查看:98
本文介绍了.Net ActiveX控件不允许MFC/ATL容器正确关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.Net ActiveX控件不允许MFC/ATL容器关闭属性

.Net ActiveX control does not allow MFC/ATL container to shutdown property

你好

首先,我在该论坛上发现了完全相同的问题:

First of all, I just found exactly the same issue reported on this forum:

http://social.msdn.microsoft .com/Forums/zh-CN/vbinterop/thread/d24962f3-ec79-4d77-9cac-2c5d46e38667

不幸的是,没有得到答复,最后建议与付费支持联系.但是,由于以下两个原因,我想再一次在普通论坛上提出这个问题:

Unfortunately it was not answered and finally it was suggested to contact paid support. However I’d like to try to raise this question on common forum one more time because of two reasons:

        • 这是一个非常普遍的问题.绝对发生任何基于MFC/ATL的容器和任何基于.Net的ActiveX控件.我将在问题描述中仅使用Microsoft示例.
        • 我认为在讨论先前报告的问题期间,错误发生的原因指定不正确,并且我们绝对不需要检查任何转储文件来了解问题的底部.问题.
        • This is very general problem. Happens with absolutely any MFC/ATL based container and any .Net based ActiveX control. I will use only Microsoft examples in the problem description.
        • I think the reason why it happen specified incorrectly during discussion of previously reported issue and we definitely don’t need to check any dump file to get to the bottom of the problem.

可以通过使用两个Microsoft示例来演示该问题:

The problem can be demonstrated by using two Microsoft examples:

  1. .Net Active X控件:它是从这里下载的: http://code.msdn.microsoft.com/windowsdesktop/CSActiveX-b86194f8
  2. 容器:  http://msdn.microsoft.com/zh-CN /library/f9adb5t5(v=VS.90).aspx    ( 实际上我在使用TstCon示例的源代码 在VS 2010中构建此应用程序)
  1. .Net Active X Control: It was downloaded from here: http://code.msdn.microsoft.com/windowsdesktop/CSActiveX-b86194f8
  2. Container:  http://msdn.microsoft.com/en-us/library/f9adb5t5(v=VS.90).aspx  (Actually I was using source code of TstCon example in VS 2010 to build this application)

所有需要做的就是启动TstCon.exe,插入"CSActiveX.CSActiveXCtrl",然后关闭应用程序.应用程序消失后,在任务管理器中检查进程列表-TstCon.exe仍然存在.

All that has to be done is to start TstCon.exe, insert "CSActiveX.CSActiveXCtrl" and then close the application. After the application disappears, check the process list in Task Manager – TstCon.exe is still there.

现在,为什么发生这种情况的解释相对简单:.Net控件从容器的宿主站点查询一堆接口(IOleIPsite,IDispatch,IAdviseSink),这自然会增加宿主的引用计数网站对象, 但是,然后,在容器释放对.Net控件的所有引用之后,由于某种原因,容器对容器的操作就不一样了(这是由任何基于ATL,MFC,基于VB6的ActiveX控件完成的).因此参考计数器不会达到零,并且有一个对象关联 与主机站点永远不会被删除.

Now explanation of why it happens is relatively simple: .Net control queries bunch of interfaces (IOleIPsite, IDispatch, IAdviseSink) from container’s host site, which naturally increases references count of the host site object, but then, after the container releases all references to the .Net control, it for some reason does not do the same for the container (which is done by any ATL, MFC, VB6 – based ActiveX control). So reference counter does not reach zero and an object associated with the host site never gets deleted.

在MFC ActiveX中,宿主站点是由COleClientItem类实现的.在构造函数中,它调用AfxOleLockApp();在析构函数中,它调用AfxOleUnlockApp(),以增加/减少容器应用程序的引用计数器.   由于从未调用OleClientItem的析构函数,因此应用程序的引用计数器也永远不会达到零.应用程序调用AfxOleCanExitApp(),如果引用计数器不为零,则返回false.   结果是应用程序不发送WM_QUIT消息,并且从不退出.看起来像是关闭的原因是因为在调用AfxOleCanExitApp(奇怪的MFC实现)之前,它隐藏了主窗口.

In MFC ActiveX host site is implemented by COleClientItem class. In constructor it calls AfxOleLockApp() and in destructor it calls AfxOleUnlockApp(), increasing/decreasing reference counter of the container application.  Since destructor of OleClientItem never gets called, reference counter of the application never reaches zero as well. The application calls AfxOleCanExitApp() , which returns false if reference counter is not zero.  As a result application does not send WM_QUIT message and never exits. The reason it looks like it was closed is because it hides main window before calling AfxOleCanExitApp (weird MFC implementation).

还有一件事情:在我检查过的所有容器应用程序中,IE似乎都可以正确退出.我最好的猜测是,它只是忽略了.Net AX控件仍保留其宿主站点这一事实.

One more thing: out of all containers applications I have checked, IE seems to exit correctly. My best guess is that it simply ignores the fact that .Net AX control still holding its host site.

所以我的问题是:这是.NET实施中的未知错误,还是无法修复的已知错误.在第一种情况下,请将其视为错误报告提交,在另一种情况下,请向我们说明原因 发生并且无法修复.

So my question is: is it an unknown bug in .NET implementation or is it a known bug that can’t be fixed. In first case please consider this as a bug report submission, in the other case please give us some explanation of why it happens and can’t be fixed.

谢谢.

推荐答案

CCC,

我正在尝试在此线程中加入其他线程,请耐心等待.

I am trying to involve some other one in this thread, please wait it patiently.

我们的 托管论坛专注于既不紧急也不复杂的中断修复问题.如果该问题对您的企业来说很紧急,建议您通过电话联系Microsoft客户支持服务(CSS),以便有专职的支持专业人员 可以更有效地为您提供帮助.请注意,联系电话支持人员将收取费用.

Our  managed forum is focused on break fix issues that are neither urgent, nor complex. If the issue is urgent to your business, it is recommended that you contact Microsoft Customer Spport Services(CSS) via telephone so that a dedicated Support Professional can assist you in a more efficient manner. Please be advised that contacting phone support will be a charged call. 

要获取针对特定技术要求的电话号码,请访问下面列出的网站.

to obtain the phone numbers for specific technology request please take a look at the web site listed below.

http://support.microsoft.com/default.aspx?scid=fh;EN-US;PHONENUMBERS  

http://support.microsoft.com/default.aspx?scid=fh;EN-US;PHONENUMBERS  

If you are outside the <st1:country-region w:st="on"><st1:place w:st="on">US</st1:place></st1:country-region> please seehttp://support.microsoft.com for regional support phone numbers.

最好的问候


这篇关于.Net ActiveX控件不允许MFC/ATL容器正确关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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