Previous Next

Creating a Device Object

A monolithic driver must create a device object for each physical, logical, or virtual device for which it handles I/O requests. A driver that does not create a device object for a device does not receive any IRPs for the device.

In some technology areas, a minidriver that is associated with a class driver or port driver does not have to create its own device objects. Instead, the class or port driver creates the device object, and receives all IRPs for the device. The class or port driver then uses a driver-specific method to pass the I/O request to the minidriver. See the documentation for your particular technology area to determine if Microsoft supplies a class or port driver that creates device objects on behalf of your driver.

Drivers call either IoCreateDevice or IoCreateDeviceSecure to create their device objects. For more information on which routine to use, see the following sections.

Creating Device Objects for WDM Function and Filter Drivers

Creating Device Objects for WDM Bus Drivers

Creating Device Objects for non-WDM Drivers

When the driver creates a device object, it supplies the following information to IoCreateDevice or IoCreateDeviceSecure:

If the call to IoCreateDevice or IoCreateDeviceSecure succeeds, the I/O Manager provides storage for the device object itself and for all other data structures associated with the device object, including the device extension, which it initializes with zeros.

Creating Device Objects for WDM Function and Filter Drivers

WDM drivers, other than bus drivers, call IoCreateDevice to create their device objects. Most WDM drivers create their device objects from within their AddDevice routines. Some drivers, such as disk drivers that must respond to drive layout IOCTLs, call IoCreateDevice from a dispatch routine.

Unless device type-specific sections of the DDK documentation state otherwise, your driver should create its device objects in its AddDevice routine. For more information, see Writing an AddDevice Routine.

Creating Device Objects for WDM Bus Drivers

A WDM bus driver creates a PDO when it is enumerating a new device in response to an IRP_MN_QUERY_DEVICE_RELATIONS request, if the relation type is BusRelations.

The following rules determine if a bus driver calls IoCreateDevice or IoCreateDeviceSecure to create a device object:

Creating Device Objects for non-WDM Drivers

A non-WDM driver uses IoCreateDevice to create unnamed device objects, and IoCreateDeviceSecure to create named device objects. Note the unnamed device objects of a non-WDM driver are not accessible from user mode, so the driver usually must create at least one named object.