The Composition of a COM DLL
All COM DLLs have the same internal composition regardless of which COM-aware language you build them in. The following figure illustrates the core atoms of the binary image of a COM DLL server:
A COM server contains some number of coclasses which is a type supporting at minimum the mandatory IUnknown interface. As shown in the above figure, the RawComServer.dll contains a single coclass named ComCar and it supports two interfaces: ICar and IUnknown.
COM servers also support a special sort of COM type termed a class factory (also termed a class object). COM class factories also support the mandatory IUnknown, as well as another standard interface named IClassFactory. This interface allows the COM client to create a given coclass in a language- and location-neutral manner. As you may be aware, it is possible for a COM class factory to support the IClassFactory2 interface (which derives from IClassFactory). The role of IClassFactory2 is to define additional methods to check for a valid license file before activating the object.
In addition to the set of coclasses and class factories, COM DLLs must support a small set of function exports. These function exports allow the COM runtime to interact with the internal types, as well as perform registration and unregistration of the COM binary itself. The following table provides a breakdown of each DLL export.
COM DLL Function Export
|
Meaning in Life
|
DllRegisterServer()
|
This method, which is technically optional, is used to install the necessary entries into the system registry.
|
DllUnregisterServer()
|
This method (also technically optional) removes any and all entries inserted by DllRegisterServer().
|
DllCanUnloadNow()
|
This method is called by the COM runtime to determine if the DLL can be unloaded from memory at the current time.
|
DllGetClassObject()
|
This method is used to retrieve a given IClassFactory interface to the COM client based on the CLSID of the COM class in question. Once this interface has been obtained, the client is able to create the associated coclass.
|