views:

40

answers:

1

Hi all

I'm sorry if this is similar to an earlier question but this is something I just noticed. I can detect when my device is attached to the system (via usb) and trap the message correctly however if I unplug and plug the device back, attempting to access the device via the CreateFile() function always returns an error: ERROR_GEN_FAILURE 31 (0x1F) which translates to -A device attached to the system is not functioning, this is however, attempted after recieving the DBT_DEVICEARRIVAL message which by microsoft's own definition says "A device or piece of media has been inserted and is now available". I believe what's going on here is that the error has more to do with the device not being ready even though it's reported as being ready because if I re-enumerate the list of devices on the system again, the device is ready. Has anyone else encountered and gotten past this problem? Or is there something I'm missing/overlooking?

A: 

The simplest way to deal with this, IMO, is through WMI.

See here: http://dotnetslackers.com/community/blogs/basharkokash/archive/2008/02/06/usb-port-insert-remove-detection-using-wmi.aspx

I have used WMI in the past for USB drive detection and it is dead simple and the callback makes things pretty clean

Foovanadil
Apologies I know nothing of WMI
Dark Star1
Yeah, neither did I the first time I tired it. However, take a look at the article I posted. It is simple.
Foovanadil