I am trying to use the .NET 2.0 Beta 2 WebBrowser control and customize
the IDocHostUIHandler as MSDN states:
"...implement classes that inherit from the
System.Windows.Forms.WebBrowser and
System.Windows.Forms.WebBrowser.WebBrowserSite classes.
The unmanaged WebBrowser ActiveX control uses the protected
System.Windows.Forms.WebBrowser.CreateWebBrowserSiteBase method
to retrieve extensibility interfaces implemented by the
System.Windows.Forms.WebBrowser.WebBrowserSite class. Override the
System.Windows.Forms.WebBrowser.CreateWebBrowserSiteBase method to
return an instance of your own class that inherits from the
System.Windows.Forms.WebBrowser.WebBrowserSite class. The
System.Windows.Forms.WebBrowser.WebBrowserSite class provides a
default implementations of the IDocHostUIHandler OLE interface.
You can provide your own implementation of this interface or implement
any other WebBrowser ActiveX control interface in order to customize
the behavior of the control. ...
Note If you provide your own implementation for any IDocHostUIHandler
members,
you must implement all the members of that interface."
Here are snippets of the relevant code:
[ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
Guid("bd3f23c0-d43e-11cf-893b-00aa00bdce1a")]
public interface IDocHostUIHandler
{
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int EnableModeless([In, MarshalAs(UnmanagedType.Bool)] bool fEnable);
.
.
.
}
public class ExtendedWebBrowser : WebBrowser
{
protected class ExtendedWebBrowserSite : WebBrowser.WebBrowserSite,
IDocHostUIHandler
{
public ExtendedWebBrowserSite(WebBrowser host) : base(host)
{
}
int IDocHostUIHandler.EnableModeless(bool fEnable)
{
return -2147467263;
}
.
.
.
}
protected override WebBrowserSiteBase CreateWebBrowserSiteBase()
{
return new ExtendedWebBrowserSite(this);
}
.
.
.
}
The problem is that the ExtendedWebBrowserSite IDocHostUIHandler interface
methods are never called. When I tried switching to the IDocHostUIHandler2
interface, the one method that IDocHostUIHandler2 adds was called, but none
of the IDocHostUIHandler methods were. I assume this is because
WebBrowser.WebBrowserSite
exposes the IDocHostUIHandler interface. So, how do you override the
IDocHostUIHandler COM interface exposed by the base class?