When a client uses a CLSID to request the creation of an object instance, the first step is creation of a class object, an intermediate object that contains an implementation of the methods of the IClassFactory interface. While COM provides several instance creation functions, the first step in the implementation of these functions is the creation of a class object.
As a result, all servers must implement the methods of the IClassFactory interface. This interface contains two methods: CreateInstance and LockServer. CreateInstance must create an uninitialized instance of the object, and return a pointer to a requested interface on the object.
The LockServer method just increments the reference count on the class object to ensure that the server stays in memory, and does not shut down before the client is ready for it to do so.
To enable a server to be responsible for its own licensing, COM defines IClassFactory2, which inherits its definition from IClassFactory. Thus, a server implementing IClassFactory2 must, by definition, implement the methods of IClassFactory. For more information on IClassFactory2, see Licensing and IClassFactory2.
COM also provides helper functions for implementing out-of-process servers. For more information, see Out-of-process Server Implementation Helpers.