Compartilhar via


Manage Device Driver Context (Compact 2013)

3/26/2014

Device drivers often must manage multiple open instances and multiple devices. When a device driver multiplexes its functionality across multiple open instances or multiple devices, it uses device driver context to keep track of which data structures and system resources go with which open instances and hardware devices. Because device drivers are DLLs with global variables and data structures that are shared by all driver instances, device drivers must use context management techniques to prevent resources that are allocated for one open instance or device from being incorrectly modified or deallocated for another open instance or device. For example, if the device driver deallocates the wrong memory block in response to an XXX_Close call, memory leaks, application failures, or an unstable system might occur.

Device drivers use device context to manage resources that are associated with a particular hardware device and open context to manage resources that are associated with a particular open instance. Depending on the functionality of your hardware, your device driver might support only one open instance and only one device, multiple open instances on one device, one open instance per hardware device, or multiple open instances across multiple devices. In each case, your device driver must correctly manage each type of context separately.

In This Section

  • Manage Device Context
    Provides an example of how to modify the stream driver initialization function to create and return a device context.
  • Manage Open Context
    Provides an example of how to modify the stream driver open function to create and return an open context.

See Also

Concepts

Implement Your Device Driver