Creating COM objects

COM objects are typically created by the API call:

result_code = CoCreateInstance(CLSID, aggregate_pointer, context_code, IID, &pInterface);

which is approximately equivalent to the C++ statement "pInstance = new CClassName". For each type of COM object (i.e. for each coclass) that a server can create, it must also supply a class object (or class factory).


COM loads the DLL file into memory, using CoLoadLibrary.

COM uses CoGetClassObject to call the DLL’s DllGetClassObject function, passing the CLSID and the IID for IClassfactory.

The DLL implements a class factory (typically a class that has a single instance, by being declared as a global variable within the DLL) which only provides one or more creation interfaces, typically IClassFactory. A pointer to this interface is returned.

COM calls the CreateInstance function in the IClassFactory interface, which creates an instance of the COM class (or coclass) specified by the CLSID, and returns a pointer to the initial interface specified by the IID.


COM executes the EXE file, with the command line argument "-embedding".

The executable creates a class factory for each CLSID that it supports, and registers them by calling CoRegisterClassObject.

Once COM has received the registration, it returns the requested interface pointer.