Basic COM   «Prev  Next»
Lesson 3 IClassFactory methods
Objective Learn IClassFactory methods.

IClassFactory Methods

Most COM applications use class factories as their class objects. A class factory implements COM interface IClassFactory.
You should be familiar with class objects and using multiple inheritance to implement a COM object to get the most from this lesson.
IClassFactory has the following methods.

  1. IUnknown: Because IClassFactory is a COM interface, it must implement IUnknown methods (QueryInterface, AddRef, and Release).
  2. HRESULT CreateInstance (IUnknown *pOuter, const IID& riid, VOID **ppv);
    This method is called by a client to have the class factory create an instance of its associated COM object.
    Parameter pOuter is used for aggregation, for now, assume its value is NULL.
    Parameter riid is the IID of an interface, within the newly created object instance, that the client wants.
    Parameter ppv is an output parameter that will hold the interface pointer specified in parameter riid.
  3. HRESULT LockServer (BOOL fLock);--This method is called to increment or decrement a lock counter within a COM server. If fLock is TRUE, the counter should be incremented; if it is FALSE, the counter should be decremented.
    This method is often used to keep a COM server in memory when none of its COM objects are in use.

IClassFactory interface (unknwn.h)

The IClassFactory interface enables a class of objects to be created.

Inheritance

The IClassFactory interface inherits from the IUnknown interface. IClassFactory also has these types of members:

Methods

The IClassFactory interface has two methods.
  1. IClassFactory::CreateInstance - Creates an uninitialized object.
  2. IClassFactory::LockServer - The IClassFactory::LockServer method locks an object application open in memory. This enables instances to be created more quickly.