#pragma warning disable 6500 // The 6500 warning is actually handled in below code, but the PreSharp explicitly checks the presence of NullReferenceException and SEHException, and still treat below code as violation of presharp rule, so suppress it here. /// <summary> /// Disconnect the current connection point. If the object is not connected, /// this method will do nothing. /// </summary> internal void Disconnect() { if (connectionPoint != null && cookie != 0) { try { connectionPoint.Unadvise(cookie); } catch (Exception ex) { if (CriticalExceptions.IsCriticalException(ex)) { throw; } } finally { cookie = 0; } try { System.Runtime.InteropServices.Marshal.FinalReleaseComObject(connectionPoint); } catch (Exception ex) { if (CriticalExceptions.IsCriticalException(ex)) { throw; } } finally { connectionPoint = null; } } }
/// <summary> /// Disconnect the current connection point. If the object is not connected, /// this method will do nothing. /// </summary> public void Disconnect() { if (connectionPoint != null && cookie != 0) { try { connectionPoint.Unadvise(cookie); } catch (Exception ex) { if (ClientUtils.IsCriticalException(ex)) { throw; } } finally { cookie = 0; } try { Marshal.ReleaseComObject(connectionPoint); } catch (Exception ex) { if (ClientUtils.IsCriticalException(ex)) { throw; } } finally { connectionPoint = null; } } }
internal ConnectionPointCookie(object source, object sink, Type eventInterface) { Exception ex = null; if (source is UnsafeNativeMethods.IConnectionPointContainer) { UnsafeNativeMethods.IConnectionPointContainer cpc = (UnsafeNativeMethods.IConnectionPointContainer)source; try { Guid tmp = eventInterface.GUID; if (cpc.FindConnectionPoint(ref tmp, out connectionPoint) != NativeMethods.S_OK) { connectionPoint = null; } } catch (Exception e) { if(CriticalExceptions.IsCriticalException(e)) { throw; } connectionPoint = null; } if (connectionPoint == null) { ex = new ArgumentException(SR.Get(SRID.AxNoEventInterface, eventInterface.Name)); } // IsComObject(sink): this is the case of a managed sink object wrapped in IDispatchSTAForwarder - // see WebBrowser.CreateSink(). else if (sink == null || !eventInterface.IsInstanceOfType(sink) && !Marshal.IsComObject(sink)) { ex = new InvalidCastException(SR.Get(SRID.AxNoSinkImplementation, eventInterface.Name)); } else { int hr = connectionPoint.Advise(sink, ref cookie); if (hr != NativeMethods.S_OK) { cookie = 0; Marshal.FinalReleaseComObject(connectionPoint); connectionPoint = null; ex = new InvalidOperationException(SR.Get(SRID.AxNoSinkAdvise, eventInterface.Name, hr)); } } } else { ex = new InvalidCastException(SR.Get(SRID.AxNoConnectionPointContainer)); } if (connectionPoint == null || cookie == 0) { if (connectionPoint != null) { Marshal.FinalReleaseComObject(connectionPoint); } if (ex == null) { throw new ArgumentException(SR.Get(SRID.AxNoConnectionPoint, eventInterface.Name)); } else { throw ex; } } }
internal void Disconnect() { if (connectionPoint != null && cookie != 0) { try { connectionPoint.Unadvise(cookie); } catch (Exception ex) { if (CriticalExceptions.IsCriticalException(ex)) { throw; } } finally { cookie = 0; } try { System.Runtime.InteropServices.Marshal.FinalReleaseComObject(connectionPoint); } catch (Exception ex) { if (CriticalExceptions.IsCriticalException(ex)) { throw; } } finally { connectionPoint = null; } } }
/// <include file='doc\AxHost.uex' path='docs/doc[@for="AxHost.ConnectionPointCookie.Disconnect"]/*' /> /// <devdoc> /// Disconnect the current connection point. If the object is not connected, /// this method will do nothing. /// </devdoc> public void Disconnect() { if (connectionPoint != null && cookie != 0) { try { connectionPoint.Unadvise(cookie); } catch (Exception ex) { if (ClientUtils.IsCriticalException(ex)) { throw; } } finally { cookie = 0; } try { Marshal.ReleaseComObject(connectionPoint); } catch (Exception ex) { if (ClientUtils.IsCriticalException(ex)) { throw; } } finally { connectionPoint = null; } } }
internal ConnectionPointCookie(object source, object sink, Type eventInterface, bool throwException) { if (source is UnsafeNativeMethods.IConnectionPointContainer) { UnsafeNativeMethods.IConnectionPointContainer cpc = (UnsafeNativeMethods.IConnectionPointContainer)source; try { Guid tmp = eventInterface.GUID; if (cpc.FindConnectionPoint(ref tmp, out connectionPoint) != NativeMethods.S_OK) { connectionPoint = null; } } catch { connectionPoint = null; } if (connectionPoint == null) { if (throwException) { throw new ArgumentException(SR.GetString(SR.AXNoEventInterface, eventInterface.Name)); } } else if (sink == null || !eventInterface.IsInstanceOfType(sink)) { if (throwException) { throw new InvalidCastException(SR.GetString(SR.AXNoSinkImplementation, eventInterface.Name)); } } else { int hr = connectionPoint.Advise(sink, ref cookie); if (hr == NativeMethods.S_OK) { threadId = Thread.CurrentThread.ManagedThreadId; } else { cookie = 0; Marshal.ReleaseComObject(connectionPoint); connectionPoint = null; if (throwException) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, SR.GetString(SR.AXNoSinkAdvise, eventInterface.Name), hr)); } } } } else { if (throwException) { throw new InvalidCastException(SR.GetString(SR.AXNoConnectionPointContainer)); } } if (connectionPoint == null || cookie == 0) { if (connectionPoint != null) { Marshal.ReleaseComObject(connectionPoint); } if (throwException) { throw new ArgumentException(SR.GetString(SR.AXNoConnectionPoint, eventInterface.Name)); } } #if DEBUG new EnvironmentPermission(PermissionState.Unrestricted).Assert(); try { callStack = Environment.StackTrace; } finally { System.Security.CodeAccessPermission.RevertAssert(); } #endif }
/// <include file='doc\NativeMethods.uex' path='docs/doc[@for="NativeMethods.ConnectionPointCookie.Disconnect1"]/*' /> /// <devdoc> /// Disconnect the current connection point. If the object is not connected, /// this method will do nothing. /// </devdoc> public void Disconnect(bool release) { if (connectionPoint != null && cookie != 0) { connectionPoint.Unadvise(cookie); cookie = 0; if (release) { Marshal.ReleaseComObject(connectionPoint); } connectionPoint = null; } }
/// <include file='doc\NativeMethods.uex' path='docs/doc[@for="NativeMethods.ConnectionPointCookie.ConnectionPointCookie1"]/*' /> /// <devdoc> /// Creates a connection point to of the given interface type. /// which will call on a managed code sink that implements that interface. /// </devdoc> public ConnectionPointCookie(object source, object sink, Type eventInterface, bool throwException, out bool connected){ connected = false; Exception ex = null; if (source is UnsafeNativeMethods.IConnectionPointContainer) { UnsafeNativeMethods.IConnectionPointContainer cpc = (UnsafeNativeMethods.IConnectionPointContainer)source; try { Guid tmp = eventInterface.GUID; if (cpc.FindConnectionPoint(ref tmp, out connectionPoint) != NativeMethods.S_OK) { connectionPoint = null; } } catch (Exception) { connectionPoint = null; } if (connectionPoint == null) { ex = new ArgumentException(SR.GetString(SR.ConnPointSourceIF, eventInterface.Name )); } else if (sink == null || !eventInterface.IsInstanceOfType(sink)) { ex = new InvalidCastException(SR.GetString(SR.ConnPointSinkIF)); } else { int hr = connectionPoint.Advise(sink, ref cookie); if (hr != S_OK) { cookie = 0; Marshal.ReleaseComObject(connectionPoint); connectionPoint = null; ex = new ExternalException(SR.GetString(SR.ConnPointAdviseFailed, eventInterface.Name, hr )); } else { connected = true; } } } else { ex = new InvalidCastException(SR.GetString(SR.ConnPointSourceIF, "IConnectionPointContainer")); } if (throwException && (connectionPoint == null || cookie == 0)) { if (connectionPoint != null) { Marshal.ReleaseComObject(connectionPoint); } if (ex == null) { throw new ArgumentException(SR.GetString(SR.ConnPointCouldNotCreate, eventInterface.Name )); } else { throw ex; } } #if DEBUG new EnvironmentPermission(PermissionState.Unrestricted).Assert(); try { callStack = Environment.StackTrace; } finally { System.Security.CodeAccessPermission.RevertAssert(); } #endif }
/// Creates a connection point to of the given interface type. /// which will call on a managed code sink that implements that interface. internal ConnectionPointCookie(object source, object sink, Type eventInterface) { Exception ex = null; if (source is UnsafeNativeMethods.IConnectionPointContainer) { UnsafeNativeMethods.IConnectionPointContainer cpc = (UnsafeNativeMethods.IConnectionPointContainer)source; try { Guid tmp = eventInterface.GUID; if (cpc.FindConnectionPoint(ref tmp, out connectionPoint) != NativeMethods.S_OK) { connectionPoint = null; } } catch (Exception e) { if (CriticalExceptions.IsCriticalException(e)) { throw; } connectionPoint = null; } if (connectionPoint == null) { ex = new ArgumentException(SR.Get(SRID.AxNoEventInterface, eventInterface.Name)); } // IsComObject(sink): this is the case of a managed sink object wrapped in IDispatchSTAForwarder - // see WebBrowser.CreateSink(). else if (sink == null || !eventInterface.IsInstanceOfType(sink) && !Marshal.IsComObject(sink)) { ex = new InvalidCastException(SR.Get(SRID.AxNoSinkImplementation, eventInterface.Name)); } else { int hr = connectionPoint.Advise(sink, ref cookie); if (hr != NativeMethods.S_OK) { cookie = 0; Marshal.FinalReleaseComObject(connectionPoint); connectionPoint = null; ex = new InvalidOperationException(SR.Get(SRID.AxNoSinkAdvise, eventInterface.Name, hr)); } } } else { ex = new InvalidCastException(SR.Get(SRID.AxNoConnectionPointContainer)); } if (connectionPoint == null || cookie == 0) { if (connectionPoint != null) { Marshal.FinalReleaseComObject(connectionPoint); } if (ex == null) { throw new ArgumentException(SR.Get(SRID.AxNoConnectionPoint, eventInterface.Name)); } else { throw ex; } } }
internal ConnectionPointCookie(object source, object sink, Type eventInterface, bool throwException) { if (source is UnsafeNativeMethods.IConnectionPointContainer cpc) { try { Guid tmp = eventInterface.GUID; if (cpc.FindConnectionPoint(ref tmp, out connectionPoint) != NativeMethods.S_OK) { connectionPoint = null; } } catch { connectionPoint = null; } if (connectionPoint == null) { if (throwException) { throw new ArgumentException(string.Format(SR.AXNoEventInterface, eventInterface.Name)); } } else if (sink == null || !eventInterface.IsInstanceOfType(sink)) { if (throwException) { throw new InvalidCastException(string.Format(SR.AXNoSinkImplementation, eventInterface.Name)); } } else { int hr = connectionPoint.Advise(sink, ref cookie); if (hr == NativeMethods.S_OK) { threadId = Thread.CurrentThread.ManagedThreadId; } else { cookie = 0; Marshal.ReleaseComObject(connectionPoint); connectionPoint = null; if (throwException) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, string.Format(SR.AXNoSinkAdvise, eventInterface.Name), hr)); } } } } else { if (throwException) { throw new InvalidCastException(SR.AXNoConnectionPointContainer); } } if (connectionPoint == null || cookie == 0) { if (connectionPoint != null) { Marshal.ReleaseComObject(connectionPoint); } if (throwException) { throw new ArgumentException(string.Format(SR.AXNoConnectionPoint, eventInterface.Name)); } } #if DEBUG callStack = Environment.StackTrace; #endif }