WdfDriverCreate function (wdfdriver.h)
[Applies to KMDF and UMDF]
The WdfDriverCreate method creates a framework driver object for the calling driver.
Syntax
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
);
Parameters
[in] 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.
[in] RegistryPath
A pointer to a UNICODE_STRING structure that contains the registry path string that the driver received as input to its DriverEntry routine.
[in, optional] 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.
[in] DriverConfig
A pointer to a caller-allocated WDF_DRIVER_CONFIG structure.
[out, optional] 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 |
---|---|
|
The driver called WdfDriverCreate more than once. |
|
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
Requirement | Value |
---|---|
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(kmdf), DriverAttributeChanged(kmdf), DriverCreate(kmdf), KmdfIrql(kmdf), KmdfIrql2(kmdf), KmdfIrqlExplicit(kmdf), MiniportOnlyWdmDevice(kmdf) |