这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 嵌入式开发 » STM32 » 获取显卡名称、显存大小 代码

共1条 1/1 1 跳转至

获取显卡名称、显存大小 代码

高工
2017-12-26 12:02:39     打赏

获取显卡容量代码

[cpp] view plain copy
  1. #include <Windows.h>  

  2. #include <string.h>  

  3. #include <dxgi.h>  

  4. #include <assert.h>  

  5.   

  6. void EnumerateUsingDXGI( IDXGIFactory* pDXGIFactory )  

  7. {  

  8.     assert( pDXGIFactory != 0 );  

  9.   

  10.     forUINT index = 0; ; ++index )  

  11.     {  

  12.         IDXGIAdapter* pAdapter = nullptr;  

  13.         HRESULT hr = pDXGIFactory->EnumAdapters( index, &pAdapter );  

  14.         if( FAILED( hr ) ) // DXGIERR_NOT_FOUND is expected when the end of the list is hit  

  15.             break;  

  16.   

  17.         DXGI_ADAPTER_DESC desc;  

  18.         memset( &desc, 0, sizeof( DXGI_ADAPTER_DESC ) );  

  19.         if( SUCCEEDED( pAdapter->GetDesc( &desc ) ) )  

  20.         {  

  21.             wprintf( L"Adapter: [%u] %s\n", index, desc.Description );  

  22.   

  23.             forUINT iOutput = 0; ; ++iOutput )  

  24.             {  

  25.                 IDXGIOutput* pOutput = nullptr;  

  26.                 hr = pAdapter->EnumOutputs( iOutput, &pOutput );  

  27.                 if( FAILED( hr ) ) // DXGIERR_NOT_FOUND is expected when the end of the list is hit  

  28.                     break;  

  29.   

  30.                 DXGI_OUTPUT_DESC outputDesc;  

  31.                 memset( &outputDesc, 0, sizeof( DXGI_OUTPUT_DESC ) );  

  32.                 if( SUCCEEDED( pOutput->GetDesc( &outputDesc ) ) )  

  33.                 {  

  34.                     //wprintf( L"hMonitor: 0x%0.8Ix\n", ( DWORD_PTR )outputDesc.Monitor );  

  35.                     //wprintf( L"hMonitor Device Name: %s\n", outputDesc.DeviceName );  

  36.                 }  

  37.   

  38.                 pOutput->Release();  

  39.             }  

  40.   

  41.             printf("Dedicated Video Memory: %Iu MB\n"  

  42.                 "Dedicated System Memory: %Iu MB\n"  

  43.                 "Shared System Memory: %Iu MB\n",  

  44.                 desc.DedicatedVideoMemory / 1024 / 1024, /*desc.DedicatedVideoMemory,*/  

  45.                 desc.DedicatedSystemMemory / 1024 / 1024, /*desc.DedicatedSystemMemory,*/  

  46.                 desc.SharedSystemMemory / 1024 / 1024/*, desc.SharedSystemMemory */);  

  47.         }  

  48.   

  49.         pAdapter->Release();  

  50.     }  

  51. }  

  52.   

  53. int main(int argc, char* argv[])  

  54. {  

  55.         HINSTANCE hDXGI = LoadLibrary( L"dxgi.dll" );  

  56.   

  57.         typedef HRESULT ( WINAPI* LPCREATEDXGIFACTORY )( REFIID, void** );  

  58.   

  59.         LPCREATEDXGIFACTORY pCreateDXGIFactory = nullptr;  

  60.         IDXGIFactory* pDXGIFactory = nullptr;  

  61.   

  62.         // We prefer the use of DXGI 1.1  

  63.         pCreateDXGIFactory = ( LPCREATEDXGIFACTORY )GetProcAddress( hDXGI, "CreateDXGIFactory1" );  

  64.   

  65.         if ( !pCreateDXGIFactory )  

  66.         {  

  67.             pCreateDXGIFactory = ( LPCREATEDXGIFACTORY )GetProcAddress( hDXGI, "CreateDXGIFactory" );  

  68.   

  69.             if ( !pCreateDXGIFactory )  

  70.             {  

  71.                 FreeLibrary( hDXGI );  

  72.                 wprintf( L"ERROR: dxgi.dll missing entry-point\n" );  

  73.                 return -1;  

  74.             }  

  75.         }  

  76.           

  77.         HRESULT hr = pCreateDXGIFactory( __uuidof( IDXGIFactory ), ( LPVOID* )&pDXGIFactory );  

  78.   

  79.         if ( SUCCEEDED(hr) )  

  80.         {  

  81.             EnumerateUsingDXGI( pDXGIFactory );  

  82.   

  83.             pDXGIFactory->Release();  

  84.   

  85.             return 0;  

  86.         }  

  87.         FreeLibrary( hDXGI );  

  88.     return 0;  




共1条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]