private void DepersistControl() { this.Freeze(true); if (this.ocxState == null) { if (this.instance is System.Windows.Forms.UnsafeNativeMethods.IPersistStreamInit) { this.iPersistStreamInit = (System.Windows.Forms.UnsafeNativeMethods.IPersistStreamInit) this.instance; try { this.storageType = 1; this.iPersistStreamInit.InitNew(); } catch (Exception) { } return; } if (this.instance is System.Windows.Forms.UnsafeNativeMethods.IPersistStream) { this.storageType = 0; this.iPersistStream = (System.Windows.Forms.UnsafeNativeMethods.IPersistStream) this.instance; return; } if (this.instance is System.Windows.Forms.UnsafeNativeMethods.IPersistStorage) { this.storageType = 2; this.ocxState = new State(this); this.iPersistStorage = (System.Windows.Forms.UnsafeNativeMethods.IPersistStorage) this.instance; try { this.iPersistStorage.InitNew(this.ocxState.GetStorage()); } catch (Exception) { } return; } if (this.instance is System.Windows.Forms.UnsafeNativeMethods.IPersistPropertyBag) { this.iPersistPropBag = (System.Windows.Forms.UnsafeNativeMethods.IPersistPropertyBag) this.instance; try { this.iPersistPropBag.InitNew(); } catch (Exception) { } } throw new InvalidOperationException(System.Windows.Forms.SR.GetString("UnableToInitComponent")); } switch (this.ocxState.Type) { case 0: try { this.iPersistStream = (System.Windows.Forms.UnsafeNativeMethods.IPersistStream) this.instance; this.DepersistFromIStream(this.ocxState.GetStream()); } catch (Exception) { } break; case 1: if (this.instance is System.Windows.Forms.UnsafeNativeMethods.IPersistStreamInit) { try { this.iPersistStreamInit = (System.Windows.Forms.UnsafeNativeMethods.IPersistStreamInit) this.instance; this.DepersistFromIStreamInit(this.ocxState.GetStream()); } catch (Exception) { } this.GetControlEnabled(); break; } this.ocxState.Type = 0; this.DepersistControl(); return; case 2: try { this.iPersistStorage = (System.Windows.Forms.UnsafeNativeMethods.IPersistStorage) this.instance; this.DepersistFromIStorage(this.ocxState.GetStorage()); } catch (Exception) { } break; default: throw new InvalidOperationException(System.Windows.Forms.SR.GetString("UnableToInitComponent")); } if (this.ocxState.GetPropBag() != null) { try { this.iPersistPropBag = (System.Windows.Forms.UnsafeNativeMethods.IPersistPropertyBag) this.instance; this.DepersistFromIPropertyBag(this.ocxState.GetPropBag()); } catch (Exception) { } } }
private void ReleaseAxControl() { this.NoComponentChangeEvents++; ContainerControl containingControl = this.ContainingControl; if (containingControl != null) { containingControl.VisibleChanged -= this.onContainerVisibleChanged; } try { if (this.instance != null) { Marshal.FinalReleaseComObject(this.instance); this.instance = null; this.iOleInPlaceObject = null; this.iOleObject = null; this.iOleControl = null; this.iOleInPlaceActiveObject = null; this.iOleInPlaceActiveObjectExternal = null; this.iPerPropertyBrowsing = null; this.iCategorizeProperties = null; this.iPersistStream = null; this.iPersistStreamInit = null; this.iPersistStorage = null; } this.axState[checkedIppb] = false; this.axState[checkedCP] = false; this.axState[disposed] = true; this.freezeCount = 0; this.axState[sinkAttached] = false; this.wndprocAddr = IntPtr.Zero; this.SetOcState(0); } finally { this.NoComponentChangeEvents--; } }