As part of the project build procedure, PhBook.idl is compiled with MIDL to create the following files:
PhBook.h defines interfaces IReadPhBook and IManagePhBook. At this time, each interface definition is empty because we have not added methods to either interface. PhBook_i.c declares variables for each IID (IID_IReadPhBook, IID_IManagePhBook), the type library (LIBID_PHBOOKLib), and the COM class (CLSID_PhBookObj).
PhBook.tlb is a type library that describes each COM interface and COM object PhBookObj and includes the interface and object IDs.
The MIDL-compile step also creates PhBook_p.c and dlldata.c. These files are used when we work with out-of-process COM servers. We will not use either of these files in this course. Nor will we use file PhBookps.mak.
(MIDL) Interface Compiler
After describing your interfaces and components in IDL, you run them through the interface compiler (MIDL). The MIDL compiler takes the IDL description of your interfaces and generates several C language source files that can be used when implementing, or using, the component from C/C++. This might seem odd, since COM is supposed to be language independent. Why can't the MIDL compiler generate interface definitions for other languages? Well, instead of having to update the MIDL compiler for every new language that comes along, Microsoft chose a far more extensible approach.
The solution was to have MIDL generate interface definitions in a single, universal format that all languages (including interpretative languages and macro programming environments) can understand.
These are called type libraries and they are compiled, binary versions of the IDL files that can be accessed programatically. A type library file provides type information about all components, interfaces, methods, properties, arguments and structures described in an IDL file.
In addition to the C/C++ interface definitions and the type library file, MIDL also generates proxy and stub code for the interfaces in the IDL file. Proxy/stubs are necessary when an interface is going to be accessed from another address space or across a network.
These will be covered in a later section.