/// <summary> /// Gets the name of the default COM interface for this object. /// </summary> /// <remarks> /// Uses the COM ITypeInfo interface to get the information. Does not throw. /// </remarks> /// <param name="obj"></param> /// <returns>The name of the interface; null on any exception</returns> /// internal static string GetDefaultCOMInterfaceName(object obj) { try { string intfName = (string)Marshal.GetComObjectData(obj, "NETLinkCOMInterface"); if (intfName == null) { UCOMIDispatch iDisp = GetIDispatch(obj); UCOMITypeInfo iTypeInfo = GetITypeInfo(obj, iDisp); string typeLibName, docStr, helpFile; int helpContext; iTypeInfo.GetDocumentation(-1, out intfName, out docStr, out helpContext, out helpFile); UCOMITypeLib iTypeLib; int index; iTypeInfo.GetContainingTypeLib(out iTypeLib, out index); iTypeLib.GetDocumentation(-1, out typeLibName, out docStr, out helpContext, out helpFile); intfName = typeLibName + "." + intfName; Marshal.SetComObjectData(obj, "NETLinkCOMInterface", intfName); // Not strictly necessary to release here, but better to force it now than rely on GC to do it later. // Cannot release iDisp or iTypeInfo, as they might be cached in the object. Marshal.ReleaseComObject(iTypeLib); } return(intfName); } catch (Exception) { return(null); } }
internal static String GetTypeName(UCOMITypeInfo typeInfo) { String name; String dummy1 = null; int dummy2 = 0; String dummy3 = null; typeInfo.GetDocumentation(-1, out name, out dummy1, out dummy2, out dummy3); return(name); }
static void DealWithTypeInfo(UCOMITypeInfo it) { // Get the names from ITypeInfo string name; string docstring; Int32 ctxt; string helpfile; // TypeInfo name it.GetDocumentation(-1, out name, out docstring, out ctxt, out helpfile); IntPtr pa; it.GetTypeAttr(out pa); TYPEATTR ta = (TYPEATTR)Marshal.PtrToStructure(pa, typeof(TYPEATTR)); DealWithName(name, ta.guid); // Deal with funcs for (int i = 0; i < ta.cFuncs; i++) { IntPtr pfd; it.GetFuncDesc(i, out pfd); FUNCDESC fd = (FUNCDESC)Marshal.PtrToStructure(pfd, typeof(FUNCDESC)); it.GetDocumentation(fd.memid, out name, out docstring, out ctxt, out helpfile); DealWithName(name, Guid.Empty); } // Deal with vars for (int i = 0; i < ta.cVars; i++) { IntPtr pvd; it.GetVarDesc(i, out pvd); VARDESC vd = (VARDESC)Marshal.PtrToStructure(pvd, typeof(VARDESC)); it.GetDocumentation(vd.memid, out name, out docstring, out ctxt, out helpfile); DealWithName(name, Guid.Empty); } }
public static String TYPEDESCToStringInt(TypeLibrary typeLib, UCOMITypeInfo typeInfo, TYPEDESC typeDesc, bool comType, int level) { String ret; try { if ((VarEnum)typeDesc.vt == VarEnum.VT_PTR || (VarEnum)(typeDesc.vt & ActiveX.VT_TYPEMASK) == VarEnum.VT_SAFEARRAY) { TYPEDESC pTypeDesc = (TYPEDESC)Marshal.PtrToStructure(typeDesc.lpValue, typeof(TYPEDESC)); ret = TYPEDESCToStringInt(typeLib, typeInfo, pTypeDesc, comType, level + 1); if ((VarEnum)(typeDesc.vt & ActiveX.VT_TYPEMASK) == VarEnum.VT_SAFEARRAY) { // FIXME - what about the non-comType return("SAFEARRAY(" + ret + ")"); } if (comType) { ret += "*"; } else { // void* become IntPtr if (ret.Equals("void")) { ret = "System.IntPtr"; } else { // The first pointer is not a ref, its only // a ref if there are two // FIXME - what if there are more? if (level == 1) { ret = "ref " + ret; } } } return(ret); } if ((VarEnum)(typeDesc.vt & ActiveX.VT_TYPEMASK) == VarEnum.VT_CARRAY) { // typeDesc.lpValue in this case is really the laValue // (since TYPEDESC is a contains a union of pointers) ARRAYDESC pArrayDesc = (ARRAYDESC)Marshal.PtrToStructure(typeDesc.lpValue, typeof(ARRAYDESC)); ret = TYPEDESCToStringInt(typeLib, typeInfo, pArrayDesc.tdescElem, comType, level + 1); // Just show the number of diminsions, don't worry about // showing the size of each since we don't want to // get into marshalling the variable length ARRAYDESC // structure for (int i = 0; i < pArrayDesc.cDims; i++) { ret += "[]"; } return(ret); } if ((VarEnum)typeDesc.vt == VarEnum.VT_USERDEFINED) { UCOMITypeInfo uTypeInfo = null; // FIXME - sometimes this chokes and hangs due to a bad // handle value here, need to do something to prevent this int href = typeDesc.lpValue.ToInt32(); typeInfo.GetRefTypeInfo(href, out uTypeInfo); if (uTypeInfo != null) { String docName; String docString; int helpContext; String helpFile; uTypeInfo.GetDocumentation(-1, out docName, out docString, out helpContext, out helpFile); // Fix up misc references if (docName.Equals("GUID")) { docName = "System.Guid"; } // Present the user names for the types in COM // mode, but for the CLR types, get the real // underlying names if (!comType) { return(typeLib.ResolveTypeDef(docName, comType)); } return(docName); } else { TraceUtil.WriteLineWarning(null, "USER: "******" 0x" + href.ToString("X") + " ***UNKNOWN***"); return("(userDef unknown)"); } } return(GetTypeStr(typeDesc.vt, comType)); } catch (Exception ex) { TraceUtil.WriteLineWarning (null, "ActiveX type conversion error: " + ex); return("(error)"); } }
internal static String GetTypeName(UCOMITypeInfo typeInfo) { String name; String dummy1 = null; int dummy2 = 0; String dummy3 = null; typeInfo.GetDocumentation(-1, out name, out dummy1, out dummy2, out dummy3); return name; }