NTSTATUS
IoGetDeviceObjectPointer(
IN PUNICODE_STRING ObjectName,
IN ACCESS_MASK DesiredAccess,
OUT PFILE_OBJECT *FileObject,
OUT PDEVICE_OBJECT *DeviceObject
);
IoGetDeviceObjectPointer returns a pointer to a named device object and corresponding file object if the requested access to the objects can be granted.
IoGetDeviceObjectPointer establishes a “connection” between the caller and the next-lower-level driver. A successful caller can use the returned device object pointer to initialize its own device object(s). It can also be used as as an argument to IoAttachDeviceToDeviceStack, IoCallDriver, and any routine that creates IRPs for lower drivers. The returned pointer is a required argument to IoCallDriver.
This routine also returns a pointer to the corresponding file object, which is useful only to highest-level drivers. A lower-level driver should call ObDereferenceObject with the returned file object pointer if such a driver is unloaded to decrement the reference count for the file object. Otherwise, the next-lower driver cannot be unloaded.
After any higher-level driver has chained itself over another driver by successfully calling this routine, the higher-level driver must set the StackSize field in its device object to that of the next-lower-level driver’s device object plus one.
Callers of IoGetDeviceObjectPointer must be running at IRQL PASSIVE_LEVEL.
DEVICE_OBJECT, IoAllocateIrp, IoAttachDevice, IoAttachDeviceToDeviceStack, ObDereferenceObject, ObReferenceObjectByPointer