Windows Driver Kit: Kernel-Mode Driver Framework
WdfDriverCreate
The WdfDriverCreate method creates a framework driver object for the calling driver.
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
- 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:
- 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.
The method might return other NTSTATUS values.
A system bug check occurs if the DriverObject, RegistryPath, or DriverConfig parameter is NULL.
Comments
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.
Example
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
Versions: The WdfDriverCreate method is available in version 1.0 and later versions of KMDF.
IRQL: PASSIVE_LEVEL
Headers: Defined in Wdfdriver.h. Include Wdf.h.
Library: See Framework Library Versions.
See Also
DRIVER_OBJECT, DriverEntry, EvtDriverDeviceAdd, UNICODE_STRING, WDF_DRIVER_CONFIG, WDF_DRIVER_CONFIG_INIT, WDF_OBJECT_ATTRIBUTES