【问题标题】:How to get the original IDocHostUIHandler provided by Internet Explorer?如何获取 Internet Explorer 提供的原始 IDocHostUIHandler?
【发布时间】:2011-12-03 19:51:19
【问题描述】:

the documentation of the IDocHostUIHandler Interface 中,当谈到使用 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).

如何获取主机接口才能释放呢?

【问题讨论】:

  • 你是如何解决第二个问题的?

标签: internet-explorer com bho mshtml


【解决方案1】:

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

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

这是来自 C# BHO 的 DocumentComplete 事件的示例代码 sn-p(ExplorerShDocVw.WebBrowserClass 的一个实例,UIHandler 是我自己的 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

【讨论】:

  • 这是解决文件丢失问题的唯一方法。如果没有这个,删除文件只会将其作为 URL 打开,但不会在 DOM 上触发“放置”事件。只需使用 GetDropTarget 实现中的 IOleClientSite。
【解决方案2】:

现在全篇是这样的

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

所以它根本不支持你正在尝试做的事情(至少正式)。

【讨论】:

    猜你喜欢
    • 2011-05-10
    • 2010-10-24
    • 1970-01-01
    • 2018-03-05
    • 2012-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多