When we connect USB mass storage device, two entries are created in the Device Manager: one under Disk Drive and another under USB as USB Mass Storage.
HDEVINFO hDevInfo = SetupDiGetClassDevs(
(LPGUID) &GUID_DEVCLASS_DISKDRIVE, // USB Device Class
NULL,
NULL,
DIGCF_PRESENT);
This will list the entry under Disk Drive
HDEVINFO hDevInfo = SetupDiGetClassDevs(
(LPGUID) &GUID_DEVCLASS_USB, // USB Device Class
NULL,
NULL,
DIGCF_PRESENT);
This will list all the USB devices.
Is there any way to map the entries obtained from the above two calls. I checked for device instance id of all the devices using SetupDiEnumDeviceInfo
, but ids did not match
The reason I need to map these two entries is because I have to get the USB device location (Hub and Port) number
Thanks Praveen
The drive letter is associated with a volume/partition on the drive. You'll see this when you use the "safe disconnect" option in Windows, where it will list all the entities that will be removed.
You could enumerate physical disk devices using the GUID_DEVINTERFACE_DISK. Using:
SetupDiGetClassDevs
(
&GUID_DEVINTERFACE_DISK,
NULL,
NULL,
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE
)
Then, query the storage adapter descriptor.
STORAGE_PROPERTY_QUERY storageProperty;
//...setup
PSTORAGE_ADAPTER_DESCRIPTOR pstorageAdapterDesc;
pstorageAdapterDesc = (PSTORAGE_ADAPTER_DESCRIPTOR)LocallAlloc( LPTR, storageDescHeader.Size );
DeviceIoControl
(
handle,
IOCTL_STORAGE_QUERY_PROPERTY,
&storageProperty,
sizeof( STORAGE_PROPERTY_QUERY ),
pstorageAdapterDesc,
storageDescHeader.Size,
bytesReturned,
NULL
)
In the descriptor, you could use the "BusType" and check for USB.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.