HRESULT DllCanUnloadNow(void)
DllCanUnloadNow is not provided by COM. Rather, it is a function implemented by and exported from .DLLs supporting the Component Object Model. DllCanUnloadNow should be exported from .DLLs designed to be dynamically loaded in CoGetClassObject or CoLoadLibrary calls. A .DLL is no longer in use when there are no existing instances of classes it manages; at this point, the .DLL can be safely freed by calling CoFreeUnusedLibraries. If the .DLL loaded by CoGetClassObject fails to export DllCanUnloadNow, the .DLL will only be unloaded when CoUninitialize is called to release the COM libraries.
If this function returns S_OK, the duration within which it is in fact safe to unload the .DLL depends on whether the .DLL is single- or multi-thread aware. For single-thread .DLLs, it is safe to unload the .DLL up until such time as the thread on which DllCanUnloadNow was invoked causes it to be otherwise (objects created, for example).
Return Value
Meaning
S_OK
The .DLL may be unloaded now.
S_FALSE
The .DLL should not be unloaded at the present time.