请教关于获取NVIDIA独显硬件ID问题

「已注销」 「已注销」 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
NVIDIA官方提供的demo code编译运行后不能读出NVIDIA独显,当EnumDisplayDevices枚举index为0,读出Intel集显ID,当index为3,debug中可以读出NVIDIA显卡信息,但是此时StateFlags 为0,函数fail,这是为什么?怎样才可以读出电脑上所有显卡的ID?而不是读出第一个就停止了。



// Example code to retrieve vendor and device ID's for the primary display
// device.
//
// NOTE: Visual Studio 6 does not ship with a winuser.h that defines the
// EnumDisplayDevices function so in order to compile this code, you'll
// need to install the Platform SDK.
#include "stdafx.h"
#include <windows.h>

#include <string>
#include <iostream>

using namespace std;

bool GetDeviceIdentification(string &vendorID, string &deviceID)
{
DISPLAY_DEVICE dd;
dd.cb = sizeof(DISPLAY_DEVICE);

int i = 0;
string id;

// locate primary display device
while (EnumDisplayDevices(NULL, i, &dd, 0))
{
if (dd.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)
{
id = dd.DeviceID;
break;
}
i++;
}

if (id == "") return false;

// get vendor ID
vendorID = id.substr(8, 4);

// get device ID
deviceID = id.substr(17, 4);

return true;
}

int main(void)
{
string vendorID;
string deviceID;

if (GetDeviceIdentification(vendorID, deviceID))
{
cout << "Vendor ID: " << vendorID << endl;
cout << "Device ID: " << deviceID << endl;
}
else
cout << "Unable to locate device information" << endl;
cin.get();

return 0;
}
...全文

相关推荐

评论 9
收藏 已收藏
分享
返回顶部
「已注销」
VC/MFC 16,550 成员 421,606 内容