Sharing A Device

To share a simple device, a driver creates a single context that can be shared by multiple applications. This context allows each application to reference and modify device characteristics set up by other applications. For example, a shared driver for a CD player should allow an application to issue a command (“resume”, for example) that is based on the context of the last command received from any other application (“stop”, for example).

Because each instance of a shared driver is created by a separate DRV_OPEN command, a separate driver ID is assigned to each instance.

For a compound device, the shareable object is the device element. Each element has a unique device ID. The driver allows multiple applications to share an element’s context. Each application can reference and modify characteristics of the element that have been set up by other applications.

If a driver can share a device (or object), the decision about whether it should share the device (or object) is based on the first MCI_OPEN_DRIVER command. If this command includes the MCI_OPEN_SHAREABLE flag, then the driver should mark the device (or object) as being shared. Each subsequent MCI_OPEN_DRIVER command received must also include the MCI_OPEN_SHAREABLE flag, or else the MCIERR_MUST_USE_SHAREABLE error value must be returned.

On the other hand, if the first MCI_OPEN_DRIVER command does not include the MCI_OPEN_SHAREABLE flag, then no subsequent MCI_OPEN_DRIVER command can include the MCI_OPEN_SHAREABLE flag either. If it does, the MCIERR_MUST_USE_SHAREABLE error value must be returned.

If an application specifies the MCI_OPEN_SHAREABLE flag but the driver does not allow device sharing, then the driver must return MCIERR_UNSUPPORTED_FUNCTION.

For compound devices, drivers can alternatively allow several applications to open a single element without specifying the MCI_OPEN_SHAREABLE flag. In this case, each application should possess its own context for the element. As a result, each application makes its own modifications to the element context without affecting any other application’s context. Each application can move independently within a single element. Also, a single application can open a single element multiple times, providing multiple contexts for one element.