public TypeInfoVariable(ComTypes.ITypeInfo typeInfo, int index) { _typeInfo = typeInfo; _typeInfo.GetVarDesc(index, out _varDescPtr); _varDesc = StructHelper.ReadStructureUnsafe <ComTypes.VARDESC>(_varDescPtr); var names = new string[1]; typeInfo.GetNames(_varDesc.memid, names, 1, out var actualCount); Name = actualCount >= 1 ? names[0] : "[unnamed]"; }
internal static string GetNameOfMethod(ComTypes.ITypeInfo typeInfo, int memid) { string[] rgNames = new string[1]; typeInfo.GetNames(memid, rgNames, 1, out int _); return(rgNames[0]); }
/// <summary> /// Gets Method Signature from FuncDesc describing the method. /// </summary> /// <param name="typeinfo">ITypeInfo interface of the object.</param> /// <param name="funcdesc">FuncDesc which defines the method.</param> /// <param name="isPropertyPut">True if this is a property put; these properties take their return type from their first parameter.</param> /// <returns>Signature of the method.</returns> internal static string GetMethodSignatureFromFuncDesc(COM.ITypeInfo typeinfo, COM.FUNCDESC funcdesc, bool isPropertyPut) { StringBuilder builder = new StringBuilder(); // First value is function name int namesCount = funcdesc.cParams + 1; string[] names = new string[funcdesc.cParams + 1]; typeinfo.GetNames(funcdesc.memid, names, namesCount, out namesCount); if (!isPropertyPut) { // First get the string for return type. string retstring = GetStringFromTypeDesc(typeinfo, funcdesc.elemdescFunc.tdesc); builder.Append(retstring + " "); } // Append the function name builder.Append(names[0]); builder.Append(" ("); IntPtr ElementDescriptionArrayPtr = funcdesc.lprgelemdescParam; int ElementDescriptionSize = Marshal.SizeOf <COM.ELEMDESC>(); for (int i = 0; i < funcdesc.cParams; i++) { COM.ELEMDESC ElementDescription; int ElementDescriptionArrayByteOffset; IntPtr ElementDescriptionPointer; ElementDescription = new COM.ELEMDESC(); ElementDescriptionArrayByteOffset = i * ElementDescriptionSize; // Disable PRefast warning for converting to int32 and converting back into intptr. // Code below takes into account 32 bit vs 64 bit conversions #pragma warning disable 56515 if (IntPtr.Size == 4) { ElementDescriptionPointer = (IntPtr)(ElementDescriptionArrayPtr.ToInt32() + ElementDescriptionArrayByteOffset); } else { ElementDescriptionPointer = (IntPtr)(ElementDescriptionArrayPtr.ToInt64() + ElementDescriptionArrayByteOffset); } #pragma warning restore 56515 ElementDescription = Marshal.PtrToStructure <COM.ELEMDESC>(ElementDescriptionPointer); string paramstring = GetStringFromTypeDesc(typeinfo, ElementDescription.tdesc); if (i == 0 && isPropertyPut) // use the type of the first argument as the return type { builder.Insert(0, paramstring + " "); } else { builder.Append(paramstring); builder.Append(" " + names[i + 1]); if (i < funcdesc.cParams - 1) { builder.Append(", "); } } } builder.Append(')'); return(builder.ToString()); }