什么是正确的方式为ActiveX(COM)控件时其父关闭清理? [英] What is the proper way for an activeX (COM) control to clean up when closed by its parent?

查看:195
本文介绍了什么是正确的方式为ActiveX(COM)控件时其父关闭清理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题,我的.NET控件没有得到正确清理包裹时,对ActiveX使用。

默认行为离开SDK的测试容器的应用程序(TstCon32.exe)作为GUIless进程中运行,当我尝试关闭它。

我开始通过谷歌找到的解决方法是重写的WndProc,并呼吁 Environment.Exit(0)手动。这确实得到TstCon32.exe完全关闭;然而,它的突破,我需要有托管控件的应用程序。

该应用程序是MDI和WM_DESTROY被发送时包含控件的页面被关闭,此时 Environment.Exit(0)呼叫被吹走了整个应用程序。我试过 Application.Exit()作为替代,但还有TstCon32仍在运行无形。

 保护覆盖无效的WndProc(参考消息M)
{
    base.WndProc(REF米);

    // WM_DESTROY
    如果(m.Msg == 2)
        Environment.Exit(0);
}
 

解决方案

通常一个ActiveX容器将调用的IOleObject ::关闭之前关闭和的IOleObject :: SetClientSite(空)。 System.Windows.Forms.Control的都有自己的实现的IOleObject的。我不认为你可以在派生类中重写它。

通过应用::退出发送WM_QUIT不是MDI的选择,因为它会关闭托管的ActiveX的页面的整个程序来代替。如果容器泄漏接口指针没有什么可以做。

System.Windows.Forms.Control的的的IOleObject实现调用Control.Dispose只有当容器实现的IHTMLDocument2。但我不认为你可以在容器指望实现此接口。

I'm having problems with my .net controls not getting cleaned up properly when wrapped for activeX use.

The default behavior leaves the SDK's test container app (TstCon32.exe) running as a GUIless process when I try and close it.

The workaround I initially found via google was to override WndProc and call Environment.Exit(0) manually. This did get TstCon32.exe to shut down completely; however it's breaking the application where i need to have the control hosted.

The App is MDI and WM_DESTROY is being sent when the page containing the control is closed, at which point the Environment.Exit(0) call is blowing away the entire app. I've tried Application.Exit() as an alternative, but that leaves TstCon32 still running invisibly.

protected override void WndProc(ref Message m)
{
    base.WndProc(ref m);

    // WM_DESTROY
    if (m.Msg == 2)
        Environment.Exit(0);
}

解决方案

Generally an ActiveX container would call IOleObject::Close and IOleObject::SetClientSite(null) before closing. System.Windows.Forms.Control has its own implementation of IOleObject. I do not think you can override it in a derived class.

Sending WM_QUIT via Application::Exit is not an option for MDI, as it will close the whole program instead of the page hosting the ActiveX. If the container is leaking interface pointers there is not much you can do.

System.Windows.Forms.Control's IOLeObject implementation calls Control.Dispose only if the container implements IHTMLDocument2. But I do not think your can count on the container to implement this interface.

这篇关于什么是正确的方式为ActiveX(COM)控件时其父关闭清理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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