gpt4 book ai didi

c++ - EnumDisplayDevices 不返回任何值

转载 作者:可可西里 更新时间:2023-11-01 11:49:48 25 4
gpt4 key购买 nike

我正在尝试枚举多显示器系统上连接的所有显示器的详细信息。所以我引用了this示例代码。完整代码供引用:

#include <windows.h>
#include <stdio.h>

#pragma comment(lib, "user32.lib")

void DumpDevice(const DISPLAY_DEVICE& dd, size_t nSpaceCount )
{
printf("%*sDevice Name: %s\n", nSpaceCount, "", dd.DeviceName );
printf("%*sDevice String: %s\n", nSpaceCount, "", dd.DeviceString );
printf("%*sState Flags: %x\n", nSpaceCount, "", dd.StateFlags );
printf("%*sDeviceID: %s\n", nSpaceCount, "", dd.DeviceID );
printf("%*sDeviceKey: ...%s\n\n", nSpaceCount, "", dd.DeviceKey+42 );
}

int main()
{
DISPLAY_DEVICE dd;

dd.cb = sizeof(DISPLAY_DEVICE);

DWORD deviceNum = 0;
while( EnumDisplayDevices(NULL, deviceNum, &dd, 0) ){
DumpDevice( dd, 0 );
DISPLAY_DEVICE newdd = {0};
newdd.cb = sizeof(DISPLAY_DEVICE);
DWORD monitorNum = 0;
while ( EnumDisplayDevices(dd.DeviceName, monitorNum, &newdd, 0))
{
DumpDevice( newdd, 4 );
monitorNum++;
}
puts("");
deviceNum++;
}

return 0;
}

但是,当我运行这段代码时,它会返回:

Device Name: \
Device String: N
State Flags: 5
DeviceID: P
DeviceKey: ...\

Device Name: \
Device String: V
State Flags: 3
DeviceID: M
DeviceKey: ...\

Device Name: \
Device String: N
State Flags: 1
DeviceID: P
DeviceKey: ...\

Device Name: \
Device String: G
State Flags: 3
DeviceID: M
DeviceKey: ...\

Device Name: \
Device String: N
State Flags: 0
DeviceID: P
DeviceKey: ...\

Device Name: \
Device String: N
State Flags: 0
DeviceID: P
DeviceKey: ...\

而它返回的是:

Device Name: \\.\DISPLAY1
Device String: NVIDIA GeForce GTX 580
State Flags: 8000005
DeviceID: PCI\VEN_10DE&DEV_1080&SUBSYS_15803842&REV_A1
DeviceKey: ...\Control\Video\{B0CDD262-FCFB-4FD4-A03C-54621896C9CD}\0000

Device Name: \\.\DISPLAY1\Monitor0
Device String: Generic PnP Monitor
State Flags: 3
DeviceID: MONITOR\DEL4016\{4d36e96e-e325-11ce-bfc1-08002be10318}\0002
DeviceKey: ...\Control\Class\{4d36e96e-e325-11ce-bfc1-08002be10318}\0002

Device Name: \\.\DISPLAY2
Device String: NVIDIA GeForce GTX 580
State Flags: 0
DeviceID: PCI\VEN_10DE&DEV_1080&SUBSYS_15803842&REV_A1
DeviceKey: ...\Control\Video\{B0CDD262-FCFB-4FD4-A03C-54621896C9CD}\0001

Device Name: \\.\DISPLAYV1
Device String: RDPDD Chained DD
State Flags: 8
DeviceID:
DeviceKey: ...\Control\Video\{DEB039CC-B704-4F53-B43E-9DD4432FA2E9}\0000

Device Name: \\.\DISPLAYV2
Device String: RDP Encoder Mirror Driver
State Flags: 200008
DeviceID:
DeviceKey: ...\Control\Video\{42cf9257-1d96-4c9d-87f3-0d8e74595f78}\0000

Device Name: \\.\DISPLAYV3
Device String: RDP Reflector Display Driver
State Flags: 200008
DeviceID:
DeviceKey: ...\Control\Video\{b043b95c-5670-4f10-b934-8ed0c8eb59a8}\0000

对于提供此引用码的用户

我这里做错了什么?

最佳答案

我怀疑你的 unicode 有问题。

看起来您的字符串只打印第一个 8 位字符,因为在您拥有的字符串中,字符是 16 位并且下一个字节为零 - 所以 printf 确定它是字符串的结尾。

在打印之前尝试将字符串从 unicode 转换为 ascii。

关于c++ - EnumDisplayDevices 不返回任何值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32883705/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com