tags:

views:

178

answers:

3

for simple code ...example we plug the pen drive and detect it then find the space and check the contant..that it..

+4  A: 

To detect from C that a new storage device, like a USB pen drive, is inserted, use GetLogicalDrives(); or GetLogicalDriveStrings() and see if any new entries are detected.

Also have a look at how GetDriveInfo2 is implemented (it uses WINAPI) and this Stack Overflow question, which is related or possibly a dupe.

Once you have the logical drive name, you open it as a directory and enumerate the files there as you would any directory with FindFirstFile().

Amigable Clark Kant
`GetLogicalDrives()` and `GetLogicalDriveStrings()` aren't part of C.
Donotalo
@Donotalo, true. :-)
Amigable Clark Kant
+2  A: 

This will be highly OS-dependent and it will also depend on what kind of USB device you actually want to talk to. Normally you would not access the USB driver directly but would use it via a higher level API. E.g. for a USB disk drive you would just access it like any other disk drive via file system APIs and would not concern yourself with USB APIs.

USB is a complex protocol stack and is designed to hook into the host OS at various points, so you don't normally need to access USB APIs unless you are writing a driver or need to communicate with some kind of non-standard device.

Paul R
A: 

If you want to write the low level by yourself, see this John Hyde's book as a reference: USB Design By Example

rursw1