The ITypeLib Interface

The member functions of the ITypeLib interface, as described in Table 3-8, are oriented primarily toward retrieving library attributes or retrieving information and ITypeInfo pointers for the elements within the library.

Member Function

Description

GetLibAttr

Allocates, fills, and returns a pointer to the library's TLIBATTR structure. This must be freed with ReleaseLibAttr.

ReleaseLibAttr

Frees the TLIBATTR structure allocated in GetLibAttr.

GetTypeInfo

Returns the ITypeInfo pointer for a top-level element in the library given a zero-based index. You would use GetTypeInfo to iterate through all the elements in the library.

GetTypeInfoCount

Returns the number of top-level elements in the type library.

GetTypeInfoType

Returns the TYPEKIND of an element in the library given its index. This is the information you might use in creating an organized tree list of type library contents.

GetTypeInfoOfGuid

Returns the ITypeInfo pointer for an element in the type library given the GUID of that element. The GUID must match a uuid attribute for some element, be it for a typedef, dispinterface, interface coclass, or whatever.

GetDocumentation

Given an index, allocates and returns a BSTR with the library name (which follows the library keyword in the ODL file) and allocates and returns BSTR copies of the helpstring, helpfile, and helpcontext attributes of the library. The caller must free the BSTRs with SysFreeString.

FindName

Returns the ITypeInfo pointers (and member IDs) for any number of elements given the element names.

IsName

Checks quickly whether the given names exist in the type library. IsName is suitable for verifying existence before calling a more expensive function such as FindName.

GetTypeComp

Returns an ITypeComp interface for the library. See "The ITypeComp Interface" on page 183.


Table 3-8.

Member functions of the ITypeLib interface.

All of these functions basically give you access to the various parts of a type library that you would describe in an ODL file or create otherwise. The relationships between these member functions and a sample ODL file are shown in Figure 3-4.

Figure 3-4.

How ITypeLib members relate to ODL entries.