Unloading In-Process Servers
As mentioned above, a .DLL must wait for someone else to explicitly unload it. The server must, however, have a mechanism through which it indicates whether or not it should be unloaded. That mechanism is a function with the name DllCanUnloadNow that is exported in the same manner as DllGetClassObject.