试图使用Windows Setupapi.h函数获取设备属性中显示的错误代码

Trying to use Windows Setupapi.h functions to obtain an error code shown in device properties

本文关键字:属性 显示 错误代码 获取 函数 Windows Setupapi      更新时间:2024-09-27

我使用的是HP Reverb G2耳机。如果它没有插入USB 3.0端口,它就无法工作。设备显示在设备管理器中,但右键单击并选择属性会显示以下设备错误:混响G2属性

在那张照片中;设备状态";文本框;"概述";设备属性的选项卡显示:

此设备工作正常。

设备错误:0x80040203:E_Device_USB_SPEED_TOO_SLOW

我需要能够在代码(C++(中检测到这种特定的状态,但我还没有找到方法。使用";"Setupapi.h";,我能找到合适的设备。然后,我可以使用SetupDiGetDevicePropertyW查询不同的信息。但我还没有找到任何能给我所需信息的东西。

我希望查询DEVPKEY_Device_ProblemCode可以满足我的需要,但它没有返回任何问题。我想是因为上面的引用确实以";此设备工作正常">

有什么方法可以让我获取设备错误代码或该文本框的全部内容吗?

以下是查询问题代码的示例代码:

long GetReverbProblemCode()
{
long returnValue = -1;
HDEVINFO hDevInfo = SetupDiGetClassDevs(NULL, NULL, NULL, DIGCF_ALLCLASSES);
if (hDevInfo != INVALID_HANDLE_VALUE)
{
SP_DEVINFO_DATA deviceInfoData;
ZeroMemory(&deviceInfoData, sizeof(SP_DEVINFO_DATA));
deviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
int devindex = 0;
while (SetupDiEnumDeviceInfo(hDevInfo, devindex, &deviceInfoData))
{
devindex++;
DWORD requiredSize = 0;
DEVPROPTYPE ulPropertyType;
ZeroMemory(&gVRNative_szBuffer[0], sizeof(gVRNative_szBuffer));
if (SetupDiGetDevicePropertyW(hDevInfo, &deviceInfoData, &DEVPKEY_Device_FriendlyName, &ulPropertyType, (BYTE*)gVRNative_szBuffer, sizeof(gVRNative_szBuffer), &requiredSize, 0))
{
if (_wcsicmp(gVRNative_szBuffer, L"HP Reverb Virtual Reality Headset G2") == 0)
{
ZeroMemory(&propertyBuffer[0], sizeof(propertyBuffer));
if (SetupDiGetDevicePropertyW(hDevInfo, &deviceInfoData, &DEVPKEY_Device_ProblemCode, &ulPropertyType, (BYTE*)propertyBuffer, sizeof(propertyBuffer), &requiredSize, 0))
{
unsigned long deviceProblemCode = *((unsigned long*)propertyBuffer);
returnValue = deviceProblemCode;
}
break;
}
}
}
SetupDiDestroyDeviceInfoList(hDevInfo);
}
return returnValue;
}

我应该多看一会儿。只需要查询DEVPKEY_Device_DriverProbelDesc。这给了我一个字符串,其中包含设备属性窗口中文本框中的错误文本:

设备错误:0x80040203:E_Device_USB_SPEED_TOO_SLOW

调整后的函数调用:

SetupDiGetDevicePropertyW(hDevInfo, &deviceInfoData, &DEVPKEY_Device_DriverProblemDesc, &ulPropertyType, (BYTE*)propertyBuffer, sizeof(propertyBuffer), &requiredSize, 0);