试图使用Windows Setupapi.h函数获取设备属性中显示的错误代码
Trying to use Windows Setupapi.h functions to obtain an error code shown in device properties
我使用的是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);
相关文章:
- 比较并显示使用最小值(a,b)和最大值(a、b)升序排列的4个数字
- 如何导出包含具有"std::unique_ptr"值的"std::map"属性的
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 字符串-C++后显示的随机字符
- 继承期间显示未知行为的子类
- 仅使用绝对值对数组进行排序,并在C++中显示实际值
- 我有一个嵌套数组,它由另一个数组中的元素组成,这些元素分组为2.之后,我想显示每个元素的属性
- gcc 显示结构属性为 0,但 clang 显示不同的值
- 直接显示筛选器属性窗口
- 我需要创建一个Display()方法,它将显示所有属性
- 自定义构件上的 float 类型的Q_PROPERTY不会显示在属性编辑器中
- 显示多个外壳对象的属性表
- VC++:如何在MFC对话框的属性表顶部显示控件
- VS 2010 c++路径显示在项目属性中,但不显示在*.vcxprojf或*.sln文件中
- 如何使用qt属性动态显示/隐藏个人定义属性的子属性
- 通过.rc文件设置dll属性:Windows 7显示哪些属性
- MFC对话框包含文件的属性页在Visual Studio 2008中显示为空
- 如何使用ostream_iterator显示对象的属性
- c ++如何在向量中的特定位置显示元素的字符串属性
- Visio & UML - 在属性和返回值中显示指针