/// <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); }
private void Initialize(object rcw, Guid sourceIid) { _sourceIid = sourceIid; _adviseCookie = -1; Debug.Assert(_connectionPoint == null, "re-initializing event sink w/o unadvising from connection point"); ComTypes.IConnectionPointContainer cpc = rcw as ComTypes.IConnectionPointContainer; if (cpc == null) { throw Error.COMObjectDoesNotSupportEvents(); } cpc.FindConnectionPoint(ref _sourceIid, out _connectionPoint); if (_connectionPoint == null) { throw Error.COMObjectDoesNotSupportSourceInterface(); } // Read the comments for ComEventSinkProxy about why we need it ComEventSinkProxy proxy = new ComEventSinkProxy(this, _sourceIid); _connectionPoint.Advise(proxy.GetTransparentProxy(), out _adviseCookie); }
public VirtualUI() : base() { if (LibHandle != IntPtr.Zero) { IntPtr pAddressOfFunctionToCall = GetProcAddress(LibHandle, "DllGetInstance"); GetInstance = (funcGetInstance)Marshal.GetDelegateForFunctionPointer( pAddressOfFunctionToCall, typeof(funcGetInstance)); GetInstance(ref m_VirtualUI); virtualUIEventSink = new VirtualUISink(this); connectionPointContainer = (System.Runtime.InteropServices.ComTypes.IConnectionPointContainer)m_VirtualUI; Guid virtualUIEventsInterfaceId = typeof(IEvents).GUID; connectionPointContainer.FindConnectionPoint(ref virtualUIEventsInterfaceId, out connectionPoint); if (connectionPoint != null) connectionPoint.Advise((IEvents)virtualUIEventSink, out connectionCookie); } m_BrowserInfo = new BrowserInfo(m_VirtualUI); m_DevServer = new DevServer(m_VirtualUI); if (!g_virtualUIExists) { g_virtualUIExists = true; g_virtualUI = new VirtualUI(); } }
public JSObject(string Id) : base() { if (LibHandle != IntPtr.Zero) { IntPtr pAddressOfFunctionToCall = GetProcAddress(LibHandle, "DllCreateJSObject"); DllCreateJSObject = (funcDllCreateJSObject)Marshal.GetDelegateForFunctionPointer( pAddressOfFunctionToCall, typeof(funcDllCreateJSObject)); DllCreateJSObject(ref m_JSObject); jsObjectEventSink = new JSObjectSink(this); connectionPointContainer = (System.Runtime.InteropServices.ComTypes.IConnectionPointContainer)m_JSObject; Guid virtualUIEventsInterfaceId = typeof(IJSObjectEvents).GUID; connectionPointContainer.FindConnectionPoint(ref virtualUIEventsInterfaceId, out connectionPoint); if (connectionPoint != null) connectionPoint.Advise((IJSObjectEvents)jsObjectEventSink, out connectionCookie); } this.Id = Id; }