Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
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;
            }
        }
Exemplo n.º 3
0
        public ComAlias(ITypeLib typeLib, ITypeInfo info, int index, TYPEATTR attributes) : base(typeLib, index)
        {
            Index         = index;
            Documentation = new ComDocumentation(typeLib, index);
            Guid          = attributes.guid;
            IsHidden      = attributes.wTypeFlags.HasFlag(TYPEFLAGS.TYPEFLAG_FHIDDEN);
            IsRestricted  = attributes.wTypeFlags.HasFlag(TYPEFLAGS.TYPEFLAG_FRESTRICTED);

            if (Name.Equals("LONG_PTR"))
            {
                TypeName = "LongPtr";
                return;
            }

            var aliased = new ComParameter(attributes, info);

            TypeName = aliased.TypeName;
        }
Exemplo n.º 4
0
        private void LoadParameters(FUNCDESC funcDesc, ITypeInfo info)
        {
            Parameters = new List<ComParameter>();
            var names = new string[255];
            int count;
            info.GetNames(Index, names, 255, out count);

            for (var index = 0; index < count - 1; index++)
            {
                var paramPtr = new IntPtr(funcDesc.lprgelemdescParam.ToInt64() + Marshal.SizeOf(typeof(ELEMDESC)) * index);
                var elemDesc = (ELEMDESC)Marshal.PtrToStructure(paramPtr, typeof(ELEMDESC));
                var param = new ComParameter(elemDesc, info, names[index + 1]);
                Parameters.Add(param);
            }
            if (Parameters.Any() && funcDesc.cParamsOpt == -1)
            {
                Parameters.Last().IsParamArray = true;
            }
        }
Exemplo n.º 5
0
        private void SetDeclarationType(FUNCDESC funcDesc, ITypeInfo info)
        {
            var returnsHResult = (VarEnum)funcDesc.elemdescFunc.tdesc.vt == VarEnum.VT_HRESULT;
            var returnsVoid    = (VarEnum)funcDesc.elemdescFunc.tdesc.vt == VarEnum.VT_VOID;

            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 (returnsVoid || !_parameters.Any(param => param.IsReturnValue) && returnsHResult)
            {
                Type = DeclarationType.Procedure;
            }
            else
            {
                Type = DeclarationType.Function;
            }

            if (Type == DeclarationType.Function || Type == DeclarationType.PropertyGet)
            {
                var returnType = new ComParameter(this, funcDesc.elemdescFunc, info, string.Empty);
                if (!_parameters.Any())
                {
                    AsTypeName = returnType;
                }
                else
                {
                    var retval = _parameters.FirstOrDefault(x => x.IsReturnValue);
                    AsTypeName = retval ?? returnType;
                }
            }
        }