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
O1
and
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:
- Creates an instance of COM object
O1
.
- 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:
- Creates an instance of
O2
.
- 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.