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()) + "]"); }
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); }
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); } }
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); }
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("};"); }