views:

49

answers:

1

i get device insertion and removal notification from WM_DEVICECHANGE

i get the dbcc_name from the DBT_DEVTYP_DEVICEINTERFACE

i get the corresponding drive letter from the DBT_DEVTYP_VOLUME

if i insert the device one by one it works correctly

but if i insert two device at a time i get duplication in drive letters

how can i solve it

kindly provide me some ideas

my code snippet

if ( DBT_DEVICEARRIVAL == wParam || DBT_DEVICEREMOVECOMPLETE == wParam )
{
     PDEV_BROADCAST_HDR pHdr = ( PDEV_BROADCAST_HDR )lParam;

     PDEV_BROADCAST_DEVICEINTERFACE pDevInf;

     PDEV_BROADCAST_VOLUME pDevVolume = reinterpret_cast<PDEV_BROADCAST_VOLUME>(lParam);

     switch( pHdr->dbch_devicetype )

     {
           case DBT_DEVTYP_DEVICEINTERFACE:
                pDevInf = ( PDEV_BROADCAST_DEVICEINTERFACE )pHdr;
      updateDevice( pDevInf, wParam , pDevVolume );
                break;

            case DBT_DEVTYP_VOLUME:
                  pDevVolume = ( PDEV_BROADCAST_VOLUME )pHdr;
                  QString aDrive = FirstDriveFromMask( pDevVolume->dbcv_unitmask );
                  break;

      }

}
A: 

The DEV_BROADCAST_VOLUME docs mention this piece of info:

Although the dbcv_unitmask member may specify more than one volume in any message, this does not guarantee that only one message is generated for a specified event. Multiple system components may independently generate messages for logical volumes at the same time.

In other words - one message can carry information about multiple volumes added (almost) simultaneously, but that does not guarantee that only one message will be generated for these volumes. You should check dbcv_unitmask for more than one volumes.

Franci Penov
is it possible to get dbcc_name from PDEV_BROADCAST_VOLUME
barbgal
No, if you want `dbcc_name`, you need to explicitly register for `DBT_DEVTYP_DEVICEINTERFACE` notifications using `RegisterDeviceNotification` and get it from the `DEV_BROADCAST_DEVICEINTERFACE` struct. (Btw, `dbcc_name` is not intended to be human-readable even thouhg it's a UNC-formatted string)
Franci Penov
i need to get dbcc_name and dbcv_unitmask
barbgal