1 out of 2 rated this helpful - Rate this topic

DllGetClassObject entry point

Applies to: desktop apps only

Retrieves the class object from a DLL object handler or object application.

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

Syntax

HRESULT __stdcall DllGetClassObject(
  __in   REFCLSID rclsid,
  __in   REFIID riid,
  __out  LPVOID *ppv
);

Parameters

rclsid [in]

The CLSID that will associate the correct data and code.

riid [in]

A reference to the identifier of the interface that the caller is to use to communicate with the class object. Usually, this is IID_IClassFactory (defined in the OLE headers as the interface identifier for IClassFactory).

ppv [out]

The address of a pointer variable that receives the interface pointer requested in riid. Upon successful return, *ppv contains the requested interface pointer. If an error occurs, the interface pointer is NULL.

Return value

This function can return the standard return values E_INVALIDARG, E_OUTOFMEMORY, and E_UNEXPECTED, as well as the following values.

Return codeDescription
S_OK

The object was retrieved successfully.

CLASS_E_CLASSNOTAVAILABLE

The DLL does not support the class (object definition).

 

Remarks

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 Implementers

You need to implement DllGetClassObject in (and export it from) DLLs that support COM.

Examples

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


HRESULT_export CALLBACK DllGetClassObject 
    (REFCLSID rclsid, REFIID riid, LPVOID * ppvObj) 
{ 
    HRESULT hr = E_OUTOFMEMORY; 
    *ppvObj = NULL; 
 
    CClassFactory *pClassFactory = new CClassFactory(rclsid); 
    if (pClassFactory != NULL)   { 
        hr = pClassFactory->QueryInterface(riid, ppvObj); 
        pClassFactory->Release(); 
    } 
    return hr;
} 


Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Objbase.h

See also

CoGetClassObject
DllCanUnloadNow

 

 

Send comments about this topic to Microsoft

Build date: 3/7/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Do not call Release Method in the DllGetClassObject
If your classfactory object's reference count initialize with 0, DO NOT call the release method, it seems the COM library would call the release method automatically. Otherwise, you'd get a access exception.
Conflicting statements
The "Notes to Callers" session says that "CoGetClassObject calls the CoLoadLibrary function to load the DLL", yet the documentation for CoLoadLibrary says that "CoGetClassObject does not call CoLoadLibrary". Which one is it after all?


[edit by ph] The result is "don't rely on either behavior". Likely it once did but doesn't do anymore. As CoLoadLibrary is now documented as "equivalent to LoadLibraryEx", it shouldn't make a difference, except when hooking OS calls.