WdfDriverCreate - NtDoc

Native API online documentation, based on the System Informer (formerly Process Hacker) phnt headers
// wdfdriver.h

NTSTATUS WdfDriverCreate(
  [in]            PDRIVER_OBJECT         DriverObject,
  [in]            PCUNICODE_STRING       RegistryPath,
  [in, optional]  PWDF_OBJECT_ATTRIBUTES DriverAttributes,
  [in]            PWDF_DRIVER_CONFIG     DriverConfig,
  [out, optional] WDFDRIVER              *Driver
);

View the official Windows Driver Kit DDI reference

NtDoc

No description available.

Windows Driver Kit DDI reference (nf-wdfdriver-wdfdrivercreate)

WdfDriverCreate function

Description

[Applies to KMDF and UMDF]

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

Parameters

DriverObject [in]

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 [in]

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

DriverAttributes [in, optional]

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 [in]

A pointer to a caller-allocated WDF_DRIVER_CONFIG structure.

Driver [out, optional]

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;
}

See also

DRIVER_OBJECT

DriverEntry

EvtDriverDeviceAdd

UNICODE_STRING

WDF_DRIVER_CONFIG

WDF_DRIVER_CONFIG_INIT

WDF_OBJECT_ATTRIBUTES