2011-10-09 47 views
1

the documentation of the IDocHostUIHandler Interface,有一个关于谈论内存泄漏从BHO因使用ICustomDoc当IE浏览器提供的默认用户界面处理的段落:如何获取Internet Explorer提供的原始IDocHostUIHandler?

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). 

如何获得主机接口,以便释放呢?

+0

你是如何解决第二期可用的代码? – walter

回答

2

虽然没有得到正式支持,但您仍然可以参考原始IDocHostUIHandler,以便通过所有您不打算在BHO中覆盖的方法传递呼叫。

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

这里是从C#BHO的DocumentComplete事件的示例代码片段(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)); 
     } 
    } 
} 

这是改编自C++中提供的PopupBlocker项目在这里http://www.codeproject.com/Articles/4003/Popup-Window-Blocker

+0

这是我解决文件丢失问题的唯一工具。如果没有这个,删除文件只会将其打开为URL,但不会在DOM上触发“删除”事件。只需使用GetDropTarget实现中的IOleClientSite。 –

1

整个通道时下读取

其并非旨在以替换现有的IDocHostUIHandler是由Internet Explorer或web浏览器控件提供 。如果您尝试使用 ICustomDoc从浏览器助手对象(BHO)替换该接口,您可能会遇到意外的行为,如内存 泄漏。

所以它根本不支持你想要做的事(至少是正式的)。

相关问题