Example #1
0
        public OWTypeDef(ITlibNode parent, ITypeInfo ti, TypeAttr ta)
        {
            Parent = parent;
            _ta    = ta;
            _ti    = ti;

            string prefix = string.Empty;

            if (VarEnum.VT_ARRAY == ((VarEnum)_ta.tdescAlias.vt & VarEnum.VT_ARRAY))
            {
                var oad = ta.tdescAlias.lpadesc;
                _ti.GetRefTypeInfo(oad.tdescElem.hreftype, out _oti);
                prefix = _oti.GetName() + " ";
            }
            else
            {
                TmpIdlFormatter tmp = new TmpIdlFormatter();
                _ta.tdescAlias.ComTypeNameAsString(ti, tmp);
                prefix = tmp.data + " ";
                if (VarEnum.VT_USERDEFINED == (VarEnum)_ta.tdescAlias.vt)
                {
                    _ti.GetRefTypeInfo(_ta.tdescAlias.hreftype, out _oti);
                }
            }
            _name = prefix + ti.GetName();
            _data = new IDLData(this);
        }
Example #2
0
        public OWTypeDef(ITlibNode parent, ITypeInfo ti, TypeAttr ta)
        {
            Parent = parent;
            _ta    = ta;
            _ti    = ti;

            string prefix = string.Empty;

            if (VarEnum.VT_PTR == ((VarEnum)_ta.tdescAlias.vt & VarEnum.VT_PTR))
            {
                var otd = _ta.tdescAlias.lptdsec;
                _ti.GetRefTypeInfo(otd.hreftype, out _oti);
                prefix = _oti.GetName() + " ";
            }
            else if (VarEnum.VT_ARRAY == ((VarEnum)_ta.tdescAlias.vt & VarEnum.VT_ARRAY))
            {
                var oad = ta.tdescAlias.lpadesc;
                _ti.GetRefTypeInfo(oad.tdescElem.hreftype, out _oti);
                prefix = _oti.GetName() + " ";
            }
            else
            {
                _ti.GetRefTypeInfo(_ta.tdescAlias.hreftype, out _oti);
                prefix = _oti.GetName() + " ";
            }
            _name = prefix + ti.GetName();
            _data = new IDLData(this);
        }
Example #3
0
        public override List <ITlibNode> GenChildren()
        {
            var res = new List <ITlibNode>();

            for (var x = 0; x < _ta.cImplTypes; ++x)
            {
                _ti.GetRefTypeOfImplType(x, out var href);
                _ti.GetRefTypeInfo(href, out var ti2);
                CommonBuildTlibNode(this, ti2, false, false, res);
            }
            return(res);
        }
Example #4
0
        private string GetTypeName(TYPEDESC desc, ITypeInfo info)
        {
            var      vt = (VarEnum)desc.vt;
            TYPEDESC tdesc;

            switch (vt)
            {
            case VarEnum.VT_PTR:
                tdesc = (TYPEDESC)Marshal.PtrToStructure(desc.lpValue, typeof(TYPEDESC));
                return(GetTypeName(tdesc, info));

            case VarEnum.VT_USERDEFINED:
                unchecked
                {
                    var       href = desc.lpValue.ToInt32();
                    ITypeInfo refTypeInfo;
                    info.GetRefTypeInfo(href, out refTypeInfo);
                    return(GetTypeName(refTypeInfo));
                }

            case VarEnum.VT_CARRAY:
                tdesc = (TYPEDESC)Marshal.PtrToStructure(desc.lpValue, typeof(TYPEDESC));
                return(GetTypeName(tdesc, info) + "()");

            default:
                string result;
                if (TypeNames.TryGetValue(vt, out result))
                {
                    return(result);
                }
                break;
            }

            return("UNKNOWN");
        }
Example #5
0
        internal static ITypeInfo GetDispatchTypeInfoFromCoClassTypeInfo(ITypeInfo typeinfo)
        {
            int       cImplTypes = (int)ComTypeInfo.GetTypeAttr(typeinfo).cImplTypes;
            ITypeInfo ppTI       = (ITypeInfo)null;

            for (int index = 0; index < cImplTypes; ++index)
            {
                int href;
                typeinfo.GetRefTypeOfImplType(index, out href);
                typeinfo.GetRefTypeInfo(href, out ppTI);
                System.Runtime.InteropServices.ComTypes.TYPEATTR typeAttr = ComTypeInfo.GetTypeAttr(ppTI);
                if (typeAttr.typekind == System.Runtime.InteropServices.ComTypes.TYPEKIND.TKIND_DISPATCH)
                {
                    return(ppTI);
                }
                if ((typeAttr.wTypeFlags & System.Runtime.InteropServices.ComTypes.TYPEFLAGS.TYPEFLAG_FDUAL) != (System.Runtime.InteropServices.ComTypes.TYPEFLAGS) 0)
                {
                    ppTI = ComTypeInfo.GetDispatchTypeInfoFromCustomInterfaceTypeInfo(ppTI);
                    if (ComTypeInfo.GetTypeAttr(ppTI).typekind == System.Runtime.InteropServices.ComTypes.TYPEKIND.TKIND_DISPATCH)
                    {
                        return(ppTI);
                    }
                }
            }
            return((ITypeInfo)null);
        }
Example #6
0
        public override void BuildIDLInto(IDLFormatter ih)
        {
            EnterElement();
            ih.AppendLine("[");
            var lprops = _data.Attributes;

            for (var i = 0; i < lprops.Count; ++i)
            {
                ih.AppendLine("  " + lprops[i] + (i < (lprops.Count - 1) ? "," : ""));
            }
            ih.AppendLine("]");

            if (_ta.cImplTypes > 0)
            {
                _ti.GetRefTypeOfImplType(0, out var href);
                _ti.GetRefTypeInfo(href, out var ti2);
                ih.AddString($"{_data.Name} : ");
                ih.AddLink(ti2.GetName(), "i");
                ih.AppendLine(" {");
            }
            else
            {
                ih.AppendLine("interface " + _data.Name + " {");
            }
            using (new IDLHelperTab(ih))
            {
                Children.ForEach(x => x.BuildIDLInto(ih));
            }
            ih.AppendLine("};");
            ExitElement();
        }
Example #7
0
        internal static ITypeInfo GetDispatchTypeInfoFromCoClassTypeInfo(ITypeInfo typeinfo)
        {
            int       cImplTypes = GetTypeAttr(typeinfo).cImplTypes;
            ITypeInfo ppTI       = null;

            for (int i = 0; i < cImplTypes; i++)
            {
                int num2;
                typeinfo.GetRefTypeOfImplType(i, out num2);
                typeinfo.GetRefTypeInfo(num2, out ppTI);
                System.Runtime.InteropServices.ComTypes.TYPEATTR typeAttr = GetTypeAttr(ppTI);
                if (typeAttr.typekind == System.Runtime.InteropServices.ComTypes.TYPEKIND.TKIND_DISPATCH)
                {
                    return(ppTI);
                }
                if (((short)(typeAttr.wTypeFlags & System.Runtime.InteropServices.ComTypes.TYPEFLAGS.TYPEFLAG_FDUAL)) != 0)
                {
                    ppTI = GetDispatchTypeInfoFromCustomInterfaceTypeInfo(ppTI);
                    if (GetTypeAttr(ppTI).typekind == System.Runtime.InteropServices.ComTypes.TYPEKIND.TKIND_DISPATCH)
                    {
                        return(ppTI);
                    }
                }
            }
            return(null);
        }
Example #8
0
        public override List <ITlibNode> GenChildren()
        {
            var res = new List <ITlibNode>();

            _ti.GetRefTypeInfo(_ta.tdescAlias.hreftype, out var oti);
            CommonBuildTlibNode(this, oti, false, false, res);
            return(res);
        }
Example #9
0
        public OWTypeDef(ITlibNode parent, ITypeInfo ti, TypeAttr ta)
        {
            Parent = parent;
            _ta    = ta;
            _ti    = ti;

            _ti.GetRefTypeInfo(_ta.tdescAlias.hreftype, out var oti);
            _name = oti.GetName() + " " + ti.GetName();
        }
Example #10
0
        private void GetParameterType(TYPEDESC desc, ITypeInfo info)
        {
            var      vt = (VarEnum)desc.vt;
            TYPEDESC tdesc;

            switch (vt)
            {
            case VarEnum.VT_PTR:
                tdesc = (TYPEDESC)Marshal.PtrToStructure(desc.lpValue, typeof(TYPEDESC));
                GetParameterType(tdesc, info);
                IsByRef = true;
                break;

            case VarEnum.VT_USERDEFINED:
                int href;
                unchecked
                {
                    href = (int)(desc.lpValue.ToInt64() & 0xFFFFFFFF);
                }
                try
                {
                    ITypeInfo refTypeInfo;
                    info.GetRefTypeInfo(href, out refTypeInfo);

                    IntPtr attribPtr;
                    refTypeInfo.GetTypeAttr(out attribPtr);
                    var attribs = (TYPEATTR)Marshal.PtrToStructure(attribPtr, typeof(TYPEATTR));
                    if (attribs.typekind == TYPEKIND.TKIND_ENUM)
                    {
                        _enumGuid = attribs.guid;
                    }
                    _type = new ComDocumentation(refTypeInfo, -1).Name;
                    refTypeInfo.ReleaseTypeAttr(attribPtr);
                }
                catch (COMException) { }
                break;

            case VarEnum.VT_SAFEARRAY:
            case VarEnum.VT_CARRAY:
            case VarEnum.VT_ARRAY:
                tdesc = (TYPEDESC)Marshal.PtrToStructure(desc.lpValue, typeof(TYPEDESC));
                GetParameterType(tdesc, info);
                IsArray = true;
                break;

            default:
                string result;
                if (ComVariant.TypeNames.TryGetValue(vt, out result))
                {
                    _type = result;
                }
                break;
            }
        }
Example #11
0
        public override void BuildIDLInto(IDLFormatter ih)
        {
            ih.AppendLine("[");
            var lprops = new List <string> {
                $"uuid({_ta.guid})"
            };
            var help = _ti.GetHelpDocumentationById(-1, out var context);

            AddHelpStringAndContext(lprops, help, context);
            if (0 != (_ta.wTypeFlags & TypeAttr.TypeFlags.TYPEFLAG_FHIDDEN))
            {
                lprops.Add("hidden");
            }
            if (0 != (_ta.wTypeFlags & TypeAttr.TypeFlags.TYPEFLAG_FDUAL))
            {
                lprops.Add("dual");
            }
            if (0 != (_ta.wTypeFlags & TypeAttr.TypeFlags.TYPEFLAG_FRESTRICTED))
            {
                lprops.Add("restricted");
            }
            if (0 != (_ta.wTypeFlags & TypeAttr.TypeFlags.TYPEFLAG_FNONEXTENSIBLE))
            {
                lprops.Add("nonextensible");
            }
            if (0 != (_ta.wTypeFlags & TypeAttr.TypeFlags.TYPEFLAG_FOLEAUTOMATION))
            {
                lprops.Add("oleautomation");
            }
            for (var i = 0; i < lprops.Count; ++i)
            {
                ih.AppendLine("  " + lprops[i] + (i < (lprops.Count - 1) ? "," : ""));
            }
            ih.AppendLine("]");

            if (_ta.cImplTypes > 0)
            {
                _ti.GetRefTypeOfImplType(0, out var href);
                _ti.GetRefTypeInfo(href, out var ti2);
                ih.AddString($"interface {_name} : ");
                ih.AddLink(ti2.GetName(), "i");
                ih.AppendLine(" {");
            }
            else
            {
                ih.AppendLine("interface " + _name + " {");
            }
            using (new IDLHelperTab(ih))
            {
                Children.ForEach(x => x.BuildIDLInto(ih));
            }
            ih.AppendLine("};");
        }
Example #12
0
        protected string GetComType(ITypeInfo typeInfo, TYPEDESC typeDesc)
        {
            VarEnum varEnum = (VarEnum)typeDesc.vt;

            switch (varEnum)
            {
            case VarEnum.VT_PTR:
                TYPEDESC ptrTypedesc = (TYPEDESC)Marshal.PtrToStructure(typeDesc.lpValue, typeof(TYPEDESC));
                return(GetComType(typeInfo, ptrTypedesc) + "*");

            case VarEnum.VT_SAFEARRAY:
                TYPEDESC arrayTypedesc = (TYPEDESC)Marshal.PtrToStructure(typeDesc.lpValue, typeof(TYPEDESC));
                return(ComBrowserSettings.GetKeyword(VarEnum.VT_SAFEARRAY) + "("
                       + GetComType(typeInfo, arrayTypedesc) + ")");

            case VarEnum.VT_CARRAY:
                TYPEDESC carrayTypedesc = (TYPEDESC)Marshal.PtrToStructure(typeDesc.lpValue, typeof(TYPEDESC));
                return(GetComType(typeInfo, carrayTypedesc) + "[]");

            case VarEnum.VT_USERDEFINED:
                // The .NET definition of GetRefTypeInfo() incorrectly takes an int instead of IntPtr, which fails
                // on 64-bit machines. At least don't throw an unhandled exception here.
                if ((long)typeDesc.lpValue > int.MaxValue)
                {
                    return("<GetRefTypeInfo bug>");
                }

                int       hreftype = (int)typeDesc.lpValue;
                ITypeInfo refTypeInfo;

                try
                {
                    typeInfo.GetRefTypeInfo(hreftype, out refTypeInfo);
                }
                catch (COMException)
                {
                    return("<GetRefTypeInfo failed>");
                }

                try
                {
                    return(Marshal.GetTypeInfoName(refTypeInfo));
                }
                finally
                {
                    Marshal.ReleaseComObject(refTypeInfo);
                }

            default:
                return(GetComType(varEnum));
            }
        }
Example #13
0
        private PropertyBag AddEnumTypeInfoInternal(ITypeInfo typeInfo)
        {
            using (var attrScope = typeInfo.CreateAttrScope())
            {
                if (attrScope.Value.typekind == TYPEKIND.TKIND_ALIAS)
                {
                    ITypeInfo refTypeInfo;
                    typeInfo.GetRefTypeInfo(unchecked ((int)attrScope.Value.tdescAlias.lpValue.ToInt64()), out refTypeInfo);

                    var node = AddEnumTypeInfoInternal(refTypeInfo);
                    if (node != null)
                    {
                        var locator = typeInfo.GetManagedName();

                        var segments = locator.Split('.');
                        if (segments.Length > 0)
                        {
                            var namespaceNode = GetOrCreateNamespaceNode(locator);
                            if (namespaceNode != null)
                            {
                                namespaceNode.SetPropertyNoCheck(segments.Last(), node);
                                return(node);
                            }
                        }
                    }
                }
                else if (attrScope.Value.typekind == TYPEKIND.TKIND_ENUM)
                {
                    var node = GetOrCreateEnumTypeInfoNode(typeInfo);
                    if (node != null)
                    {
                        var count = attrScope.Value.cVars;
                        for (var index = 0; index < count; index++)
                        {
                            using (var varDescScope = typeInfo.CreateVarDescScope(index))
                            {
                                if (varDescScope.Value.varkind == VARKIND.VAR_CONST)
                                {
                                    var name = typeInfo.GetMemberName(varDescScope.Value.memid);
                                    node.SetPropertyNoCheck(name, Marshal.GetObjectForNativeVariant(varDescScope.Value.desc.lpvarValue));
                                }
                            }
                        }

                        return(node);
                    }
                }
            }

            return(null);
        }
        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);
        }
Example #15
0
        private void GetFieldType(TYPEDESC desc, ITypeInfo info)
        {
            var      vt = (VarEnum)desc.vt;
            TYPEDESC tdesc;

            if (vt == VarEnum.VT_PTR)
            {
                tdesc = Marshal.PtrToStructure <TYPEDESC>(desc.lpValue);
                GetFieldType(tdesc, info);
            }
            else if (vt == VarEnum.VT_USERDEFINED)
            {
                int href;
                unchecked
                {
                    //The href is a long, but the size of lpValue depends on the platform, so truncate it after the lword.
                    href = (int)(desc.lpValue.ToInt64() & 0xFFFFFFFF);
                }
                try
                {
                    info.GetRefTypeInfo(href, out ITypeInfo refTypeInfo);
                    refTypeInfo.GetTypeAttr(out IntPtr attribPtr);
                    using (DisposalActionContainer.Create(attribPtr, refTypeInfo.ReleaseTypeAttr))
                    {
                        var attribs = Marshal.PtrToStructure <TYPEATTR>(attribPtr);
                        if (attribs.typekind == TYPEKIND.TKIND_ENUM)
                        {
                            _enumGuid = attribs.guid;
                        }
                        IsReferenceType = ReferenceTypeKinds.Contains(attribs.typekind);
                        _valueType      = new ComDocumentation(refTypeInfo, ComDocumentation.LibraryIndex).Name;
                    }
                }
                catch (COMException) { }
            }
            else if (vt == VarEnum.VT_SAFEARRAY || vt == VarEnum.VT_CARRAY || vt.HasFlag(VarEnum.VT_ARRAY))
            {
                tdesc = Marshal.PtrToStructure <TYPEDESC>(desc.lpValue);
                GetFieldType(tdesc, info);
                IsArray = true;
            }
            else
            {
                if (ComVariant.TypeNames.TryGetValue(vt, out string result))
                {
                    _valueType = result;
                }
            }
        }
        private ComParameter GetParameterInfo(TYPEDESC desc, ITypeInfo info)
        {
            var      vt = (VarEnum)desc.vt;
            TYPEDESC tdesc;

            switch (vt)
            {
            case VarEnum.VT_PTR:
                tdesc = (TYPEDESC)Marshal.PtrToStructure(desc.lpValue, typeof(TYPEDESC));
                var pointer = GetParameterInfo(tdesc, info);
                pointer.IsByRef = true;
                return(pointer);

            case VarEnum.VT_USERDEFINED:
                int href;
                unchecked
                {
                    href = (int)(desc.lpValue.ToInt64() & 0xFFFFFFFF);
                }
                try
                {
                    ITypeInfo refTypeInfo;
                    info.GetRefTypeInfo(href, out refTypeInfo);
                    return(new ComParameter(GetTypeName(refTypeInfo), false));
                }
                catch (Exception)
                {
                    return(new ComParameter("Object", false));
                }

            case VarEnum.VT_SAFEARRAY:
            case VarEnum.VT_CARRAY:
            case VarEnum.VT_ARRAY:
                tdesc = (TYPEDESC)Marshal.PtrToStructure(desc.lpValue, typeof(TYPEDESC));
                var array = GetParameterInfo(tdesc, info);
                array.IsArray = true;
                array.Name   += "()";
                return(array);

            default:
                string result;
                if (TypeNames.TryGetValue(vt, out result))
                {
                    return(new ComParameter(result, false));
                }
                break;
            }
            return(new ComParameter("Object", false));
        }
Example #17
0
        private static string GetStringFromCustomType(ITypeInfo typeinfo, IntPtr refptr)
        {
            int       hRef = (int)(long)refptr;
            ITypeInfo ppTI;

            typeinfo.GetRefTypeInfo(hRef, out ppTI);
            if (ppTI == null)
            {
                return("UnknownCustomtype");
            }
            string strName;

            ppTI.GetDocumentation(-1, out strName, out string _, out int _, out string _);
            return(strName);
        }
Example #18
0
        private static IEnumerable <ITypeInfo> GetReferencedEnums(ITypeLib typeLib, ITypeInfo typeInfo, TYPEDESC typeDesc, Dictionary <Guid, ITypeInfo> processedTypeInfo)
        {
            if ((typeDesc.vt == (short)VarEnum.VT_PTR) || (typeDesc.vt == (short)VarEnum.VT_CARRAY))
            {
                return(GetReferencedEnums(typeLib, typeInfo, (TYPEDESC)Marshal.PtrToStructure(typeDesc.lpValue, typeof(TYPEDESC)), processedTypeInfo));
            }

            if (typeDesc.vt == (short)VarEnum.VT_USERDEFINED)
            {
                typeInfo.GetRefTypeInfo(unchecked ((int)typeDesc.lpValue.ToInt64()), out var refTypeInfo);
                return(GetReferencedEnums(typeLib, refTypeInfo, processedTypeInfo));
            }

            return(Enumerable.Empty <ITypeInfo>());
        }
Example #19
0
        public unsafe void GetFunctionDescriptionsForIUnknown()
        {
            TypeLibTests.LoadStdOle2(out ITypeLib typeLib);
            ITypeInfo typeInfo = typeLib.GetTypeInfoByName("IUnknown");

            // From OleView:
            //
            // [restricted]
            // HRESULT _stdcall QueryInterface(
            //                [in] GUID* riid,
            //                [out] void** ppvObj);

            HResult result = typeInfo.GetFuncDesc(0, out FUNCDESC * description);

            result.Should().Be(HResult.S_OK);

            description->cParams.Should().Be(2);
            description->cParamsOpt.Should().Be(0);
            description->cScodes.Should().Be(0);
            description->callconv.Should().Be(CallConvention.StdCall);
            description->funckind.Should().Be(FunctionKind.PureVirtual);
            description->invkind.Should().Be(InvokeKind.Function);
            description->wFuncFlags.Should().Be(FunctionFlags.Restricted);

            // Return type
            description->elemdescFunc.tdesc.vt.Should().Be(VariantType.HResult);

            // First arg GUID*
            ELEMDESC *element = description->lprgelemdescParam;

            element->tdesc.vt.Should().Be(VariantType.Pointer);
            element->Union.paramdesc.wParamFlags.Should().Be(ParameterFlags.In);
            element->tdesc.Union.lptdesc->vt.Should().Be(VariantType.UserDefined);
            RefTypeHandle handle = element->tdesc.Union.lptdesc->Union.hreftype;

            result = typeInfo.GetRefTypeInfo(handle, out ITypeInfo userDefined);
            result.Should().Be(HResult.S_OK);
            userDefined.GetMemberName(MemberId.Nil).Should().Be("GUID");

            // Second arg void**
            element++;
            element->tdesc.vt.Should().Be(VariantType.Pointer);
            element->Union.paramdesc.wParamFlags.Should().Be(ParameterFlags.Out);
            element->tdesc.Union.lptdesc->vt.Should().Be(VariantType.Pointer);
            element->tdesc.Union.lptdesc->Union.lptdesc->vt.Should().Be(VariantType.Void);

            typeInfo.ReleaseFuncDesc(description);
        }
Example #20
0
        public override List <ITlibNode> GenChildren()
        {
            var res = new List <ITlibNode>();

            if (_ta.cImplTypes > 0)
            {
                if (_ta.cImplTypes > 1)
                {
                    throw new Exception("Multiple inheritance!?");
                }
                _ti.GetRefTypeOfImplType(0, out var href);
                _ti.GetRefTypeInfo(href, out var ti2);
                CommonBuildTlibNode(this, ti2, false, true, res);
            }
            return(res);
        }
Example #21
0
        private static string GetStringFromCustomType(ITypeInfo typeinfo, IntPtr refptr)
        {
            ITypeInfo info;
            int       hRef = (int)((long)refptr);

            typeinfo.GetRefTypeInfo(hRef, out info);
            if (info != null)
            {
                string str;
                string str2;
                string str3;
                int    num2;
                info.GetDocumentation(-1, out str, out str2, out num2, out str3);
                return(str);
            }
            return("UnknownCustomtype");
        }
Example #22
0
 public static bool SwapForInterface(ref ITypeInfo ti, ref TypeAttr ta)
 {
     try
     {
         if (ta.typekind == TypeAttr.TypeKind.TKIND_DISPATCH && 0 != (ta.wTypeFlags & TypeAttr.TypeFlags.TYPEFLAG_FDUAL))
         {
             ti.GetRefTypeOfImplType(-1, out var href);
             ti.GetRefTypeInfo(href, out ti);
             ta = new TypeAttr(ti);
             return(true);
         }
     }
     // ReSharper disable once EmptyGeneralCatchClause
     catch (Exception)
     {
     }
     return(false);
 }
Example #23
0
        public static bool IsEnum(this ITypeInfo typeInfo)
        {
            using (var attrScope = typeInfo.CreateAttrScope())
            {
                if (attrScope.Value.typekind == TYPEKIND.TKIND_ENUM)
                {
                    return(true);
                }

                if (attrScope.Value.typekind == TYPEKIND.TKIND_ALIAS)
                {
                    typeInfo.GetRefTypeInfo(unchecked ((int)attrScope.Value.tdescAlias.lpValue.ToInt64()), out var refTypeInfo);
                    return(refTypeInfo.IsEnum());
                }

                return(false);
            }
        }
Example #24
0
        internal static ITypeInfo GetDispatchTypeInfoFromCustomInterfaceTypeInfo(ITypeInfo typeinfo)
        {
            ITypeInfo ppTI = null;

            try
            {
                int num;
                typeinfo.GetRefTypeOfImplType(-1, out num);
                typeinfo.GetRefTypeInfo(num, out ppTI);
            }
            catch (COMException exception)
            {
                if (exception.ErrorCode != -2147319765)
                {
                    throw;
                }
            }
            return(ppTI);
        }
Example #25
0
        private void GetImplementedInterfaces(ITypeInfo info, TYPEATTR typeAttr)
        {
            IsExtensible = !typeAttr.wTypeFlags.HasFlag(TYPEFLAGS.TYPEFLAG_FNONEXTENSIBLE);
            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, implemented.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);
                    _inherited.Add(intface);
                    ComProject.KnownTypes.TryAdd(attribs.guid, intface);
                }
            }
        }
Example #26
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();
            }
        }
Example #27
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);
            }
        }
Example #28
0
        private void GetImplementedInterfaces(ITypeInfo info, TYPEATTR typeAttr)
        {
            IsExtensible = !typeAttr.wTypeFlags.HasFlag(TYPEFLAGS.TYPEFLAG_FNONEXTENSIBLE);
            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);
                _inherited.Add(intface);
                ComProject.KnownTypes.TryAdd(attribs.guid, intface);

                info.ReleaseTypeAttr(attribPtr);
            }
        }
Example #29
0
 internal static ITypeInfo GetDispatchTypeInfoFromCoClassTypeInfo(ITypeInfo typeinfo)
 {
     int cImplTypes = GetTypeAttr(typeinfo).cImplTypes;
     ITypeInfo ppTI = null;
     for (int i = 0; i < cImplTypes; i++)
     {
         int num2;
         typeinfo.GetRefTypeOfImplType(i, out num2);
         typeinfo.GetRefTypeInfo(num2, out ppTI);
         System.Runtime.InteropServices.ComTypes.TYPEATTR typeAttr = GetTypeAttr(ppTI);
         if (typeAttr.typekind == System.Runtime.InteropServices.ComTypes.TYPEKIND.TKIND_DISPATCH)
         {
             return ppTI;
         }
         if (((short) (typeAttr.wTypeFlags & System.Runtime.InteropServices.ComTypes.TYPEFLAGS.TYPEFLAG_FDUAL)) != 0)
         {
             ppTI = GetDispatchTypeInfoFromCustomInterfaceTypeInfo(ppTI);
             if (GetTypeAttr(ppTI).typekind == System.Runtime.InteropServices.ComTypes.TYPEKIND.TKIND_DISPATCH)
             {
                 return ppTI;
             }
         }
     }
     return null;
 }
Example #30
0
        private void GetParameterType(TYPEDESC desc, ITypeInfo info)
        {
            var      vt = (VarEnum)desc.vt;
            TYPEDESC tdesc;

            if (vt == VarEnum.VT_PTR)
            {
                tdesc = Marshal.PtrToStructure <TYPEDESC>(desc.lpValue);
                GetParameterType(tdesc, info);
                IsByRef = true;
            }
            else if (vt == VarEnum.VT_USERDEFINED)
            {
                int href;
                unchecked
                {
                    href = (int)(desc.lpValue.ToInt64() & 0xFFFFFFFF);
                }

                try
                {
                    info.GetRefTypeInfo(href, out ITypeInfo refTypeInfo);
                    refTypeInfo.GetTypeAttr(out IntPtr attribPtr);
                    using (DisposalActionContainer.Create(attribPtr, refTypeInfo.ReleaseTypeAttr))
                    {
                        var attribs = Marshal.PtrToStructure <TYPEATTR>(attribPtr);
                        var type    = new ComDocumentation(refTypeInfo, ComDocumentation.LibraryIndex).Name;
                        if (attribs.typekind == TYPEKIND.TKIND_ENUM)
                        {
                            _typeName = new ComTypeName(Project, type, attribs.guid, Guid.Empty);
                        }
                        else if (attribs.typekind == TYPEKIND.TKIND_ALIAS)
                        {
                            _typeName = new ComTypeName(Project, type, Guid.Empty, attribs.guid);
                        }
                        else
                        {
                            _typeName = new ComTypeName(Project, type);
                        }
                    }
                }
                catch (COMException)
                {
                    _typeName = new ComTypeName(Project, Tokens.Object);
                }
            }
            else if (vt == VarEnum.VT_SAFEARRAY || vt == VarEnum.VT_CARRAY || vt.HasFlag(VarEnum.VT_ARRAY))
            {
                tdesc = Marshal.PtrToStructure <TYPEDESC>(desc.lpValue);
                GetParameterType(tdesc, info);
                IsArray = true;
            }
            else if (vt == VarEnum.VT_HRESULT)
            {
                _typeName = new ComTypeName(Project, Tokens.Long);
            }
            else
            {
                _typeName = new ComTypeName(Project, (ComVariant.TypeNames.TryGetValue(vt, out string result)) ? result : Tokens.Object);
            }
        }
Example #31
0
 private static string GetStringFromCustomType(ITypeInfo typeinfo, IntPtr refptr)
 {
     ITypeInfo info;
     int hRef = (int) ((long) refptr);
     typeinfo.GetRefTypeInfo(hRef, out info);
     if (info != null)
     {
         string str;
         string str2;
         string str3;
         int num2;
         info.GetDocumentation(-1, out str, out str2, out num2, out str3);
         return str;
     }
     return "UnknownCustomtype";
 }
Example #32
0
        private static IEnumerable <ITypeInfo> GetReferencedEnums(ITypeLib typeLib, ITypeInfo typeInfo, Dictionary <Guid, ITypeInfo> processedTypeInfo)
        {
            if (typeInfo == null)
            {
                yield break;
            }

            var guid = typeInfo.GetOrCreateGuid();

            if (processedTypeInfo.ContainsKey(guid))
            {
                yield break;
            }

            processedTypeInfo.Add(guid, typeInfo);

            if (typeInfo.IsEnum())
            {
                yield return(typeInfo);

                yield break;
            }

            if (typeInfo.GetContainingTypeLib().GetGuid() != typeLib.GetGuid())
            {
                yield break;
            }

            using (var typeAttrScope = typeInfo.CreateAttrScope())
            {
                for (var funcIndex = 0; funcIndex < typeAttrScope.Value.cFuncs; funcIndex++)
                {
                    using (var funcDescScope = typeInfo.CreateFuncDescScope(funcIndex))
                    {
                        foreach (var enumTypeInfo in GetReferencedEnums(typeLib, typeInfo, funcDescScope.Value, processedTypeInfo))
                        {
                            yield return(enumTypeInfo);
                        }
                    }
                }

                for (var varIndex = 0; varIndex < typeAttrScope.Value.cVars; varIndex++)
                {
                    using (var varDescScope = typeInfo.CreateVarDescScope(varIndex))
                    {
                        foreach (var enumTypeInfo in GetReferencedEnums(typeLib, typeInfo, varDescScope.Value, processedTypeInfo))
                        {
                            yield return(enumTypeInfo);
                        }
                    }
                }

                for (var implTypeIndex = 0; implTypeIndex < typeAttrScope.Value.cImplTypes; implTypeIndex++)
                {
                    typeInfo.GetRefTypeOfImplType(implTypeIndex, out var href);
                    typeInfo.GetRefTypeInfo(href, out var refTypeInfo);

                    var refGuid = refTypeInfo.GetGuid();
                    if ((refGuid == typeof(IDispatch).GUID) || (refGuid == typeof(IDispatchEx).GUID))
                    {
                        continue;
                    }

                    foreach (var enumTypeInfo in GetReferencedEnums(typeLib, refTypeInfo, processedTypeInfo))
                    {
                        yield return(enumTypeInfo);
                    }
                }
            }
        }
Example #33
0
 internal static ITypeInfo GetDispatchTypeInfoFromCustomInterfaceTypeInfo(ITypeInfo typeinfo)
 {
     ITypeInfo ppTI = null;
     try
     {
         int num;
         typeinfo.GetRefTypeOfImplType(-1, out num);
         typeinfo.GetRefTypeInfo(num, out ppTI);
     }
     catch (COMException exception)
     {
         if (exception.ErrorCode != -2147319765)
         {
             throw;
         }
     }
     return ppTI;
 }