Basic COM   «Prev  Next»
Lesson 9 COM clients - Creating COM objects
Objective Learn how a COM client gets a class factory and creates an instance of COM object, getting its first interface pointer into the object.

Creating COM Objects

A COM server and its objects do not stand alone. They exist to provide services to COM clients. A COM application contains both clients and servers.
Before accessing any COM services a client must call COM function CoInitialize(NULL). This call must be made in each client thread that accesses COM! For now we will only deal with single-threaded clients.
After calling CoInitialize a client gets class factories, one for each type of COM object it wants to use, by calling CoGetClassObject. The following Slideshow will step you through this process.

StdApi CoGetClassObject
Once a client has an IClassFactory pointer, it can call IClassFactory::CreateInstance to create an instance of the COM object and get its first interface pointer into the object.
When finished using the IClassFactory pointer, a client calls IClassFactory::Release.
COM provides helper function CoCreateInstance, which calls CoGetClassObject, IClassFactory::CreateInstance, and IClassFactory::Release.
After releasing its COM interface pointers, a client calls CoUninitialize() to tell COM that its thread will no longer access COM services or COM objects.

Accessing Com Objects - Quiz

Click the Quiz link below to check your understanding of how COM objects are accessed.
Accessing Com Objects - Quiz