The system calls a kernel-mode DLL's DllUnload routine when it unloads the DLL.
NTSTATUS
DllUnload(
);
None
The routine should return STATUS_SUCCESS on success, or the appropriate error code on failure. The system only unloads the DLL if DllUnload returns STATUS_SUCCESS.
Export drivers must provide DllUnload routines. You can use the DllUnload routine to release any resources used by the routines in the DLL. For more information about export drivers, see Creating Export Drivers.