如何获取Internet Explorer提供的原始IDocHostUIHandler?

发布于 2024-12-08 21:03:01 字数 487 浏览 1 评论 0原文

IDocHostUIHandler 接口的文档 ,在谈论使用 BHO 中的 ICustomDoc 导致的内存泄漏时,有一段关于 IE 提供的默认 UI 处理程序:

To avoid a memory leak: 

 1. Always forward the IDocHostUIHandler::ShowUI and
IDocHostUIHandler::HideUI methods to the original handler. 
 2. Release the pointer to the original UI handler when your object is called
with IObjectWithSite::SetSite(NULL).

如何获取主机接口以释放它?

In the documentation of the IDocHostUIHandler Interface, there is a paragraph about the default UI handler provided by IE when talking about a memory leak caused by using ICustomDoc from a BHO:

To avoid a memory leak: 

 1. Always forward the IDocHostUIHandler::ShowUI and
IDocHostUIHandler::HideUI methods to the original handler. 
 2. Release the pointer to the original UI handler when your object is called
with IObjectWithSite::SetSite(NULL).

How to get the host interface in order to release it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怎樣才叫好 2024-12-15 21:03:01

虽然不受官方支持,但您仍然可以获得对原始 IDocHostUIHandler 的引用,以便传递对您不打算在 BHO 中覆盖的所有方法的调用。

首先,将文档转换为 IOleObject,然后调用 GetClientSite 以获取原始 IOleClientSite 对象。然后可以将其转换为 IDocHostUIHandlerIOleCommandTarget,以便从原始处理程序/目标上的这些接口调用方法。

下面是来自 C# BHO 的 DocumentComplete 事件的示例代码片段(ExplorerShDocVw.WebBrowserClass 的实例,UIHandler 是我自己的< code>IDocHostUIHandler 类,它将调用传递给初始化程序中传递的对象,所有接口均直接取自 http://pinvoke.net):

IOleObject obj = Explorer.Document as IOleObject;
if (obj != null)
{
    IOleClientSite cs = null;
    obj.GetClientSite(ref cs);

    if (cs != null)
    {
        ICustomDoc cDoc = Explorer.Document as ICustomDoc;
        if (cDoc != null)
        {
            cDoc.SetUIHandler(new UIHandler(cs));
        }
    }
}

这是根据 PopupBlocker 项目中的 C++ 代码改编的,此处提供 http://www.codeproject.com/Articles/4003/Popup-Window-Blocker

While not officially supported, you can still get a reference to the original IDocHostUIHandler in order to pass calls through on all of the methods you don't plan on overriding in your BHO.

First you cast the document as an IOleObject and then call GetClientSite in order to obtain the original IOleClientSite object. This can then be cast to either IDocHostUIHandler or IOleCommandTarget in order to call the methods from those interfaces on the original handler/target.

Here is an example code snippet from the DocumentComplete event of a C# BHO (Explorer is an instance of ShDocVw.WebBrowserClass, UIHandler is my own IDocHostUIHandler class which passes calls through to the object passed in the initializer, and all of the interfaces were taken directly from http://pinvoke.net):

IOleObject obj = Explorer.Document as IOleObject;
if (obj != null)
{
    IOleClientSite cs = null;
    obj.GetClientSite(ref cs);

    if (cs != null)
    {
        ICustomDoc cDoc = Explorer.Document as ICustomDoc;
        if (cDoc != null)
        {
            cDoc.SetUIHandler(new UIHandler(cs));
        }
    }
}

This was adapted from C++ code available in the PopupBlocker project available here http://www.codeproject.com/Articles/4003/Popup-Window-Blocker

零度° 2024-12-15 21:03:01

如今整段文字如下:

它并不是要替换现有的 IDocHostUIHandler
由 Internet Explorer 或 WebBrowser 控件提供。如果你尝试
使用浏览器帮助程序对象 (BHO) 替换该接口
ICustomDoc,您可能会遇到意外行为,例如内存
泄漏。


所以它根本不支持你想要做的事情(至少官方)。

The whole passage nowadays reads

It is not intended to replace an existing IDocHostUIHandler that is
provided by Internet Explorer
or the WebBrowser control. If you try to
replace that interface from a Browser Helper Object (BHO) using
ICustomDoc, you may experience unexpected behavior such as memory
leaks.

So it is simply not supported what you are trying to do (at least officially).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文