Lesson 12
Component Object Model (Conclusion)
COM Component Technology
Let us summarize what we have studied in this module:
- First, we were introduced to COM classes, class objects, and class factories.
- We studied
IClassFactory
i.e., how CreateInstance
creates instances of a COM object and how LockServer
locks or unlocks a server.
In-process servers
- An in-process server provides function
DllRegisterServer
to register its COM classes (i.e., types of COM objects). Tool RegSvr32.exe loads an in-process server and calls DllRegisterServer
.
For each COM class supported by the server, the following registry entries must be made:
HKEY_CLASSES_ROOT\CLSID\
{COM Object 1 CLSID} = "optional string value"
HKEY_CLASSES_ROOT\CLSID\
{COM Object 1 CLSID}\InprocServer32 = Full path to DLL
- An optional ProgID may also be entered. COM objects must also specify a threading model or apartment type. We will defer discussion of COM threading and apartments to another course.
For now, we will use the default-threading model which is single threaded.
- Tool RegEdit.exe can be used to examine the contents of the registry.
DllUnRegisterServer
can be invoked via RegSvr32 /u
to remove a server's registry entries.
- COM calls
DllGetClassObject
, when a client calls CoGetClassObject
, to get a specific class object/factory from the server.
Normally, the server will examine the CLSID
parameter of DllGetClassObject
and, if it supports the requested COM class, create a class factory and return its
IClassFactory
interface to COM. In turn, COM returns the IClassFactory
pointer to the client.
- COM periodically calls
DllCanUnloadNow
to ask the server if any of its objects are in use. If no objects are active, the calls returns TRUE
(non-zero) to tell COM the server can be unloaded from memory.
COM clients