Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detect USB Flash Card Insertion - Any Windows Language 1

Status
Not open for further replies.

DanielCBaxter

Programmer
Mar 15, 2005
3
US
I haven't been able to find anything on this, so I guess its not a popular issue, but I'm hoping someone has run into this before:

I'm trying to detect the insertion of a Flash Memory Card into a card reader. I can use the SysInfo Control in VB to detect the connection of the drive (which triggers a DeviceArrival event), however I need to detect the insertion of a card into the reader (which triggers none of the SysInfo events). Interesting piece of information: Insertion of a CD-Rom in a CD-Drive does trigger the DeviceArrivalEvent.

WindowsXP knows when a card is inserted into the device (it brings up a dialog), so I know the device is alerting the OS of a state change, just not how to subscribe to it myself.

Any help on this would be greatly appreciated, it doesn't really matter what language a solution comes in.

 
First thought would be to listen for the Windows message WM_DEVICECHANGE. A search at AllAPI returned this Visual Basic example:




Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
Thanks DrJavaJoe,

The method showcased in the link you sent is far more powerful than the SysInfo Control (which is probably just a wrapper for it), however, I am still running into the same problem. A WM_DEVICECHANGE is not getting sent on the insertion of the card, only when the actual device is disconnected/connected to the USB. I've been looking through WINUSER.H for another WM message that it can be, but my future is looking pretty bleak.
 
I am not sure about your application , but the answer may lie in the driver for the card reader or alternatively can you poll the card reader at regular intervals ?
 
Thanks aakhrinaam,

The reader I am currently testing with uses the Generic Storage Device USB Device by Microsoft. I don't really have experience with communicating directly with drivers, which was why I was hoping to subscribe to a message from the system. How would I go about accesing the driver directly and will I need the DDK?
 
Sorry Daniel , I don't know wmuch about Drivers, but I have a suggestion.
If you have the USB open as a COM port (OpenFile API), you should be able to poll it very frequently to see if there is data in there. I don't know how it fits in your application architecture.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top