All COM/DCOM server follows factory design pattern.IClassFactory class is the standard used in COM/DCOM to achieve this design. The IClassFactory interface contains two methods intended to deal with an entire class of objects, and so is implemented on the class object for a specific class of objects (identified by a CLSID).


The first method, CreateInstance, creates an uninitialized object of a specified CLSID, and the second,


LockServer, locks the object's server in memory, allowing new objects to be created more quickly and enhances performance of the program.

IClassFactory class prototype

class IClassFactory : public IUnknown {
    virtual HRESULT __stdcall CreateInstance(
            /* [in] */ IUnknown  *pUnkOuter,
            /* [in] */ REFIID riid,
            /* [out] */ void **ppvObject) = 0;

            /* [in] */ BOOL fLock) = 0;

IUnknown Methods

IClassFactory is derived from IUnknown so the vtable would list the function pointers of IUnknown abstruct methods.

  • QueryInterface - Returns pointers to supported interfaces.
  • AddRef - Increments reference count.
  • Release - Decrements reference count.

IClassFactory Methods

IClassFactory's own methods will follow after IUnknown's methods.

  • CreateInstance - Creates an uninitialized object.
  • LockServer - Locks object application open in memory.

CLIENT Create functions

CoGetClassObject function to get an IClassFactory interface pointer to the class object, call the CreateInstance method of this interface to create a new uninitialized object. This approach is good when multiple instances of the same class or different classes are needed.

It is not, however, always necessary to go through this process to create an object. To create a single uninitialized object, you can, instead, just call CoCreateInstance.

About our authors: Team EQA

You have viewed 1 page out of 67. Your COM/DCOM learning is 0.00% complete. Login to check your learning progress.