简体   繁体   English

未使用保护模式实例化托管BHO

[英]Managed BHOs not instantiated using Protected Mode

I am writing a BHO for IE using C#. 我正在使用C#为IE编写BHO。 The code I'm concerned with is this: 我关注的代码是这样的:

public class BHO : IObjectWithSite, IOleCommandTarget
{
    ...
    public BHO()
    {
        MessageBox.Show("Constructor called");
    }

    public int SetSite(object site)
    {
        MessageBox.Show("SetSite called!");
        if( site != null )
        {
            _webBrowser = (WebBrowser) site;
            _webBrowser.NavigateComplete2 += OnNavigateComplete2;
        }
        else
        {
            _webBrowser.NavigateComplete2 -= OnNavigateComplete2;
            _webBrowser = null;
        }
        return 0;
    }

    private void OnNavigateComplete2(object pDisp, ref object URL)
    {
        MessageBox.Show("OnNavigateComplete2 called");
    }

When IE is run with Protected Mode off, everything works fine. 在保护模式关闭的情况下运行IE时,一切正常。 However, if Protected Mode is turned on, NavigateCompleted2() is called, but SetSite() and the constructor are never called (!?!). 但是,如果启用了保护模式,则将调用NavigateCompleted2(),但永远不会调用SetSite()和构造函数(!?!)。 However, if I create a menu item which calls a method in the BHO class, or open a new tab, everything is correctly called. 但是,如果我创建一个菜单项,该菜单项调用BHO类中的方法,或者打开一个新选项卡,则所有内容都将正确调用。 Does anyone know why it doesn't work when I open a new IE window? 有谁知道为什么当我打开新的IE窗口时它不起作用?

The full source listing can be found here . 完整的源代码清单可以在这里找到。

Someone on MSDN answered my question: the constructor and method were still being called, but for some reason the MessageBoxes don't show when I open a new window in Protected Mode until the page is loaded. MSDN上的某个人回答了我的问题:构造函数和方法仍在被调用,但是由于某种原因,当我在保护模式下打开新窗口直到加载页面时,MessageBox才显示。 Variables weren't being set due to a different problem - the constructor was instantiating an object which was silently failing. 由于存在其他问题,未设置变量-构造函数实例化了一个静默失败的对象。

I now need help with a different ( very much related ) problem. 我现在需要另一个不同( 非常相关 )的问题的帮助。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM