Colin Neller said:
David,
The CCW does take care of the QueryInterface call, but if your
IDocHostUIHandler is not getting called, I am suspicious of how you have
it defined. Verify that the GUID attribute on the interface definition is
correct and that the interface is COM visible. If you like, post it here
and I'll take a look.
The interface is as correct as I can get it. I tried emorcillo olelib,
pinvoke.net and manual.
The interface is implemented on class ExtWebBrowserSite :
WebBrowser.WebBrowserSite, which is the way I read the docs. I assume this
class cannot be made COM visible, since it inherits from a protected class,
but doesn't need to be.
I implemented IDocHostUIHandler, IDocHostUIHandler2 and IServiceProvider on
this class (see code). Of these, only IDocHostUIHandler2.GetOverrideKeyPath
and IServiceProvider.QueryService get called.
IServiceProvider.QueryService gets called for many SIDs including
ISecurityManager but not including IDocHostUIHandler or IDocHostUIHandler2.
Without this, I don't see how I can implement IDocHostUIHandler on a
different class.
But there are probably many things I don't understand. Any help much
appreciated. Sample code would be even better.
[BTW thanks for the link on your blog. I've seen that C# code for NewWindow3
mentioned before, but not been able to find it.]
DavidB
------------ code starts here (long) -------------------
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Diagnostics;
namespace WebGetWebControl {
/// <summary>
/// Implement class to extend the Web Browser
/// </summary>
public class ExtWebBrowser : WebBrowser
{
////////////////////////////////////////////////////////////////
/// <summary>
/// Implement class that allows ActiveX control to retrieve
extensibility interfaces
/// </summary>
class ExtWebBrowserSite : WebBrowser.WebBrowserSite
, olelib.IServiceProvider
, olelib.IDocHostUIHandler
, olelib.IDocHostUIHandler2
{
WebBrowser _host;
public ExtWebBrowserSite(WebBrowser host)
: base(host) {
_host = host;
Debug.WriteLine(String.Format("ExWBSite ctor {0}", host));
}
#region IDocHostUIHandler Members
void olelib.IDocHostUIHandler.EnableModeless(int fEnable) {
Debug.WriteLine(String.Format("IDocHostUIHandler {0}", 0));
throw new Exception("The method or operation is not
implemented.");
}
olelib.IDataObject
olelib.IDocHostUIHandler.FilterDataObject(olelib.IDataObject pDO) {
Debug.WriteLine(String.Format("IDocHostUIHandler {0}", 1));
throw new Exception("The method or operation is not
implemented.");
}
olelib.IDropTarget
olelib.IDocHostUIHandler.GetDropTarget(olelib.IDropTarget pDropTarget) {
Debug.WriteLine(String.Format("IDocHostUIHandler {0}", 2));
throw new Exception("The method or operation is not
implemented.");
}
object olelib.IDocHostUIHandler.GetExternal() {
Debug.WriteLine(String.Format("IDocHostUIHandler {0}", 3));
throw new Exception("The method or operation is not
implemented.");
}
void olelib.IDocHostUIHandler.GetHostInfo(ref
olelib.DOCHOSTUIINFO pInfo) {
Debug.WriteLine(String.Format("IDocHostUIHandler {0}", 4));
throw new Exception("The method or operation is not
implemented.");
}
void olelib.IDocHostUIHandler.GetOptionKeyPath(ref int
pOLESTRchKey, int dw) {
Debug.WriteLine(String.Format("IDocHostUIHandler {0}", 5));
throw new Exception("The method or operation is not
implemented.");
}
void olelib.IDocHostUIHandler.HideUI() {
Debug.WriteLine(String.Format("IDocHostUIHandler {0}", 6));
throw new Exception("The method or operation is not
implemented.");
}
void olelib.IDocHostUIHandler.OnDocWindowActivate(int fActivate)
{
Debug.WriteLine(String.Format("IDocHostUIHandler {0}", 7));
throw new Exception("The method or operation is not
implemented.");
}
void olelib.IDocHostUIHandler.OnFrameWindowActivate(int
fActivate) {
Debug.WriteLine(String.Format("IDocHostUIHandler {0}", 8));
throw new Exception("The method or operation is not
implemented.");
}
void olelib.IDocHostUIHandler.ResizeBorder(ref olelib.RECT
prcBorder, olelib.IOleInPlaceUIWindow pUIWindow, int fRameWindow) {
Debug.WriteLine(String.Format("IDocHostUIHandler {0}", 9));
throw new Exception("The method or operation is not
implemented.");
}
void
olelib.IDocHostUIHandler.ShowContextMenu(olelib.ContextMenuTarget dwContext,
ref olelib.POINT pPOINT, olelib.IOleCommandTarget pCommandTarget, object
HTMLTagElement) {
Debug.WriteLine(String.Format("IDocHostUIHandler {0}", 10));
throw new Exception("The method or operation is not
implemented.");
}
void olelib.IDocHostUIHandler.ShowUI(int dwID,
olelib.IOleInPlaceActiveObject pActiveObject, olelib.IOleCommandTarget
pCommandTarget, olelib.IOleInPlaceFrame pFrame, olelib.IOleInPlaceUIWindow
pDoc) {
Debug.WriteLine(String.Format("IDocHostUIHandler {0}", 11));
throw new Exception("The method or operation is not
implemented.");
}
void olelib.IDocHostUIHandler.TranslateAccelerator(ref
olelib.MSG lpmsg, ref olelib.UUID pguidCmdGroup, int nCmdID) {
Debug.WriteLine(String.Format("IDocHostUIHandler {0}", 12));
throw new Exception("The method or operation is not
implemented.");
}
int olelib.IDocHostUIHandler.TranslateUrl(int dwTranslate, int
pchURLIn) {
Debug.WriteLine(String.Format("IDocHostUIHandler {0}", 13));
throw new Exception("The method or operation is not
implemented.");
}
void olelib.IDocHostUIHandler.UpdateUI() {
Debug.WriteLine(String.Format("IDocHostUIHandler {0}", 14));
throw new Exception("The method or operation is not
implemented.");
}
#endregion
#region IDocHostUIHandler2 Members
void olelib.IDocHostUIHandler2.EnableModeless(int fEnable) {
Debug.WriteLine(String.Format("IDocHostUIHandler2 {0}", 0));
throw new Exception("The method or operation is not
implemented.");
}
olelib.IDataObject
olelib.IDocHostUIHandler2.FilterDataObject(olelib.IDataObject pDO) {
Debug.WriteLine(String.Format("IDocHostUIHandler2 {0}", 1));
throw new Exception("The method or operation is not
implemented.");
}
olelib.IDropTarget
olelib.IDocHostUIHandler2.GetDropTarget(olelib.IDropTarget pDropTarget) {
Debug.WriteLine(String.Format("IDocHostUIHandler2 {0}", 2));
throw new Exception("The method or operation is not
implemented.");
}
object olelib.IDocHostUIHandler2.GetExternal() {
Debug.WriteLine(String.Format("IDocHostUIHandler2 {0}", 3));
throw new Exception("The method or operation is not
implemented.");
}
void olelib.IDocHostUIHandler2.GetHostInfo(ref
olelib.DOCHOSTUIINFO pInfo) {
Debug.WriteLine(String.Format("IDocHostUIHandler2 {0}", 4));
throw new Exception("The method or operation is not
implemented.");
}
void olelib.IDocHostUIHandler2.GetOptionKeyPath(ref int
pOLESTRchKey, int dw) {
Debug.WriteLine(String.Format("IDocHostUIHandler2 {0}", 5));
throw new Exception("The method or operation is not
implemented.");
}
void olelib.IDocHostUIHandler2.GetOverrideKeyPath(ref int
pchKey, int dw) {
Debug.WriteLine(String.Format("IDocHostUIHandler2 {0}", 6));
throw new Exception("The method or operation is not
implemented.");
}
void olelib.IDocHostUIHandler2.HideUI() {
Debug.WriteLine(String.Format("IDocHostUIHandler2 {0}", 7));
throw new Exception("The method or operation is not
implemented.");
}
void olelib.IDocHostUIHandler2.OnDocWindowActivate(int
fActivate) {
Debug.WriteLine(String.Format("IDocHostUIHandler2 {0}", 8));
throw new Exception("The method or operation is not
implemented.");
}
void olelib.IDocHostUIHandler2.OnFrameWindowActivate(int
fActivate) {
Debug.WriteLine(String.Format("IDocHostUIHandler2 {0}", 8));
throw new Exception("The method or operation is not
implemented.");
}
void olelib.IDocHostUIHandler2.ResizeBorder(ref olelib.RECT
prcBorder, olelib.IOleInPlaceUIWindow pUIWindow, int fRameWindow) {
Debug.WriteLine(String.Format("IDocHostUIHandler2 {0}", 8));
throw new Exception("The method or operation is not
implemented.");
}
void
olelib.IDocHostUIHandler2.ShowContextMenu(olelib.ContextMenuTarget
dwContext, ref olelib.POINT pPOINT, olelib.IOleCommandTarget pCommandTarget,
object HTMLTagElement) {
Debug.WriteLine(String.Format("IDocHostUIHandler2 {0}", 9));
throw new Exception("The method or operation is not
implemented.");
}
void olelib.IDocHostUIHandler2.ShowUI(int dwID,
olelib.IOleInPlaceActiveObject pActiveObject, olelib.IOleCommandTarget
pCommandTarget, olelib.IOleInPlaceFrame pFrame, olelib.IOleInPlaceUIWindow
pDoc) {
Debug.WriteLine(String.Format("IDocHostUIHandler2 {0}",
10));
throw new Exception("The method or operation is not
implemented.");
}
void olelib.IDocHostUIHandler2.TranslateAccelerator(ref
olelib.MSG lpmsg, ref olelib.UUID pguidCmdGroup, int nCmdID) {
Debug.WriteLine(String.Format("IDocHostUIHandler2 {0}",
11));
throw new Exception("The method or operation is not
implemented.");
}
int olelib.IDocHostUIHandler2.TranslateUrl(int dwTranslate, int
pchURLIn) {
Debug.WriteLine(String.Format("IDocHostUIHandler2 {0}",
12));
throw new Exception("The method or operation is not
implemented.");
}
void olelib.IDocHostUIHandler2.UpdateUI() {
Debug.WriteLine(String.Format("IDocHostUIHandler2 {0}",
13));
throw new Exception("The method or operation is not
implemented.");
}
#endregion
#region IServiceProvider Members
void olelib.IServiceProvider.QueryService(ref olelib.UUID
guidService, ref olelib.UUID riid, IntPtr ppvObject) {
Debug.WriteLine(String.Format("IServiceProvider {0}",
guidService));
throw new Exception("The method or operation is not
implemented.");
}
#endregion
}
//--------------------------------------------------------------
// Override method to tell ActiveX host where to find extensibility
interfaces
//
protected override WebBrowserSiteBase CreateWebBrowserSiteBase() {
return new ExtWebBrowserSite(this);
}
public void Test() {
}
}
}