OOPortal OOPortal


Basic COM   «Prev  Next»
Lesson 4 How IClassFactory creates objects
Objective Discover how IClassFactory creates objects.

How IClassFactory Creates Objects

Recall that there is a one-to-one association between a class object/factory and a COM object. If we implement two COM objects, namely
  1. O1 and
  2. O2
we must implement two class factories, one for each type of COM object.
Assume CF01 is the class factory for O1 and CF02 is the class factory for O2. A call to CF01::CreateInstance does the following:
  1. Creates an instance of COM object O1.
  2. Within CreateInstance, after object O1 is created, calls O1::QueryInterface to have O1 return the requested interface pointer to the client.
A call to CF02::CreateInstance does the following:
  1. Creates an instance of O2.
  2. Calls O2::QueryInterface to have O2 return the requested interface pointer to the client.

We will revisit class factories in a follow-up lesson.
IClassFactory shows C++-style logic that demonstrates how to implement a class factory. One question that still needs to be addressed is how does a client get a pointer into a class factory to create instances of COM object? We will discuss this in the next set of lessons when we examine COM servers and clients.

Debug Class Factory - Exercise

Click the Exercise link below to apply what you have learned about class factories.
Debug Class Factory - Exercise