Recall that peripheral devices are exposed to applications as special files, and when you create an installable device driver you are providing the implementation of such a file. Therefore, one thing you have to consider when writing your device driver is whether it makes sense to allow applications to open this special file more than once simultaneously. Your installable device driver can implement either policy—single access or multiple access—by using the hOpenContext parameter that is used by the Win32 file I/O functions.
If you wish to allow multiple access, each call to your xxx_Open function should return a different value for hOpenContext. Your device driver will have to track which return values from xxx_Open are in use. Subsequent calls by the application to your xxx_Close, xxx_Read, xxx_Write, xxx_Seek, and xxx_IOControl functions will pass this value back to your device driver so that the driver can identify which internal data structures to manipulate.
If you wish to enfore single-access, then only the first call to xxx_Open should return a valid hOpenContext value. So long as that value is still valid (which is until the application calls xxx_Close for that value), subsequent calls to xxx_Open should return NULL to indicate failure to the calling application.