16,472
社区成员
发帖
与我相关
我的任务
分享
m_combobox.ResetContent();
SP_DEVINFO_DATA DeviceInfoData;
SP_DEVICE_INTERFACE_DATA DeviceInterfaceData;
PSP_DEVICE_INTERFACE_DETAIL_DATA DeviceInterfaceDetailData;
//get device id
GUID deviceId;
HidD_GetHidGuid(&deviceId);
//get device info
HDEVINFO handle;
handle = SetupDiGetClassDevs(&deviceId, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
bool result1 = false;
bool result2 = false;
DWORD strSize = 0;
DWORD requiredSize = 0;
CString temp;
int countNum = 0;
DWORD dwError;
do
{
DeviceInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
result1 = SetupDiEnumDeviceInterfaces(handle, NULL, &deviceId, countNum, &DeviceInterfaceData);
if (result1 == FALSE)
{
dwError = GetLastError();
break;
}
SetupDiGetDeviceInterfaceDetail(handle, &DeviceInterfaceData, NULL, 0, &strSize, NULL);
requiredSize = strSize;
DeviceInterfaceDetailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)malloc(requiredSize);
DeviceInterfaceDetailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
result2 = SetupDiGetDeviceInterfaceDetail(handle, &DeviceInterfaceData, DeviceInterfaceDetailData,
strSize, &requiredSize, &DeviceInfoData);
temp = DeviceInterfaceDetailData->DevicePath;
UpdateData(FALSE);
m_combobox.AddString(temp);
countNum++;
free(DeviceInterfaceDetailData);
} while (result1);