private static void ScanSourceInterface(ComTypes.ITypeInfo sourceTypeInfo, ref Dictionary <string, ComEventDesc> events) { ComTypes.TYPEATTR sourceTypeAttribute = ComRuntimeHelpers.GetTypeAttrForTypeInfo(sourceTypeInfo); for (int index = 0; index < sourceTypeAttribute.cFuncs; index++) { IntPtr funcDescHandleToRelease = IntPtr.Zero; try { GetFuncDescForDescIndex(sourceTypeInfo, index, out ComTypes.FUNCDESC funcDesc, out funcDescHandleToRelease); // we are not interested in hidden or restricted functions for now. if ((funcDesc.wFuncFlags & (int)ComTypes.FUNCFLAGS.FUNCFLAG_FHIDDEN) != 0) { continue; } if ((funcDesc.wFuncFlags & (int)ComTypes.FUNCFLAGS.FUNCFLAG_FRESTRICTED) != 0) { continue; } string name = ComRuntimeHelpers.GetNameOfMethod(sourceTypeInfo, funcDesc.memid); name = name.ToUpper(System.Globalization.CultureInfo.InvariantCulture); // Sometimes coclass has multiple source interfaces. Usually this is caused by // adding new events and putting them on new interfaces while keeping the // old interfaces around. This may cause name collisioning which we are // resolving by keeping only the first event with the same name. if (!events.ContainsKey(name)) { ComEventDesc eventDesc = new ComEventDesc { Dispid = funcDesc.memid, SourceIID = sourceTypeAttribute.guid }; events.Add(name, eventDesc); } } finally { if (funcDescHandleToRelease != IntPtr.Zero) { sourceTypeInfo.ReleaseFuncDesc(funcDescHandleToRelease); } } } }
private DynamicMetaObject BindEvent(ComEventDesc eventDesc) { // BoundDispEvent CreateComEvent(object rcw, Guid sourceIid, int dispid) Expression result = Expression.Call( typeof(ComRuntimeHelpers).GetMethod(nameof(ComRuntimeHelpers.CreateComEvent)), ComObject.RcwFromComObject(Expression), Expression.Constant(eventDesc.SourceIID), Expression.Constant(eventDesc.Dispid) ); return(new DynamicMetaObject( result, IDispatchRestriction() )); }
internal bool TryGetMemberEvent(string name, out ComEventDesc @event) { EnsureScanDefinedEvents(); return(_comTypeDesc.TryGetEvent(name, out @event)); }
internal bool TryGetEvent(string name, out ComEventDesc @event) { name = name.ToUpper(System.Globalization.CultureInfo.InvariantCulture); return(Events.TryGetValue(name, out @event)); }