Exemple #1
0
 private void AnalyzeElement(ITypeInfo typeInfo, System.Runtime.InteropServices.ComTypes.ELEMDESC elementDesc)
 {
     System.Runtime.InteropServices.ComTypes.TYPEDESC tdesc = elementDesc.tdesc;
     while ((tdesc.vt == 0x1a) || (tdesc.vt == 0x1b))
     {
         tdesc = (System.Runtime.InteropServices.ComTypes.TYPEDESC)Marshal.PtrToStructure(tdesc.lpValue, typeof(System.Runtime.InteropServices.ComTypes.TYPEDESC));
     }
     if (tdesc.vt == 0x1d)
     {
         IntPtr         lpValue = tdesc.lpValue;
         IFixedTypeInfo ppTI    = null;
         try
         {
             ((IFixedTypeInfo)typeInfo).GetRefTypeInfo(lpValue, out ppTI);
             this.AnalyzeTypeInfo((ITypeInfo)ppTI);
         }
         finally
         {
             if (ppTI != null)
             {
                 this.marshalReleaseComObject(ppTI);
             }
         }
     }
 }
Exemple #2
0
 private void ScanDefinedFunctions(ITypeInfo typeInfo, System.Runtime.InteropServices.ComTypes.TYPEATTR typeAttributes)
 {
     for (int i = 0; i < typeAttributes.cFuncs; i++)
     {
         IntPtr zero = IntPtr.Zero;
         try
         {
             System.Runtime.InteropServices.ComTypes.FUNCDESC funcdesc;
             ComReference.GetFuncDescForDescIndex(typeInfo, i, out funcdesc, out zero);
             int num2 = 0;
             for (int j = 0; j < funcdesc.cParams; j++)
             {
                 System.Runtime.InteropServices.ComTypes.ELEMDESC elementDesc = (System.Runtime.InteropServices.ComTypes.ELEMDESC)Marshal.PtrToStructure(new IntPtr(funcdesc.lprgelemdescParam.ToInt64() + num2), typeof(System.Runtime.InteropServices.ComTypes.ELEMDESC));
                 this.AnalyzeElement(typeInfo, elementDesc);
                 num2 += Marshal.SizeOf(typeof(System.Runtime.InteropServices.ComTypes.ELEMDESC));
             }
             this.AnalyzeElement(typeInfo, funcdesc.elemdescFunc);
         }
         finally
         {
             if (zero != IntPtr.Zero)
             {
                 typeInfo.ReleaseFuncDesc(zero);
             }
         }
     }
 }
Exemple #3
0
        private void LoadParameters()
        {
            _parameters = new List <ComParameterInfo>();

            string[] rgBstrNames = new string[_funcDesc.cParams + 1];
            int      pcNames     = 0;

            _comTypeInfo.GetITypeInfo().GetNames(_funcDesc.memid, rgBstrNames, rgBstrNames.Length, out pcNames);

            IntPtr pElemDesc = _funcDesc.lprgelemdescParam;

            _returnParameter = new ComParameterInfo(this, rgBstrNames[0], _funcDesc.elemdescFunc);

            if (_funcDesc.cParams > 0)
            {
                for (int cParams = 0; cParams < _funcDesc.cParams; cParams++)
                {
                    System.Runtime.InteropServices.ComTypes.ELEMDESC elemDesc = (System.Runtime.InteropServices.ComTypes.ELEMDESC)Marshal.PtrToStructure(pElemDesc, typeof(System.Runtime.InteropServices.ComTypes.ELEMDESC));
                    _parameters.Add(new ComParameterInfo(this, rgBstrNames[cParams + 1], elemDesc));
                    pElemDesc = new IntPtr(pElemDesc.ToInt64() + Marshal.SizeOf(typeof(System.Runtime.InteropServices.ComTypes.ELEMDESC)));
                }
            }
            else
            {
                //list.Add(new ElemDesc(this, m_funcDesc.elemdescFunc, rgBstrNames[0], -1));
            }

            //m_parameters = list.ToArray();
        }
Exemple #4
0
        public ComParameter(ELEMDESC elemDesc, ITypeInfo info, string name)
        {
            Name = name;
            var paramDesc = elemDesc.desc.paramdesc;

            GetParameterType(elemDesc.tdesc, info);
            IsOptional = paramDesc.wParamFlags.HasFlag(PARAMFLAG.PARAMFLAG_FOPT);
            if (!paramDesc.wParamFlags.HasFlag(PARAMFLAG.PARAMFLAG_FHASDEFAULT) || string.IsNullOrEmpty(name))
            {
                DefaultAsEnum = string.Empty;
                return;
            }

            //lpVarValue points to a PARAMDESCEX structure, but we don't care about the cBytes here at all.
            //Offset and dereference the VARIANTARG directly.
            var defValue = new ComVariant(paramDesc.lpVarValue + Marshal.SizeOf(typeof(ulong)));

            DefaultValue = defValue.Value;

            ComEnumeration enumType;

            if (!IsEnumMember || !ComProject.KnownEnumerations.TryGetValue(_enumGuid, out enumType))
            {
                return;
            }
            var member = enumType.Members.FirstOrDefault(m => m.Value == (int)DefaultValue);

            DefaultAsEnum = member != null ? member.Name : string.Empty;
        }
Exemple #5
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);
        }
Exemple #6
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);
            }
        }
Exemple #7
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);
        }
Exemple #8
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());
        }
Exemple #9
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();
 }
Exemple #10
0
        internal static ParameterInformation[] GetParameterInformation(
            System.Runtime.InteropServices.ComTypes.FUNCDESC funcdesc,
            bool skipLastParameter)
        {
            int cParams = (int)funcdesc.cParams;

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

            for (int index = 0; index < cParams; ++index)
            {
                System.Runtime.InteropServices.ComTypes.ELEMDESC elemdesc = new System.Runtime.InteropServices.ComTypes.ELEMDESC();
                int num2 = index * num1;
                elemdesc = (System.Runtime.InteropServices.ComTypes.ELEMDESC)Marshal.PtrToStructure(IntPtr.Size != 4 ? (IntPtr)(lprgelemdescParam.ToInt64() + (long)num2) : (IntPtr)(lprgelemdescParam.ToInt32() + num2), typeof(System.Runtime.InteropServices.ComTypes.ELEMDESC));
                Type   typeFromTypeDesc = ComUtil.GetTypeFromTypeDesc(elemdesc.tdesc);
                object defaultValue     = (object)null;
                bool   isOptional;
                if ((elemdesc.desc.paramdesc.wParamFlags & System.Runtime.InteropServices.ComTypes.PARAMFLAG.PARAMFLAG_FOPT) != System.Runtime.InteropServices.ComTypes.PARAMFLAG.PARAMFLAG_NONE)
                {
                    isOptional   = true;
                    defaultValue = Type.Missing;
                }
                else
                {
                    isOptional = false;
                }
                bool isByRef = false;
                if ((elemdesc.desc.paramdesc.wParamFlags & System.Runtime.InteropServices.ComTypes.PARAMFLAG.PARAMFLAG_FOUT) != System.Runtime.InteropServices.ComTypes.PARAMFLAG.PARAMFLAG_NONE)
                {
                    isByRef = true;
                }
                parameterInformationArray[index] = new ParameterInformation(typeFromTypeDesc, isOptional, defaultValue, isByRef);
            }
            return(parameterInformationArray);
        }
Exemple #11
0
        internal static string GetMethodSignatureFromFuncDesc(
            ITypeInfo typeinfo,
            System.Runtime.InteropServices.ComTypes.FUNCDESC funcdesc,
            bool isPropertyPut)
        {
            StringBuilder stringBuilder    = new StringBuilder();
            string        nameFromFuncDesc = ComUtil.GetNameFromFuncDesc(typeinfo, funcdesc);

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

            for (int index = 0; index < (int)funcdesc.cParams; ++index)
            {
                System.Runtime.InteropServices.ComTypes.ELEMDESC elemdesc = new System.Runtime.InteropServices.ComTypes.ELEMDESC();
                int num2 = index * num1;
                elemdesc = (System.Runtime.InteropServices.ComTypes.ELEMDESC)Marshal.PtrToStructure(IntPtr.Size != 4 ? (IntPtr)(lprgelemdescParam.ToInt64() + (long)num2) : (IntPtr)(lprgelemdescParam.ToInt32() + num2), typeof(System.Runtime.InteropServices.ComTypes.ELEMDESC));
                string stringFromTypeDesc = ComUtil.GetStringFromTypeDesc(typeinfo, elemdesc.tdesc);
                if (index == 0 && isPropertyPut)
                {
                    stringBuilder.Insert(0, stringFromTypeDesc + " ");
                }
                else
                {
                    stringBuilder.Append(stringFromTypeDesc);
                    if (index < (int)funcdesc.cParams - 1)
                    {
                        stringBuilder.Append(", ");
                    }
                }
            }
            stringBuilder.Append(")");
            return(stringBuilder.ToString());
        }
Exemple #12
0
        /// <summary>
        /// Creates a representation for the paramter of a COM method
        /// </summary>
        internal ComParamDesc(ref ELEMDESC elemDesc, string name)
        {
            // Ensure _defaultValue is set to DBNull.Value regardless of whether or not the
            // default value is extracted from the parameter description.  Failure to do so
            // yields a runtime exception in the ToString() function.
            _defaultValue = DBNull.Value;

            if (!String.IsNullOrEmpty(name)) {
                // This is a parameter, not a return value
                this._isOut = (elemDesc.desc.paramdesc.wParamFlags & PARAMFLAG.PARAMFLAG_FOUT) != 0;
                this._isOpt = (elemDesc.desc.paramdesc.wParamFlags & PARAMFLAG.PARAMFLAG_FOPT) != 0;
                // TODO: The PARAMDESCEX struct has a memory issue that needs to be resolved.  For now, we ignore it.
                //_defaultValue = PARAMDESCEX.GetDefaultValue(ref elemDesc.desc.paramdesc);
            }

            _name = name;
            _vt = (VarEnum)elemDesc.tdesc.vt;
            TYPEDESC typeDesc = elemDesc.tdesc;
            while (true) {
                if (_vt == VarEnum.VT_PTR) {
                    this._byRef = true;
                } else if (_vt == VarEnum.VT_ARRAY) {
                    this._isArray = true;
                } else {
                    break;
                }

                TYPEDESC childTypeDesc = (TYPEDESC)Marshal.PtrToStructure(typeDesc.lpValue, typeof(TYPEDESC));
                _vt = (VarEnum)childTypeDesc.vt;
                typeDesc = childTypeDesc;
            }

            VarEnum vtWithoutByref = _vt;
            if ((_vt & VarEnum.VT_BYREF) != 0) {
                vtWithoutByref = (_vt & ~VarEnum.VT_BYREF);
                _byRef = true;
            }

            _type = GetTypeForVarEnum(vtWithoutByref);
        }
        public ComParameter(ComMember parent, ELEMDESC elemDesc, ITypeInfo info, string name)
        {
            Debug.Assert(name != null, "Parameter name is null");

            Parent = parent;
            Name   = name;
            var paramDesc = elemDesc.desc.paramdesc;

            GetParameterType(elemDesc.tdesc, info);
            IsOptional    = paramDesc.wParamFlags.HasFlag(PARAMFLAG.PARAMFLAG_FOPT);
            IsReturnValue = paramDesc.wParamFlags.HasFlag(PARAMFLAG.PARAMFLAG_FRETVAL);
            if (!paramDesc.wParamFlags.HasFlag(PARAMFLAG.PARAMFLAG_FHASDEFAULT) || string.IsNullOrEmpty(name))
            {
                return;
            }

            //lpVarValue points to a PARAMDESCEX structure, but we don't care about the cBytes here at all.
            //Offset and dereference the VARIANTARG directly.
            var defValue = new ComVariant(paramDesc.lpVarValue + Marshal.SizeOf(typeof(ulong)));

            DefaultValue = defValue.Value;
        }
Exemple #14
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();
            string        name    = GetNameFromFuncDesc(typeinfo, funcdesc);

            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(name);
            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);

                    if (i < funcdesc.cParams - 1)
                    {
                        builder.Append(", ");
                    }
                }
            }

            builder.Append(")");

            return(builder.ToString());
        }
Exemple #15
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();
            string name = GetNameFromFuncDesc(typeinfo, funcdesc);

            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(name);
            builder.Append(" (");

            IntPtr ElementDescriptionArrayPtr = funcdesc.lprgelemdescParam;
            int ElementDescriptionSize = ClrFacade.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 = ClrFacade.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);

                    if (i < funcdesc.cParams - 1)
                    {
                        builder.Append(", ");
                    }
                }
            }
            builder.Append(")");

            return builder.ToString();
        }
Exemple #16
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 = ClrFacade.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 = ClrFacade.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;
        }
 public ComParameterInfo(ComFunctionInfo comFunctionInfo, string name, System.Runtime.InteropServices.ComTypes.ELEMDESC elemDesc)
 {
     _comFunctionInfo = comFunctionInfo;
     _name = name;
     _elemDesc = elemDesc;
 }
Exemple #18
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);
        }
Exemple #19
0
 private static IEnumerable <ITypeInfo> GetReferencedEnums(ITypeLib typeLib, ITypeInfo typeInfo, ELEMDESC elemDesc, Dictionary <Guid, ITypeInfo> processedTypeInfo)
 {
     return(GetReferencedEnums(typeLib, typeInfo, elemDesc.tdesc, processedTypeInfo));
 }
Exemple #20
0
 public ComParameterInfo(ComFunctionInfo comFunctionInfo, string name, System.Runtime.InteropServices.ComTypes.ELEMDESC elemDesc)
 {
     _comFunctionInfo = comFunctionInfo;
     _name            = name;
     _elemDesc        = elemDesc;
 }
Exemple #21
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;
 }
Exemple #22
0
 /// <summary>
 /// Creates a representation for the return value of a COM method
 /// TODO: Return values should be represented by a different type
 /// </summary>
 internal ComParamDesc(ref ELEMDESC elemDesc)
     : this(ref elemDesc, String.Empty)
 {
 }