示例#1
0
        internal static string GetNameFromFuncDesc(ITypeInfo typeinfo, System.Runtime.InteropServices.ComTypes.FUNCDESC funcdesc)
        {
            string strName;

            typeinfo.GetDocumentation(funcdesc.memid, out strName, out string _, out int _, out string _);
            return(strName);
        }
示例#2
0
        private void Initialize()
        {
            if (this.typeinfo != null)
            {
                System.Runtime.InteropServices.ComTypes.TYPEATTR typeAttr = GetTypeAttr(this.typeinfo);
                this.guid = typeAttr.guid;
                for (int i = 0; i < typeAttr.cFuncs; i++)
                {
                    string nameFromFuncDesc;
                    System.Runtime.InteropServices.ComTypes.FUNCDESC funcDesc = GetFuncDesc(this.typeinfo, i);
                    if ((funcDesc.wFuncFlags & 1) != 1)
                    {
                        nameFromFuncDesc = ComUtil.GetNameFromFuncDesc(this.typeinfo, funcDesc);
                        switch (funcDesc.invkind)
                        {
                        case System.Runtime.InteropServices.ComTypes.INVOKEKIND.INVOKE_FUNC:
                            this.AddMethod(nameFromFuncDesc, i);
                            break;

                        case System.Runtime.InteropServices.ComTypes.INVOKEKIND.INVOKE_PROPERTYGET:
                        case System.Runtime.InteropServices.ComTypes.INVOKEKIND.INVOKE_PROPERTYPUT:
                        case System.Runtime.InteropServices.ComTypes.INVOKEKIND.INVOKE_PROPERTYPUTREF:
                            goto Label_0075;
                        }
                    }
                    continue;
Label_0075:
                    this.AddProperty(nameFromFuncDesc, funcDesc, i);
                }
            }
        }
        private DeclarationType GetDeclarationType(string memberName, FUNCDESC funcDesc, VarEnum funcValueType, TYPEKIND typekind, IMPLTYPEFLAGS parentImplTypeFlags)
        {
            DeclarationType memberType;

            if (funcDesc.invkind.HasFlag(INVOKEKIND.INVOKE_PROPERTYGET))
            {
                memberType = DeclarationType.PropertyGet;
            }
            else if (funcDesc.invkind.HasFlag(INVOKEKIND.INVOKE_PROPERTYPUT))
            {
                memberType = DeclarationType.PropertyLet;
            }
            else if (funcDesc.invkind.HasFlag(INVOKEKIND.INVOKE_PROPERTYPUTREF))
            {
                memberType = DeclarationType.PropertySet;
            }
            else if ((parentImplTypeFlags.HasFlag(IMPLTYPEFLAGS.IMPLTYPEFLAG_FSOURCE) ||
                      ((FUNCFLAGS)funcDesc.wFuncFlags).HasFlag(FUNCFLAGS.FUNCFLAG_FSOURCE)))
            {
                memberType = DeclarationType.Event;
            }
            else if (funcValueType == VarEnum.VT_VOID)
            {
                memberType = DeclarationType.Procedure;
            }
            else
            {
                memberType = DeclarationType.Function;
            }
            return(memberType);
        }
示例#4
0
        private DeclarationType GetDeclarationType(FUNCDESC funcDesc, VarEnum funcValueType, TYPEKIND typekind)
        {
            DeclarationType memberType;

            if (funcDesc.invkind.HasFlag(INVOKEKIND.INVOKE_PROPERTYGET))
            {
                memberType = DeclarationType.PropertyGet;
            }
            else if (funcDesc.invkind.HasFlag(INVOKEKIND.INVOKE_PROPERTYPUT))
            {
                memberType = DeclarationType.PropertyLet;
            }
            else if (funcDesc.invkind.HasFlag(INVOKEKIND.INVOKE_PROPERTYPUTREF))
            {
                memberType = DeclarationType.PropertySet;
            }
            else if (funcValueType == VarEnum.VT_VOID)
            {
                memberType = DeclarationType.Procedure;
            }
            else if (funcDesc.funckind == FUNCKIND.FUNC_PUREVIRTUAL && typekind == TYPEKIND.TKIND_COCLASS)
            {
                memberType = DeclarationType.Event;
            }
            else
            {
                memberType = DeclarationType.Function;
            }
            return(memberType);
        }
示例#5
0
        internal ComMethodDesc(ITypeInfo typeInfo, FUNCDESC funcDesc)
            : this(funcDesc.memid) {

            _hasTypeInfo = true;
            InvokeKind = funcDesc.invkind;

            int cNames;
            string[] rgNames = new string[1 + funcDesc.cParams];
            typeInfo.GetNames(_memid, rgNames, rgNames.Length, out cNames);
            if (IsPropertyPut && rgNames[rgNames.Length - 1] == null) {
                rgNames[rgNames.Length - 1] = "value";
                cNames++;
            }
            Debug.Assert(cNames == rgNames.Length);
            _name = rgNames[0];

            _parameters = new ComParamDesc[funcDesc.cParams];

            int offset = 0;
            for (int i = 0; i < funcDesc.cParams; i++) {
                ELEMDESC elemDesc = (ELEMDESC)Marshal.PtrToStructure(
                    new IntPtr(funcDesc.lprgelemdescParam.ToInt64() + offset),
                    typeof(ELEMDESC));

                _parameters[i] = new ComParamDesc(ref elemDesc, rgNames[1 + i]);

                offset += Marshal.SizeOf(typeof(ELEMDESC));
            }
        }
示例#6
0
        private void SetDeclarationType(FUNCDESC funcDesc, ITypeInfo info)
        {
            if (funcDesc.invkind.HasFlag(INVOKEKIND.INVOKE_PROPERTYGET))
            {
                Type = DeclarationType.PropertyGet;
            }
            else if (funcDesc.invkind.HasFlag(INVOKEKIND.INVOKE_PROPERTYPUT))
            {
                Type = DeclarationType.PropertyLet;
            }
            else if (funcDesc.invkind.HasFlag(INVOKEKIND.INVOKE_PROPERTYPUTREF))
            {
                Type = DeclarationType.PropertySet;
            }
            else if ((VarEnum)funcDesc.elemdescFunc.tdesc.vt == VarEnum.VT_VOID)
            {
                Type = DeclarationType.Procedure;
            }
            else
            {
                Type = DeclarationType.Function;
            }

            if (Type == DeclarationType.Function || Type == DeclarationType.PropertyGet)
            {
                ReturnType = new ComParameter(funcDesc.elemdescFunc, info, string.Empty);
            }
        }
示例#7
0
        private void Initialize()
        {
            using (ComTypeInfo.tracer.TraceMethod())
            {
                if (this.typeinfo == null)
                {
                    return;
                }
                System.Runtime.InteropServices.ComTypes.TYPEATTR typeAttr = ComTypeInfo.GetTypeAttr(this.typeinfo);
                this.guid = typeAttr.guid;
                for (int firstUserMethod = ComTypeInfo.FindFirstUserMethod(typeAttr); firstUserMethod < (int)typeAttr.cFuncs; ++firstUserMethod)
                {
                    System.Runtime.InteropServices.ComTypes.FUNCDESC funcDesc = ComTypeInfo.GetFuncDesc(this.typeinfo, firstUserMethod);
                    string nameFromFuncDesc = ComUtil.GetNameFromFuncDesc(this.typeinfo, funcDesc);
                    switch (funcDesc.invkind)
                    {
                    case System.Runtime.InteropServices.ComTypes.INVOKEKIND.INVOKE_FUNC:
                        this.AddMethod(nameFromFuncDesc, firstUserMethod);
                        break;

                    case System.Runtime.InteropServices.ComTypes.INVOKEKIND.INVOKE_PROPERTYGET:
                    case System.Runtime.InteropServices.ComTypes.INVOKEKIND.INVOKE_PROPERTYPUT:
                    case System.Runtime.InteropServices.ComTypes.INVOKEKIND.INVOKE_PROPERTYPUTREF:
                        this.AddProperty(nameFromFuncDesc, funcDesc, firstUserMethod);
                        break;
                    }
                }
            }
        }
示例#8
0
        private void LoadParameters(FUNCDESC funcDesc, ITypeInfo info)
        {
            var names = new string[255];

            info.GetNames(Index, names, names.Length, out _);

            for (var index = 0; index < funcDesc.cParams; index++)
            {
                var paramPtr = new IntPtr(funcDesc.lprgelemdescParam.ToInt64() + Marshal.SizeOf(typeof(ELEMDESC)) * index);
                var elemDesc = Marshal.PtrToStructure <ELEMDESC>(paramPtr);
                var param    = new ComParameter(this, elemDesc, info, names[index + 1] ?? $"{index}unnamedParameter");
                _parameters.Add(param);
            }

            // See https://docs.microsoft.com/en-us/windows/desktop/midl/propput
            // "A function that has the [propput] attribute must also have, as its last parameter, a parameter that has the [in] attribute."
            if (funcDesc.invkind.HasFlag(INVOKEKIND.INVOKE_PROPERTYPUTREF) ||
                funcDesc.invkind.HasFlag(INVOKEKIND.INVOKE_PROPERTYPUT))
            {
                AsTypeName  = _parameters.Last();
                _parameters = _parameters.Take(funcDesc.cParams - 1).ToList();
                return;
            }

            if (Parameters.Any() && funcDesc.cParamsOpt == -1)
            {
                Parameters.Last().IsParamArray = true;
            }
        }
示例#9
0
        /// <summary>
        /// Updates the COM property with setter and getter information.
        /// </summary>
        /// <param name="desc">functional descriptor for property getter or setter</param>
        /// <param name="index">index of function descriptor in type information</param>
        internal void UpdateFuncDesc(COM.FUNCDESC desc, int index)
        {
            _dispId = desc.memid;
            switch (desc.invkind)
            {
            case COM.INVOKEKIND.INVOKE_PROPERTYGET:
                IsGettable   = true;
                _getterIndex = index;

                if (desc.cParams > 0)
                {
                    IsParameterized = true;
                }
                break;

            case COM.INVOKEKIND.INVOKE_PROPERTYPUT:
                _hasSetter   = true;
                _setterIndex = index;

                if (desc.cParams > 1)
                {
                    IsParameterized = true;
                }
                break;

            case COM.INVOKEKIND.INVOKE_PROPERTYPUTREF:
                _setterByRefIndex = index;
                _hasSetterByRef   = true;
                if (desc.cParams > 1)
                {
                    IsParameterized = true;
                }
                break;
            }
        }
示例#10
0
        internal MethodInfo(FUNCDESC funcDesc, ITypeInfo info, IVbaTypeRepository repo)
        {
            Contract.Requires <ArgumentNullException>(info != null);
            Contract.Requires <ArgumentNullException>(repo != null);

            BuildMethod(funcDesc, info, repo);
            RewriteHResult();
        }
示例#11
0
 /// <summary>
 /// Gets the name of the method or property defined by funcdesc.
 /// </summary>
 /// <param name="typeinfo">ITypeInfo interface of the type.</param>
 /// <param name="funcdesc">FuncDesc of property of method.</param>
 /// <returns>Name of the method or property.</returns>
 internal static string GetNameFromFuncDesc(COM.ITypeInfo typeinfo, COM.FUNCDESC funcdesc)
 {
     // Get the method or property name.
     string strName, strDoc, strHelp;
     int id;
     typeinfo.GetDocumentation(funcdesc.memid, out strName, out strDoc, out id, out strHelp);
     return strName;
 }
示例#12
0
        /// <summary>
        /// Obtains the parameter information for a given FuncDesc.
        /// </summary>
        internal static ParameterInformation[] GetParameterInformation(COM.FUNCDESC funcdesc, bool skipLastParameter)
        {
            int cParams = funcdesc.cParams;

            if (skipLastParameter)
            {
                Diagnostics.Assert(cParams > 0, "skipLastParameter is only true for property setters where there is at least one parameter");
                cParams--;
            }

            ParameterInformation[] parameters = new ParameterInformation[cParams];

            IntPtr ElementDescriptionArrayPtr = funcdesc.lprgelemdescParam;
            int    ElementDescriptionSize     = Marshal.SizeOf <COM.ELEMDESC>();

            for (int i = 0; i < cParams; i++)
            {
                COM.ELEMDESC ElementDescription;
                int          ElementDescriptionArrayByteOffset;
                IntPtr       ElementDescriptionPointer;
                bool         fOptional = false;

                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 enable 56515

                ElementDescription = Marshal.PtrToStructure <COM.ELEMDESC>(ElementDescriptionPointer);

                // get the type of parameter
                Type   type         = ComUtil.GetTypeFromTypeDesc(ElementDescription.tdesc);
                object defaultvalue = null;

                // check is this parameter is optional.
                if ((ElementDescription.desc.paramdesc.wParamFlags & COM.PARAMFLAG.PARAMFLAG_FOPT) != 0)
                {
                    fOptional    = true;
                    defaultvalue = Type.Missing;
                }

                bool fByRef = (ElementDescription.desc.paramdesc.wParamFlags & COM.PARAMFLAG.PARAMFLAG_FOUT) != 0;
                parameters[i] = new ParameterInformation(type, fOptional, defaultvalue, fByRef);
            }

            return(parameters);
        }
示例#13
0
        internal static COM.FUNCDESC GetFuncDesc(COM.ITypeInfo typeinfo, int index)
        {
            IntPtr pFuncDesc;

            typeinfo.GetFuncDesc(index, out pFuncDesc);
            COM.FUNCDESC funcdesc = Marshal.PtrToStructure <COM.FUNCDESC>(pFuncDesc);
            typeinfo.ReleaseFuncDesc(pFuncDesc);
            return(funcdesc);
        }
示例#14
0
        internal static System.Runtime.InteropServices.ComTypes.FUNCDESC GetFuncDesc(ITypeInfo typeinfo, int index)
        {
            IntPtr ptr;

            typeinfo.GetFuncDesc(index, out ptr);
            System.Runtime.InteropServices.ComTypes.FUNCDESC funcdesc = (System.Runtime.InteropServices.ComTypes.FUNCDESC)Marshal.PtrToStructure(ptr, typeof(System.Runtime.InteropServices.ComTypes.FUNCDESC));
            typeinfo.ReleaseFuncDesc(ptr);
            return(funcdesc);
        }
示例#15
0
 internal static IEnumerable <ComTypes.ELEMDESC> GetElemDescs(ComTypes.FUNCDESC funcDesc)
 {
     for (var iParam = 0; iParam < funcDesc.cParams; iParam++)
     {
         yield return((ComTypes.ELEMDESC)Marshal.PtrToStructure(
                          new IntPtr(funcDesc.lprgelemdescParam.ToInt64() +
                                     Marshal.SizeOf(typeof(ComTypes.ELEMDESC)) * iParam),
                          typeof(ComTypes.ELEMDESC)));
     }
 }
示例#16
0
        internal static string GetNameFromFuncDesc(ITypeInfo typeinfo, System.Runtime.InteropServices.ComTypes.FUNCDESC funcdesc)
        {
            string str;
            string str2;
            string str3;
            int    num;

            typeinfo.GetDocumentation(funcdesc.memid, out str, out str2, out num, out str3);
            return(str);
        }
示例#17
0
 public ComMember(ITypeInfo info, FUNCDESC funcDesc) : base(info, funcDesc)
 {                      
     LoadParameters(funcDesc, info);
     var flags = (FUNCFLAGS)funcDesc.wFuncFlags;
     IsHidden = flags.HasFlag(FUNCFLAGS.FUNCFLAG_FHIDDEN);
     IsRestricted = flags.HasFlag(FUNCFLAGS.FUNCFLAG_FRESTRICTED);
     ReturnsWithEventsObject = flags.HasFlag(FUNCFLAGS.FUNCFLAG_FSOURCE);
     IsDefault = Index == (int)DispId.Value;
     IsEnumerator = Index == (int)DispId.NewEnum;
     IsEvaluateFunction = Index == (int)DispId.Evaluate;
     SetDeclarationType(funcDesc, info);
 }
示例#18
0
        public ComFunctionInfo(ComTypeInfo parent, IntPtr pFuncDesc)
            : base(parent)
        {
            _pFuncDesc = pFuncDesc;
            _funcDesc = pFuncDesc.ToStructure < System.Runtime.InteropServices.ComTypes.FUNCDESC>();
            _comTypeInfo.GetITypeInfo().GetDocumentation(_funcDesc.memid, out _name, out _description, out _helpContext, out _helpFile);

            if (_description == null) _description = String.Empty;
            if (_helpFile == null) _helpFile = String.Empty;

            LoadParameters();
        }
        private ParameterDeclaration CreateParameterDeclaration(IReadOnlyList <string> memberNames, int paramIndex,
                                                                FUNCDESC memberDescriptor, QualifiedModuleName typeQualifiedModuleName, Declaration memberDeclaration, ITypeInfo info)
        {
            var paramName = memberNames[paramIndex + 1];

            var paramPointer = new IntPtr(memberDescriptor.lprgelemdescParam.ToInt64() + Marshal.SizeOf(typeof(ELEMDESC)) * paramIndex);
            var elementDesc  = (ELEMDESC)Marshal.PtrToStructure(paramPointer, typeof(ELEMDESC));
            var isOptional   = elementDesc.desc.paramdesc.wParamFlags.HasFlag(PARAMFLAG.PARAMFLAG_FOPT);
            var paramDesc    = elementDesc.tdesc;
            var paramInfo    = GetParameterInfo(paramDesc, info);

            return(new ParameterDeclaration(new QualifiedMemberName(typeQualifiedModuleName, paramName), memberDeclaration, paramInfo.Name, null, null, isOptional, paramInfo.IsByRef, paramInfo.IsArray));
        }
示例#20
0
        public TypeInfoFunc(TypeInfoWrapper typeInfo, int funcIndex)
        {
            _typeInfo = typeInfo;

            ((ComTypes.ITypeInfo)_typeInfo).GetFuncDesc(funcIndex, out _funcDescPtr);
            FuncDesc = StructHelper.ReadStructureUnsafe <ComTypes.FUNCDESC>(_funcDescPtr);

            ((ComTypes.ITypeInfo)_typeInfo).GetNames(FuncDesc.memid, _names, _names.Length, out _cNames);
            if (_cNames == 0)
            {
                _names[0] = "[unnamed]";
            }
        }
示例#21
0
        private void AddProperty(string strName, COM.FUNCDESC funcdesc, int index)
        {
            ComProperty prop;

            if (!_properties.TryGetValue(strName, out prop))
            {
                prop = new ComProperty(_typeinfo, strName);
                _properties[strName] = prop;
            }

            if (prop != null)
            {
                prop.UpdateFuncDesc(funcdesc, index);
            }
        }
示例#22
0
        internal Collection <string> MethodDefinitions()
        {
            Collection <string> collection = new Collection <string>();

            foreach (int num in this.methods)
            {
                IntPtr ptr;
                this.typeInfo.GetFuncDesc(num, out ptr);
                System.Runtime.InteropServices.ComTypes.FUNCDESC funcdesc = (System.Runtime.InteropServices.ComTypes.FUNCDESC)Marshal.PtrToStructure(ptr, typeof(System.Runtime.InteropServices.ComTypes.FUNCDESC));
                string item = ComUtil.GetMethodSignatureFromFuncDesc(this.typeInfo, funcdesc, false);
                collection.Add(item);
                this.typeInfo.ReleaseFuncDesc(ptr);
            }
            return(collection);
        }
示例#23
0
        private void AddProperty(string strName, System.Runtime.InteropServices.ComTypes.FUNCDESC funcdesc, int index)
        {
            ComProperty comProperty;

            if (this.properties.ContainsKey(strName))
            {
                comProperty = this.properties[strName];
            }
            else
            {
                comProperty = new ComProperty(this.typeinfo, strName);
                this.properties[strName] = comProperty;
            }
            comProperty?.UpdateFuncDesc(funcdesc, index);
        }
示例#24
0
        public MethodDesc(ITypeInfo typeInfo, FUNCDESC funcDesc)
        {
            // Initialise the standard member information.

            string name;
            string docString;
            int    helpContext;
            string helpFile;

            typeInfo.GetDocumentation(funcDesc.memid, out name, out docString, out helpContext, out helpFile);
            Initialise(MemberTypes.Method, name);

            // Get the names of the parameters (index 0 corresponds to the method name itself).

            string[] names = new string[funcDesc.cParams + 1];
            int      nameCount;

            typeInfo.GetNames(funcDesc.memid, names, funcDesc.cParams + 1, out nameCount);

            // Need to account for the return value if there is one.

            bool includeReturnParam = (VarEnum)funcDesc.elemdescFunc.tdesc.vt != VarEnum.VT_VOID &&
                                      (VarEnum)funcDesc.elemdescFunc.tdesc.vt != VarEnum.VT_HRESULT;

            int paramCount = funcDesc.cParams + (includeReturnParam ? 1 : 0);

            m_parameters = new ParameterDesc[paramCount];

            // Iterate over the specified parameters.

            for (int index = 0; index < funcDesc.cParams; ++index)
            {
                // Extract the ELEMDESC.

                IntPtr ptr = (IntPtr)(funcDesc.lprgelemdescParam.ToInt64()
                                      + (long)(Marshal.SizeOf(typeof(ELEMDESC)) * index));
                ELEMDESC elemdesc = (ELEMDESC)Marshal.PtrToStructure(ptr, typeof(ELEMDESC));

                m_parameters[index] = new ParameterDesc(names[index + 1], GetComType(typeInfo, elemdesc.tdesc), elemdesc.desc.idldesc.wIDLFlags);
            }

            // Now add the return value if needed.

            if (includeReturnParam)
            {
                m_parameters[paramCount - 1] = new ParameterDesc("ret", GetComType(typeInfo, funcDesc.elemdescFunc.tdesc) + "*", funcDesc.elemdescFunc.desc.idldesc.wIDLFlags | IDLFLAG.IDLFLAG_FOUT | IDLFLAG.IDLFLAG_FRETVAL);
            }
        }
示例#25
0
#pragma warning restore 618

        /// <summary>
        /// Converts a FuncDesc out of GetFuncDesc into a MethodInformation.
        /// </summary>
        private static ComMethodInformation GetMethodInformation(COM.FUNCDESC funcdesc, bool skipLastParameter)
        {
            Type returntype = GetTypeFromTypeDesc(funcdesc.elemdescFunc.tdesc);
            ParameterInformation[] parameters = GetParameterInformation(funcdesc, skipLastParameter);
            bool hasOptional = false;
            foreach (ParameterInformation p in parameters)
            {
                if (p.isOptional)
                {
                    hasOptional = true;
                    break;
                }
            }

            return new ComMethodInformation(false, hasOptional, parameters, returntype, funcdesc.memid, funcdesc.invkind);
        }
示例#26
0
        internal static ComMethodInformation[] GetMethodInformationArray(ITypeInfo typeInfo, Collection <int> methods, bool skipLastParameters)
        {
            int count = methods.Count;
            int num2  = 0;

            ComMethodInformation[] informationArray = new ComMethodInformation[count];
            foreach (int num3 in methods)
            {
                IntPtr ptr;
                typeInfo.GetFuncDesc(num3, out ptr);
                System.Runtime.InteropServices.ComTypes.FUNCDESC funcdesc = (System.Runtime.InteropServices.ComTypes.FUNCDESC)Marshal.PtrToStructure(ptr, typeof(System.Runtime.InteropServices.ComTypes.FUNCDESC));
                informationArray[num2++] = GetMethodInformation(funcdesc, skipLastParameters);
                typeInfo.ReleaseFuncDesc(ptr);
            }
            return(informationArray);
        }
示例#27
0
        internal static ParameterInformation[] GetParameterInformation(System.Runtime.InteropServices.ComTypes.FUNCDESC funcdesc, bool skipLastParameter)
        {
            int cParams = funcdesc.cParams;

            if (skipLastParameter)
            {
                cParams--;
            }
            ParameterInformation[] informationArray = new ParameterInformation[cParams];
            IntPtr lprgelemdescParam = funcdesc.lprgelemdescParam;
            int    num2 = Marshal.SizeOf(typeof(System.Runtime.InteropServices.ComTypes.ELEMDESC));

            for (int i = 0; i < cParams; i++)
            {
                IntPtr ptr2;
                bool   isOptional = false;
                System.Runtime.InteropServices.ComTypes.ELEMDESC elemdesc = new System.Runtime.InteropServices.ComTypes.ELEMDESC();
                int num4 = i * num2;
                if (IntPtr.Size == 4)
                {
                    ptr2 = (IntPtr)(lprgelemdescParam.ToInt32() + num4);
                }
                else
                {
                    ptr2 = (IntPtr)(lprgelemdescParam.ToInt64() + num4);
                }
                elemdesc = (System.Runtime.InteropServices.ComTypes.ELEMDESC)Marshal.PtrToStructure(ptr2, typeof(System.Runtime.InteropServices.ComTypes.ELEMDESC));
                Type   typeFromTypeDesc = GetTypeFromTypeDesc(elemdesc.tdesc);
                object defaultValue     = null;
                if (((short)(elemdesc.desc.paramdesc.wParamFlags & (System.Runtime.InteropServices.ComTypes.PARAMFLAG.PARAMFLAG_NONE | System.Runtime.InteropServices.ComTypes.PARAMFLAG.PARAMFLAG_FOPT))) != 0)
                {
                    isOptional   = true;
                    defaultValue = Type.Missing;
                }
                else
                {
                    isOptional = false;
                }
                bool isByRef = false;
                if (((short)(elemdesc.desc.paramdesc.wParamFlags & (System.Runtime.InteropServices.ComTypes.PARAMFLAG.PARAMFLAG_NONE | System.Runtime.InteropServices.ComTypes.PARAMFLAG.PARAMFLAG_FOUT))) != 0)
                {
                    isByRef = true;
                }
                informationArray[i] = new ParameterInformation(typeFromTypeDesc, isOptional, defaultValue, isByRef);
            }
            return(informationArray);
        }
示例#28
0
        /// <summary>
        /// Converts a MethodBase[] into a MethodInformation[]
        /// </summary>
        /// <returns>the ComMethodInformation[] corresponding to methods</returns>
        internal static ComMethodInformation[] GetMethodInformationArray(COM.ITypeInfo typeInfo, Collection <int> methods, bool skipLastParameters)
        {
            int methodCount = methods.Count;
            int count       = 0;

            ComMethodInformation[] returnValue = new ComMethodInformation[methodCount];

            foreach (int index in methods)
            {
                IntPtr pFuncDesc;
                typeInfo.GetFuncDesc(index, out pFuncDesc);
                COM.FUNCDESC funcdesc = ClrFacade.PtrToStructure <COM.FUNCDESC>(pFuncDesc);
                returnValue[count++] = ComUtil.GetMethodInformation(funcdesc, skipLastParameters);
                typeInfo.ReleaseFuncDesc(pFuncDesc);
            }
            return(returnValue);
        }
示例#29
0
        private static ComMethodInformation GetMethodInformation(System.Runtime.InteropServices.ComTypes.FUNCDESC funcdesc, bool skipLastParameter)
        {
            Type typeFromTypeDesc = GetTypeFromTypeDesc(funcdesc.elemdescFunc.tdesc);

            ParameterInformation[] parameterInformation = GetParameterInformation(funcdesc, skipLastParameter);
            bool hasoptional = false;

            foreach (ParameterInformation information in parameterInformation)
            {
                if (information.isOptional)
                {
                    hasoptional = true;
                    break;
                }
            }
            return(new ComMethodInformation(false, hasoptional, parameterInformation, typeFromTypeDesc));
        }
示例#30
0
        internal ComMethodDesc(ITypeInfo typeInfo, FUNCDESC funcDesc)
            : this(funcDesc.memid) {

            InvokeKind = funcDesc.invkind;

            int cNames;
            string[] rgNames = new string[1 + funcDesc.cParams];
            typeInfo.GetNames(_memid, rgNames, rgNames.Length, out cNames);
            if (IsPropertyPut && rgNames[rgNames.Length - 1] == null) {
                rgNames[rgNames.Length - 1] = "value";
                cNames++;
            }
            Debug.Assert(cNames == rgNames.Length);
            _name = rgNames[0];

            _paramCnt = funcDesc.cParams;
        }
示例#31
0
        /// <summary>
        /// Initializes the typeinfo object.
        /// </summary>
        private void Initialize()
        {
            if (_typeinfo != null)
            {
                COM.TYPEATTR typeattr = GetTypeAttr(_typeinfo);

                // Initialize the type information guid
                _guid = typeattr.guid;

                for (int i = 0; i < typeattr.cFuncs; i++)
                {
                    COM.FUNCDESC funcdesc = GetFuncDesc(_typeinfo, i);
                    if (funcdesc.memid == DISPID_NEWENUM)
                    {
                        NewEnumInvokeKind = funcdesc.invkind;
                    }

                    if ((funcdesc.wFuncFlags & 0x1) == 0x1)
                    {
                        // https://msdn.microsoft.com/library/ee488948.aspx
                        // FUNCFLAGS -- FUNCFLAG_FRESTRICTED = 0x1:
                        //     Indicates that the function should not be accessible from macro languages.
                        //     This flag is intended for system-level functions or functions that type browsers should not display.
                        //
                        // For IUnknown methods (AddRef, QueryInterface and Release) and IDispatch methods (GetTypeInfoCount, GetTypeInfo, GetIDsOfNames and Invoke)
                        // FUNCFLAG_FRESTRICTED (0x1) is set for the 'wFuncFlags' field
                        continue;
                    }

                    string strName = ComUtil.GetNameFromFuncDesc(_typeinfo, funcdesc);

                    switch (funcdesc.invkind)
                    {
                    case COM.INVOKEKIND.INVOKE_PROPERTYGET:
                    case COM.INVOKEKIND.INVOKE_PROPERTYPUT:
                    case COM.INVOKEKIND.INVOKE_PROPERTYPUTREF:
                        AddProperty(strName, funcdesc, i);
                        break;

                    case COM.INVOKEKIND.INVOKE_FUNC:
                        AddMethod(strName, i);
                        break;
                    }
                }
            }
        }
示例#32
0
        private void AddMemberFunctions(SortedList members, int count)
        {
            for (int index = 0; index < count; ++index)
            {
                IntPtr funcptr = IntPtr.Zero;
                m_typeInfo.ComType.GetFuncDesc(index, out funcptr);
                FUNCDESC funcDesc = (FUNCDESC)Marshal.PtrToStructure(funcptr, typeof(FUNCDESC));

                try
                {
                    string memberNodeText;

                    // Only add the method if it is not restricted (removes IUnknown, IDispatch methods etc).

                    if ((funcDesc.wFuncFlags & (short)FUNCFLAGS.FUNCFLAG_FRESTRICTED) == 0)
                    {
                        switch (funcDesc.invkind)
                        {
                        case INVOKEKIND.INVOKE_FUNC:
                            MethodDesc methodDesc = new MethodDesc(m_typeInfo.ComType, funcDesc);
                            memberNodeText = methodDesc.Name + "(" + GetParameterTypes(methodDesc.Parameters) + ")";
                            members.Add(new ComMemberBrowserInfo(this, methodDesc, memberNodeText), memberNodeText);
                            break;

                        case INVOKEKIND.INVOKE_PROPERTYGET:
                        case INVOKEKIND.INVOKE_PROPERTYPUT:
                        case INVOKEKIND.INVOKE_PROPERTYPUTREF:
                            PropertyDesc propertyDesc = new PropertyDesc(m_typeInfo.ComType, funcDesc);
                            memberNodeText = propertyDesc.Name + GetPropertyKind(propertyDesc)
                                             + " (" + GetParameterTypes(propertyDesc.Parameters) + ")";
                            members.Add(new ComMemberBrowserInfo(this, propertyDesc, memberNodeText), memberNodeText);
                            break;

                        default:
                            Debug.Fail("Unexpected value of funcDesc.invkind: " + funcDesc.invkind.ToString());
                            break;
                        }
                    }
                }
                finally
                {
                    m_typeInfo.ComType.ReleaseFuncDesc(funcptr);
                }
            }
        }
示例#33
0
        internal static string GetMethodSignatureFromFuncDesc(ITypeInfo typeinfo, System.Runtime.InteropServices.ComTypes.FUNCDESC funcdesc, bool isPropertyPut)
        {
            StringBuilder builder          = new StringBuilder();
            string        nameFromFuncDesc = GetNameFromFuncDesc(typeinfo, funcdesc);

            if (!isPropertyPut)
            {
                builder.Append(GetStringFromTypeDesc(typeinfo, funcdesc.elemdescFunc.tdesc) + " ");
            }
            builder.Append(nameFromFuncDesc);
            builder.Append(" (");
            IntPtr lprgelemdescParam = funcdesc.lprgelemdescParam;
            int    num = Marshal.SizeOf(typeof(System.Runtime.InteropServices.ComTypes.ELEMDESC));

            for (int i = 0; i < funcdesc.cParams; i++)
            {
                IntPtr ptr2;
                System.Runtime.InteropServices.ComTypes.ELEMDESC elemdesc = new System.Runtime.InteropServices.ComTypes.ELEMDESC();
                int num3 = i * num;
                if (IntPtr.Size == 4)
                {
                    ptr2 = (IntPtr)(lprgelemdescParam.ToInt32() + num3);
                }
                else
                {
                    ptr2 = (IntPtr)(lprgelemdescParam.ToInt64() + num3);
                }
                elemdesc = (System.Runtime.InteropServices.ComTypes.ELEMDESC)Marshal.PtrToStructure(ptr2, typeof(System.Runtime.InteropServices.ComTypes.ELEMDESC));
                string stringFromTypeDesc = GetStringFromTypeDesc(typeinfo, elemdesc.tdesc);
                if ((i == 0) && isPropertyPut)
                {
                    builder.Insert(0, stringFromTypeDesc + " ");
                }
                else
                {
                    builder.Append(stringFromTypeDesc);
                    if (i < (funcdesc.cParams - 1))
                    {
                        builder.Append(", ");
                    }
                }
            }
            builder.Append(")");
            return(builder.ToString());
        }
示例#34
0
        internal ComMethodDesc(ITypeInfo typeInfo, FUNCDESC funcDesc)
            : this(funcDesc.memid)
        {
            InvokeKind = funcDesc.invkind;

            int cNames;
            string[] rgNames = new string[1 + funcDesc.cParams];
            typeInfo.GetNames(DispId, rgNames, rgNames.Length, out cNames);

            bool skipLast = false;
            if (IsPropertyPut && rgNames[rgNames.Length - 1] == null)
            {
                rgNames[rgNames.Length - 1] = "value";
                cNames++;
                skipLast = true;
            }
            Debug.Assert(cNames == rgNames.Length);
            _name = rgNames[0];

            ParamCount = funcDesc.cParams;

            ReturnType = ComUtil.GetTypeFromTypeDesc(funcDesc.elemdescFunc.tdesc);
            ParameterInformation = ComUtil.GetParameterInformation(funcDesc, skipLast);
        }
示例#35
0
        /// <summary>
        /// Helper method for retrieving the function description structure for the given function index.
        /// This method needs to also return the native pointer to be released when we're done with our FUNCDESC.
        /// It's not really possible to copy everything to a managed struct and then release the ptr immediately
        /// here, since FUNCDESCs contain other native pointers we may need to access.
        /// </summary>
        /// <param name="typeInfo"></param>
        /// <param name="funcIndex"></param>
        /// <param name="funcDesc"></param>
        /// <param name="funcDescHandle"></param>
        /// <returns></returns>
        internal static void GetFuncDescForDescIndex(ITypeInfo typeInfo, int funcIndex, out FUNCDESC funcDesc, out IntPtr funcDescHandle)
        {
            IntPtr pFuncDesc = IntPtr.Zero;
            typeInfo.GetFuncDesc(funcIndex, out pFuncDesc);

            // GetFuncDesc should never return null, this is just to be safe
            if (pFuncDesc == IntPtr.Zero)
            {
                throw new COMException(
                    ResourceUtilities.FormatResourceString("ResolveComReference.CannotRetrieveTypeInformation"));
            }

            funcDesc = (FUNCDESC)Marshal.PtrToStructure(pFuncDesc, typeof(FUNCDESC));
            funcDescHandle = pFuncDesc;
        }
示例#36
0
        public void GetFuncDesc(int index, out IntPtr ppFuncDesc)
        {
            // Fail BEFORE allocating the handle to avoid leaks. If the real COM object fails in this method
            // and doesn't return the handle or clean it up itself there's not much we can do to avoid the leak.
            _faultInjector.FailurePointThrow(MockTypeLibrariesFailurePoints.ITypeInfo_GetFuncDesc);

            ppFuncDesc = _memoryHelper.AllocateHandle(Marshal.SizeOf<FUNCDESC>());

            _memoryHelper.EnterSubAllocationScope(ppFuncDesc);
            FUNCDESC funcDesc = new FUNCDESC();

            funcDesc.lprgelemdescParam = _memoryHelper.AllocateHandle(_definedFunctions[index].parameters.Length * Marshal.SizeOf<ELEMDESC>());
            funcDesc.cParams = (short)_definedFunctions[index].parameters.Length;

            for (int i = 0; i < _definedFunctions[index].parameters.Length; i++)
            {
                ELEMDESC elemDesc = new ELEMDESC();
                elemDesc.tdesc = _definedFunctions[index].parameters[i].CreateTypeDesc(
                    new IntPtr(index * s_HREF_FUNCSPARAM_OFFSET_PERFUNC + i + s_HREF_FUNCSPARAM_OFFSET), _memoryHelper);

                Marshal.StructureToPtr(
                    elemDesc,
                    new IntPtr(funcDesc.lprgelemdescParam.ToInt64() + i * Marshal.SizeOf<ELEMDESC>()),
                    false);
            }

            funcDesc.elemdescFunc.tdesc = _definedFunctions[index].returnType.CreateTypeDesc(
                new IntPtr(index + s_HREF_FUNCSRET_OFFSET), _memoryHelper);
            _memoryHelper.ExitSubAllocationScope();

            Marshal.StructureToPtr(funcDesc, ppFuncDesc, false);
        }