阅读:1429回复:5
驱动程序中的困惑,请高手指点迷经,谢谢啊。
NTSTATUS
Ezusb_PnPAddDevice( IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject ) /*++ Routine Description: This routine is called to create a new instance of the device Arguments: DriverObject - pointer to the driver object for this instance of Ezusb PhysicalDeviceObject - pointer to a device object created by the bus Return Value: STATUS_SUCCESS if successful, STATUS_UNSUCCESSFUL otherwise --*/ { NTSTATUS ntStatus = STATUS_SUCCESS; PDEVICE_OBJECT deviceObject = NULL; PDEVICE_EXTENSION pdx; int instance; Ezusb_KdPrint(("enter Ezusb_PnPAddDevice\n")); #define MAX_EZUSB_DEVICES 8 // // create our functional device object (FDO). This driver supports multiple ezusb devices. // This loop will look for an available instance number. Keep incrementing the instance // until a call to Ezusb_CreateDeviceObject succeeds. // instance = 0; do { ntStatus = Ezusb_CreateDeviceObject(DriverObject, &deviceObject, instance); instance++; } while (!NT_SUCCESS(ntStatus) && (instance < MAX_EZUSB_DEVICES)); if (NT_SUCCESS(ntStatus)) { pdx = deviceObject->DeviceExtension; // // Non plug and play drivers usually create the device object in // driver entry, and the I/O manager autimatically clears this flag. // Since we are creating the device object ourselves in response to // a PnP START_DEVICE IRP, we need to clear this flag ourselves. // deviceObject->Flags &= ~DO_DEVICE_INITIALIZING; // // This driver uses direct I/O for read/write requests // deviceObject->Flags |= DO_DIRECT_IO; deviceObject->Flags |= DO_POWER_PAGABLE; // // // store away the Physical device Object // pdx->PhysicalDeviceObject=PhysicalDeviceObject; // // Attach to the StackDeviceObject. This is the device object that what we // use to send Irps and Urbs down the USB software stack // pdx->StackDeviceObject = IoAttachDeviceToDeviceStack(deviceObject, PhysicalDeviceObject); ASSERT (pdx->StackDeviceObject != NULL); pdx->LastFailedUrbStatus = 0; pdx->usage = 1; // locked until RemoveDevice KeInitializeEvent(&pdx->evRemove, NotificationEvent, FALSE); // set when use count drops to zero } 主要是斜体部分,那这里为什么要加上这个 API函数呢,创建这个时间有什么用处。而且另外的地方也设置和等待这个事件了,我感觉不使用他程序更简洁。 |
|
|
沙发#
发布于:2005-07-18 16:22
好象不是创建的时间吧!创建的是一个等待触发的事件!
|
|
板凳#
发布于:2005-07-18 16:31
哦,打字错误。事件,创建一个等待事件,他的作用是什么啊,可能是我的基础知识不够,所以理解不清楚,请楼上的或是那位高手讲讲,谢谢了。^_^.
|
|
|
地板#
发布于:2005-07-19 09:11
Walter Oney 的“Programming the Windows Driver Model”讲的很清楚了,好好看看吧
|
|
地下室#
发布于:2005-07-19 11:02
提示一点,创建事件是为了保证卸载驱动程序的时候没有Pending/Running IRP
|
|
|
5楼#
发布于:2005-07-19 11:22
谢谢楼上的,感觉这个答案可以说的过去啊。谢谢啊。
|
|
|