The Win32 multimedia APIs and the multimedia dynamic-link libraries allow multiple clients to simultaneously open a user-mode driver. You can choose whether to allow multiple open driver instances, as follows:
·If you want to allow multiple open instances, your user-mode driver should define a linked list of dynamically allocated structures. All instance data should be stored in this list, and you should not use any static or global variables. When the driver's DriverProc function receives a DRV_OPEN message, it should:
1.Allocate memory space for a structure instance.
2.Add the structure instance to the linked list.
3.Store instance data in the new list entry.
4.Specify the entry's number or address as the return value for the DriverProc function.
Subsequent calls to DriverProc will include the list entry's identifier as its dwDriverID argument. The sample audio device drivers use this technique, although they use the customized audio driver entry points and messages instead of DriverProc and DRV_OPEN.
If a user-mode driver allows multiple instances, the kernel-mode driver is usually responsible for rejecting conflicting requests for access to the hardware.
·If you do not want to allow multiple open instances, your driver can set a flag the first time it receives a DRV_OPEN message. When subsequent DRV_OPEN messages are received, the driver can provide an error return value for DriverProc until a DRV_CLOSE message is received, at which point it can clear the flag. The sample video capture device drivers use this technique.