Windows Driver Kit: Kernel-Mode Driver Architecture
AddDevice
The AddDevice routine is responsible for creating functional device objects (FDO) or filter device objects (filter DO) for devices enumerated by the Plug and Play (PnP) manager.
DRIVER_ADD_DEVICE AddDevice;
NTSTATUS
AddDevice(
__in struct _DRIVER_OBJECT *DriverObject,
__in struct _DEVICE_OBJECT *PhysicalDeviceObject
)
{...}
Parameters
- DriverObject
- Caller-supplied pointer to a DRIVER_OBJECT structure. This is the driver's driver object.
- PhysicalDeviceObject
- Caller-supplied pointer to a DEVICE_OBJECT structure representing a physical device object (PDO) created by a lower-level driver.
Return Value
If the routine succeeds, it must return STATUS_SUCCESS. Otherwise, it must return one of the error status values defined in Ntstatus.h.
Comments
All kernel-mode drivers that support PnP must provide an AddDevice routine.
A driver's AddDevice routine should be named XxxAddDevice, where Xxx is a driver-specific prefix. The driver's DriverEntry routine must store the AddDevice routine's address in DriverObject->DriverExtension->AddDevice.
An AddDevice routine's primary responsibilities are calling IoCreateDevice to create a device object, then calling IoAttachDeviceToDeviceStack to attach the device object to the device stack. For detailed information about implementing a driver's AddDevice routine, see Writing an AddDevice Routine.
Example
To define an AddDevice callback routine that is named MyAddDevice, you must first provide a function declaration that Static Driver Verifier (SDV) and other verification tools require, as shown in the following code example:
DRIVER_ADD_DEVICE MyAddDevice;
Then, implement your callback routine as follows:
NTSTATUS
MyAddDevice(
__in struct _DRIVER_OBJECT *DriverObject,
__in struct _DEVICE_OBJECT *PhysicalDeviceObject
)
{
// Function body
}
The DRIVER_ADD_DEVICE function type is defined in the Wdm.h header file. For more information about SDV requirements for function declarations, see Declaring Functions Using Function Role Types for WDM Drivers.
Requirements
IRQL: PASSIVE_LEVEL
Headers: Declared in Wdm.h. Include Wdm.h, Ntddk.h, or Ntifs.h.