0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Windows Visual C++でプライマリーディスプレイアダプターのベンダーIDを取得する

Last updated at Posted at 2025-01-11

Windowsアプリでプライマリーディスプレイアダプターのベンダーidを取得したい!

作成しているWindowsアプリでGPUのハードウェアエンコーダを利用したいと考えていますが、GPUのメーカーをどうやって取得したらいいのだろう?
Win32、Direct3D、WinRTなどいろいろなやり方があるっぽいですが、とりあえず動けば何でもいい。できれば簡単なやつがいい。
Windows Copilotに聞きました。

Windows Copilotさんが提案してくれたコード

VisualStudioのリンカー>入力にDXGI.libを追加

#include <iostream>
#include <vector>
#include <map>
#include <dxgi1_6.h>
#include <wrl/client.h>

using namespace Microsoft::WRL;

int main() {
    // ベンダーIDとメーカー名のマップを作成
    std::map<UINT, std::wstring> vendorMap = {
        {0x10DE, L"NVIDIA"},
        {0x1002, L"AMD"},
        {0x8086, L"Intel"}
    };

    // DXGIファクトリーの作成
    ComPtr<IDXGIFactory6> factory;
    HRESULT hr = CreateDXGIFactory1(IID_PPV_ARGS(&factory));
    if (FAILED(hr)) {
        std::cerr << "Failed to create DXGI factory." << std::endl;
        return -1;
    }

    // アダプターの列挙
    ComPtr<IDXGIAdapter1> adapter;
    for (UINT adapterIndex = 0; factory->EnumAdapters1(adapterIndex, &adapter) != DXGI_ERROR_NOT_FOUND; ++adapterIndex) {
        DXGI_ADAPTER_DESC1 desc;
        adapter->GetDesc1(&desc);

        // プライマリアダプターを確認
        if (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) {
            continue;  // ソフトウェアアダプターをスキップ
        }

        // ベンダーIDの取得と16進数形式での表示
        std::wcout << L"Vendor ID: 0x" << std::hex << desc.VendorId << std::endl;

        // ベンダーIDに対応するメーカー名の取得と表示
        auto it = vendorMap.find(desc.VendorId);
        if (it != vendorMap.end()) {
            std::wcout << L"Manufacturer: " << it->second << std::endl;
        } else {
            std::wcout << L"Manufacturer: Unknown" << std::endl;
        }
        break;
    }

    return 0;
}

その他の方法として

AMDのライブラリを使おうかとも考えたりしてました。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?