flywithlove
驱动小牛
驱动小牛
  • 注册日期2002-11-05
  • 最后登录2009-10-09
  • 粉丝0
  • 关注0
  • 积分8分
  • 威望18点
  • 贡献值0点
  • 好评度10点
  • 原创分0分
  • 专家分0分
阅读:1343回复:2

有关拔出USB设备时产生的“不安全的设备删除“对话框的问题?

楼主#
更多 发布于:2003-01-08 10:47
我看了站长的这个帖子http://www.driverdevelop.com/forum/viewthread.php?tid=301,按照这样做了,可还是不行,哪位大侠能给我看看除了什么毛病。
NTSTATUS
BulkUsb_QueryCapabilities(
    IN PDEVICE_OBJECT       LowerDeviceObject,
    IN PDEVICE_CAPABILITIES DeviceCapabilities
    )
{
    PIO_STACK_LOCATION nextStack;
    PIRP irp;
    NTSTATUS ntStatus;
    KEVENT event;


    // This is a DDK-defined DBG-only macro that ASSERTS we are not running pageable code
    // at higher than APC_LEVEL.
    PAGED_CODE();


    // Build an IRP for us to generate an internal query request to the PDO
    irp = IoAllocateIrp(LowerDeviceObject->StackSize, FALSE);

    if (!irp) {
        return STATUS_INSUFFICIENT_RESOURCES;
    }

    //
    // Preinit the device capability structures appropriately.
    //
    RtlZeroMemory( DeviceCapabilities, sizeof(DEVICE_CAPABILITIES) );
    DeviceCapabilities->Size = sizeof(DEVICE_CAPABILITIES);
    DeviceCapabilities->Version = 1;
    DeviceCapabilities->Address = -1;
    DeviceCapabilities->UINumber = -1;


DeviceCapabilities->SurpriseRemovalOK=TRUE;
DeviceCapabilities->Removable=TRUE;
DeviceCapabilities->EjectSupported=TRUE;
DeviceCapabilities->WarmEjectSupported=TRUE;

    // IoGetNextIrpStackLocation gives a higher level driver access to the next-lower
    // driver\'s I/O stack location in an IRP so the caller can set it up for the lower driver.
    nextStack = IoGetNextIrpStackLocation(irp);
    nextStack->MajorFunction= IRP_MJ_PNP;
    nextStack->MinorFunction= IRP_MN_QUERY_CAPABILITIES;



    // init an event to tell us when the completion routine\'s been called
    KeInitializeEvent(&event, NotificationEvent, FALSE);

    // Set a completion routine so it can signal our event when
    //  the next lower driver is done with the Irp
    IoSetCompletionRoutine(irp,
                           BulkUsb_IrpCompletionRoutine,
                           &event,  // pass the event as Context to completion routine
                           TRUE,    // invoke on success
                           TRUE,    // invoke on error
                           TRUE);   // invoke on cancellation of the Irp


    // set our pointer to the DEVICE_CAPABILITIES struct
    nextStack->Parameters.DeviceCapabilities.Capabilities = DeviceCapabilities;

    // preset the irp to report not supported
    irp->IoStatus.Status = STATUS_NOT_SUPPORTED;

    ntStatus = IoCallDriver(LowerDeviceObject,
                            irp);

    //BULKUSB_KdPrint( DBGLVL_MEDIUM,(\" BulkUsb_QueryCapabilities() ntStatus from IoCallDriver to PCI = 0x%x\\n\", ntStatus));

    if (ntStatus == STATUS_PENDING) {
       // wait for irp to complete

       KeWaitForSingleObject(
            &event,
            Suspended,
            KernelMode,
            FALSE,
            NULL);

       ntStatus = irp->IoStatus.Status;
    }

    // failed? this is probably a bug
    //BULKUSB_KdPrintCond( DBGLVL_DEFAULT,(!NT_SUCCESS(ntStatus)), (\"BulkUsb_QueryCapabilities() failed\\n\"));

    IoFreeIrp(irp);

    return ntStatus;
}
痛并快乐着!
zhoujiamurong
驱动小牛
驱动小牛
  • 注册日期2006-03-20
  • 最后登录2009-05-06
  • 粉丝4
  • 关注0
  • 积分1081分
  • 威望360点
  • 贡献值0点
  • 好评度215点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2008-03-17 16:03
标记一下,备用
rayyang2000
管理员
管理员
  • 注册日期2001-03-23
  • 最后登录2012-09-13
  • 粉丝3
  • 关注0
  • 积分1036分
  • 威望925点
  • 贡献值3点
  • 好评度823点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2003-01-09 19:26
你把顺序搞反了。先传下去,再修改。
天天coding-debugging中----超稀饭memory dump file ======================================================== [b]Windows Device Driver Development and Consulting Service[/b] [color=blue][url]http://www.ybwork.com[/url][/color] ========================================================
游客

返回顶部