简体   繁体   English

Internet Explorer 在什么情况下无法正确卸载 ActiveX 控件?

[英]Under what circumstances does Internet Explorer fail to properly unload an ActiveX control?

I'm running into a perplexing problem with an ActiveX control I'm writing - sometimes, Internet Explorer appears to fail to properly unload the control on process shutdown.我正在编写的 ActiveX 控件遇到一个令人困惑的问题 - 有时,Internet Explorer 似乎无法在进程关闭时正确卸载控件。 This results in the control instance's destructor not being called.这导致不调用控件实例的析构函数。

The control is written in C++, uses ATL and it's compiled using Visual Studio 2005. The control instance's destructor is always called when the user browses away from the page the control is embedded in - the problem only occurs when the browser is closed.该控件是用 C++ 编写的,使用 ATL 并使用 Visual Studio 2005 编译。当用户浏览远离嵌入控件的页面时,始终调用控件实例的析构函数 - 只有在关闭浏览器时才会出现问题。

When I run IE under a debugger, I don't see anything unusual - the debugger doesn't catch any exceptions, access violations or assertion failures, but the problem is still there - I can set a breakpoint in the control's destructor and it's never hit when I close the broswer.当我在调试器下运行 IE 时,我没有看到任何异常 - 调试器没有捕获任何异常、访问冲突或断言失败,但问题仍然存在 - 我可以在控件的析构函数中设置断点,它永远不会当我关闭浏览器时点击。

In addition, when I load a simple HTML page that embeds multiple instances of the control I don't see the problem.此外,当我加载一个嵌入多个控件实例的简单 HTML 页面时,我看不到问题。 The problem only appears to happen when the control is instantiated from our web application, which inserts tags dynamically into the web page - of course, not knowing what causes this problem, I don't know whether this bit of information is relevant or not, but it does seem to indicate that this might be an IE problem, since it's data dependent.仅当从我们的 web 应用程序实例化控件时才会出现该问题,该应用程序将标签动态插入 web 页面 - 当然,不知道导致此问题的原因,我不知道这部分信息是否相关,但它似乎表明这可能是一个 IE 问题,因为它依赖于数据。

When I run the simple test case under the debugger, I can set a breakpoint in the control's destructor and it's hit every time.当我在调试器下运行简单的测试用例时,我可以在控件的析构函数中设置一个断点,并且每次都会命中它。 I believe this rules out a problem with the control itself (say, an error that would prevent the destructor from ever being called, like an interface leak.)我相信这排除了控件本身的问题(例如,会阻止调用析构函数的错误,例如接口泄漏。)

I do most of my testing with IE 6, but I've seen the problem occur on IE 7, as well.我用 IE 6 进行了大部分测试,但我也看到 IE 7 上也出现了问题。 I haven't tested IE 8.我还没有测试过 IE 8。

My working hypothesis right now is that there's something in the dynamic HTML code that causes the browser to leak an interface on the ActiveX control.我现在的工作假设是动态 HTML 代码中有一些东西会导致浏览器泄漏 ActiveX 控件上的接口。 So far, I haven't been able to produce a good test case that reproduces this outside of the application, and the application is a bit too large to make a good test case.到目前为止,我还没有能够在应用程序之外生成一个好的测试用例来重现这个,而且应用程序有点太大而无法制作一个好的测试用例。

I was hoping that someone might be able to provide insight into possible IE bugs that are known to cause this kind of behavior.我希望有人能够深入了解可能导致这种行为的 IE 错误。 The answer provided below, by the way, is too general - I'm looking for a specific set of circumstances that is known to cause this.顺便说一句,下面提供的答案太笼统了——我正在寻找一组已知会导致这种情况的特定情况。 Surely someone out there has seen this before.肯定有人以前见过这种情况。

To debug a problem in COM with C++ where an object's (C++) destructor is not being called, the best approach is to focus on how the COM object's refcounts are being incremented or decremented.要使用 C++ 调试 COM 中未调用对象的 (C++) 析构函数的问题,最好的方法是关注 COM 的析构函数是如何递增或递减的。 What is probably happening is that somebody is incrementing the refcount one too many times, and then not decrementing it the same number of times.可能发生的情况是有人将引用计数增加了太多次,然后没有减少相同的次数。 This leads to the object not being freed.这会导致 object 未被释放。

It is possible that your dynamic HTML is simply showing up a bug in IE, which doesn't happen if you use a static page.您的动态 HTML 可能只是在 IE 中显示了一个错误,如果您使用 static 页面,则不会发生这种情况。

If there is a bug in IE, the trick would be to figure out what causes the bug to appear, and what you can do to trick IE into releasing your COM object properly (like, making the HTML go away). If there is a bug in IE, the trick would be to figure out what causes the bug to appear, and what you can do to trick IE into releasing your COM object properly (like, making the HTML go away).

Another approach - add cleanup code to your DllMain function (adding that function if it doesn't already exist).另一种方法 - 将清理代码添加到您的DllMain function (添加 function 如果它不存在)。 Then regardless of reference counts (and reference count errors), when your DLL is unloaded you can clean yourself up:然后不管引用计数(和引用计数错误),当你的 DLL 被卸载时,你可以清理自己:

BOOL WINAPI DllMain(HINSTANCE, DWORD dwReason, LPVOID) {
    if (dwReason == DLL_PROCESS_DETACH) {
        CleanUpAnyObjectsStillAlive();
    }
}

Oh, and a word of warning - don't take too long doing your cleanup - if you do, I can't promise the process shutdown won't kill you anyway.哦,还有一点警告 - 不要花太长时间进行清理 - 如果你这样做了,我不能 promise 进程关闭无论如何都不会杀死你。

I have the same problem, but only on a specific computer.我有同样的问题,但只在特定的计算机上。 This computer also has a problem with the Flash ActiveX, that remains alive after closing the tab.这台计算机的 Flash ActiveX 也有问题,关闭选项卡后它仍然存在。 My guess is that the problem is not with your code.我的猜测是问题不在于您的代码。 Do you have that problem on other computers?其他电脑有这个问题吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在什么情况下glGenBuffers / glGenBuffersARB会失败? - Under what circumstances would glGenBuffers/glGenBuffersARB fail? 如何在Internet Explorer的安装窗口上设置ActiveX控件名称和链接? - How to Set ActiveX Control name and link on the install window of Internet Explorer? 更改Internet Explorer的安全设置(初始化和未编写ActiveX控件脚本…) - Change internet explorer security settings(initaize and script activex control not maked …) 什么情况ostream :: write或ostream :: operator &lt;&lt;会失败? - What circumstances ostream::write or ostream::operator<< would fail under? 在什么情况下C ++无法调用继承类的构造函数? - Under what circumstances will C++ fail to call an inherited class's constructor? 在什么情况下sprintf比stringstream更可取? - Under What Circumstances Would sprintf be Preferred to stringstream? “Lambda 很便宜”——真的吗? 在什么情况下? - “Lambdas are cheap” - Really? Under what circumstances? 在什么情况下释放 python GIL 是安全的? - Under what circumstances is it safe to release the python GIL? 在什么情况下 EXCEPTION_RECORD 链接到另一个嵌套异常? - Under what circumstances does EXCEPTION_RECORD link to another nested exception? 在任何情况下,“首次使用时构建”成语都会失败吗? - Can “construct on first use” idiom fail under any circumstances?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM