The Class Factory Object: IClassFactory Interface

The class factory is another object itself that exists to manufacture objects (hence the name "factory") of a specific class (hence the qualifier "class").1. A class factory object is implemented by a server module, either a .DLL or .EXE, and supports the IClassFactory interface described below. For the purposes of COM Clients, the IClassFactory interface is and interface on an object used by a client. For information on implementation, see Chapter 6, "COM Servers."

Figure 5-1 A client asks a class factory in the server to create an object.

The IClassFactory interface is implemented by COM servers on a "class factory" object for the purpose of creating new objects of a particular class. The interface also provides for a COM client to keep the server in memory even when it is not servicing any object. A class factory has a one-to-one correspondence with a CLSID (although actual implementations can be made generic to service multiple classes if the COM server so chooses).


[
    object,
    uuid(00000001-0000-0000-C000-000000000046), // IID_IClassFactory
    pointer_default(unique)
]
interface IClassFactory : IUnknown 
{
.....HRESULT CreateInstance([in] IUnknown * pUnkOuter, [in] REFIID iid, [out] void * ppv);
.....HRESULT LockServer([in]BOOL fLock);
}