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();
        }
 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();
 }
示例#3
0
        /// <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 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);
            }
        }
示例#5
0
        public static bool HasNewEnumMember(ConverterInfo info, TypeInfo typeInfo, string fullName)
        {
            bool hasNewEnumMember = false;
            bool hasDuplicateNewEnumMember = false;
            int firstNewEnum = -1;

            using (TypeAttr attr = typeInfo.GetTypeAttr())
            {
                if (attr.IsDispatch ||
                    (attr.IsInterface && ConvCommon.IsDerivedFromIDispatch(typeInfo)))
                {
                    // Check to see if the interface has a function with a DISPID of DISPID_NEWENUM.
                    for (int i = 0; i < attr.cFuncs; ++i)
                    {
                        using(FuncDesc func = typeInfo.GetFuncDesc(i))
                        {
                            if (IsNewEnumFunc(info, typeInfo, func, i))
                            {
                                if (!hasNewEnumMember)
                                    firstNewEnum = func.memid;

                                if (hasNewEnumMember)
                                    hasDuplicateNewEnumMember = true;

                                // The interface has a function with a DISPID of DISPID_NEWENUM.
                                hasNewEnumMember = true;
                            }
                        }
                    }

                    // Check to see if the interface as a property with a DISPID of DISPID_NEWENUM.
                    for (int i = 0; i < attr.cVars; ++i)
                    {
                        using (VarDesc varDesc = typeInfo.GetVarDesc(i))
                        {
                            if (IsNewEnumDispatchProperty(info, typeInfo, varDesc, i))
                            {
                                if (!hasNewEnumMember)
                                    firstNewEnum = varDesc.memid;

                                if (hasNewEnumMember)
                                    hasDuplicateNewEnumMember = true;

                                // The interface has a property with a DISPID of DISPID_NEWENUM.
                                hasNewEnumMember = true;
                            }
                        }
                    }

                    // Check to see if the ForceIEnumerable custom value exists on the type
                    if (HasForceIEnumerableCustomAttribute(typeInfo))
                        hasNewEnumMember = true;

                    if (hasDuplicateNewEnumMember)
                    {
                        info.ReportEvent(
                            WarningCode.Wrn_MultiNewEnum,
                            Resource.FormatString("Wrn_MultiNewEnum", fullName, typeInfo.GetDocumentation(firstNewEnum)));
                    }
                }
                else
                {
                    // Check to see if the ForceIEnumerable custom value exists on the type
                    //  If it does, spit out a warning.
                    if (HasForceIEnumerableCustomAttribute(typeInfo))
                    {
                        string msg = Resource.FormatString(
                            "Wrn_IEnumCustomAttributeOnIUnknown",
                            CustomAttributeGuids.GUID_ForceIEnumerable.ToString().ToUpper(),
                            typeInfo.GetDocumentation());

                        info.ReportEvent(WarningCode.Wrn_IEnumCustomAttributeOnIUnknown, msg);
                    }
                }
            }

            return hasNewEnumMember;
        }