You are not allowed to fail pnp state changing irps (query is ok) like you are doing. If the device is disappearing, I think you are confusing stop with remove. From what menu is the device disappearing from?
Let me say this one last tile. You are wasting your time in a pretty dramatic way. If you use kmdf, you would be focusing on your he and whatever value the driver is adding. Instead, you are creating a mess of code, that once you get kind of stable, you will be very afraid to change in the future
d
debt from my phone
-----Original Message-----
From: xxxxx@yahoo.com
Sent: Monday, August 29, 2011 3:52 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] IRP_MN_QUERY_STOP_DEVICE and CancelAll
Here goes my code of PnP handler:
NTSTATUS IrpMjPnP(PDEVICE_OBJECT pDeviceObject, PIRP pIrp)
{
NTSTATUS status;
KIRQL Irql;
PDEVICE_EXTENSION pDeviceExtension;
PIO_STACK_LOCATION pStackLocation;
pDeviceExtension = pDeviceObject ->DeviceExtension;
pStackLocation = IoGetCurrentIrpStackLocation(pIrp);
status = STATUS_SUCCESS;
KeAcquireSpinLock(&pDeviceExtension ->Lock, &Irql);
if ((pDeviceExtension ->State == DEVICE_REMOVED || pDeviceExtension ->State == DEVICE_SURPRISE_REMOVAL) &&
!(pDeviceExtension ->State == DEVICE_SURPRISE_REMOVAL && pStackLocation ->MinorFunction == IRP_MN_REMOVE_DEVICE))
{
status = STATUS_DELETE_PENDING;
}
KeReleaseSpinLock(&pDeviceExtension ->Lock, Irql);
if (!NT_SUCCESS(status))
{
CompletePnPRequest(pIrp, status);
}
else
{
status = IoAcquireRemoveLock(&pDeviceExtension ->RemoveLock, pIrp);
if (status != STATUS_SUCCESS)
{
CompletePnPRequest(pIrp, status);
}
else
{
switch(pStackLocation ->MinorFunction)
{
case IRP_MN_START_DEVICE:
status = IrpMnStartDevice(pDeviceObject, pIrp);
break;
case IRP_MN_STOP_DEVICE:
status = IrpMnStopDevice(pDeviceObject, pIrp);
break;
case IRP_MN_QUERY_CAPABILITIES:
status = IrpMnQueryCapabilities(pDeviceObject, pIrp);
break;
default:
status = DefaultPnpHandler(pDeviceObject, pIrp);
break;
}
if (pStackLocation ->MinorFunction != IRP_MN_REMOVE_DEVICE)
{
IoReleaseRemoveLock(&pDeviceExtension ->RemoveLock, pIrp);
}
}
}
return status;
}
It is very alphs version. I put a breakpoint on IrpMnStopDevice and it is not triggered. I tried only once (it was late evening), I have to try it again today. Also I don’t know how to start the device since it disappears from menu after stopping.
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer