[Previous] [Contents] [Next]

Chapter Nine

Type Information

The architectures of connection points and type information were developed together. In fact, connection points as implemented by high-level languages such as Microsoft Visual Basic and Java could not exist without the presence of type information. As you saw in Chapter 3, a type library is the binary form of an interface definition. The Microsoft Interface Definition Language (MIDL) compiler was initially designed to generate C language bindings for programmers using Remote Procedure Calls1 (RPCs) but has since been extended to create type library files. MIDL does not contain all the code necessary to create a type library, however. Microsoft has defined and implemented interfaces that do this job; MIDL is only a consumer of these interfaces.

The two primary interfaces that MIDL uses to create type libraries are ICreateTypeLib(2) and ICreateTypeInfo(2). Together, these interfaces enable MIDL to generate a type library that describes practically any interface you might write in IDL.2 The ITypeLib(2) and ITypeInfo(2) interfaces implemented by COM+ enable applications to read type information stored in type libraries.

Other programs besides the MIDL compiler use the ICreateTypeLib(2) and ICreateTypeInfo(2) interfaces. Visual Basic, for example, automatically generates a type library for all components. So does Microsoft Visual J++.3 To understand the structure and contents of a type library, you must take at least a cursory look at these interfaces. In the following section, we'll use these interfaces and their associated methods to create a type library that exactly matches the type library produced by the MIDL compiler when it is fed the IDL file shown in Listing 9-1. The numbers in parentheses in the comments correspond to the numbers in the code that creates those elements of type information later in this section.


import "unknwn.idl";

[ object, uuid(10000001-0000-0000-0000-000000000001),    // (6)
  oleautomation ]                                        // (7)
interface ISum                                           // (5)
    : IUnknown                                           // (12)
    HRESULT Sum(int x, int y, [out, retval] int* retval);// (13)
[ uuid(10000003-0000-0000-0000-000000000001),            // (1)
  helpstring("Inside COM+ Component Type Library"),      // (4)
  version(1.0) ]                                         // (3)
library Component                                        // (2)
    importlib("stdole32.tlb");                           // (12)

    interface ISum;

    [ uuid(10000002-0000-0000-0000-000000000001) ]       // (9)
    coclass InsideCOM                                    // (8)
        [default]                                        // (11)
            interface ISum;                              // (10)

Listing 9-1. An IDL file containing library information that the MIDL compiler uses to produce a type library file.