Detect removable drive (e.g. USB flash drive) C/C++

user197967 picture user197967 · Feb 2, 2010 · Viewed 9.3k times · Source

How can I detect when a removable disk drive is (dis)connected to the system? How to get the mount path (for Linux) and the drive letter (for windows)?

EDIT: Is there a way to detect the currently connected devices?

Answer

Mark Wilkins picture Mark Wilkins · Feb 2, 2010

For Windows, the API RegisterDeviceNotification will let you know when a USB device is added. The information about the volume is given in the DEV_BROADCAST_VOLUME structure. The dbcv_unitmask gives the drive letter.