EvtDriverDeviceAdd function

[Applies to KMDF and UMDF]

A driver's EvtDriverDeviceAdd event callback function performs device initialization operations when the Plug and Play (PnP) manager reports the existence of a device.



NTSTATUS EvtDriverDeviceAdd(
  _In_    WDFDRIVER       Driver,
  _Inout_ PWDFDEVICE_INIT DeviceInit
{ ... }


Driver [in]

A handle to a framework driver object that represents the driver.

DeviceInit [in, out]

A pointer to a framework-allocated WDFDEVICE_INIT structure.

Return value

TheEvtDriverDeviceAdd callback function must return STATUS_SUCCESS if the operation succeeds. Otherwise, this callback function must return one of the error status values that are defined in Ntstatus.h. For more information, see the following Remarks section.


Each framework-based driver that supports PnP devices must provide the EvtDriverDeviceAdd callback function. The driver must place the callback function's address in its WDF_DRIVER_CONFIG structure before calling WdfDriverCreate.

The framework calls your driver's EvtDriverDeviceAdd callback function after a bus driver detects a device that has a hardware identifier (ID) that matches a hardware ID that your driver supports. You specify the hardware IDs that your driver supports by providing an INF file, which the operating system uses to install drivers the first time that one of your devices is connected to the computer. For more information about how the system uses INF files and hardware IDs, see How Setup Selects Drivers.

A driver's EvtDriverDeviceAdd callback function typically performs at least some of the following initialization operations:

Some drivers, especially filter drivers, might not create device objects for some devices. If an EvtDriverDeviceAdd callback function does not create a device object, it must still return STATUS_SUCCESS unless an error was encountered.

If a driver's EvtDriverDeviceAdd callback function creates a device object but does not return STATUS_SUCCESS, the framework deletes the device object and its child devices.

If a function driver's EvtDriverDeviceAdd callback function does not return STATUS_SUCCESS, the I/O manager does not build a device stack for the device.

If a filter driver's EvtDriverDeviceAdd callback function does not return STATUS_SUCCESS, the framework converts the return value to STATUS_SUCCESS, and the I/O manager builds the device stack without the filter driver.


To define an EvtDriverDeviceAdd callback function, you must first provide a function declaration that identifies the type of callback function you’re defining. Windows provides a set of callback function types for drivers. Declaring a function using the callback function types helps Code Analysis for Drivers, Static Driver Verifier (SDV), and other verification tools find errors, and it’s a requirement for writing drivers for the Windows operating system.

For example, to define an EvtDriverDeviceAdd callback function that is named MyDriverDeviceAdd, use the EVT_WDF_DRIVER_DEVICE_ADD type as shown in this code example:


Then, implement your callback function as follows:

 MyDriverDeviceAdd (
    WDFDRIVER Driver,

The EVT_WDF_DRIVER_DEVICE_ADD function type is defined in the WdfDriver.h header file. To more accurately identify errors when you run the code analysis tools, be sure to add the _Use_decl_annotations_ annotation to your function definition. The _Use_decl_annotations_ annotation ensures that the annotations that are applied to the EVT_WDF_DRIVER_DEVICE_ADD function type in the header file are used. For more information about the requirements for function declarations, see Declaring Functions by Using Function Role Types for KMDF Drivers. For information about _Use_decl_annotations_, see Annotating Function Behavior.


Target platform

Universal, introduced version 10.0.10030.0

Minimum KMDF version


Minimum UMDF version



Wdfdriver.h (include Wdf.h)



See also




Send comments about this topic to Microsoft

© 2015 Microsoft