c++ - SetupDiEnumDeviceInterfaces 显示错误 259

标签 c++ winapi

我正在尝试检索一组与显示相关的界面,但似乎总是出现 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/

相关文章:

windows - 在哪些情况下,GetSystemInfo/GetLogicalProcessorInformationEx 在同一程序运行中返回不同的处理器计数?

c++ - 如何使函数线程安全

java - 在 32 位 JVM 上将 -Xmx 设置为高是否可能会缩小 JNI 可用的空间,从而导致 JNI 失败?

c++ - 在 SFML 2.4 中使用碰撞检测来增加游戏分数的问题

c++ - 在C++中将字节流拆分为位

c++ - 在 win32 C++ 编程中如何复制窗口样式?

c++ - pthread_cond_wait() 之前的检查标志

c++ - 来自 .evt 文件的 WinAPI LookupAccountSid

检查线程是否正在运行

windows - 检测 "suspended"Windows 8/10 进程