An application sends the MCI_CLOSE message to relinquish access to a driver. MCI interprets the MCI_CLOSE message and substitutes the MCI_CLOSE_DRIVER and DRV_CLOSE messages.
For nonshared simple devices, a close message directly corresponds to an open message. These device drivers should prepare to terminate when they receive a close message.
For nonshared compound devices, a close message for a device element directly corresponds to an open message for that element. These device driver should close the element corresponding to the dwDriverID. Even when all device elements are closed, the driver can remain open if an application had also opened it without a device element. Nonshared compound device drivers need to be aware of when they are opened this way. They should not prepare for termination until all applications have closed them.
Shared devices and device elements also need to be aware of being opened by multiple applications. The close messages received for these cases indicates only that an application is finished using the device or device element. Other applications can have these devices and device elements open and will continue to access them. These device drivers should not prepare for termination until they know that all applications that have opened them have closed them. Your device driver might keep track of the using applications by maintaining a count of the number of times it has been opened.
The system will send the DRV_FREE message when all applications have closed a device driver. Use this message to ensure that your device driver is properly closed before it terminates. If your device driver registered a custom command table, it should free it at this time.