Windows Driver Kit: Kernel-Mode Driver Framework
WdfControlDeviceInitAllocate

The WdfControlDeviceInitAllocate method allocates a WDFDEVICE_INIT structure that a driver uses when creating a new control device object.

PWDFDEVICE_INIT
  WdfControlDeviceInitAllocate(
    IN WDFDRIVER  Driver,
    IN CONST UNICODE_STRING*  SDDLString
    );

Parameters

Driver
A handle to a framework driver object.
SDDLString
A pointer to a UNICODE_STRING structure that describes a Unicode string. This string is a Security Descriptor Definition Language (SDDL) representation of a security descriptor. For more information, see the following Comments section.

Return Value

WdfControlDeviceInitAllocate returns a pointer to a framework-allocated WDFDEVICE_INIT structure, if the operation succeeds. Otherwise, the method returns NULL.

Comments

If you want your driver to create a control device object, the driver must call WdfControlDeviceInitAllocate to obtain a WDFDEVICE_INIT structure that it can pass to WdfDeviceCreate.

Your driver can specify a security setting by using a subset of SDDL. The Wdmsec.h file defines a set of SDDL_DEVOBJ_Xxx-formatted constants that you can use. For more information about security descriptors and SDDL, see Securing Device Objects.

The WdfDeviceInitAssignSDDLString method overwrites the security setting, if any, that WdfControlDeviceInitAllocate specifies.

For more information about calling WdfControlDeviceInitAllocate, see Using Control Device Objects.

Example

The following code example allocates a DEVICE_INIT structure, assigns a device object name, registers a shutdown notification callback function, and creates a control device object. For a more complex example that uses WdfControlDeviceInitAllocate, see the NONPNP sample driver or the NDISProt sample driver.

PWDFDEVICE_INIT  deviceInit = NULL;
NTSTATUS  status;
WDF_OBJECT_ATTRIBUTES  objectAttribs;

deviceInit = WdfControlDeviceInitAllocate(
                                     hDriver,
                                     &SDDL_DEVOBJ_SYS_ALL_ADM_RWX_WORLD_RW_RES_R
                                     );
if (deviceInit == NULL) {
    status = STATUS_INSUFFICIENT_RESOURCES;
    goto Error;
}
status = WdfDeviceInitAssignName(
                                 deviceInit,
                                 &ntDeviceName
                                 );
if (!NT_SUCCESS(status)) {
    WdfDeviceInitFree(deviceInit);
    deviceInit = NULL;
    goto Error;
}
WdfControlDeviceInitSetShutdownNotification(
                                            deviceInit,
                                            EvtShutdownNotification,
                                            WdfDeviceShutdown
                                            );
WDF_OBJECT_ATTRIBUTES_INIT(&objectAttribs);

status = WdfDeviceCreate(
                         &deviceInit,
                         &objectAttribs,
                         &controlDevice
                         );
if (!NT_SUCCESS(status)) {
    WdfDeviceInitFree(deviceInit);
    deviceInit = NULL;
    goto Error;
}
WdfControlFinishInitializing(controlDevice);

Requirements

Versions: The WdfControlDeviceInitAllocate method is available in version 1.0 and later versions of KMDF.

IRQL: PASSIVE_LEVEL

Headers: Declared in WdfControl.h. Include Wdf.h.

Library: See Framework Library Versions.

See Also

WDF_OBJECT_ATTRIBUTES_INIT, WDFDEVICE_INIT, WdfControlFinishInitializing, WdfDeviceInitAssignName, WdfControlDeviceInitSetShutdownNotification, WdfDeviceCreate, WdfDeviceInitAssignSDDLString


Send feedback on this topic
Built on November 19, 2009
Page view tracker