WdfDriverCreate function

[Applies to KMDF and UMDF]

The WdfDriverCreate method creates a framework driver object for the calling driver.

Syntax

NTSTATUS WdfDriverCreate(
  PDRIVER_OBJECT         DriverObject,
  PCUNICODE_STRING       RegistryPath,
  PWDF_OBJECT_ATTRIBUTES DriverAttributes,
  PWDF_DRIVER_CONFIG     DriverConfig,
  WDFDRIVER              *Driver
);

Parameters

DriverObject

A pointer to a DRIVER_OBJECT structure that represents a Windows Driver Model (WDM) driver object. The driver receives this pointer as input to its DriverEntry routine.

RegistryPath

A pointer to a UNICODE_STRING structure that contains the registry path string that the driver received as input to its DriverEntry routine.

DriverAttributes

A pointer to a caller-allocated WDF_OBJECT_ATTRIBUTES structure. (The structure's ParentObject member must be NULL.) This parameter is optional and can be WDF_NO_OBJECT_ATTRIBUTES.

DriverConfig

A pointer to a caller-allocated WDF_DRIVER_CONFIG structure.

Driver

A pointer to a location that receives a handle to the new framework driver object. This parameter is optional and can be WDF_NO_HANDLE.

Return Value

WdfDriverCreate returns STATUS_SUCCESS if the operation succeeds. Otherwise, this method might return one of the following values:

Return code Description
STATUS_DRIVER_INTERNAL_ERROR
The driver called WdfDriverCreate more than once.
STATUS_INVALID_PARAMETER
A non-Plug and Play (PnP) driver specified an EvtDriverDeviceAdd callback function.

For more information about return values, see Framework Object Creation Errors.

This method might also return other NTSTATUS values.

A system bug check occurs if the DriverObject, RegistryPath, or DriverConfig parameter is NULL.

Remarks

A driver that uses Kernel-Mode Driver Framework must call WdfDriverCreate from within its DriverEntry routine, before calling any other framework routines. For more information about DriverEntry, see DriverEntry for Framework-based Drivers.

Before your driver calls WdfDriverCreate, the driver must call WDF_DRIVER_CONFIG_INIT to initialize its WDF_DRIVER_CONFIG structure.

The framework driver object is the top of your driver's tree of framework objects and therefore does not have a parent object.

If your driver provides EvtCleanupCallback or EvtDestroyCallback callback functions for the driver object, note that the framework calls these callback functions at IRQL = PASSIVE_LEVEL.

Examples

The following code example is a DriverEntry routine that initializes a WDF_DRIVER_CONFIG structure and then creates a framework driver object.

NTSTATUS
DriverEntry(
    IN PDRIVER_OBJECT  DriverObject,
    IN PUNICODE_STRING  RegistryPath
    )
{
    WDF_DRIVER_CONFIG  config;
    NTSTATUS  status = STATUS_SUCCESS;

    WDF_DRIVER_CONFIG_INIT(
                           &config,
                           MyEvtDeviceAdd
                           );
    config.EvtDriverUnload = MyEvtDriverUnload;
    status = WdfDriverCreate(
                             DriverObject,
                             RegistryPath,
                             WDF_NO_OBJECT_ATTRIBUTES,
                              &config,
                             WDF_NO_HANDLE
                             );
    if (!NT_SUCCESS(status)) {
        TraceEvents(
                    TRACE_LEVEL_ERROR,
                    DBG_PNP,
                    "WdfDriverCreate failed with status %!STATUS!",
                    status
                    );
    }
    return status;
}

Requirements

   
Target Platform Universal
Minimum KMDF version 1.0
Minimum UMDF version 2.0
Header wdfdriver.h (include Wdf.h)
Library Wdf01000.sys (KMDF); WUDFx02000.dll (UMDF)
IRQL PASSIVE_LEVEL
DDI compliance rules ChangeQueueState, DriverAttributeChanged, DriverCreate, KmdfIrql, KmdfIrql2, MiniportOnlyWdmDevice

See Also

DRIVER_OBJECT

DriverEntry

EvtDriverDeviceAdd

UNICODE_STRING

WDF_DRIVER_CONFIG

WDF_DRIVER_CONFIG_INIT

WDF_OBJECT_ATTRIBUTES