views:

196

answers:

1

I am writing a BHO for IE using C#. 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. However, if Protected Mode is turned on, NavigateCompleted2() is called, but SetSite() and the constructor are never called (!?!). However, if I create a menu item which calls a method in the BHO class, or open a new tab, everything is correctly called. Does anyone know why it doesn't work when I open a new IE window?

The full source listing can be found here.

A: 

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

BlueRaja - Danny Pflughoeft