views:

143

answers:

2

Hello all,

I get the devices list from the system using SetupDiGetClassDevs Function - MSDN.

Also i can able to get the vendor id and product id from the devices.

But i cant able to get the drive letter and the mount path

For Example if i plug the usb drive means , i have to get the drive letter like "G:/"

Please help me to get the drive letter and mount path for the devices

if (SetupDiEnumDeviceInterfaces(hDevInfo,
    NULL,&GUID_DEVINTERFACE_USB_DEVICE,i,&Interface_Info))
{
    wprintf(L"\tDeviccvcvcveInstanceId : %d\n", i); 

    pspdidd->cbSize = sizeof(*pspdidd); 

    SP_DEVICE_INTERFACE_DETAIL_DATA *pDetData = NULL;

    DWORD dwDetDataSize = sizeof (SP_DEVICE_INTERFACE_DETAIL_DATA) + 256;

    pDetData = (SP_DEVICE_INTERFACE_DETAIL_DATA*) malloc (dwDetDataSize);

    pDetData->cbSize = sizeof (SP_DEVICE_INTERFACE_DETAIL_DATA);

   SetupDiGetDeviceInterfaceDetail(hDevInfo,&Interface_Info,pDetData,dwDetDataSize, 
   NULL,&DeviceInfoData);

   qDebug ()<<QString::fromWCharArray( pDetData->DevicePath );

}
A: 

Unfortunately this is not a very straightforward operation. There is a good walk-through on how to accomplish something similar on CodeProject. Basically every disk is assigned a unique device number and every volume has a device number corresponding to the disk on which it resides. So you have to open all the volumes and query for their device numbers (IOCTL_STORAGE_GET_DEVICE_NUMBER), then match them against the device number of the disk in question. The CodeProject code is going the other way (volume to disk), but you should be able to modify it easily enough.

Luke
+1  A: 

You can use QueryDosDevice function (see http://msdn.microsoft.com/en-us/library/aa365461(VS.85).aspx). See http://msdn.microsoft.com/en-us/library/cc542456(VS.85).aspx for an code example.

Oleg