Ejemplo n.º 1
0
        private string ParamFlagsDescription(ParamDesc pd)
        {
            var flg = pd.wParamFlags;
            var res = new List <string>();

            if (0 != (flg & ParamDesc.ParamFlags.PARAMFLG_FIN))
            {
                res.Add("in");
            }
            if (0 != (flg & ParamDesc.ParamFlags.PARAMFLG_FOUT))
            {
                res.Add("out");
            }
            if (0 != (flg & ParamDesc.ParamFlags.PARAMFLG_FRETVAL))
            {
                res.Add("retval");
            }
            if (0 != (flg & ParamDesc.ParamFlags.PARAMFLG_FOPT))
            {
                res.Add("optional");
            }
            if (0 != (flg & ParamDesc.ParamFlags.PARAMFLG_FLCID))
            {
                res.Add("lcid");
            }
            if (0 != (flg & ParamDesc.ParamFlags.PARAMFLG_FHASDEFAULT) && pd.varDefaultValue != null)
            {
                res.Add("defaultvalue(" + ITypeInfoXtra.QuoteString(pd.varDefaultValue) + ")");
            }
            return("[" + string.Join(", ", res.ToArray()) + "]");
        }
Ejemplo n.º 2
0
        public override List <string> GetAttributes()
        {
            var liba = new List <string>();

            using (var tla = new TypeLibAttr(_tlib))
            {
                liba.Add($"uuid({tla.guid})");
                liba.Add($"version({tla.wMajorVerNum}.{tla.wMinorVerNum})");
            }

            if (_tlib is ITypeLib2 tlib2)
            {
                var cds = new CustomDatas(tlib2);
                {
                    foreach (var cd in cds.Items)
                    {
                        liba.Add("custom(" + cd.guid + ", " + ITypeInfoXtra.QuoteString(cd.varValue) + ")");
                    }
                }
            }

            var help = _tlib.GetHelpDocumentation(out var cnt);

            if (!string.IsNullOrEmpty(help))
            {
                liba.Add($"helpstring(\"{help}\")");
            }
            if (cnt != 0)
            {
                liba.Add($"helpcontext({cnt.PaddedHex()})");
            }

            return(liba);
        }
Ejemplo n.º 3
0
        public override List <ITlibNode> GenChildren()
        {
            var ti = _ti;
            var ta = _ta;

            ITypeInfoXtra.SwapForInterface(ref ti, ref ta);
            var res = new List <ITlibNode> {
                new OWInterface(this, ti, ta, false)
            };

            return(res);
        }
Ejemplo n.º 4
0
        public static void GetAllFuncCustData(int memberid, INVOKEKIND invokekind, ITypeInfo ti, ref List <string> lprops)
        {
            if (!(ti is ITypeInfo2 t2))
            {
                return;
            }

            var custdata = new CUSTDATA();
            var ptr      = Marshal.AllocHGlobal(Marshal.SizeOf(custdata));

            try
            {
                t2.GetFuncIndexOfMemId(memberid, invokekind, out var index);
                t2.GetAllFuncCustData(index, ptr);
                try
                {
                    custdata = Marshal.PtrToStructure <CUSTDATA>(ptr);
                    for (var x = 0; x < custdata.cCustData; x++)
                    {
                        var item    = new CUSTDATAITEM(); // just to size it for next line
                        var itemPtr = custdata.prgCustData + (x * Marshal.SizeOf(item));
                        item = Marshal.PtrToStructure <CUSTDATAITEM>(itemPtr);
                        lprops.Add($"custom({item.guid}, {ITypeInfoXtra.QuoteString(item.varValue)})");
                    }
                }
                finally
                {
                    NativeMethods.ClearCustData(ptr);
                }
            }
            catch (COMException e)
            {
                const int TYPE_E_ELEMENTNOTFOUND = unchecked ((int)0x8002802B);
                if (e.HResult != TYPE_E_ELEMENTNOTFOUND)
                {
                    throw;
                }

                // not found; ignore
            }
            finally
            {
                Marshal.FreeHGlobal(ptr);
            }
        }
Ejemplo n.º 5
0
        public void CommonBuildTlibNode(ITlibNode parent, ITypeInfo ti, bool topLevel, bool swapfordispatch, List <ITlibNode> res)
        {
            var ta = ti.GetTypeAttr();

            switch (ta.typekind)
            {
            case TypeAttr.TypeKind.TKIND_DISPATCH:
                res.Add(new OWDispInterface(this, ti, ta, topLevel));
                if (swapfordispatch && ITypeInfoXtra.SwapForInterface(ref ti, ref ta))
                {
                    res.Add(new OWInterface(this, ti, ta, topLevel));
                }
                break;

            case TypeAttr.TypeKind.TKIND_INTERFACE:
                res.Add(new OWInterface(this, ti, ta, topLevel));
                break;

            case TypeAttr.TypeKind.TKIND_ALIAS:
                res.Add(new OWTypeDef(this, ti, ta));
                break;

            case TypeAttr.TypeKind.TKIND_ENUM:
                res.Add(new OWEnum(this, ti, ta));
                break;

            case TypeAttr.TypeKind.TKIND_COCLASS:
                res.Add(new OWCoClass(this, ti, ta));
                break;

            case TypeAttr.TypeKind.TKIND_RECORD:
                res.Add(new OWRecord(this, ti, ta));
                break;

            case TypeAttr.TypeKind.TKIND_MODULE:
                res.Add(new OWModule(this, ti, ta));
                break;
            }
        }
Ejemplo n.º 6
0
        public static void GetCustData(ITypeInfo ti, ref List <string> lprops)
        {
            if (!(ti is ITypeInfo2 t2))
            {
                return;
            }

            var custdata = new CUSTDATA();
            var ptr      = Marshal.AllocHGlobal(Marshal.SizeOf(custdata));

            t2.GetAllCustData(ptr);
            custdata = Marshal.PtrToStructure <CUSTDATA>(ptr);
            for (var x = 0; x < custdata.cCustData; x++)
            {
                var item    = new CUSTDATAITEM(); // just to size it for next line
                var itemPtr = custdata.prgCustData + (x * Marshal.SizeOf(item));
                item = Marshal.PtrToStructure <CUSTDATAITEM>(itemPtr);
                lprops.Add($"custom({item.guid}, {ITypeInfoXtra.QuoteString(item.varValue)})");
            }
            NativeMethods.ClearCustData(ptr);
            Marshal.FreeHGlobal(ptr);
        }
Ejemplo n.º 7
0
        public override void BuildIDLInto(IDLFormatter ih)
        {
            // Header for type library, followed by a first pass to pre-declare
            // interfaces.
            // dispinterfaces aren't shown seperately.

            ih.AppendLine("// Generated .IDL file (by OleWoo)");
            ih.AppendLine("[");
            var liba = new List <string>();

            using (var tla = new TypeLibAttr(_tlib))
            {
                liba.Add($"uuid({tla.guid})");
                liba.Add($"version({tla.wMajorVerNum}.{tla.wMinorVerNum})");
            }
            var cds = new CustomDatas(_tlib as ITypeLib2);
            {
                foreach (var cd in cds.Items)
                {
                    liba.Add("custom(" + cd.guid + ", " + ITypeInfoXtra.QuoteString(cd.varValue) + ")");
                }
            }
            var help = _tlib.GetHelpDocumentation(out var cnt);

            if (!string.IsNullOrEmpty(help))
            {
                liba.Add($"helpstring(\"{help}\")");
            }
            if (cnt != 0)
            {
                liba.Add($"helpcontext({cnt.PaddedHex()})");
            }

            cnt = 0;
            liba.ForEach(x => ih.AppendLine("  " + x + (++cnt == liba.Count ? "" : ",")));
            ih.AppendLine("]");
            ih.AppendLine("library " + ShortName);
            ih.AppendLine("{");
            using (new IDLHelperTab(ih))
            {
                // How do I know I'm importing stdole2??!
                // Forward declare all interfaces.
                ih.AppendLine("// Forward declare all types defined in this typelib");

                /*
                 * Need to collect all dumpable interface names, in case we have dispinterfaces which don't have
                 * top level interfaces.  In THIS case, we'd dump the dispinterface.
                 */
                var interfaceNames = Children.Aggregate <ITlibNode, ICollection <string> >(new HashSet <string>(),
                                                                                           (x, y) =>
                {
                    if ((y as OWInterface) != null)
                    {
                        x.Add(y.ShortName);
                    }
                    return(x);
                });
                Children.FindAll(x => ((x as OWInterface) != null || (x as OWDispInterface) != null)).ForEach(
                    x => ih.AppendLine(x.Name)
                    );
                Children.FindAll(x => x.DisplayAtTLBLevel(interfaceNames)).ForEach(
                    x => { x.BuildIDLInto(ih); ih.AppendLine(""); }
                    );
            }
            ih.AppendLine("};");
        }