// wdfiotarget.h
PDEVICE_OBJECT WdfIoTargetWdmGetTargetDeviceObject(
[in] WDFIOTARGET IoTarget
);
View the official Windows Driver Kit DDI referenceNo description available.
[Applies to KMDF only]
The WdfIoTargetWdmGetTargetDeviceObject method returns a pointer to the Windows Driver Model (WDM) device object that is associated with a specified local or remote I/O target.
IoTarget [in]A handle to a local or remote I/O target object that was obtained from a previous call to WdfDeviceGetIoTarget or WdfIoTargetCreate or from a method that a specialized I/O target supplies.
WdfIoTargetWdmGetTargetDeviceObject returns a pointer to a WDM DEVICE_OBJECT structure.
A bug check occurs if the driver supplies an invalid object handle.
Most framework-based drivers do not need to access an I/O target's WDM device object.
The pointer that the WdfIoTargetWdmGetTargetDeviceObject method returns is valid until the driver calls WdfIoTargetClose or WdfIoTargetCloseForQueryRemove, or until the remote I/O target object is deleted. If the driver provides an EvtCleanupCallback function for the remote I/O target object, and if the object is deleted before the remote I/O target is closed, the pointer is valid until the EvtCleanupCallback function returns.
If the driver attempts to access the WDM device object after it has been removed, the driver can cause the system to crash. The toastmon sample demonstrates how the driver can provide an EvtIoTargetQueryRemove callback function so that it is notified if the I/O target is removed.
For more information about WdfIoTargetWdmGetTargetDeviceObject, see Obtaining Information About a General I/O Target.
For more information about I/O targets, see Using I/O Targets.
[!NOTE] The framework does not take a reference on the target device object before returning it to the driver. The caller does not need to dereference it unless it explicitly adds a reference.
The following code example checks an I/O target's WDM DEVICE_OBJECT structure to verify that the target supports direct I/O operations.
if (!((WdfIoTargetWdmGetTargetDeviceObject(Adapter->IoTarget))->Flags
& DO_DIRECT_IO)) {
ASSERTMSG("Target device doesn't support direct I/O\n", FALSE);
return STATUS_INVALID_DEVICE_REQUEST;
}