I am trying to detect the insertion of removable devices and get the drive letter of the mentioned device using the NT service. I managed to detect the insertion and removal of devices, but could not configure the structure DEV_BROADCAST_VOLUME, which would allow me to get the drive letter, GUID, etc. From the volume.
case SERVICE_CONTROL_DEVICEEVENT:{
switch(evtype){
case DBT_DEVICEARRIVAL:{
DEV_BROADCAST_VOLUME *hdr = (DEV_BROADCAST_VOLUME*) evdata;
ofstream log ("C:\\log.txt", ios::app);
log << hdr->dbcv_devicetype;
log.close();
}
break;
The above code fragment compiles and runs correctly, but when I insert a USB flash drive, it hdr->dbcv_devicetyperegisters as a value 55555and DBT_DEVTYP_VOLUME(which is a USB drive), it is defined as 2(it hdr->dbcv_devicetypeshould equal DBT_DEVTYP_VOLUMEbecause I inserted a USB flash drive). For some reason, either it is DBT_DEVTYP_VOLUMEnot initializing correctly, or something else that I am doing is incorrect. I am using Windows 7 with Visual Studio 2011 C ++.
source
share