Basic COM   «Prev  Next»
Lesson 12

Component Object Model (Conclusion)

COM Component Technology
Let us summarize what we have studied in this module:
  1. First, we were introduced to COM classes, class objects, and class factories.
  2. We studied IClassFactory i.e., how CreateInstance creates instances of a COM object and how LockServer locks or unlocks a server.

In-process servers

  1. 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

  1. 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.
  2. Tool RegEdit.exe can be used to examine the contents of the registry.
  3. DllUnRegisterServer can be invoked via RegSvr32 /u to remove a server's registry entries.
  4. 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.
  5. 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

  1. This module showed us how a COM client uses CoGetClassObject and IClassFactory::CreateInstance or CoCreateInstance to create an instance of a COM object and get its first interface pointer into the object.
  2. We discussed how a client makes calls into a COM interface. We looked at how to call QueryInterface in one interface to get an interface pointer to another interface within the COM object. We also briefly discussed the differences between how a server and a client view a COM interface.
  3. Finally, we looked at the coding steps in a COM client.
The knowledge we have gained from Modules 2 and 3 provides us with a solid foundation of core COM concepts and development techniques. We are now ready to move on to developing COM servers, objects, and clients with ATL--the active template library.