Unloading Installable Device Drivers

An installable device driver DLL can be unloaded in two ways, depending on the method by which the DLL was loaded. If the Device Manager loaded the DLL, then the Device Manager will also detect when the installable device driver's peripheral is disconnected from the Windows CE platform (for example, when a PC Card is ejected from its socket). At that time, the Device Manager will remove the driver's entry from the [HKEY_LOCAL_MACHINE\Drivers\Active] key, will call DeregisterDevice to remove the peripheral's device filename from the filesystem, and will call FreeLibrary to unload the DLL itself.

If the DLL was loaded by an application, then the application should also unload the DLL before it exits by calling DeregisterDevice.