创建了一个DeviceObject
status=IoCreateDevice(DriverObject, sizeof (DEVICE_EXTENSION), &ntName, FILE_DEVICE_DISK, FILE_DEVICE_SECURE_OPEN, FALSE, &deviceObject);
deviceExtension=(PDEVICE_EXTENSION)deviceObject->DeviceExtension;
deviceExtension->NextLowerDriver=IoAttachDeviceToDeviceStack(deviceObject, pdo);
deviceObject是我刚刚创建的设备,pdo是依附的目标,返回值NextLowerDriver比较模糊,MSDN的解释是:
IoAttachDeviceToDeviceStack returns a pointer to the device object to which theSourceDevice was attached. The returned device object pointer can differ fromTargetDevice(在上面的程序中是pdo) if TargetDevice had additional drivers layered on top of it.
尽管说的很细,但是缺乏例子
例子:
比如原来的链是 Fido1---Fido2---pdo
那么我将deviceObject绑定到pdo上后,就成了:
deviceObject----Fido1----Fido2----pdo
此时的返回值是Fido1
注意,新加的Dev只能放在最末尾。
IoAttachDevice也是如此
可以利用DeviceTree软件来看设备链和Attached链的关系,一目了然。