Single Access and Multiple Access

Because peripheral devices are exposed to applications as special files when you create a stream interface driver, you provide the implementation of such a file. Therefore, consider whether it is practical, based on the capabilities of the device that your driver serves, to enable multiple applications to have simultaneous access to the special file; that is, consider whether your driver can have multiple open file handles on its device. A stream interface driver can implement either single access or multiple access by using the hOpenContext parameter that Windows CE passes to all file I/O functions.

To enable multiple access, each call to the XXX_Open function should return a different value for hOpenContext. The device driver must track which return values from XXX_Open are in use. Subsequent calls by Windows CE to XXX_Close, XXX_Read, XXX_Write, XXX_Seek, and XXX_IOControl pass these values back to the device driver, enabling the driver to identify which internal data structures to manipulate.

To enforce single access, only the first call to XXX_Open should return a valid hOpenContext value. As long as this value remains valid, which is until Windows CE calls XXX_Close for the value, subsequent calls to XXX_Open should return NULL to the calling application to indicate failure.