/// <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); }