PhBook.cpp: PhBook.cpp contains (DLL-based) server functions DllMain, DllCanUnloadNow, DllGetClassObject, DllRegisterServer, and DllUnregisterServer. It also contains the global declaration of CComModule in variable _Module and the object map.
PhBook.def: PhBook.def exports required functions from the DLL.
PhBook.idl, PhBook.h, and PhBook.tlb contain interface definitions for IReadPhBook and IManagePhBook, type library PHBOOKLib, and COM class PhBookObj.
PhBook.idl, PhBook.h, PhBook.tlb used in COM: Visual C++ automatically generates PhBook.idl to
define interfaces,
a type ibrary, and
COM classes.
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.
PhBook.rc, Resource.h, PhBookObj.rgs
PhBook.rc, Resource.h, and PhBookObj.rgs contain our application's resources. These include the compiled type library (PhBook.tlb), version information, a registry resource (discussed below), and a string table.
Project Resources: Files PhBook.rc and Resource.h define our project's resources. Like many MS-Windows development projects, we include version and string resources. A type library can also be included as a resource. Our type library is embedded within the DLL as a binary resource. PhBookObj.rgs is a registration script. A registration script contains commands that describe how to register our COM objects. The registration script is compiled into a binary resource and included in the executable file. The ATL framework uses the script to register and unregister the server's objects.
Macro DECLARE_REGISTRY_RESOURCEID
(IDR_PhBookObj) in PhBookObj.h adds a method called UpdateRegistry into a COM class. UpdateRegistry is used by the ATL framework to register or unregister a COM object using the registration script.
PhBookObj.cpp, PhBookObj.h
PhBookObj.cpp and PhBookObj.h contain the declarations and code for CPhBookObj.
Precompiled COM files:
Precompiling files can reduce compilation times, resulting in faster edit, compile, link, and debug cycles.
The general idea is to precompile header and implementation files that do not change and reuse the compiled code, instead of recompiling the same files
for each source code module in the project. The ATL COM AppWizard automatically sets up precompiling of the standard ATL files by designating file StdAfx.cpp to be precompiled through file StdAfx.h. This produces a precompiled header file (*.pch) using the project name, for example, PhBook.pch.
See the Visual C++ documentation for more details.
They are used to build a precompiled header file PhBook.pch. Visual C++ 6.0 users will see also see file basetsd.h under External Dependencies.
This file handles 64-bit wide types and values. We will not use 64-bit types in this course.