Use IDL to describe a COM object and build a type library.
COM Type Libraries
(IDL to describe COM object)
A COM interface pointer is a pointer to a vtable pointer, that is, a pointer to a pointer to a table of function pointers. The only way to communicate with a COM object is through its interfaces.
Given these properties, how can a Visual Basic client, using a high-level development language that does not provide access to pointers, access a COM object?
The designers of COM broke the solution into two parts:
First, they provided a language-independent way to describe COM objects and interfaces.
Second, they provided a standard "front end" to act as a dispatcher between high-level development environments and COM objects.
In this lesson, we study how to describe COM objects and interfaces in a language-independent manner using type libraries.
The standard front end is called (OLE) automation. This course does not cover automation.
A type library can be considered a type of binary include file. Interfaces and COM objects can be defined in a type library. Visual C++ has been extended to allow C++ programmers access to type libraries.
The Visual C++ ATL COM-Wizard, covered later in this course, automatically generates type libraries.
Type libraries are described using IDL and compiled into binary format with MIDL.
The following is an IDL file, MyComObject.idl, that describes MyComObject from the previous lessons and its
IMyComInterface and IYourComInterface interfaces.
The first 16 lines of the MouseOver below use IDL to define COM interfaces in the same way we described earlier.
The remaining lines define a type library called MyTypeLib.
Like COM interfaces and COM objects, type libraries are defined by a 128-character ID.
For a type library, the ID is called a LIBID.
Compiling an IDL file with MIDL produces the *.h and *.c files described in Lesson 8, MIDL: Compiling IDL files.
It also produces the type library MyComObject.tlb, which contains type library MyTypeLib.
The OLE/COM Object Viewer utility can be used to view the contents of a type library.