An application closes an installable driver by calling the CloseDriver function. When the application calls this function, Windows deletes the corresponding driver name from an internal list.
When an application calls the CloseDriver function to close the last instance of a driver, Windows issues the DRV_CLOSE, DRV_DISABLE, and DRV_FREE messages, in that order. (When the application is not closing the last instance of the driver, only DRV_CLOSE is sent.) When the driver processes the DRV_CLOSE message, it frees any resources that were allocated when the driver was opened and returns a nonzero value. If the driver returns a value of zero, closing fails.
When the driver processes the DRV_DISABLE message, it places any associated peripherals in an inactive state and unhooks all interrupts.
When the driver processes the DRV_FREE message, it frees any resources that are still allocated.