让设备即插即用—任务栏右下角弹出设备

这篇博文是在上一篇基础上修改一下的...如果有不清楚地方可以先看上一篇博文

其实也就是处理一下IRP_MJ_PNPIRP_MN_QUERY_CAPABILITIES

先上图,

先写个完成例程


NTSTATUS DRIVERWDMTEST_DispatchPnp_IoCompletion(
	IN PDEVICE_OBJECT  DeviceObject,
	IN PIRP  Irp,
	IN PVOID  Context
	)
{
	KeSetEvent((KEVENT*)Context, 0, FALSE);
	return STATUS_MORE_PROCESSING_REQUIRED;
}
重点修改的地方就是pnp



NTSTATUS DRIVERWDMTEST_DispatchPnp(
           IN PDEVICE_OBJECT    DeviceObject,
           IN PIRP              Irp)
{
    DEVICE_EXTENSION *pDEX=(DEVICE_EXTENSION*)DeviceObject->DeviceExtension;
    IO_STACK_LOCATION *pIOStack=IoGetCurrentIrpStackLocation(Irp);
    KdPrint(("DRIVERWDMTEST_DispatchPnp pIOStack->MinorFunction %d ",pIOStack->MinorFunction));
    switch(pIOStack->MinorFunction){
        case IRP_MN_QUERY_CAPABILITIES:
            {
                KdPrint(("IRP_MN_QUERY_CAPABILITIES"));

                NTSTATUS statusQC=STATUS_SUCCESS;
                KEVENT eventWait;
                KeInitializeEvent(&eventWait,NotificationEvent,FALSE);
                IoCopyCurrentIrpStackLocationToNext(Irp);
                IoSetCompletionRoutine(Irp,DRIVERWDMTEST_DispatchPnp_IoCompletion,PVOID)&eventWait,true,true,true);
                statusQC=IoCallDriver(pDEX->pStackNextDeviceObject,Irp);
                KeWaitForSingleObject(&eventWait,Executive,KernelMode,FALSE,NULL);
                pIOStack->Parameters.DeviceCapabilities.Capabilities->Removable=true;//重点在这里

                KdPrint(("IRP_MN_QUERY_CAPABILITIES finished"));
                return statusQC;
            }
        default:
                IoSkipCurrentIrpStackLocation(Irp);
                return IoCallDriver(pDEX->pStackNextDeviceObject, Irp);
	}
    return STATUS_SUCCESS;
}
评论列表