As you can probably expect from the plethora of structures you can get from ITypeInfo, shown in Table 3-7, there are a good number of member functions, shown in Table 3-9. As with ITypeLib, each of these functions relates to specific parts of an ODL file, as illustrated in Figure 3-5 on page 182.
Member Function | Description |
GetContainingTypeLib | Retrieves the ITypeLib pointer for the library that contains this type information as well as the index of this type information in the library. |
GetDocumentation | Given an index, allocates and returns a BSTR with the item name and allocates and returns BSTR copies of the helpstring, helpfile, and helpcontext attributes of the item. The caller must free the BSTRs with SysFreeString. |
GetFuncDesc | Allocates, fills, and returns the FUNCDESC structure for a method with a given index in an interface. This must be freed with ReleaseFuncDesc. |
ReleaseFuncDesc | Frees the FUNCDESC from GetFuncDesc. |
GetNames | Retrieves the names of properties, types, variables, methods, method arguments, and so forth in BSTR variables, which the caller frees with SysFreeString. |
GetIDsOfNames | Maps text names of a dispinterface to dispIDs and argument IDs. |
GetRefTypeInfo | Returns the ITypeInfo of a given HREFTYPE. |
GetTypeAttr | Allocates, fills, and returns the TYPEATTR structure for this ITypeInfo. This must be freed with ReleaseTypeAttr. |
ReleaseTypeAttr | Frees the TYPEATTR from GetTypeAttr. |
GetRefTypeOfImplType | Returns the HREFTYPE for an interface or dispinterface in a coclass. |
GetImplTypeFlags | Returns the IMPLTYPE flags of an interface or dispinterface item if it's in a coclass. |
GetVarDesc | Allocates, fills, and returns a VARDESC structure describing the specified variable. This must be freed with ReleaseVarDesc. |
ReleaseVarDesc | Frees the VARDESC from GetVarDesc. |
Invoke | Invokes a method or accesses a property of an object that implements the interface described by this ITypeInfo. |
CreateInstance | Attempts to create a new instance of a coclass using CoCreateInstance for the uuid attribute, using the process described in Chapter 5. |
AddressOfMember | Retrieves the addresses of static functions or variables defined in a DLL as well as the INVOKEKIND flag. |
GetDllEntry | Retrieves the DLL module name and function name (or ordinal) of an exported DLL function as well as its INVOKEKIND flag. |
GetMops | Retrieves marshaling information for an argument. |
GetTypeComp | Returns the ITypeComp interface for this ITypeInfo. See "The ITypeComp Interface" later in this chapter. |
Table 3-9.
The ITypeInfo interface.
There is nothing sacred about OLE's type information services that provide the standard implementations of type library and type information objects. You are perfectly free to implement your own objects with these interfaces that sit on top of a type library. Such custom implementations might be used to extend the available information for the purposes of a particular client. For example, if you want to extend the properties available on an object with a set of client-supplied properties and to use type information consistently throughout the controller, you can implement wrapper interfaces that filter out the specific client types before passing the calls on to OLE's standard implementations.
With ITypeLib and ITypeInfo, you can see how a client could load a type library using registry information, obtain an ITypeLib pointer, and then call ITypeLib::GetTypeInfoOfGuid to retrieve an ITypeInfo pointer for a coclass. Through ITypeInfo::GetRefTypeOfImplType, you then obtain the HREFTYPE for each interface or dispinterface in that class and can pass that HREFTYPE to ITypeInfo::GetRefTypeInfo to retrieve the ITypeInfo pointer for each particular interface. From there you can call, with this new pointer, ITypeInfo::GetTypeAttr to retrieve the TYPEATTR structure, which contains the interface IID. This is how you retrieve the IIDs of all of an object's incoming and outgoing interfaces directly from type information. This does involve a number of iterations and is a little convoluted, I must admit, but it is the only way to retrieve this information without otherwise instantiating the object itself.
Figure 3-5.
How ITypeInfo members relate to ODL entries. Although not drawn in this figure (to keep it readable), AddressOfMember and GetDllEntry work with module entries and the appobject coclass, and GetMops works with structures as well as arguments.