public virtual void SetSite(Object pUnkSite) { if (inputObjectSite != null) { Marshal.ReleaseComObject(inputObjectSite); } if (webBrowserClass != null) { Marshal.ReleaseComObject(webBrowserClass); webBrowserClass = null; } inputObjectSite = (IInputObjectSite)pUnkSite; if (inputObjectSite != null) { //pUnkSite is a pointer to object that implements IOleWindowSite or something similar //we need to get access to the top level object - explorer itself //to allows this explorer objects also implement IServiceProvider interface //(don't mix it with System.IServiceProvider!) //we get this interface and ask it to find WebBrowserApp _IServiceProvider sp = inputObjectSite as _IServiceProvider; Guid guid = ExplorerGUIDs.IID_IWebBrowserApp; Guid riid = ExplorerGUIDs.IID_IUnknown; try { object w; sp.QueryService(ref guid, ref riid, out w); //once we have interface to the COM object we can create RCW from it webBrowserClass = (WebBrowserClass)Marshal.CreateWrapperOfType(w as IWebBrowser, typeof(WebBrowserClass)); if (SetSiteEvent != null) { SetSiteEvent(pUnkSite); } } catch (COMException) { //we anticipate this exception in case our object instantiated //as a Desk Band. There is no web browser service available. } } else { if (SetSiteEvent != null) { SetSiteEvent(pUnkSite); } } }
public virtual void SetSite(Object pUnkSite) { if (BandObjectSite != null) { Marshal.ReleaseComObject(BandObjectSite); } if (Explorer != null) { Marshal.ReleaseComObject(Explorer); Explorer = null; } BandObjectSite = (IInputObjectSite)pUnkSite; if (BandObjectSite != null) { //pUnkSite is a pointer to object that implements IOleWindowSite or something similar //we need to get access to the top level object - explorer itself //to allows this explorer objects also implement IServiceProvider interface //(don't mix it with System.IServiceProvider!) //we get this interface and ask it to find WebBrowserApp _IServiceProvider sp = BandObjectSite as _IServiceProvider; Guid guid = ExplorerGUIDs.IID_IWebBrowserApp; Guid riid = ExplorerGUIDs.IID_IUnknown; try { object w; sp.QueryService( ref guid, ref riid, out w); //once we have interface to the COM object we can create RCW from it //Error 8 Interop type 'SHDocVw.WebBrowserClass' cannot be embedded. Use the applicable interface instead. Explorer = (WebBrowserClass)Marshal.CreateWrapperOfType( w as IWebBrowser, typeof(WebBrowserClass) ); OnExplorerAttached(EventArgs.Empty); } catch (COMException) { //we anticipate this exception in case our object instantiated //as a Desk Band. There is no web browser service available. } } }
virtual public void QueryExplorerWindow() { if (BandObjectSite != null) { _IServiceProvider sp = BandObjectSite as _IServiceProvider; Guid guid = ExplorerGUIDs.IID_IWebBrowserApp; Guid riid = ExplorerGUIDs.IID_IUnknown; try { object w; sp.QueryService(ref guid, ref riid, out w); //once we have interface to the COM object we can create RCW from it _Explorer = (WebBrowserClass)Marshal.CreateWrapperOfType( w as IWebBrowser, typeof(WebBrowserClass)); OnExplorerAttached(EventArgs.Empty); } catch (COMException) { } } }