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;
}