WdfDeviceGetFileObject function (wdfdevice.h)

[Applies to KMDF only]

The WdfDeviceGetFileObject method returns a handle to the framework file object that is associated with a specified WDM file object.

Syntax

WDFFILEOBJECT WdfDeviceGetFileObject(
  [in] WDFDEVICE    Device,
  [in] PFILE_OBJECT FileObject
);

Parameters

[in] Device

A handle to a framework device object.

[in] FileObject

A pointer to a WDM FILE_OBJECT structure.

Return value

WdfDeviceGetFileObject returns a handle to the framework file object that is associated with the specified WDM file object. If a framework file object was not created for the file, or if the FileObject pointer is invalid, the method returns NULL.

A bug check occurs if the driver supplies an invalid object handle.

Remarks

For more information about framework file objects, see Framework File Objects.

Examples

The following code example obtains a pointer to a named WDM device object and its corresponding WDM file object, if the requested access to the objects can be granted. Then, the example obtains a handle to the framework file object that is associated with the WDM file object.

PFILE_OBJECT  pWdmFileObject = NULL;
PDEVICE_OBJECT  pWdmDeviceObject = NULL;
WDFFILEOBJECT  fileObject = NULL;
NTSTATUS  status = STATUS_SUCCESS;
BOOLEAN  success = TRUE;

status = IoGetDeviceObjectPointer(
                                  &inputFileName,    // File name 
                                  FILE_ALL_ACCESS,   // Access mask
                                  &pWdmFileObject,   // Output pointer of WDM file object
                                  &pWdmDeviceObject  // Output pointer of WDM device object
                                  );

if(!NT_SUCCESS(status)){
    success = FALSE;
    break;
}

fileObject = WdfDeviceGetFileObject(
                                    gDeviceObject,  // Handle to device object
                                    pWdmFileObject  // Handle to WDM file object
                                    );
if(fileObject == NULL){
    success = FALSE;
}

Requirements

Requirement Value
Target Platform Universal
Minimum KMDF version 1.0
Header wdfdevice.h (include Wdf.h)
Library Wdf01000.sys (see Framework Library Versioning.)
IRQL <= DISPATCH_LEVEL
DDI compliance rules DriverCreate(kmdf), KmdfIrql(kmdf), KmdfIrql2(kmdf), KmdfIrqlExplicit(kmdf)

See also

IoGetDeviceObjectPointer