public SignatureInfoMatchTarget(TypeInfo interfaceTypeInfo, int functionIndex, ElemDesc elemDesc, int parameterIndex) { if (interfaceTypeInfo == null) throw new ArgumentNullException(nameof(interfaceTypeInfo)); m_interfaceTypeInfo = interfaceTypeInfo; m_functionIndex = functionIndex; m_funcDesc = interfaceTypeInfo.GetFuncDesc(m_functionIndex); m_elemDesc = elemDesc; m_parameterIndex = parameterIndex; if (m_parameterIndex == 0) { m_name = "return"; } else { // the name of the parameter. string[] signatureNames = m_interfaceTypeInfo.GetNames(m_funcDesc.memid, m_funcDesc.cParams + 1); m_name = signatureNames[m_parameterIndex]; if (m_name == null || m_name.Trim().Equals("")) m_name = "_unnamed_arg_" + m_parameterIndex; } // NativeParentFunctionName m_nativeParentFunctionName = m_interfaceTypeInfo.GetDocumentation(m_funcDesc.memid); // NativeSignature m_nativeSignature = (new TlbType2String(interfaceTypeInfo, m_elemDesc.tdesc)).GetTypeString(); }
/// <summary> /// If the type is aliased, return the ultimated non-aliased type if the type is user-defined, otherwise, return /// the aliased type directly. So the result could still be aliased to a built-in type. /// If the type is not aliased, just return the type directly /// </summary> public static void ResolveAlias(TypeInfo type, TypeDesc typeDesc, out TypeInfo realType, out TypeAttr realAttr) { if (type == null) throw new ArgumentNullException(nameof(type)); if (typeDesc == null) throw new ArgumentNullException(nameof(typeDesc)); if ((VarEnum)typeDesc.vt != VarEnum.VT_USERDEFINED) { // Already resolved realType = type; realAttr = type.GetTypeAttr(); return; } else { TypeInfo refType = type.GetRefTypeInfo(typeDesc.hreftype); TypeAttr refAttr = refType.GetTypeAttr(); // If the userdefined typeinfo is not itself an alias, then it is what the alias aliases. // Also, if the userdefined typeinfo is an alias to a builtin type, then the builtin // type is what the alias aliases. if (refAttr.typekind != TypeLibTypes.Interop.TYPEKIND.TKIND_ALIAS || (VarEnum)refAttr.tdescAlias.vt != VarEnum.VT_USERDEFINED) { // Resolved realType = refType; realAttr = refAttr; } else { // Continue resolving the type ResolveAlias(refType, refAttr.tdescAlias, out realType, out realAttr); } } }
public FieldInfoMatchTarget(TypeInfo parentTypeInfo, int index) { if (parentTypeInfo == null) throw new ArgumentNullException(nameof(parentTypeInfo)); m_parentTypeInfo = parentTypeInfo; m_index = index; m_varDesc = m_parentTypeInfo.GetVarDesc(m_index); m_nativeParentTypeName = m_parentTypeInfo.GetDocumentation(); }
public FunctionInfoMatchTarget(TypeInfo parentTypeInfo, int index) { if (parentTypeInfo == null) throw new ArgumentNullException(nameof(parentTypeInfo)); m_interfaceTypeInfo = parentTypeInfo; m_index = index; m_funcDesc = parentTypeInfo.GetFuncDesc(m_index); m_nativeParentTypeName = m_interfaceTypeInfo.GetDocumentation(); }
public TypeInfoMatchTarget(TypeLib typeLib, TypeInfo typeInfo, TYPEKIND typeKind) { if (typeInfo == null) throw new ArgumentNullException(nameof(typeInfo)); m_typeLib = typeLib; m_typeInfo = typeInfo; m_typeKind = typeKind; m_typeString = TypeLibUtility.TypeKind2String(m_typeKind); m_guid = typeInfo.GetTypeAttr().Guid; }
/// <summary> /// This function is used to workaround around the fact that the TypeInfo might return IUnknown/IDispatch methods (in the case of dual interfaces) /// So we should always call this function to get the first index for different TypeInfo and never save the id /// </summary> public static int GetIndexOfFirstMethod(TypeInfo type, TypeAttr attr) { if (type == null) throw new ArgumentNullException(nameof(type)); if (attr == null) throw new ArgumentNullException(nameof(attr)); if (attr.typekind != TypeLibTypes.Interop.TYPEKIND.TKIND_DISPATCH) return 0; int nIndex = 0; if (attr.cFuncs >= 3) { // Check for IUnknown first using (FuncDesc func = type.GetFuncDesc(0)) { if (func.memid == 0x60000000 && func.elemdescFunc.tdesc.vt == (int)VarEnum.VT_VOID && func.cParams == 2 && func.GetElemDesc(0).tdesc.vt == (int)VarEnum.VT_PTR && func.GetElemDesc(1).tdesc.vt == (int)VarEnum.VT_PTR && "QueryInterface" == type.GetDocumentation(func.memid)) { nIndex = 3; } } if (attr.cFuncs >= 7) { using (FuncDesc func = type.GetFuncDesc(3)) { // Check IDispatch if (func.memid == 0x60010000 && func.elemdescFunc.tdesc.vt == (int)VarEnum.VT_VOID && func.cParams == 1 && func.GetElemDesc(0).tdesc.vt == (int)VarEnum.VT_PTR && "GetTypeInfoCount" == type.GetDocumentation(func.memid)) { nIndex = 7; } } } } return nIndex; }
private static void ProcessFunctions(TypeInfo parentTypeInfo, TreeNode parentTreeNode) { using (TypeAttr attr = parentTypeInfo.GetTypeAttr()) { // // Walk through all the function/propput/propget/propref properties // for (int i = ConvCommon2.GetIndexOfFirstMethod(parentTypeInfo, attr); i < attr.cFuncs; ++i) { FunctionInfoMatchTarget functionInfo = new FunctionInfoMatchTarget(parentTypeInfo, (short) i); TreeNode funcTreeNode = new TreeNode(); if (functionInfo.FuncDesc.IsPropertyGet) { funcTreeNode.Text = functionInfo.Name + " (getter)" + ": " + functionInfo.Type; } else if (functionInfo.FuncDesc.IsPropertyPut || functionInfo.FuncDesc.IsPropertyPutRef) { funcTreeNode.Text = functionInfo.Name + " (setter)" + ": " + functionInfo.Type; } else { funcTreeNode.Text = functionInfo.Name + ": " + functionInfo.Type; } funcTreeNode.Tag = functionInfo; SetTlbTreeNodeImage(funcTreeNode); parentTreeNode.Nodes.Add(funcTreeNode); ProcessFuncParams(parentTypeInfo, functionInfo.Index, funcTreeNode); } } }
private static void ProcessFuncParams(TypeInfo interfaceTypeInfo, int funcIndex, TreeNode parentTreeNode) { int paramIndex = 0; FuncDesc funcDesc = interfaceTypeInfo.GetFuncDesc(funcIndex); ElemDesc retElemDesc = funcDesc.elemdescFunc; SignatureInfoMatchTarget retSignatureInfo = new SignatureInfoMatchTarget(interfaceTypeInfo, funcIndex, retElemDesc, paramIndex); TreeNode retTreeNode = new TreeNode(); string typeString = (new TlbType2String(interfaceTypeInfo, retElemDesc.tdesc)).GetTypeString(); retTreeNode.Text = typeString + " " + retSignatureInfo.Name + ": " + retSignatureInfo.Type; retTreeNode.Tag = retSignatureInfo; SetTlbTreeNodeImage(retTreeNode); parentTreeNode.Nodes.Add(retTreeNode); ++paramIndex; // Parameters //string[] signatureNames = interfaceTypeInfo.GetNames(funcDesc.memid, funcDesc.cParams + 1); for (int i = 0; i < funcDesc.cParams; ++i) { ElemDesc paramElemDesc = funcDesc.GetElemDesc(i); typeString = (new TlbType2String(interfaceTypeInfo, paramElemDesc.tdesc)).GetTypeString(); //string signatureName = signatureNames[i + 1]; //if (signatureName.Trim().Equals("")) // signatureName = "_unnamed_arg_" + paramIndex; SignatureInfoMatchTarget paramSignatureInfo = new SignatureInfoMatchTarget( interfaceTypeInfo, funcIndex, paramElemDesc, paramIndex); TreeNode paramTreeNode = new TreeNode(); paramTreeNode.Text = typeString + " " + paramSignatureInfo.Name + ": " + paramSignatureInfo.Type; ++paramIndex; paramTreeNode.Tag = paramSignatureInfo; SetTlbTreeNodeImage(paramTreeNode); parentTreeNode.Nodes.Add(paramTreeNode); } }
private static void ProcessFields(TypeInfo parentTypeInfo, TreeNode parentTreeNode) { // // Walk through all vars (including elements from structs and disp interface, ...) // using (TypeAttr attr = parentTypeInfo.GetTypeAttr()) { for (int i = 0; i < attr.cVars; ++i) { FieldInfoMatchTarget variableInfo = new FieldInfoMatchTarget(parentTypeInfo, i); TreeNode dispVarTreeNode = new TreeNode(); dispVarTreeNode.Text = variableInfo.Name + ": " + variableInfo.Type; dispVarTreeNode.Tag = variableInfo; SetTlbTreeNodeImage(dispVarTreeNode); parentTreeNode.Nodes.Add(dispVarTreeNode); } } }
public TypeInfo GetUserDefinedTypeInfo(TypeInfo typeinfo) { if (typeinfo == null) throw new ArgumentNullException(nameof(typeinfo)); return typeinfo.GetRefTypeInfo(hreftype); }