Esempio n. 1
0
        internal ComTypeEnumDesc(ComTypes.ITypeInfo typeInfo, ComTypeLibDesc typeLibDesc) :
            base(typeInfo, ComType.Enum, typeLibDesc)
        {
            ComTypes.TYPEATTR typeAttr     = ComRuntimeHelpers.GetTypeAttrForTypeInfo(typeInfo);
            string[]          memberNames  = new string[typeAttr.cVars];
            object[]          memberValues = new object[typeAttr.cVars];

            IntPtr p = IntPtr.Zero;

            // For each enum member get name and value.
            for (int i = 0; i < typeAttr.cVars; i++)
            {
                typeInfo.GetVarDesc(i, out p);

                // Get the enum member value (as object).
                ComTypes.VARDESC varDesc;

                try {
                    varDesc = (ComTypes.VARDESC)Marshal.PtrToStructure(p, typeof(ComTypes.VARDESC));

                    if (varDesc.varkind == ComTypes.VARKIND.VAR_CONST)
                    {
                        memberValues[i] = Marshal.GetObjectForNativeVariant(varDesc.desc.lpvarValue);
                    }
                } finally {
                    typeInfo.ReleaseVarDesc(p);
                }

                // Get the enum member name
                memberNames[i] = ComRuntimeHelpers.GetNameOfMethod(typeInfo, varDesc.memid);
            }

            _memberNames  = memberNames;
            _memberValues = memberValues;
        }
Esempio n. 2
0
        internal static IEnumerable <ComTypes.VARDESC> GetTypeVariables(ComTypes.ITypeInfo typeInfo, ComTypes.TYPEATTR typeAttr)
        {
            for (var iVar = 0; iVar < typeAttr.cVars; iVar++)
            {
                IntPtr pVarDesc;
                typeInfo.GetVarDesc(iVar, out pVarDesc);
                var varDesc = (ComTypes.VARDESC)Marshal.PtrToStructure(pVarDesc, typeof(ComTypes.VARDESC));
                yield return(varDesc);

                typeInfo.ReleaseVarDesc(pVarDesc);
            }
        }
        public TypeInfoVariable(ComTypes.ITypeInfo typeInfo, int index)
        {
            _typeInfo = typeInfo;

            _typeInfo.GetVarDesc(index, out _varDescPtr);
            _varDesc = StructHelper.ReadStructureUnsafe <ComTypes.VARDESC>(_varDescPtr);

            var names = new string[1];

            typeInfo.GetNames(_varDesc.memid, names, 1, out var actualCount);
            Name = actualCount >= 1 ? names[0] : "[unnamed]";
        }