CII_GZH
驱动中牛
驱动中牛
  • 注册日期2005-06-16
  • 最后登录2007-08-27
  • 粉丝0
  • 关注0
  • 积分257分
  • 威望127点
  • 贡献值0点
  • 好评度33点
  • 原创分0分
  • 专家分0分
阅读:1429回复:5

驱动程序中的困惑,请高手指点迷经,谢谢啊。

楼主#
更多 发布于:2005-07-18 10:55
  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函数呢,创建这个时间有什么用处。而且另外的地方也设置和等待这个事件了,我感觉不使用他程序更简洁。
学习
kinglea
驱动牛犊
驱动牛犊
  • 注册日期2005-06-07
  • 最后登录2005-08-02
  • 粉丝0
  • 关注0
  • 积分5分
  • 威望1点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2005-07-18 16:22
好象不是创建的时间吧!创建的是一个等待触发的事件!
CII_GZH
驱动中牛
驱动中牛
  • 注册日期2005-06-16
  • 最后登录2007-08-27
  • 粉丝0
  • 关注0
  • 积分257分
  • 威望127点
  • 贡献值0点
  • 好评度33点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2005-07-18 16:31
哦,打字错误。事件,创建一个等待事件,他的作用是什么啊,可能是我的基础知识不够,所以理解不清楚,请楼上的或是那位高手讲讲,谢谢了。^_^.
学习
thx1180
驱动牛犊
驱动牛犊
  • 注册日期2005-06-21
  • 最后登录2006-04-20
  • 粉丝0
  • 关注0
  • 积分18分
  • 威望3点
  • 贡献值0点
  • 好评度1点
  • 原创分0分
  • 专家分0分
地板#
发布于:2005-07-19 09:11
Walter Oney 的“Programming the Windows Driver Model”讲的很清楚了,好好看看吧
Henry
驱动牛犊
驱动牛犊
  • 注册日期2001-04-27
  • 最后登录2011-06-20
  • 粉丝0
  • 关注0
  • 积分4分
  • 威望27点
  • 贡献值0点
  • 好评度1点
  • 原创分0分
  • 专家分0分
地下室#
发布于:2005-07-19 11:02
提示一点,创建事件是为了保证卸载驱动程序的时候没有Pending/Running IRP
驱动人生。
CII_GZH
驱动中牛
驱动中牛
  • 注册日期2005-06-16
  • 最后登录2007-08-27
  • 粉丝0
  • 关注0
  • 积分257分
  • 威望127点
  • 贡献值0点
  • 好评度33点
  • 原创分0分
  • 专家分0分
5楼#
发布于:2005-07-19 11:22
谢谢楼上的,感觉这个答案可以说的过去啊。谢谢啊。
学习
游客

返回顶部