首页->【EZ-USB CY7C68013 CYUSB3014小组】

972 0

当您写好了USB设备的驱动程序,并且正确的安装了驱动程序。现在插入USB设备,这时WINDOWS任务栏的右下角会出现一USB设备的托盘图标,当你想拔下USB设备时,你需要先点击这个托盘图标,选择“停止XXX设备"选项。否则你会看到一个 “不安全的设备删除”的警告对话框。对于那种不需要在插拔设备就停止的设备,你可以在IRP_MJ_PNP的派遣例程中作如下的工作:

NTSTATUS Dispatch_Pnp( IN PDEVICE_OBJECT fdo, IN PIRP Irp )
{
     PIO_STACK_LOCATION pStack = IoGetCurrentIrpStackLocation( Irp );
     switch( pStack->MinoRFunction )
     {
     // Others...
     case IRP_MN_QUERY_CAPABILITIES:
      {
           PDEVICE_CAPABILITIES pdc = pStack->Parameters.DeviceCapabilities.Capabilities;
           if (pdc->Version < 1)
                {
                 status = PNPDefaultHandler(pdx, Irp);
                 break;
                }
                status = ForwardIrpAndWait(fdo, Irp);
                if (NT_SUCCESS(status))
                {
                 pdc = pStack->Parameters.DeviceCapabilities.Capabilities;
                 pdc->SurpriseRemovalOK = TRUE;         & nbsp;// 关键在这
                }
                status = CompleteIrp(Irp, status, Irp->IoStatus.Information);
      }
      break;
     default:
           status = PNPDefaultHandler( pdx, Irp );
     }
}


NTSTATUS PNPDefaultHandler( IN PMVCEXT pdx, IN PIRP Irp )
{
     IoSkipCurrentIrpStackLocation( Irp );
     return IoCallDriver( pdx->NextDevice, Irp );
}

好了,让我们看看DDK对SurpriseRemovalOK的解释吧!

SurpriseRemovalOK
Specifies whether the system should display a pop-up window if a user removes the device from the machine without first going through the Unplug or Eject Hardware applet (a "surprise-style" removal).

别说你不会英文哦,要不然我还得翻译。:)

OK,你的托盘图标消失了!

楼主可见