Reputation: 1
I use the following demo to simultaneously obtain the instanceId and guid of the device, but on my computer, all devices obtain the same SPDRP_CLASSGUID value. Why is this?
int main()
{
HDEVINFO hDeviceInfoSet = SetupDiGetClassDevs(&GUID_DEVCLASS_MEDIA, NULL, NULL, DIGCF_PRESENT);
if (hDeviceInfoSet == INVALID_HANDLE_VALUE)
{
printf("Failed to get device information set.\n");
return 1;
}
SP_DEVINFO_DATA deviceInfoData;
deviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
for (DWORD i = 0; SetupDiEnumDeviceInfo(hDeviceInfoSet, i, &deviceInfoData); i++)
{
WCHAR deviceId[MAX_DEVICE_ID_LEN];
if (CM_Get_Device_ID(deviceInfoData.DevInst, deviceId, MAX_DEVICE_ID_LEN, 0) != CR_SUCCESS)
{
printf("Failed to get device ID.\n");
}
else
{
printf("Device Instance ID: %ws\n", deviceId);
}
WCHAR deviceGuidString[MAX_GUID_STRING_LEN];
DWORD bufferSize = sizeof(deviceGuidString);
if (SetupDiGetDeviceRegistryProperty(hDeviceInfoSet, &deviceInfoData, SPDRP_CLASSGUID, NULL, (PBYTE)deviceGuidString, bufferSize, &bufferSize))
{
printf("Device GUID: %ws\n", deviceGuidString);
}
else
{
printf("Failed to get device GUID.\n");
}
}
SetupDiDestroyDeviceInfoList(hDeviceInfoSet);
return 0;
}
How can I obtain the correct instanceId and guid for the device simultaneously
Upvotes: 0
Views: 23