c++cdetectremovable-storage

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


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?


Solution

  • 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.