Getting Typelib Information

In Part 2 of this series some of you may have wondered how it was that you only had to send in the name of the COM server and all of the OLEPublic classes as well as their progids and clsids would be added to the application manifest XML. Well, that was facilitated by using the TLI.TypeLibInfo class (part of the typinf32.dll). I thought it might be useful to post a short blog entry that gave you some code so that you could explore this object and what it provides in a little more depth. You might also take a look at the source for the Object Browser that comes with VFP as well. In any event, here is the code. I’ve provided all of the constants to be thorough, but the actual working code I’m providing is quite short. Disclaimer: I believe I got the code that I modified for this example out on the MSDN originally. I don’t have the link handy or I would post it. (cut-n-paste the code into a prg and run it, when prompted go select a COM server.

#DEFINE tliErrNoCurrentTypelib    -2147220991    && No current typelib. Use the ContainingFile property or LoadRegTypeLib method to load a current typelib.
#DEFINE tliErrCantLoadLibrary    -2147220990    && The specified file could not be found, or the file doesn‘t contain a valid typelib.
#DEFINE tliErrTypeLibNotRegistered    -2147220989    && No matching typelib is registered, or the registered information is invalid.
#DEFINE tliErrSearchResultsChanged    -2147220988    && The parent search object has changed. This reference is no longer valid.
#DEFINE tliErrNotApplicable    -2147220987    && Not applicable to current search results.
#DEFINE tliErrIncompatibleData    -2147220986    && Previous data incompatible with current search.
#DEFINE tliErrIncompatibleSearchType    -2147220985    && The requested TypeInfo does not match the requested search type.
#DEFINE tliErrIncompatibleTypeKind    -2147220984    && Not applicable for this type of TypeInfo object.
#DEFINE tliErrInaccessibleImportLib    -2147220983    && This TypeInfo refers to an external type library which isn‘t available through the registry.
#DEFINE tliErrNoDefaultValue    -2147220982    && Default value not specified.
#DEFINE tliErrDataNotAvailable    -2147220981    && For this functionality, the MemberInfo object must be obtained through the Members collection, not GetMember.
#DEFINE tliErrNotAnEntryPoint    -2147220980    && DllEntry data is not applicable to this MemberInfo.
#DEFINE tliErrStopFiltering    -2147220979    && Raise this error in CustomFilter_Visit to stop filtering.
#DEFINE tliErrArrayBoundsNotAvailable    -2147220978    && Type is not a fixed size array.
#DEFINE tliErrSearchResultsNotSorted    -2147220977    && SearchResults collection must be sorted.
#DEFINE tliErrTypeNotArray    -2147220976    && Type not an array.
#DEFINE TYPEFLAG_NONE    0    && OLE Automation TYPEFLAG values
#DEFINE TYPEFLAG_FAPPOBJECT    1    && OLE Automation TYPEFLAG values
#DEFINE TYPEFLAG_FCANCREATE    2    && OLE Automation TYPEFLAG values
#DEFINE TYPEFLAG_FLICENSED    4    && OLE Automation TYPEFLAG values
#DEFINE TYPEFLAG_FPREDECLID    8    && OLE Automation TYPEFLAG values
#DEFINE TYPEFLAG_FHIDDEN    16    && OLE Automation TYPEFLAG values
#DEFINE TYPEFLAG_FCONTROL    32    && OLE Automation TYPEFLAG values
#DEFINE TYPEFLAG_FDUAL    64    && OLE Automation TYPEFLAG values
#DEFINE TYPEFLAG_FNONEXTENSIBLE    128    && OLE Automation TYPEFLAG values
#DEFINE TYPEFLAG_FOLEAUTOMATION    256    && OLE Automation TYPEFLAG values
#DEFINE TYPEFLAG_FRESTRICTED    512    && OLE Automation TYPEFLAG values
#DEFINE TYPEFLAG_FAGGREGATABLE    1024    && OLE Automation TYPEFLAG values
#DEFINE TYPEFLAG_FREPLACEABLE    2048    && OLE Automation TYPEFLAG values
#DEFINE TYPEFLAG_FDISPATCHABLE    4096    && OLE Automation TYPEFLAG values
#DEFINE TYPEFLAG_FREVERSEBIND    8192    && OLE Automation TYPEFLAG values
#DEFINE TYPEFLAG_FPROXY    16384    && OLE Automation TYPEFLAG values
#DEFINE TYPEFLAG_DEFAULTFILTER    528    && OLE Automation TYPEFLAG values
#DEFINE TYPEFLAG_COCLASSATTRIBUTES    1599    && Valid attributes for specified type kind
#DEFINE TYPEFLAG_INTERFACEATTRIBUTES    31696    && Valid attributes for specified type kind
#DEFINE TYPEFLAG_DISPATCHATTRIBUTES    23184    && Valid attributes for specified type kind
#DEFINE TYPEFLAG_ALIASATTRIBUTES    528    && Valid attributes for specified type kind
#DEFINE TYPEFLAG_MODULEATTRIBUTES    528    && Valid attributes for specified type kind
#DEFINE TYPEFLAG_ENUMATTRIBUTES    528    && Valid attributes for specified type kind
#DEFINE TYPEFLAG_RECORDATTRIBUTES    528    && Valid attributes for specified type kind
#DEFINE TYPEFLAG_UNIONATTRIBUTES    528    && Valid attributes for specified type kind
#DEFINE IMPLTYPEFLAG_FDEFAULT    1    && OLE Automation IMPLTYPEFLAG values
#DEFINE IMPLTYPEFLAG_FSOURCE    2    && OLE Automation IMPLTYPEFLAG values
#DEFINE IMPLTYPEFLAG_FRESTRICTED    4    && OLE Automation IMPLTYPEFLAG values
#DEFINE IMPLTYPEFLAG_FDEFAULTVTABLE    8    && OLE Automation IMPLTYPEFLAG values
#DEFINE TKIND_ENUM    0    && OLE Automation TYPEKIND values
#DEFINE TKIND_RECORD    1    && OLE Automation TYPEKIND values
#DEFINE TKIND_MODULE    2    && OLE Automation TYPEKIND values
#DEFINE TKIND_INTERFACE    3    && OLE Automation TYPEKIND values
#DEFINE TKIND_DISPATCH    4    && OLE Automation TYPEKIND values
#DEFINE TKIND_COCLASS    5    && OLE Automation TYPEKIND values
#DEFINE TKIND_ALIAS    6    && OLE Automation TYPEKIND values
#DEFINE TKIND_UNION    7    && OLE Automation TYPEKIND values
#DEFINE TKIND_MAX    8    && OLE Automation TYPEKIND values
#DEFINE FUNCFLAG_NONE    0    && OLE Automation FUNCFLAG values
#DEFINE FUNCFLAG_FRESTRICTED    1    && OLE Automation FUNCFLAG values
#DEFINE FUNCFLAG_FSOURCE    2    && OLE Automation FUNCFLAG values
#DEFINE FUNCFLAG_FBINDABLE    4    && OLE Automation FUNCFLAG values
#DEFINE FUNCFLAG_FREQUESTEDIT    8    && OLE Automation FUNCFLAG values
#DEFINE FUNCFLAG_FDISPLAYBIND    16    && OLE Automation FUNCFLAG values
#DEFINE FUNCFLAG_FDEFAULTBIND    32    && OLE Automation FUNCFLAG values
#DEFINE FUNCFLAG_FHIDDEN    64    && OLE Automation FUNCFLAG values
#DEFINE FUNCFLAG_FUSESGETLASTERROR    128    && OLE Automation FUNCFLAG values
#DEFINE FUNCFLAG_FDEFAULTCOLLELEM    256    && OLE Automation FUNCFLAG values
#DEFINE FUNCFLAG_FUIDEFAULT    512    && OLE Automation FUNCFLAG values
#DEFINE FUNCFLAG_FNONBROWSABLE    1024    && OLE Automation FUNCFLAG values
#DEFINE FUNCFLAG_FREPLACEABLE    2048    && OLE Automation FUNCFLAG values
#DEFINE FUNCFLAG_FIMMEDIATEBIND    4096    && OLE Automation FUNCFLAG values
#DEFINE FUNCFLAG_DEFAULTFILTER    65    && OLE Automation FUNCFLAG values
#DEFINE VARFLAG_NONE    0    && OLE Automation VARFLAG values
#DEFINE VARFLAG_FREADONLY    1    && OLE Automation VARFLAG values
#DEFINE VARFLAG_FSOURCE    2    && OLE Automation VARFLAG values
#DEFINE VARFLAG_FBINDABLE    4    && OLE Automation VARFLAG values
#DEFINE VARFLAG_FREQUESTEDIT    8    && OLE Automation VARFLAG values
#DEFINE VARFLAG_FDISPLAYBIND    16    && OLE Automation VARFLAG values
#DEFINE VARFLAG_FDEFAULTBIND    32    && OLE Automation VARFLAG values
#DEFINE VARFLAG_FHIDDEN    64    && OLE Automation VARFLAG values
#DEFINE VARFLAG_FRESTRICTED    128    && OLE Automation VARFLAG values
#DEFINE VARFLAG_FDEFAULTCOLLELEM    256    && OLE Automation VARFLAG values
#DEFINE VARFLAG_FUIDEFAULT    512    && OLE Automation VARFLAG values
#DEFINE VARFLAG_FNONBROWSABLE    1024    && OLE Automation VARFLAG values
#DEFINE VARFLAG_FREPLACEABLE    2048    && OLE Automation VARFLAG values
#DEFINE VARFLAG_FIMMEDIATEBIND    4096    && OLE Automation VARFLAG values
#DEFINE VARFLAG_DEFAULTFILTER    192    && OLE Automation VARFLAG values
#DEFINE SYS_WIN16    0    && OLE Automation SYS values
#DEFINE SYS_WIN32    1    && OLE Automation SYS values
#DEFINE SYS_MAC    2    && OLE Automation SYS values
#DEFINE LIBFLAG_FRESTRICTED    1    && OLE Automation LIBFLAG values
#DEFINE LIBFLAG_FCONTROL    2    && OLE Automation LIBFLAG values
#DEFINE LIBFLAG_FHIDDEN    4    && OLE Automation LIBFLAG values
#DEFINE LIBFLAG_FHASDISKIMAGE    8    && OLE Automation LIBFLAG values
#DEFINE INVOKE_UNKNOWN    0    && OLE Automation INVOKEKIND values
#DEFINE INVOKE_FUNC    1    && OLE Automation INVOKEKIND values
#DEFINE INVOKE_PROPERTYGET    2    && OLE Automation INVOKEKIND values
#DEFINE INVOKE_PROPERTYPUT    4    && OLE Automation INVOKEKIND values
#DEFINE INVOKE_PROPERTYPUTREF    8    && OLE Automation INVOKEKIND values
#DEFINE INVOKE_EVENTFUNC    16    && Special value for TLI
#DEFINE INVOKE_CONST    32    && Special value for TLI
#DEFINE IDLFLAG_NONE    0    && OLE Automation IDLFLAG values
#DEFINE IDLFLAG_FIN    1    && OLE Automation IDLFLAG values
#DEFINE IDLFLAG_FOUT    2    && OLE Automation IDLFLAG values
#DEFINE IDLFLAG_FLCID    4    && OLE Automation IDLFLAG values
#DEFINE IDLFLAG_FRETVAL    8    && OLE Automation IDLFLAG values
#DEFINE PARAMFLAG_NONE    0    && OLE Automation PARAMFLAG values
#DEFINE PARAMFLAG_FIN    1    && OLE Automation PARAMFLAG values
#DEFINE PARAMFLAG_FOUT    2    && OLE Automation PARAMFLAG values
#DEFINE PARAMFLAG_FLCID    4    && OLE Automation PARAMFLAG values
#DEFINE PARAMFLAG_FRETVAL    8    && OLE Automation PARAMFLAG values
#DEFINE PARAMFLAG_FOPT    16    && OLE Automation PARAMFLAG values
#DEFINE PARAMFLAG_FHASDEFAULT    32    && OLE Automation PARAMFLAG values
#DEFINE PARAMFLAG_FHASCUSTDATA    64    && OLE Automation PARAMFLAG values
#DEFINE DESCKIND_NONE    0    && OLE Automation DESCKIND values
#DEFINE DESCKIND_FUNCDESC    1    && OLE Automation DESCKIND values
#DEFINE DESCKIND_VARDESC    2    && OLE Automation DESCKIND values
#DEFINE VT_EMPTY    0    && OLE Automation VARIANT types
#DEFINE VT_NULL    1    && OLE Automation VARIANT types
#DEFINE VT_I2    2    && OLE Automation VARIANT types
#DEFINE VT_I4    3    && OLE Automation VARIANT types
#DEFINE VT_R4    4    && OLE Automation VARIANT types
#DEFINE VT_R8    5    && OLE Automation VARIANT types
#DEFINE VT_CY    6    && OLE Automation VARIANT types
#DEFINE VT_DATE    7    && OLE Automation VARIANT types
#DEFINE VT_BSTR    8    && OLE Automation VARIANT types
#DEFINE VT_DISPATCH    9    && OLE Automation VARIANT types
#DEFINE VT_ERROR    10    && OLE Automation VARIANT types
#DEFINE VT_BOOL    11    && OLE Automation VARIANT types
#DEFINE VT_VARIANT    12    && OLE Automation VARIANT types
#DEFINE VT_UNKNOWN    13    && OLE Automation VARIANT types
#DEFINE VT_DECIMAL    14    && OLE Automation VARIANT types
#DEFINE VT_I1    16    && OLE Automation VARIANT types
#DEFINE VT_UI1    17    && OLE Automation VARIANT types
#DEFINE VT_UI2    18    && OLE Automation VARIANT types
#DEFINE VT_UI4    19    && OLE Automation VARIANT types
#DEFINE VT_I8    20    && OLE Automation VARIANT types
#DEFINE VT_UI8    21    && OLE Automation VARIANT types
#DEFINE VT_INT    22    && OLE Automation VARIANT types
#DEFINE VT_UINT    23    && OLE Automation VARIANT types
#DEFINE VT_VOID    24    && OLE Automation VARIANT types
#DEFINE VT_HRESULT    25    && OLE Automation VARIANT types
#DEFINE VT_PTR    26    && OLE Automation VARIANT types
#DEFINE VT_SAFEARRAY    27    && OLE Automation VARIANT types
#DEFINE VT_CARRAY    28    && OLE Automation VARIANT types
#DEFINE VT_USERDEFINED    29    && OLE Automation VARIANT types
#DEFINE VT_LPSTR    30    && OLE Automation VARIANT types
#DEFINE VT_LPWSTR    31    && OLE Automation VARIANT types
#DEFINE VT_RECORD    36    && OLE Automation VARIANT types
#DEFINE VT_FILETIME    64    && OLE Automation VARIANT types
#DEFINE VT_BLOB    65    && OLE Automation VARIANT types
#DEFINE VT_STREAM    66    && OLE Automation VARIANT types
#DEFINE VT_STORAGE    67    && OLE Automation VARIANT types
#DEFINE VT_STREAMED_OBJECT    68    && OLE Automation VARIANT types
#DEFINE VT_STORED_OBJECT    69    && OLE Automation VARIANT types
#DEFINE VT_BLOB_OBJECT    70    && OLE Automation VARIANT types
#DEFINE VT_CF    71    && OLE Automation VARIANT types
#DEFINE VT_CLSID    72    && OLE Automation VARIANT types
#DEFINE VT_VECTOR    4096    && OLE Automation VARIANT types
#DEFINE VT_ARRAY    8192    && OLE Automation VARIANT types
#DEFINE VT_BYREF    16384    && OLE Automation VARIANT types
#DEFINE VT_RESERVED    32768    && OLE Automation VARIANT types
#DEFINE tliStDefault    4096    && Use the current value of TypeLibInfo.SearchDefault
#DEFINE tliStClasses    1    && Return Classes
#DEFINE tliStEvents    2    && Include Events in member lists. Use with tliStClasses.
#DEFINE tliStConstants    4    && Return Enums and Modules containing constants
#DEFINE tliStDeclarations    8    && Return Modules with declarations
#DEFINE tliStAppObject    16    && Returned value if TypeLibInfo.AppObjString is set.
#DEFINE tliStRecords    32    && Return Records
#DEFINE tliStIntrinsicAliases    64    && Return Aliases which resolve to simple intrinsic types
#DEFINE tliStUnions    128    && Return Structures
#DEFINE tliStAll    239    && Return all types
#DEFINE tliWtListBox    0    && Specified hWnd is a ListBox
#DEFINE tliWtComboBox    1    && Specified hWnd is a ComboBox
#DEFINE tliIdtMemberID    0    && Place MemberID property in ItemData
#DEFINE tliIdtInvokeKinds    1    && Place InvokeKinds property in ItemData
#DEFINE tliCfaLeave    0    && Leave item as is
#DEFINE tliCfaDuplicate    1    && Copy item into returned SearchResults collection
#DEFINE tliCfaExtract    2    && Move item into returned SearchResults collection
#DEFINE tliCfaDelete    3    && Remove item from SearchResults collection
#DEFINE CC_FASTCALL    0    && OLE Automation CALLCONV values
#DEFINE CC_CDECL    1    && OLE Automation CALLCONV values
#DEFINE CC_MSCPASCAL    2    && OLE Automation CALLCONV values
#DEFINE CC_PASCAL    2    && OLE Automation CALLCONV values
#DEFINE CC_MACPASCAL    3    && OLE Automation CALLCONV values
#DEFINE CC_STDCALL    4    && OLE Automation CALLCONV values
#DEFINE CC_FPFASTCALL    5    && OLE Automation CALLCONV values
#DEFINE CC_SYSCALL    6    && OLE Automation CALLCONV values
#DEFINE CC_MPWCDECL    7    && OLE Automation CALLCONV values
#DEFINE CC_MPWPASCAL    8    && OLE Automation CALLCONV values
#DEFINE CC_MAX    9    && OLE Automation CALLCONV values

#DEFINE CRLF CHR(13) + CHR(10)

LOCAL lnCounter, lcFileName, loTypeLib as TLI.TypeLibInfo, loTypeInfo
m.lcFileName = GETFILE()
m.loTypeLib = CreateObject(“TLI.TypeLibInfo”)
If Type(“m.loTypeLib”) = “O”
m.loTypeLib.ContainingFile = m.lcFileName
Messagebox(“Typelib Name: “ + Transform(m.loTypeLib.Name))
Messagebox(“Typelib ID: “ + Transform(m.loTypeLib.GUID))
Messagebox(“Locale ID: “ + Transform(m.loTypeLib.LCID))
Messagebox(“Major Version: “ + Transform(m.loTypeLib.MajorVersion))
Messagebox(“Min Version: “ + Transform(m.loTypeLib.MinorVersion))
For m.lnCounter = 1 To m.loTypeLib.TypeInfoCount
m.loTypeInfo = m.loTypeLib.TypeInfos(m.lnCounter)
If m.loTypeInfo.TypeKind = TKIND_COCLASS
    Messagebox(“CLSID: “ + Transform(m.loTypeInfo.Name) + ” “ + TRANSFORM(m.loTypeInfo.GUID))
ENDIF
Next
EndIf