Tech Support > Microsoft Windows > Drivers > question about usb device removed unexpectly(IRP_MN_SURPRISE_REMOV
question about usb device removed unexpectly(IRP_MN_SURPRISE_REMOV
Posted by Steve on September 12th, 2007


Hi all,

I want to handle the situation when usb device is removed unexpectly.

I found that when I unplug the usb device unexpectly, the filter
dirver receives IRP_MN_SURPRISE_REMOVAL ,but no IRP_MN_REMOVE_DEVICE can be
received.

Meanwhile, I went through some examples in WDK and found they do not
delete the deviceobject for handling IRP_MN_SURPRISE_REMOVAL. Actually they
done it for handling IRP_MN_REMOVE_DEVICE.

My question is,
Do I need to delete deviceobject by calling IoDetachDevice() and
IoDeleteDevice() for handling IRP_MN_SURPRISE_REMOVAL?

If I do not delete deviceobject for handling IRP_MN_SURPRISE_REMOVAL,
the device object that will not be used can not be deleted.
This is a very bad result.

Therefore, I really need some suggestions for this question.
Your help will be very appreciated.

Posted by Eliyas Yakub [MSFT] on September 15th, 2007


You are not getting remove because somebody has an handle open to your
device. Get the application to close the handle to the device when the
device is removed. The app should listen for pnp notiication (sample:
src\general\toaster\exe\notify).

No you cannot detach and delete in surprise-remove. You should wait for
remove to come.

Why aren't you using KMDF to write this driver?

--
- This posting is provided "AS IS" with no warranties, and confers no
rights.