private IEnumerable <string> GetImplementedInterfaceNames(TYPEATTR typeAttr, ITypeInfo info)
        {
            var output = new List <string>();

            for (var implIndex = 0; implIndex < typeAttr.cImplTypes; implIndex++)
            {
                int href;
                info.GetRefTypeOfImplType(implIndex, out href);

                ITypeInfo implTypeInfo;
                info.GetRefTypeInfo(href, out implTypeInfo);

                IntPtr typeAttributesPointer;
                implTypeInfo.GetTypeAttr(out typeAttributesPointer);

                var typeAttributes = (TYPEATTR)Marshal.PtrToStructure(typeAttributesPointer, typeof(TYPEATTR));

                IMPLTYPEFLAGS flags = 0;
                try
                {
                    info.GetImplTypeFlags(implIndex, out flags);
                }
                catch (COMException) { }

                var implTypeName = GetTypeName(implTypeInfo);
                if (implTypeName != "IDispatch" && implTypeName != "IUnknown")
                {
                    // skip IDispatch.. just about everything implements it and RD doesn't need to care about it; don't care about IUnknown either
                    output.Add(implTypeName);
                }

                if (flags != 0)
                {
                    ComInformation comInfo;
                    if (_comInformation.TryGetValue(typeAttributes.guid, out comInfo))
                    {
                        _comInformation[typeAttributes.guid].ImplTypeFlags =
                            _comInformation[typeAttributes.guid].ImplTypeFlags | flags;
                    }
                    else
                    {
                        _comInformation.Add(typeAttributes.guid,
                                            new ComInformation(typeAttributes, flags, implTypeInfo, implTypeName, new QualifiedModuleName(), null, 0));
                    }
                }

                info.ReleaseTypeAttr(typeAttributesPointer);
            }
            return(output);
        }
예제 #2
0
        void ComTypes.ITypeInfo.GetImplTypeFlags(int index, out ComTypes.IMPLTYPEFLAGS pImplTypeFlags)
        {
            // initialize out parameters
            pImplTypeFlags = default;

            using (var implTypeFlags = AddressableVariables.Create <ComTypes.IMPLTYPEFLAGS>())
            {
                var hr = _this_Internal.GetImplTypeFlags(index, implTypeFlags.Address);
                if (ComHelper.HRESULT_FAILED(hr))
                {
                    HandleBadHRESULT(hr);
                }

                pImplTypeFlags = implTypeFlags.Value;
            }
        }
예제 #3
0
        private void GetImplementedInterfaces(ITypeInfo info, TYPEATTR typeAttr)
        {
            for (var implIndex = 0; implIndex < typeAttr.cImplTypes; implIndex++)
            {
                info.GetRefTypeOfImplType(implIndex, out int href);
                info.GetRefTypeInfo(href, out ITypeInfo implemented);

                implemented.GetTypeAttr(out IntPtr attribPtr);
                using (DisposalActionContainer.Create(attribPtr, info.ReleaseTypeAttr))
                {
                    var attribs = Marshal.PtrToStructure <TYPEATTR>(attribPtr);

                    ComProject.KnownTypes.TryGetValue(attribs.guid, out ComType inherited);
                    var intface = inherited as ComInterface ?? new ComInterface(Project, implemented, attribs);

                    ComProject.KnownTypes.TryAdd(attribs.guid, intface);

                    IMPLTYPEFLAGS flags = 0;
                    try
                    {
                        info.GetImplTypeFlags(implIndex, out flags);
                    }
                    catch (COMException) { }

                    if (flags.HasFlag(IMPLTYPEFLAGS.IMPLTYPEFLAG_FSOURCE))
                    {
                        _events.Add(intface);
                    }
                    else
                    {
                        DefaultInterface = flags.HasFlag(IMPLTYPEFLAGS.IMPLTYPEFLAG_FDEFAULT) ? intface : DefaultInterface;
                    }
                    _interfaces.Add(intface, flags.HasFlag(IMPLTYPEFLAGS.IMPLTYPEFLAG_FRESTRICTED));
                }
            }

            if (DefaultInterface == null)
            {
                DefaultInterface = VisibleInterfaces.FirstOrDefault();
            }
        }
예제 #4
0
        private void GetImplementedInterfaces(ITypeInfo info, TYPEATTR typeAttr)
        {
            for (var implIndex = 0; implIndex < typeAttr.cImplTypes; implIndex++)
            {
                int href;
                info.GetRefTypeOfImplType(implIndex, out href);

                ITypeInfo implemented;
                info.GetRefTypeInfo(href, out implemented);

                IntPtr attribPtr;
                implemented.GetTypeAttr(out attribPtr);
                var attribs = (TYPEATTR)Marshal.PtrToStructure(attribPtr, typeof(TYPEATTR));

                ComType inherited;
                ComProject.KnownTypes.TryGetValue(attribs.guid, out inherited);
                var intface = inherited as ComInterface ?? new ComInterface(implemented, attribs);
                ComProject.KnownTypes.TryAdd(attribs.guid, intface);

                IMPLTYPEFLAGS flags = 0;
                try
                {
                    info.GetImplTypeFlags(implIndex, out flags);
                }
                catch (COMException) { }

                if (flags.HasFlag(IMPLTYPEFLAGS.IMPLTYPEFLAG_FSOURCE))
                {
                    _events.Add(intface);
                }
                else
                {
                    DefaultInterface = flags.HasFlag(IMPLTYPEFLAGS.IMPLTYPEFLAG_FDEFAULT) ? intface : DefaultInterface;
                }
                _interfaces.Add(intface, flags.HasFlag(IMPLTYPEFLAGS.IMPLTYPEFLAG_FRESTRICTED));
                info.ReleaseTypeAttr(attribPtr);
            }
        }
        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);
        }
        private Declaration CreateMemberDeclaration(FUNCDESC memberDescriptor, TYPEKIND typeKind, ITypeInfo info, IMPLTYPEFLAGS parentImplFlags,
                                                    QualifiedModuleName typeQualifiedModuleName, Declaration moduleDeclaration, out string[] memberNames)
        {
            if (memberDescriptor.callconv != CALLCONV.CC_STDCALL)
            {
                memberNames = new string[] { };
                return(null);
            }

            memberNames = new string[255];
            int namesArrayLength;

            info.GetNames(memberDescriptor.memid, memberNames, 255, out namesArrayLength);

            var memberName            = memberNames[0];
            var funcValueType         = (VarEnum)memberDescriptor.elemdescFunc.tdesc.vt;
            var memberDeclarationType = GetDeclarationType(memberName, memberDescriptor, funcValueType, typeKind, parentImplFlags);

            if (((FUNCFLAGS)memberDescriptor.wFuncFlags).HasFlag(FUNCFLAGS.FUNCFLAG_FRESTRICTED) &&
                IgnoredInterfaceMembers.Contains(memberName)) // Ignore IDispatch and IUnknown members - quick-and-dirty for beta
            {
                return(null);
            }

            var asTypeName = new ComParameter(string.Empty, false);

            if (memberDeclarationType != DeclarationType.Procedure)
            {
                asTypeName = GetParameterInfo(memberDescriptor.elemdescFunc.tdesc, info);
            }
            var attributes = new Attributes();

            if (memberName == "_NewEnum" && ((FUNCFLAGS)memberDescriptor.wFuncFlags).HasFlag(FUNCFLAGS.FUNCFLAG_FNONBROWSABLE))
            {
                attributes.AddEnumeratorMemberAttribute(memberName);
            }
            else if (memberDescriptor.memid == 0)
            {
                attributes.AddDefaultMemberAttribute(memberName);
            }
            else if (((FUNCFLAGS)memberDescriptor.wFuncFlags).HasFlag(FUNCFLAGS.FUNCFLAG_FHIDDEN))
            {
                attributes.AddHiddenMemberAttribute(memberName);
            }

            switch (memberDeclarationType)
            {
            case DeclarationType.Procedure:
                return(new SubroutineDeclaration(
                           new QualifiedMemberName(typeQualifiedModuleName, memberName),
                           moduleDeclaration,
                           moduleDeclaration,
                           asTypeName.Name,
                           Accessibility.Global,
                           null,
                           Selection.Home,
                           true,
                           null,
                           attributes));

            case DeclarationType.Function:
                return(new FunctionDeclaration(
                           new QualifiedMemberName(typeQualifiedModuleName, memberName),
                           moduleDeclaration,
                           moduleDeclaration,
                           asTypeName.Name,
                           null,
                           null,
                           Accessibility.Global,
                           null,
                           Selection.Home,
                           asTypeName.IsArray,
                           true,
                           null,
                           attributes));

            case DeclarationType.PropertyGet:
                return(new PropertyGetDeclaration(
                           new QualifiedMemberName(typeQualifiedModuleName, memberName),
                           moduleDeclaration,
                           moduleDeclaration,
                           asTypeName.Name,
                           null,
                           null,
                           Accessibility.Global,
                           null,
                           Selection.Home,
                           asTypeName.IsArray,
                           true,
                           null,
                           attributes));

            case DeclarationType.PropertySet:
                return(new PropertySetDeclaration(
                           new QualifiedMemberName(typeQualifiedModuleName, memberName),
                           moduleDeclaration,
                           moduleDeclaration,
                           asTypeName.Name,
                           Accessibility.Global,
                           null,
                           Selection.Home,
                           true,
                           null,
                           attributes));

            case DeclarationType.PropertyLet:
                return(new PropertyLetDeclaration(
                           new QualifiedMemberName(typeQualifiedModuleName, memberName),
                           moduleDeclaration,
                           moduleDeclaration,
                           asTypeName.Name,
                           Accessibility.Global,
                           null,
                           Selection.Home,
                           true,
                           null,
                           attributes));

            default:
                return(new Declaration(
                           new QualifiedMemberName(typeQualifiedModuleName, memberName),
                           moduleDeclaration,
                           moduleDeclaration,
                           asTypeName.Name,
                           null,
                           false,
                           false,
                           Accessibility.Global,
                           memberDeclarationType,
                           null,
                           Selection.Home,
                           false,
                           null,
                           true,
                           null,
                           attributes));
            }
        }