IoGetAttachedDeviceReference function

The IoGetAttachedDeviceReference routine returns a pointer to the highest level device object in a driver stack and increments the reference count on that object.

Syntax

NTKERNELAPI PDEVICE_OBJECT IoGetAttachedDeviceReference(
  PDEVICE_OBJECT DeviceObject
);

Parameters

DeviceObject

Pointer to the device object for which the topmost attached device object is retrieved.

Return Value

IoGetAttachedDeviceReference returns a pointer to the highest level device object in a stack of attached device objects after incrementing the reference count on the object.

Remarks

If the device object at DeviceObject has no device objects attached to it, DeviceObject and the returned pointer are equal.

Device driver writers must ensure that when they have completed all operations that required them to make this call, that they call ObDereferenceObject with the device object pointer returned by this routine. Failure to do so will prevent the system from freeing or deleting the device object because of an outstanding reference count.

Requirements

   
Windows version Available starting with Windows 2000.
Target Platform Universal
Header ntifs.h (include Wdm.h, Ntddk.h, Ntifs.h)
Library NtosKrnl.lib
DLL NtosKrnl.exe
IRQL "<= DISPATCH_LEVEL"
DDI compliance rules DanglingDeviceObjectReference, HwStorPortProhibitedDDIs

See Also

ObDereferenceObject