/// <summary> /// </summary> public void CreateMSHTML() { Debug.Assert(tridentDocument == null, "Must call CloseMSHTML before recreating."); bool created = false; try { // create the trident instance tridentDocument = (Interop.IHTMLDocument2) new Interop.HTMLDocument(); tridentOleObject = (Interop.IOleObject)tridentDocument; // hand it our Interop.IOleClientSite implementation tridentOleObject.SetClientSite((Interop.IOleClientSite) this); created = true; propNotifyCookie = new Interop.ConnectionPointCookie(tridentDocument, this, typeof(Interop.IPropertyNotifySink), false); tridentOleObject.Advise((Interop.IAdviseSink) this, out adviseSinkCookie); Debug.Assert(adviseSinkCookie != 0); tridentCmdTarget = (Interop.IOleCommandTarget)tridentDocument; } finally { if (created == false) { tridentDocument = null; tridentOleObject = null; tridentCmdTarget = null; } } }
/// <summary> /// </summary> public void CreateMSHTML() { bool created = false; try { // create our base instance this.htmlbaseDocument = (Interop.IHTMLDocument2) new Interop.HTMLDocument(); this.activeObject = (Interop.IOleInPlaceActiveObject)htmlbaseDocument; this.windowHandle = new IntPtr(); this.activeObject.GetWindow(out this.windowHandle); oleDocumentObject = (Interop.IOleObject)htmlbaseDocument; if (oleDocumentObject == null) { throw new ApplicationException("InteropOleObject not created. No document available."); } // hand it our Interop.IOleClientSite implementation Win32.OleRun(htmlbaseDocument); oleDocumentObject.SetClientSite(this); Win32.OleLockRunning(htmlbaseDocument, true, false); created = true; // attach document and window base events propNotifyCookie = new ConnectionPointCookie(htmlbaseDocument, this, typeof(Interop.IPropertyNotifySink), false); // set document properties oleDocumentObject.SetHostNames("NetRix", "NetRix"); // set ole events oleDocumentObject.Advise(this, out adviseSinkCookie); // set IConnectionPointContainer icpc = (IConnectionPointContainer)htmlbaseDocument; //find the source interface ////get IPropertyNotifySink interface //Guid g = new Guid("9BFBBC02-EFF1-101A-84ED-00AA00341D07"); //icpc.FindConnectionPoint(ref g, out icp); ////pass a pointer to the host to the connection point //icp.Advise(this._site, out this._cookie); } catch (Exception ex) { Debug.Fail("CreateHtml failed", ex.Message); } finally { if (created == false) { htmlbaseDocument = null; oleDocumentObject = null; } } }