Retrieves the class object from a DLL object handler or object application. It is called from within the CoGetClassObject function when the class context is a DLL.

Note OLE does not provide this function. DLLs that support the OLE Component Object Model must implement DllGetClassObject in OLE object handlers or DLL applications.

HRESULT DllGetClassObject(

REFCLSID rclsid,
//CLSID for the class object
REFIID riid,
//Identifier that identifies the interface that communicates with the class object
LPVOID * ppv
//Points to the pointer of the communicating interface



Specifies the CLSID that will associate the correct data and code.


Specifies the interface that the caller is to use to communicate with the class object. Usually, this is IID_IClassFactory.


Points either to the pointer of the requested interface or, if an error occurs, to NULL.

Return Values


Indicates that the object was retrieved successfully.


Indicates that the DLL does not support the class (object definition).


Out of memory.


Indicates that one or more arguments are invalid.


Indicates that an unexpected error occurred.


If a call to the CoGetClassObject function finds the class object that is to be loaded in a DLL, CoGetClassObject uses the DLL's exported DllGetClassObject function.

Notes to Callers

You should not call DllGetClassObject directly. When an object is defined in a DLL, CoGetClassObject calls the CoLoadLibrary function to load the DLL, which, in turn, calls DllGetClassObject.

Notes to Implementors

You need to implement DllGetClassObject in (and export it from) DLLs that support the OLE Component Object Model.


Following is an example (in C++) of an implementation of DllGetClassObject. In this example, DllGetClassObject creates a class factory object and calls its QueryInterface method to retrieve a pointer to the interface requested in riid. The implementation safely releases the reference it holds to the IClassFactory interface because it returns a reference-counted pointer to IClassFactory to the caller.

HRESULT_export PASCAL DllGetClassObject

(REFCLSID rclsid, REFIID riid, LPVOID * ppvObj)



  • ppvObj = NULL;

CClassFactory *pClassFactory = new CClassFactory(rclsid);

if (pClassFactory != NULL) {

hRes = pClassFactory->QueryInterface(riid, ppvObj);



return hRes;


See Also

CoGetClassObject, DllCanUnloadNow

Software for developers
Delphi Components
.Net Components
Software for Android Developers
More information resources
Unix Manual Pages
Delphi Examples