/// <summary>
        /// Returns a list of CONNECTDATA instances representing the current
        /// event sink connections to the given IConnectionPoint.
        /// </summary>
        /// <param name="connectionPoint">The IConnectionPoint to return connection data for.</param>
        /// <returns>A List of CONNECTDATA instances representing all the current event sink connections to the
        /// given connection point.</returns>
        private static List <COM.CONNECTDATA> GetConnectionData(COM.IConnectionPoint connectionPoint)
        {
            COM.IEnumConnections   enumConnections;
            COM.CONNECTDATA[]      oneConnectData     = new COM.CONNECTDATA[1];
            List <COM.CONNECTDATA> connectDataObjects = new List <COM.CONNECTDATA>();

            connectionPoint.EnumConnections(out enumConnections);
            enumConnections.Reset();
            int        fetchCount  = 0;
            SafeIntPtr pFetchCount = new SafeIntPtr();

            do
            {
                if (0 != enumConnections.Next(1, oneConnectData, pFetchCount.ToIntPtr()))
                {
                    break;
                }
                fetchCount = pFetchCount.Value;
                if (fetchCount > 0)
                {
                    connectDataObjects.Add(oneConnectData[0]);
                }
            } while (fetchCount > 0);
            pFetchCount.Dispose();
            return(connectDataObjects);
        }
        /// <summary>
        /// Get all the event connection points for a given COM object.
        /// </summary>
        /// <param name="comObject">A COM object that raises events.</param>
        /// <returns>A List of IConnectionPoint instances for the COM object.</returns>
        private static List <COM.IConnectionPoint> GetConnectionPoints(object comObject)
        {
            COM.IConnectionPointContainer connectionPointContainer = (COM.IConnectionPointContainer)comObject;
            COM.IEnumConnectionPoints     enumConnectionPoints;
            COM.IConnectionPoint[]        oneConnectionPoint = new COM.IConnectionPoint[1];
            List <COM.IConnectionPoint>   connectionPoints   = new List <COM.IConnectionPoint>();

            connectionPointContainer.EnumConnectionPoints(out enumConnectionPoints);
            enumConnectionPoints.Reset();
            int        fetchCount  = 0;
            SafeIntPtr pFetchCount = new SafeIntPtr();

            do
            {
                if (0 != enumConnectionPoints.Next(1, oneConnectionPoint, pFetchCount.ToIntPtr()))
                {
                    break;
                }
                fetchCount = pFetchCount.Value;
                if (fetchCount > 0)
                {
                    connectionPoints.Add(oneConnectionPoint[0]);
                }
            } while (fetchCount > 0);
            pFetchCount.Dispose();
            return(connectionPoints);
        }
Beispiel #3
0
        private void DisposeAll()
        {
            if (_connectionPoint == null)
            {
                return;
            }

            if (_adviseCookie == -1)
            {
                return;
            }

            try
            {
                _connectionPoint.Unadvise(_adviseCookie);

                // _connectionPoint has entered the CLR in the constructor
                // for this object and hence its ref counter has been increased
                // by us. We have not exposed it to other components and
                // hence it is safe to call RCO on it w/o worrying about
                // killing the RCW for other objects that link to it.
                Marshal.ReleaseComObject(_connectionPoint);
            }
            catch (Exception ex)
            {
                // if something has gone wrong, and the object is no longer attached to the CLR,
                // the Unadvise is going to throw.  In this case, since we're going away anyway,
                // we'll ignore the failure and quietly go on our merry way.
                COMException exCOM = ex as COMException;
                if (exCOM != null && exCOM.ErrorCode == ComHresults.CONNECT_E_NOCONNECTION)
                {
                    Debug.Assert(false, "IConnectionPoint::Unadvise returned CONNECT_E_NOCONNECTION.");
                    throw;
                }
            }
            finally
            {
                _connectionPoint = null;
                _adviseCookie    = -1;
                _sourceIid       = Guid.Empty;
            }
        }
        public void Disconnect()
        {
            try
            {
                if (_connectionPoint == null)
                {
                    return;
                }

                if (_cookie.HasValue)
                {
                    // TODO: Fix: hangs when disposing.
                    _connectionPoint.Unadvise(_cookie.Value);
                    _cookie = null;
                }

                Marshal.ReleaseComObject(_connectionPoint);
                _connectionPoint = null;
            }
            catch (Exception ex)
            {
                Log.Error("Failed to unsubscribe callback.", ex);
            }
        }
Beispiel #5
0
        private void DisposeAll() {
            if (_connectionPoint == null) {
                return;
            }

            if (_adviseCookie == -1) {
                return;
            }

            try {
                _connectionPoint.Unadvise(_adviseCookie);

                // _connectionPoint has entered the CLR in the constructor
                // for this object and hence its ref counter has been increased
                // by us. We have not exposed it to other components and
                // hence it is safe to call RCO on it w/o worrying about
                // killing the RCW for other objects that link to it.
                Marshal.ReleaseComObject(_connectionPoint);
            } catch (Exception ex) {
                // if something has gone wrong, and the object is no longer attached to the CLR,
                // the Unadvise is going to throw.  In this case, since we're going away anyway,
                // we'll ignore the failure and quietly go on our merry way.
                COMException exCOM = ex as COMException;
                if (exCOM != null && exCOM.ErrorCode == ComHresults.CONNECT_E_NOCONNECTION) {
                    Debug.Assert(false, "IConnectionPoint::Unadvise returned CONNECT_E_NOCONNECTION.");
                    throw;
                }
            } finally {
                _connectionPoint = null;
                _adviseCookie = -1;
                _sourceIid = Guid.Empty;
            }
        }
 public void Dispose()
 {
     if (connectionPoint != null)
     {
         try
         {
             //connectionPoint.Unadvise(connectionCookie);
         }
         catch (Exception)
         {
         }
         connectionPoint = null;
         connectionCookie = 0;
     }
     if (m_JSObject != null)
         Marshal.ReleaseComObject(m_JSObject);
     m_JSObject = null;
 }