Program writing to USB HID device results in "freeze" when device is repeatedly inserted and removed
When I unplug and replug a custom HID 开发者_运维百科device enough times on a low-ish-end machine (XP Pro SP3), Windows stops recognizing new USB connects and disconnects on any USB port (any device class). We turned on the Driver Verifier, and got a 0xC9 bugcheck (DRIVER_VERIFIER_IOMANAGER_VIOLATION), with an error code of 0x21D (An IRP dispatch handler has not properly detached from the stack below it upon receiving a remove IRP). The driver file that was referenced is HIDCORE.SYS. We are using the HID driver built into Windows.
The problem only occurs when a utility we wrote is running that sends a few commands to the device. While this utility is running, we can connect and disconnect the device anywhere from 3 to 30 times before the USB "locks up". Any connected devices still work, but no new connect/disconnect events are recognized. It's most reproducible on lower-end machines, but will occasionally happen on a medium-end PC. The only way, that we have found, out of this is to reboot, closing our application does not cause USB devices to be recognized again.
I've made sure we're closing all our file handles to the device when we get a disconnect event.
I am not using RegisterDeviceNotification, rather I am using the WMI ManagementEventWatcher to get events when devices are connected and disconnected.
I would like to know how to avoid this "freeze". I am not sure if our application is not disconnecting from the driver properly, if the device is doing something wrong, or if there is something wrong the the Window XP HID driver.
精彩评论