public override List <ITlibNode> GenChildren() { var res = new List <ITlibNode>(); for (var x = 0; x < _ta.cImplTypes; ++x) { _ti.GetRefTypeOfImplType(x, out var href); _ti.GetRefTypeInfo(href, out var ti2); CommonBuildTlibNode(this, ti2, false, false, res); } return(res); }
public override void BuildIDLInto(IDLFormatter ih) { EnterElement(); ih.AppendLine("["); var lprops = _data.Attributes; for (var i = 0; i < lprops.Count; ++i) { ih.AppendLine(" " + lprops[i] + (i < (lprops.Count - 1) ? "," : "")); } ih.AppendLine("]"); if (_ta.cImplTypes > 0) { _ti.GetRefTypeOfImplType(0, out var href); _ti.GetRefTypeInfo(href, out var ti2); ih.AddString($"{_data.Name} : "); ih.AddLink(ti2.GetName(), "i"); ih.AppendLine(" {"); } else { ih.AppendLine("interface " + _data.Name + " {"); } using (new IDLHelperTab(ih)) { Children.ForEach(x => x.BuildIDLInto(ih)); } ih.AppendLine("};"); ExitElement(); }
internal static ITypeInfo GetDispatchTypeInfoFromCoClassTypeInfo(ITypeInfo typeinfo) { int cImplTypes = GetTypeAttr(typeinfo).cImplTypes; ITypeInfo ppTI = null; for (int i = 0; i < cImplTypes; i++) { int num2; typeinfo.GetRefTypeOfImplType(i, out num2); typeinfo.GetRefTypeInfo(num2, out ppTI); System.Runtime.InteropServices.ComTypes.TYPEATTR typeAttr = GetTypeAttr(ppTI); if (typeAttr.typekind == System.Runtime.InteropServices.ComTypes.TYPEKIND.TKIND_DISPATCH) { return(ppTI); } if (((short)(typeAttr.wTypeFlags & System.Runtime.InteropServices.ComTypes.TYPEFLAGS.TYPEFLAG_FDUAL)) != 0) { ppTI = GetDispatchTypeInfoFromCustomInterfaceTypeInfo(ppTI); if (GetTypeAttr(ppTI).typekind == System.Runtime.InteropServices.ComTypes.TYPEKIND.TKIND_DISPATCH) { return(ppTI); } } } return(null); }
internal static ITypeInfo GetDispatchTypeInfoFromCoClassTypeInfo(ITypeInfo typeinfo) { int cImplTypes = (int)ComTypeInfo.GetTypeAttr(typeinfo).cImplTypes; ITypeInfo ppTI = (ITypeInfo)null; for (int index = 0; index < cImplTypes; ++index) { int href; typeinfo.GetRefTypeOfImplType(index, out href); typeinfo.GetRefTypeInfo(href, out ppTI); System.Runtime.InteropServices.ComTypes.TYPEATTR typeAttr = ComTypeInfo.GetTypeAttr(ppTI); if (typeAttr.typekind == System.Runtime.InteropServices.ComTypes.TYPEKIND.TKIND_DISPATCH) { return(ppTI); } if ((typeAttr.wTypeFlags & System.Runtime.InteropServices.ComTypes.TYPEFLAGS.TYPEFLAG_FDUAL) != (System.Runtime.InteropServices.ComTypes.TYPEFLAGS) 0) { ppTI = ComTypeInfo.GetDispatchTypeInfoFromCustomInterfaceTypeInfo(ppTI); if (ComTypeInfo.GetTypeAttr(ppTI).typekind == System.Runtime.InteropServices.ComTypes.TYPEKIND.TKIND_DISPATCH) { return(ppTI); } } } return((ITypeInfo)null); }
public override void BuildIDLInto(IDLFormatter ih) { ih.AppendLine("["); var lprops = new List <string> { $"uuid({_ta.guid})" }; var help = _ti.GetHelpDocumentationById(-1, out var context); AddHelpStringAndContext(lprops, help, context); if (0 != (_ta.wTypeFlags & TypeAttr.TypeFlags.TYPEFLAG_FHIDDEN)) { lprops.Add("hidden"); } if (0 != (_ta.wTypeFlags & TypeAttr.TypeFlags.TYPEFLAG_FDUAL)) { lprops.Add("dual"); } if (0 != (_ta.wTypeFlags & TypeAttr.TypeFlags.TYPEFLAG_FRESTRICTED)) { lprops.Add("restricted"); } if (0 != (_ta.wTypeFlags & TypeAttr.TypeFlags.TYPEFLAG_FNONEXTENSIBLE)) { lprops.Add("nonextensible"); } if (0 != (_ta.wTypeFlags & TypeAttr.TypeFlags.TYPEFLAG_FOLEAUTOMATION)) { lprops.Add("oleautomation"); } for (var i = 0; i < lprops.Count; ++i) { ih.AppendLine(" " + lprops[i] + (i < (lprops.Count - 1) ? "," : "")); } ih.AppendLine("]"); if (_ta.cImplTypes > 0) { _ti.GetRefTypeOfImplType(0, out var href); _ti.GetRefTypeInfo(href, out var ti2); ih.AddString($"interface {_name} : "); ih.AddLink(ti2.GetName(), "i"); ih.AppendLine(" {"); } else { ih.AppendLine("interface " + _name + " {"); } using (new IDLHelperTab(ih)) { Children.ForEach(x => x.BuildIDLInto(ih)); } ih.AppendLine("};"); }
private IEnumerable <string> GetImplementedInterfaceNames(TYPEATTR typeAttr, ITypeInfo info) { var output = new List <string>(); for (var implIndex = 0; implIndex < typeAttr.cImplTypes; implIndex++) { int href; info.GetRefTypeOfImplType(implIndex, out href); ITypeInfo implTypeInfo; info.GetRefTypeInfo(href, out implTypeInfo); IntPtr typeAttributesPointer; implTypeInfo.GetTypeAttr(out typeAttributesPointer); var typeAttributes = (TYPEATTR)Marshal.PtrToStructure(typeAttributesPointer, typeof(TYPEATTR)); IMPLTYPEFLAGS flags = 0; try { info.GetImplTypeFlags(implIndex, out flags); } catch (COMException) { } var implTypeName = GetTypeName(implTypeInfo); if (implTypeName != "IDispatch" && implTypeName != "IUnknown") { // skip IDispatch.. just about everything implements it and RD doesn't need to care about it; don't care about IUnknown either output.Add(implTypeName); } if (flags != 0) { ComInformation comInfo; if (_comInformation.TryGetValue(typeAttributes.guid, out comInfo)) { _comInformation[typeAttributes.guid].ImplTypeFlags = _comInformation[typeAttributes.guid].ImplTypeFlags | flags; } else { _comInformation.Add(typeAttributes.guid, new ComInformation(typeAttributes, flags, implTypeInfo, implTypeName, new QualifiedModuleName(), null, 0)); } } info.ReleaseTypeAttr(typeAttributesPointer); } return(output); }
public override List <ITlibNode> GenChildren() { var res = new List <ITlibNode>(); if (_ta.cImplTypes > 0) { if (_ta.cImplTypes > 1) { throw new Exception("Multiple inheritance!?"); } _ti.GetRefTypeOfImplType(0, out var href); _ti.GetRefTypeInfo(href, out var ti2); CommonBuildTlibNode(this, ti2, false, true, res); } return(res); }
public static bool SwapForInterface(ref ITypeInfo ti, ref TypeAttr ta) { try { if (ta.typekind == TypeAttr.TypeKind.TKIND_DISPATCH && 0 != (ta.wTypeFlags & TypeAttr.TypeFlags.TYPEFLAG_FDUAL)) { ti.GetRefTypeOfImplType(-1, out var href); ti.GetRefTypeInfo(href, out ti); ta = new TypeAttr(ti); return(true); } } // ReSharper disable once EmptyGeneralCatchClause catch (Exception) { } return(false); }
internal static ITypeInfo GetDispatchTypeInfoFromCustomInterfaceTypeInfo(ITypeInfo typeinfo) { ITypeInfo ppTI = null; try { int num; typeinfo.GetRefTypeOfImplType(-1, out num); typeinfo.GetRefTypeInfo(num, out ppTI); } catch (COMException exception) { if (exception.ErrorCode != -2147319765) { throw; } } return(ppTI); }
private void GetImplementedInterfaces(ITypeInfo info, TYPEATTR typeAttr) { IsExtensible = !typeAttr.wTypeFlags.HasFlag(TYPEFLAGS.TYPEFLAG_FNONEXTENSIBLE); for (var implIndex = 0; implIndex < typeAttr.cImplTypes; implIndex++) { info.GetRefTypeOfImplType(implIndex, out int href); info.GetRefTypeInfo(href, out ITypeInfo implemented); implemented.GetTypeAttr(out IntPtr attribPtr); using (DisposalActionContainer.Create(attribPtr, implemented.ReleaseTypeAttr)) { var attribs = Marshal.PtrToStructure <TYPEATTR>(attribPtr); ComProject.KnownTypes.TryGetValue(attribs.guid, out ComType inherited); var intface = inherited as ComInterface ?? new ComInterface(Project, implemented, attribs); _inherited.Add(intface); ComProject.KnownTypes.TryAdd(attribs.guid, intface); } } }
private void GetImplementedInterfaces(ITypeInfo info, TYPEATTR typeAttr) { for (var implIndex = 0; implIndex < typeAttr.cImplTypes; implIndex++) { info.GetRefTypeOfImplType(implIndex, out int href); info.GetRefTypeInfo(href, out ITypeInfo implemented); implemented.GetTypeAttr(out IntPtr attribPtr); using (DisposalActionContainer.Create(attribPtr, info.ReleaseTypeAttr)) { var attribs = Marshal.PtrToStructure <TYPEATTR>(attribPtr); ComProject.KnownTypes.TryGetValue(attribs.guid, out ComType inherited); var intface = inherited as ComInterface ?? new ComInterface(Project, implemented, attribs); ComProject.KnownTypes.TryAdd(attribs.guid, intface); IMPLTYPEFLAGS flags = 0; try { info.GetImplTypeFlags(implIndex, out flags); } catch (COMException) { } if (flags.HasFlag(IMPLTYPEFLAGS.IMPLTYPEFLAG_FSOURCE)) { _events.Add(intface); } else { DefaultInterface = flags.HasFlag(IMPLTYPEFLAGS.IMPLTYPEFLAG_FDEFAULT) ? intface : DefaultInterface; } _interfaces.Add(intface, flags.HasFlag(IMPLTYPEFLAGS.IMPLTYPEFLAG_FRESTRICTED)); } } if (DefaultInterface == null) { DefaultInterface = VisibleInterfaces.FirstOrDefault(); } }
private void GetImplementedInterfaces(ITypeInfo info, TYPEATTR typeAttr) { for (var implIndex = 0; implIndex < typeAttr.cImplTypes; implIndex++) { int href; info.GetRefTypeOfImplType(implIndex, out href); ITypeInfo implemented; info.GetRefTypeInfo(href, out implemented); IntPtr attribPtr; implemented.GetTypeAttr(out attribPtr); var attribs = (TYPEATTR)Marshal.PtrToStructure(attribPtr, typeof(TYPEATTR)); ComType inherited; ComProject.KnownTypes.TryGetValue(attribs.guid, out inherited); var intface = inherited as ComInterface ?? new ComInterface(implemented, attribs); ComProject.KnownTypes.TryAdd(attribs.guid, intface); IMPLTYPEFLAGS flags = 0; try { info.GetImplTypeFlags(implIndex, out flags); } catch (COMException) { } if (flags.HasFlag(IMPLTYPEFLAGS.IMPLTYPEFLAG_FSOURCE)) { _events.Add(intface); } else { DefaultInterface = flags.HasFlag(IMPLTYPEFLAGS.IMPLTYPEFLAG_FDEFAULT) ? intface : DefaultInterface; } _interfaces.Add(intface, flags.HasFlag(IMPLTYPEFLAGS.IMPLTYPEFLAG_FRESTRICTED)); info.ReleaseTypeAttr(attribPtr); } }
private void GetImplementedInterfaces(ITypeInfo info, TYPEATTR typeAttr) { IsExtensible = !typeAttr.wTypeFlags.HasFlag(TYPEFLAGS.TYPEFLAG_FNONEXTENSIBLE); for (var implIndex = 0; implIndex < typeAttr.cImplTypes; implIndex++) { int href; info.GetRefTypeOfImplType(implIndex, out href); ITypeInfo implemented; info.GetRefTypeInfo(href, out implemented); IntPtr attribPtr; implemented.GetTypeAttr(out attribPtr); var attribs = (TYPEATTR)Marshal.PtrToStructure(attribPtr, typeof(TYPEATTR)); ComType inherited; ComProject.KnownTypes.TryGetValue(attribs.guid, out inherited); var intface = inherited as ComInterface ?? new ComInterface(implemented, attribs); _inherited.Add(intface); ComProject.KnownTypes.TryAdd(attribs.guid, intface); info.ReleaseTypeAttr(attribPtr); } }
private static IEnumerable <ITypeInfo> GetReferencedEnums(ITypeLib typeLib, ITypeInfo typeInfo, Dictionary <Guid, ITypeInfo> processedTypeInfo) { if (typeInfo == null) { yield break; } var guid = typeInfo.GetOrCreateGuid(); if (processedTypeInfo.ContainsKey(guid)) { yield break; } processedTypeInfo.Add(guid, typeInfo); if (typeInfo.IsEnum()) { yield return(typeInfo); yield break; } if (typeInfo.GetContainingTypeLib().GetGuid() != typeLib.GetGuid()) { yield break; } using (var typeAttrScope = typeInfo.CreateAttrScope()) { for (var funcIndex = 0; funcIndex < typeAttrScope.Value.cFuncs; funcIndex++) { using (var funcDescScope = typeInfo.CreateFuncDescScope(funcIndex)) { foreach (var enumTypeInfo in GetReferencedEnums(typeLib, typeInfo, funcDescScope.Value, processedTypeInfo)) { yield return(enumTypeInfo); } } } for (var varIndex = 0; varIndex < typeAttrScope.Value.cVars; varIndex++) { using (var varDescScope = typeInfo.CreateVarDescScope(varIndex)) { foreach (var enumTypeInfo in GetReferencedEnums(typeLib, typeInfo, varDescScope.Value, processedTypeInfo)) { yield return(enumTypeInfo); } } } for (var implTypeIndex = 0; implTypeIndex < typeAttrScope.Value.cImplTypes; implTypeIndex++) { typeInfo.GetRefTypeOfImplType(implTypeIndex, out var href); typeInfo.GetRefTypeInfo(href, out var refTypeInfo); var refGuid = refTypeInfo.GetGuid(); if ((refGuid == typeof(IDispatch).GUID) || (refGuid == typeof(IDispatchEx).GUID)) { continue; } foreach (var enumTypeInfo in GetReferencedEnums(typeLib, refTypeInfo, processedTypeInfo)) { yield return(enumTypeInfo); } } } }
internal static ITypeInfo GetDispatchTypeInfoFromCoClassTypeInfo(ITypeInfo typeinfo) { int cImplTypes = GetTypeAttr(typeinfo).cImplTypes; ITypeInfo ppTI = null; for (int i = 0; i < cImplTypes; i++) { int num2; typeinfo.GetRefTypeOfImplType(i, out num2); typeinfo.GetRefTypeInfo(num2, out ppTI); System.Runtime.InteropServices.ComTypes.TYPEATTR typeAttr = GetTypeAttr(ppTI); if (typeAttr.typekind == System.Runtime.InteropServices.ComTypes.TYPEKIND.TKIND_DISPATCH) { return ppTI; } if (((short) (typeAttr.wTypeFlags & System.Runtime.InteropServices.ComTypes.TYPEFLAGS.TYPEFLAG_FDUAL)) != 0) { ppTI = GetDispatchTypeInfoFromCustomInterfaceTypeInfo(ppTI); if (GetTypeAttr(ppTI).typekind == System.Runtime.InteropServices.ComTypes.TYPEKIND.TKIND_DISPATCH) { return ppTI; } } } return null; }
internal static ITypeInfo GetDispatchTypeInfoFromCustomInterfaceTypeInfo(ITypeInfo typeinfo) { ITypeInfo ppTI = null; try { int num; typeinfo.GetRefTypeOfImplType(-1, out num); typeinfo.GetRefTypeInfo(num, out ppTI); } catch (COMException exception) { if (exception.ErrorCode != -2147319765) { throw; } } return ppTI; }