How to get USB device address?
-
for (index=0; SetupDiEnumDeviceInterfaces(deviceInfo, 0, (LPGUID)&GUID_CLASS_USB, index, &DeviceInterfaceData); index++) { memset(tempstr, 0, 1024); deviceDetailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)tempstr; deviceDetailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); SetupDiGetDeviceInterfaceDetail(deviceInfo, &DeviceInterfaceData, deviceDetailData, 1024, &requiredLength, NULL); hUSBHandle = CreateFile(deviceDetailData->DevicePath, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); CloseHandle(hUSBHandle); } I would like enumerate all usb devices and get their device address. How could I do? I counld use the following codes to get DeviceAddress. DeviceIoControl(hHubDevice,IOCTL_USB_GET_NODE_CONNECTION_INFORMATION,connectionInfo, nBytes,connectionInfo,nBytes,&nBytes, NULL) ; But how to get device address without through usbHub. Thanks and regards
-
for (index=0; SetupDiEnumDeviceInterfaces(deviceInfo, 0, (LPGUID)&GUID_CLASS_USB, index, &DeviceInterfaceData); index++) { memset(tempstr, 0, 1024); deviceDetailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)tempstr; deviceDetailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); SetupDiGetDeviceInterfaceDetail(deviceInfo, &DeviceInterfaceData, deviceDetailData, 1024, &requiredLength, NULL); hUSBHandle = CreateFile(deviceDetailData->DevicePath, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); CloseHandle(hUSBHandle); } I would like enumerate all usb devices and get their device address. How could I do? I counld use the following codes to get DeviceAddress. DeviceIoControl(hHubDevice,IOCTL_USB_GET_NODE_CONNECTION_INFORMATION,connectionInfo, nBytes,connectionInfo,nBytes,&nBytes, NULL) ; But how to get device address without through usbHub. Thanks and regards
how does the deviceDetailData->DevicePath look like??? I use GetLogicalDrives to retrieve all removable drives and get: A:\, I:\...............(I:\ is my USB drive mount point). But my application needs to determine which drive letter (mount point) is for the USB. Then use this mount point to access files stored in the root directory of the USB flash drive. hUSBHandle = CreateFile(deviceDetailData->DevicePath, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); CloseHandle(hUSBHandle); ReadFile returns false using this handle.