winapi - Detecting USB notification in Qt on windows -
in qt application want save application output data file in usb pen drive. need put following features in qt application
- detect usb drive insertion
- i have 1 usb slot.
- after insert want know drive number , letter , transfer file @ specific location in pc usb drive.
can tell me winapi .lib , .h , .dll file hav use above functionalities ?
if can provide code snippets, helpful me.
handle wm_devicechange
- see http://lists.trolltech.com/qt-interest/2001-08/thread00698-0.html how handle windows messages in qt.
if wparam dbt_devicearrival
cast lparam dev_broadcast_hdr *
if structures dbch_devicetype
dbt_devtyp_volume
cast lparam again, time dev_broadcast_volume *
now check dbcv_unitmask
bit field, iterate on bits 0..31 , check if corresponding drive match usb drive.
if (wparam == dbt_devicearrival) { if (((dev_broadcast_hdr *) lparam)->dbch_devicetype == dbt_devtyp_volume) { dword mask = ((dev_broadcast_volume *) lparam)->dbcv_unitmask; (int = 0; < 32; ++i) { if (mask & (1 << i)) { char rootpath[4] = "a:\\"; rootpath[0] += i; // check if root path in rootpath usb drive. } } } }
Comments
Post a Comment