public override void GetDetailText() { // See if we have type lib information from the registry if (_container == null && _typeLibString != null && _typeLibVersion != null) { try { _container = TypeLibrary.GetTypeLib (new Guid(_typeLibString), _typeLibVersion); _typeLib = (TypeLibrary)_container; } catch (Exception ex) { TraceUtil.WriteLineWarning (this, "Error getting typelib for " + this + " ex: " + ex); // Ignore } } base.GetDetailText(); }
internal static void MemberDetailText(MemberInfo mi) { GetDesc(mi, "Member"); String memberType; if (mi.MemberType == MemberTypes.TypeInfo) { memberType = GetTypeKind((Type)mi); } else { memberType = mi.MemberType.ToString(); } String memInfo = MemberInfoString(mi, PARENS); if (memInfo != null) { memberType += memInfo; } ILinkTarget linkTarget = null; if (mi.DeclaringType != null) { TypeLibrary typeLib = TypeLibrary.GetTypeLib(mi.DeclaringType); if (typeLib != null) { linkTarget = ComLinkHelper.CLHelper; } } // No AX type linkage available, link to the assy/types nodes if (linkTarget == null) { linkTarget = TypeLinkHelper.TLHelper; } DetailPanel.AddLink(memberType, !ObjectBrowser.INTERNAL, 10, linkTarget, mi, HelpLinkHelper. MakeLinkModifier(mi)); if (mi.DeclaringType != null) { DetailPanel.AddLink("Member Declaring Type", !ObjectBrowser.INTERNAL, 61, TypeLinkHelper.TLHelper, mi.DeclaringType, HelpLinkHelper. MakeLinkModifier(mi.DeclaringType)); } }
internal static void OpenFile(String fileName) { TypeLibrary lib = TypeLibrary.GetTypeLib(fileName); if (lib == null) { throw new Exception("Typelib failed to open"); } // Make sure this node is presented and selected ObjectBrowser.TabControl.SelectedTab = _comTabPage; SelectTypeLib(lib); }
// For linking to the type information for this object public String GetLinkName(Object linkModifier) { if (linkModifier is TypeLibrary) { return(((TypeLibrary)linkModifier).GetName()); } if (linkModifier is Type) { Type type = (Type)linkModifier; TypeLibrary typeLib = TypeLibrary.GetTypeLib(type); return(typeLib.GetMemberName(type)); } return(linkModifier.ToString()); }
// This could either be a MemberInfo, Type or a TypeLibrary, // and we point // to the correct node public void ShowTarget(Object linkModifier) { BrowserTreeNode resultNode = null; // A type library if (linkModifier is TypeLibrary) { resultNode = ComSupport.FindTypeLib(((TypeLibrary)linkModifier).Key); } else { Type type; if (linkModifier is Type) { type = (Type)linkModifier; } else { type = ((MemberInfo)linkModifier).DeclaringType; } // Get the typelib node TypeLibrary typeLib = TypeLibrary.GetTypeLib(type); if (typeLib == null) { return; } // Find the type, this could be a class or an interface ComTypeLibTreeNode typeLibNode = (ComTypeLibTreeNode)ComSupport.FindTypeLib(typeLib.Key); String typeName = typeLib.GetMemberName(type); typeLibNode.ExpandNode(); resultNode = SearchNode(typeLibNode, typeName); // Find the member (Type is also a MemberInfo) if (!(linkModifier is Type)) { MemberInfo mi = (MemberInfo)linkModifier; ComTypeTreeNode typeTreeNode = (ComTypeTreeNode)resultNode; resultNode = FindMember(typeLibNode, typeTreeNode, mi); } } // Point to the result if (resultNode != null) { ObjectBrowser.TabControl.SelectedTab = ComSupport.ComTabPage; resultNode.PointToNode(); } }
internal static void GetDetailAxType(Type type, MemberInfo memberInfo, String desc, int position) { TypeLibrary typeLib = TypeLibrary.GetTypeLib(type); if (typeLib != null) { if (desc == null) { desc = "ActiveX Type"; } if (memberInfo is MethodInfo) { desc = "Method Return Type (AX)"; } if (position == 0) { position = 15; } DetailPanel.AddLink(desc, !ObjectBrowser.INTERNAL, position, ComLinkHelper.CLHelper, type, HelpLinkHelper. MakeLinkModifier(type)); DetailPanel.AddLink("Type Library", !ObjectBrowser.INTERNAL, 180, ComLinkHelper.CLHelper, typeLib, HelpLinkHelper. MakeLinkModifier(typeLib)); } }
// This is used for the case of a class outside of a type // libarary protected Type GetTypeForClass() { Type type = null; // See if we have type lib information from the registry if (_typeLibString != null) { return(GetTypeFromTypeLib (TypeLibrary.GetTypeLib(new Guid(_typeLibString), _typeLibVersion))); } // Have to try and create the object and get the type lib // information from the created object if (TraceUtil.If(this, TraceLevel.Info)) { TraceUtil.WriteLineInfo(this, "Attempting to create obj for: " + this); } IntPtr comObj; int result = ActiveX.CoCreateInstance(ref _guid, (IntPtr)0, ActiveX.CLSCTX_SERVER, ref ActiveX.IUnknownIID, out comObj); if (result == 0) { ComObjectInfo objInfo = null; try { // Wrap our object info stuff and get the type objInfo = new ComObjectInfo(comObj); type = GetTypeFromTypeLib(objInfo.TypeLib); } catch (Exception ex) { _typeFailedException = new Exception("Unable to determine CLR type for " + GetName(), ex); throw _typeFailedException; } finally { try { // Clean up the object info, if we made it that // far if (objInfo != null) { Object o = objInfo.Obj; ObjectInfo.RemoveObjectInfo(o); while (true) { int count = Marshal.ReleaseComObject(o); TraceUtil.WriteLineInfo (this, "final Marshal.ReleaseComObject count: " + count); if (count <= 0) { break; } } } while (true) { int count = Marshal.Release(comObj); TraceUtil.WriteLineInfo (this, "final Marshal.Release count: " + count); if (count <= 0) { break; } } } catch (Exception ex) { TraceUtil.WriteLineWarning (this, "error on cleanup: " + ex); // We tried... } ActiveX.CoFreeUnusedLibraries(); } return(type); } _typeFailedException = new Exception("Unable to determine CLR type because " + "I can't create a COM object (0x" + result.ToString("X") + ") from CLSID: " + _guidStr); throw _typeFailedException; }
// Returns the index of this object's type in the typelib protected int GetTypeLib(IntPtr dispPtr) { if (TraceUtil.If(this, TraceLevel.Info)) { Trace.WriteLine("ComObjInfo::GetTypeLib: " + _obj + " type: " + _obj.GetType()); } if (_typeLib != null) { return(-1); } UCOMITypeLib iTypeLib; int index = -1; try { IDispatch idisp = (IDispatch) Marshal.GetObjectForIUnknown(dispPtr); int count; int result = idisp.GetTypeInfoCount(out count); if (result != 0) { TraceUtil.WriteLineWarning (typeof(ComObjectInfo), "ComObjInfo - " + "GetTypeInfoCount failed: 0x" + result.ToString("x") + " obj: " + _obj); throw new COMException("(probably a bug, please report) " + "Failed on GetTypeInfoCount", result); } if (count == 0) { TraceUtil.WriteLineWarning (typeof(ComObjectInfo), "ComObjInfo - " + " typeinfo count = 0: " + _obj); throw new Exception("This object has no type information " + "(GetTypeInfoCount returned 0). "); } result = idisp.GetTypeInfo(0, 0, out _typeInfo); if (result != 0) { TraceUtil.WriteLineWarning(typeof(ComObjectInfo), "ComObjInfo - " + "typeInfo not found:" + _obj); throw new COMException("(probably a bug, please report) " + "Failed to get ITypeInfo", result); } if (_typeInfo == null) { TraceUtil.WriteLineWarning(typeof(ComObjectInfo), "ComObjInfo - " + "typeInfo not found:" + _obj); throw new Exception("(probably a bug, please report) " + "Null TypeInfo pointer returned"); } // Now we can get the type library information using these // nice interfaces provided as part of the interop services _typeInfo.GetContainingTypeLib(out iTypeLib, out index); _typeLib = TypeLibrary.GetTypeLib(iTypeLib); } catch (Exception ex) { if (_typeInfo != null) { Guid guid = BasicInfo.GuidFromTypeInfo(_typeInfo); TraceUtil.WriteLineWarning(typeof(ComObjectInfo), "ComObjInfo (type " + guid + ")"); } TraceUtil.WriteLineWarning(typeof(ComObjectInfo), "Containing typelib not found:" + ex); throw new Exception("Cannot get TypeLib for object. " + "Getting the TypeLib information for " + "an object is required as this contains " + "the type information used to display " + "the object. ", ex); } if (TraceUtil.If(this, TraceLevel.Info)) { Trace.WriteLine("ComObjInfo - containing typelib index: " + index); } return(index); }
// Constructor from creating withing a typelib internal override void Setup(TypeLibrary typeLib, TYPEKIND typeKind, int index) { base.Setup(typeLib, typeKind, index); Init(); _container = typeLib; TYPEATTR typeAttr; IntPtr typeAttrPtr; _typeInfo.GetTypeAttr(out typeAttrPtr); typeAttr = (TYPEATTR)Marshal.PtrToStructure(typeAttrPtr, typeof(TYPEATTR)); if (typeKind == TYPEKIND.TKIND_DISPATCH) { _infoType = "Dispatch Interface"; _dispatch = true; } else { _infoType = "Interface"; } if ((typeAttr.wTypeFlags & TYPEFLAGS.TYPEFLAG_FDUAL) != 0) { _infoType = "Dual Interface"; _dispatch = true; _dual = true; } // Members for (int i = 0; i < typeAttr.cFuncs; i++) { // Some members for a dispatch interface are not added // because they are the inherited members from the // IDispatch interface ComMemberInfo mi = ComMemberInfo. MakeComMemberInfo(this, typeKind, _typeInfo, i, _dispatch, _dual); if (mi != null) { _members.Add(mi); _memberNames.Add(mi.NameKey, mi); } } // Inherited interfaces for (int i = 0; i < typeAttr.cImplTypes; i++) { int href; int refTypeIndex; UCOMITypeInfo refTypeInfo; UCOMITypeLib refITypeLib; TypeLibrary refTypeLib; try { _typeInfo.GetRefTypeOfImplType(i, out href); _typeInfo.GetRefTypeInfo(href, out refTypeInfo); refTypeInfo.GetContainingTypeLib(out refITypeLib, out refTypeIndex); refTypeLib = TypeLibrary.GetTypeLib(refITypeLib); ComInterfaceInfo mi = ComInterfaceInfo.GetInterfaceInfo(refTypeLib, typeAttr.typekind, refTypeIndex); if (TraceUtil.If(this, TraceLevel.Verbose)) { Trace.WriteLine(" inherit: " + mi); } _members.Add(mi); _parentCount += 1 + mi.ParentCount; // Don't set the typelib on the member as multiple // typelibs may refer to the same interface mi._container = this; } catch (Exception ex) { ErrorDialog.Show (ex, "Warning - this error was detected when attempting " + "to find an ancestor of the interface " + _name + ". This is normal in the case where the type " + "library containing that interface " + "is not available. " + "In other situations this might be a bug and " + "should be reported.", "Warning - Cannot Access Inherited Interface", MessageBoxIcon.Warning); } } if (_dual) { _printName = (String)_name.Clone(); _printName += " (Dual)"; } else { _printName = _name; } _typeInfo.ReleaseTypeAttr(typeAttrPtr); }