WM_DEVICECHANGE handle - see http://lists.trolltech.com/qt-interest/2001-08/thread00698-0.html for handling Windows messages in QT.
If wParam DBT_DEVICEARRIVAL , then drop lParam to DEV_BROADCAST_HDR *
If the dbch_devicetype DBT_DEVTYP_VOLUME structures again outline lParam, this time until DEV_BROADCAST_VOLUME *
Now check the dbcv_unitmask bit dbcv_unitmask , repeat bit 0..31 and check if the corresponding drive matches your USB drive.
if (wParam == DBT_DEVICEARRIVAL) { if (((DEV_BROADCAST_HDR *) lParam)->dbch_devicetype == DBT_DEVTYP_VOLUME) { DWORD Mask = ((DEV_BROADCAST_VOLUME *) lParam)->dbcv_unitmask; for (int i = 0; i < 32; ++i) { if (Mask & (1 << i)) { char RootPath[4] = "A:\\"; RootPath[0] += i; // Check if the root path in RootPath is your USB drive. } } } }
source share