Exemple #1
0
        public ComField(IComBase parent, ITypeInfo info, string name, VARDESC varDesc, int index, DeclarationType type)
        {
            Parent = parent;
            Name   = name;
            Index  = index;
            Type   = type;

            Flags = (VARFLAGS)varDesc.wVarFlags;

            if (Type == DeclarationType.Constant)
            {
                var value = new ComVariant(varDesc.desc.lpvarValue);
                DefaultValue = value.Value;

                if (ComVariant.TypeNames.TryGetValue(value.VariantType, out string typeName))
                {
                    _valueType = typeName;
                }

                if (value.VariantType.HasFlag(VarEnum.VT_ARRAY))
                {
                    IsArray = true;
                }
            }
            else
            {
                GetFieldType(varDesc.elemdescVar.tdesc, info);
            }
        }
        internal static void GetVarDescForVarIndex(ITypeInfo typeInfo, int varIndex, out System.Runtime.InteropServices.ComTypes.VARDESC varDesc, out IntPtr varDescHandle)
        {
            IntPtr zero = IntPtr.Zero;

            typeInfo.GetVarDesc(varIndex, out zero);
            if (zero == IntPtr.Zero)
            {
                throw new COMException(Microsoft.Build.Shared.ResourceUtilities.FormatResourceString("ResolveComReference.CannotRetrieveTypeInformation", new object[0]));
            }
            varDesc       = (System.Runtime.InteropServices.ComTypes.VARDESC)Marshal.PtrToStructure(zero, typeof(System.Runtime.InteropServices.ComTypes.VARDESC));
            varDescHandle = zero;
        }
        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]";
        }
        public ComEnumerationMember(ITypeInfo info, VARDESC varDesc)
        {
            var value = new ComVariant(varDesc.desc.lpvarValue);

            Value     = (int)value.Value;
            ValueType = value.VariantType;

            var names = new string[1];
            int count;

            info.GetNames(varDesc.memid, names, names.Length, out count);
            Debug.Assert(count == 1);
            Name = names[0];
        }
Exemple #5
0
 public ComVariableInfo(ComTypeInfo parent, System.Runtime.InteropServices.ComTypes.VARDESC varDesc, object constantValue)
     : base(parent)
 {
     _varDesc = varDesc;
     _comTypeInfo.GetITypeInfo().GetDocumentation(_varDesc.memid, out _name, out _description, out _helpContext, out _helpFile);
     _constantValue = constantValue;
     if (_description == null)
     {
         _description = String.Empty;
     }
     if (_helpFile == null)
     {
         _helpFile = String.Empty;
     }
 }
        private DeclarationType GetDeclarationType(VARDESC varDesc, DeclarationType typeDeclarationType)
        {
            var memberType = DeclarationType.Variable;

            if (varDesc.varkind == VARKIND.VAR_CONST)
            {
                memberType = typeDeclarationType == DeclarationType.Enumeration
                    ? DeclarationType.EnumerationMember
                    : DeclarationType.Constant;
            }
            else if (typeDeclarationType == DeclarationType.UserDefinedType)
            {
                memberType = DeclarationType.UserDefinedTypeMember;
            }
            return(memberType);
        }
Exemple #7
0
 internal static object GetConstantValue(ComTypes.VARDESC varDesc)
 {
     if (varDesc.varkind == ComTypes.VARKIND.VAR_CONST)
     {
         try
         {
             var constantValue = varDesc.desc.lpvarValue;
             return(Marshal.GetObjectForNativeVariant(constantValue));
         }
         catch (Exception e)
         {
             return(null);
         }
     }
     return(null);
 }
Exemple #8
0
        public TypeInfoVar(TypeInfoWrapper typeInfo, int index)
        {
            _typeInfo = typeInfo;

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

            var names = new string[1];

            if (_varDesc.memid != (int)TypeLibConsts.MEMBERID_NIL)
            {
                ((ComTypes.ITypeInfo)_typeInfo).GetNames(_varDesc.memid, names, names.Length, out _);
                _name = names[0];
            }
            else
            {
                _name = "{unknown}";     // VBA Constants appear in the typelib with no name
            }
        }
Exemple #9
0
        public ComField(string name, VARDESC varDesc, int index, DeclarationType type)
        {
            Name  = name;
            Index = index;
            Type  = type;

            Flags = (VARFLAGS)varDesc.wVarFlags;

            if (Type == DeclarationType.Constant)
            {
                var value = new ComVariant(varDesc.desc.lpvarValue);
                DefaultValue = value.Value;
                string typeName;
                ValueType = ComVariant.TypeNames.TryGetValue(value.VariantType, out typeName) ? typeName : "Object";
            }
            else
            {
                Debug.Assert(varDesc.varkind == VARKIND.VAR_PERINSTANCE);
                string typeName;
                ValueType = ComVariant.TypeNames.TryGetValue((VarEnum)varDesc.elemdescVar.tdesc.vt, out typeName) ? typeName : "Object";
            }
        }
 public ComVariableInfo(ComTypeInfo parent, System.Runtime.InteropServices.ComTypes.VARDESC varDesc, object constantValue)
     : base(parent)
 {
     _varDesc = varDesc;
     _comTypeInfo.GetITypeInfo().GetDocumentation(_varDesc.memid, out _name, out _description, out _helpContext, out _helpFile);
     _constantValue = constantValue;
     if (_description == null) _description = String.Empty;
     if (_helpFile == null) _helpFile = String.Empty;
 }
Exemple #11
0
        public void GetVarDesc(int index, out IntPtr ppVarDesc)
        {
            // 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_GetVarDesc);

            ppVarDesc = _memoryHelper.AllocateHandle(Marshal.SizeOf<VARDESC>());

            _memoryHelper.EnterSubAllocationScope(ppVarDesc);
            VARDESC varDesc = new VARDESC();
            varDesc.elemdescVar.tdesc = _definedVariables[index].CreateTypeDesc(new IntPtr(index + s_HREF_VARS_OFFSET), _memoryHelper);
            _memoryHelper.ExitSubAllocationScope();

            Marshal.StructureToPtr(varDesc, ppVarDesc, false);
        }
Exemple #12
0
 private static IEnumerable <ITypeInfo> GetReferencedEnums(ITypeLib typeLib, ITypeInfo typeInfo, VARDESC varDesc, Dictionary <Guid, ITypeInfo> processedTypeInfo)
 {
     return(GetReferencedEnums(typeLib, typeInfo, varDesc.elemdescVar, processedTypeInfo));
 }
Exemple #13
0
 internal static bool IsConstant(ComTypes.VARDESC varDesc)
 {
     return(varDesc.varkind == ComTypes.VARKIND.VAR_CONST);
 }
Exemple #14
0
 internal static string GetMemberName(ComTypes.ITypeInfo typeInfo, ComTypes.VARDESC varDesc)
 {
     // first element in the sequence is the name of the method.
     return(GetNames(typeInfo, varDesc.memid).First());
 }
Exemple #15
0
        /// <summary>
        /// Helper method for retrieving type attributes for a given type info
        /// This method needs to also return the native pointer to be released when we're done with our VARDESC.
        /// It's not really possible to copy everything to a managed struct and then release the ptr immediately
        /// here, since VARDESCs contain other native pointers we may need to access.
        /// </summary>
        /// <param name="typeInfo"></param>
        /// <param name="varIndex"></param>
        /// <param name="typeAttr"></param>
        /// <param name="varDesc"></param>
        /// <param name="varDescHandle"></param>
        /// <returns></returns>
        internal static void GetVarDescForVarIndex(ITypeInfo typeInfo, int varIndex, out VARDESC varDesc, out IntPtr varDescHandle)
        {
            IntPtr pVarDesc = IntPtr.Zero;
            typeInfo.GetVarDesc(varIndex, out pVarDesc);

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

            varDesc = (VARDESC)Marshal.PtrToStructure(pVarDesc, typeof(VARDESC));
            varDescHandle = pVarDesc;
        }