I just solved the exact same problem: how to provide a custom implementation of IDocHostUIHandler control for WinForms WebBrowser . The problem is that the WebBrowserSite base class has already implemented its own version of IDocHostUIHandler (which is the internal interface, so it is impossible to explicitly repeat the implementation in the NewWebBrowserSite derived class). However, theoretically, there should not be a problem with the implementation of another C # interface with the same GIID layout and methods (since in this particular case this applies to the entire COM client - the basic ActiveX WebBrowser control).
Unfortunately, this was not possible until .NET 4.0. Fortunately, this is now using the new ICustomQueryInterface function:
protected class NewWebBrowserSite : WebBrowserSite, UnsafeNativeMethods.IDocHostUIHandler ICustomQueryInterface { private MyBrowser host; public NewWebBrowserSite(MyBrowser h): base(h) { this.host = h; } int UnsafeNativeMethods.IDocHostUIHandler.ShowContextMenu(int dwID, NativeMethods.POINT pt, object pcmdtReserved, object pdispReserved) { MyBrowser wb = (MyBrowser)this.host; // other code } // rest of IDocHostUIHandler methods // ICustomQueryInterface public CustomQueryInterfaceResult GetInterface(ref Guid iid, out IntPtr ppv) { if (iid == typeof(UnsafeNativeMethods.IDocHostUIHandler).GUID) { ppv = Marshal.GetComInterfaceForObject(this, typeof(UnsafeNativeMethods.IDocHostUIHandler), CustomQueryInterfaceMode.Ignore); } else { ppv = IntPtr.Zero; return CustomQueryInterfaceResult.NotHandled; } return CustomQueryInterfaceResult.Handled; } }
Noseratio
source share