我正在尝试检索一组与显示相关的界面,但似乎总是出现 259 错误。由于我对 WinApi
非常缺乏经验,因此我可能需要一些提示 :)
#include <atlstr.h>
#include <SetupApi.h>
#pragma comment(lib, "setupapi.lib")
#include <stdio.h>
#include <windows.h>
#include <setupapi.h>
#include <devguid.h>
#include <regstr.h>
const GUID GUID_CLASS_MONITOR = {0x4d36e96e, 0xe325, 0x11ce, 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18};
const GUID GUID_DEVINTERFACE_MONITOR = {0xe6f07b5f, 0xee97, 0x4a90, 0xb0, 0x76, 0x33, 0xf5, 0x7b, 0xf4, 0xea, 0xa7};
int main( int argc, char *argv[ ] )
{
HDEVINFO hDevInfo;
SP_DEVICE_INTERFACE_DATA ifData;
ifData.cbSize = sizeof(ifData);
DWORD dwError;
hDevInfo = SetupDiGetClassDevs(NULL /*&GUID_CLASS_MONITOR*/, NULL, NULL, DIGCF_ALLCLASSES);
dwError = GetLastError();
BOOL bRtn = SetupDiEnumDeviceInterfaces(hDevInfo, NULL, &GUID_CLASS_MONITOR, 0, &ifData); // GUID_DEVINTERFACE_MONITOR did not work either
dwError = GetLastError();
return 0;
}
我看不出我做错了什么 SetupDiGetClassDevs
没有错误,但我尝试的关于 SetupDiEnumDeviceInterfaces
的所有操作都返回 259。
我一直在尝试设备设置和设备界面 GUID,但没有成功。
编辑:澄清:bRtn 返回 0,这意味着 SetupDiEnumDeviceInterfaces
失败。 259
错误意味着没有更多的项目,但我的系统连接了两个屏幕,因为我正在调用没有 GUID 的 SetupDiGetClassDevs
我希望至少获得我的两个屏幕项目。
编辑:按照建议添加了 cbSize
最佳答案
您知道在调用 SetupDiEnumDeviceInterfaces
之前必须正确设置 ifData.cbSize
吗?
( http://msdn.microsoft.com/en-us/library/windows/hardware/ff551015(v=vs.85).aspx )
The caller must set DeviceInterfaceData.cbSize to sizeof(SP_DEVICE_INTERFACE_DATA) before calling this function.
( http://msdn.microsoft.com/en-us/library/windows/hardware/ff552342(v=vs.85).aspx )
A SetupAPI function that takes an instance of the SP_DEVICE_INTERFACE_DATA structure as a parameter verifies whether the cbSize member of the supplied structure is equal to the size, in bytes, of the structure.
您没有在代码中显示设置此值。
关于c++ - SetupDiEnumDeviceInterfaces 显示错误 259,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18917583/