0

我正在尝试检索一组与显示相关的接口,并且似乎总是得到 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错误意味着没有更多项目,但我的系统连接了两个屏幕,并且由于我在SetupDiGetClassDevs没有 GUID 的情况下调用,我希望至少获得我的两个屏幕项目。

编辑:按照建议添加了 cbSize

4

2 回答 2

2

Do you know that ifData.cbSize must be set properly before you call SetupDiEnumDeviceInterfaces?

(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.

You did not show setting this value in your code.

于 2013-09-20T13:18:41.357 回答
0

For some reason the answer I found by try and error is not intuitive for me but it seems to work.

As I am unable to retrieve the device setup GUID but I had to add DIGCF_DEVICEINTERFACE with conjunction to device interface GUID GUID_DEVINTERFACE_MONITOR to be able to retrieve the interfaces.

Thanks for the hints as missing cbSize would have resulted in another error too :/

于 2013-09-20T13:31:19.413 回答