在 Windows C++ 应用程序中获取显卡名称和信息的最佳方式是什么?
What is the optimal way to fetch graphics card name and info in a Windows C++ app?
我正在尝试从客户端计算机中提取一些信息,我希望这些信息的格式几乎与此处从“dxdiag.exe”中看到的完全一样:
我知道应该有一个 API 用于此类功能,但是 I've searched and searched and can't figure out library or header file I need to include 才能访问此工具。非常感谢任何帮助。
对于 Windows Vista 或更高版本,使用 DXGI。
#include <dxgi.h>
#include <wrl/client.h>
#pragma comment(lib, "dxgi.lib")
using Microsoft::WRL::ComPtr;
ComPtr<IDXGIFactory1> dxgiFactory;
HRESULT hr = CreateDXGIFactory1(IID_PPV_ARGS(dxgiFactory.ReleaseAndGetAddressOf()));
if (FAILED(hr)) // ... error handling
ComPtr<IDXGIAdapter1> adapter;
for (UINT adapterIndex = 0;
SUCCEEDED(dxgiFactory->EnumAdapters1(
adapterIndex,
adapter.ReleaseAndGetAddressOf()));
adapterIndex++)
{
DXGI_ADAPTER_DESC1 desc = {};
hr = adapter->GetDesc1(&desc);
if (FAILED(hr)) // ... error handling
if (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE)
{
// Don't select the Basic Render Driver adapter.
continue;
}
// desc.VendorId: VID
// desc.DeviceId: PID
// desc.Description: name string seen above
}
You can also look at the source code for DirectX Capabilities Viewer and the sample SystemInfoUWP.
我使用 Microsoft::WRL::ComPtr 作为 COM 的 C++ 智能指针。
我正在尝试从客户端计算机中提取一些信息,我希望这些信息的格式几乎与此处从“dxdiag.exe”中看到的完全一样:
我知道应该有一个 API 用于此类功能,但是 I've searched and searched and can't figure out library or header file I need to include 才能访问此工具。非常感谢任何帮助。
对于 Windows Vista 或更高版本,使用 DXGI。
#include <dxgi.h>
#include <wrl/client.h>
#pragma comment(lib, "dxgi.lib")
using Microsoft::WRL::ComPtr;
ComPtr<IDXGIFactory1> dxgiFactory;
HRESULT hr = CreateDXGIFactory1(IID_PPV_ARGS(dxgiFactory.ReleaseAndGetAddressOf()));
if (FAILED(hr)) // ... error handling
ComPtr<IDXGIAdapter1> adapter;
for (UINT adapterIndex = 0;
SUCCEEDED(dxgiFactory->EnumAdapters1(
adapterIndex,
adapter.ReleaseAndGetAddressOf()));
adapterIndex++)
{
DXGI_ADAPTER_DESC1 desc = {};
hr = adapter->GetDesc1(&desc);
if (FAILED(hr)) // ... error handling
if (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE)
{
// Don't select the Basic Render Driver adapter.
continue;
}
// desc.VendorId: VID
// desc.DeviceId: PID
// desc.Description: name string seen above
}
You can also look at the source code for DirectX Capabilities Viewer and the sample SystemInfoUWP.
我使用 Microsoft::WRL::ComPtr 作为 COM 的 C++ 智能指针。