获取显卡容量代码
[cpp] view plain copy#include <Windows.h>
#include <string.h>
#include <dxgi.h>
#include <assert.h>
void EnumerateUsingDXGI( IDXGIFactory* pDXGIFactory )
{
assert( pDXGIFactory != 0 );
for( UINT index = 0; ; ++index )
{
IDXGIAdapter* pAdapter = nullptr;
HRESULT hr = pDXGIFactory->EnumAdapters( index, &pAdapter );
if( FAILED( hr ) ) // DXGIERR_NOT_FOUND is expected when the end of the list is hit
break;
DXGI_ADAPTER_DESC desc;
memset( &desc, 0, sizeof( DXGI_ADAPTER_DESC ) );
if( SUCCEEDED( pAdapter->GetDesc( &desc ) ) )
{
wprintf( L"Adapter: [%u] %s\n", index, desc.Description );
for( UINT iOutput = 0; ; ++iOutput )
{
IDXGIOutput* pOutput = nullptr;
hr = pAdapter->EnumOutputs( iOutput, &pOutput );
if( FAILED( hr ) ) // DXGIERR_NOT_FOUND is expected when the end of the list is hit
break;
DXGI_OUTPUT_DESC outputDesc;
memset( &outputDesc, 0, sizeof( DXGI_OUTPUT_DESC ) );
if( SUCCEEDED( pOutput->GetDesc( &outputDesc ) ) )
{
//wprintf( L"hMonitor: 0x%0.8Ix\n", ( DWORD_PTR )outputDesc.Monitor );
//wprintf( L"hMonitor Device Name: %s\n", outputDesc.DeviceName );
}
pOutput->Release();
}
printf("Dedicated Video Memory: %Iu MB\n"
"Dedicated System Memory: %Iu MB\n"
"Shared System Memory: %Iu MB\n",
desc.DedicatedVideoMemory / 1024 / 1024, /*desc.DedicatedVideoMemory,*/
desc.DedicatedSystemMemory / 1024 / 1024, /*desc.DedicatedSystemMemory,*/
desc.SharedSystemMemory / 1024 / 1024/*, desc.SharedSystemMemory */);
}
pAdapter->Release();
}
}
int main(int argc, char* argv[])
{
HINSTANCE hDXGI = LoadLibrary( L"dxgi.dll" );
typedef HRESULT ( WINAPI* LPCREATEDXGIFACTORY )( REFIID, void** );
LPCREATEDXGIFACTORY pCreateDXGIFactory = nullptr;
IDXGIFactory* pDXGIFactory = nullptr;
// We prefer the use of DXGI 1.1
pCreateDXGIFactory = ( LPCREATEDXGIFACTORY )GetProcAddress( hDXGI, "CreateDXGIFactory1" );
if ( !pCreateDXGIFactory )
{
pCreateDXGIFactory = ( LPCREATEDXGIFACTORY )GetProcAddress( hDXGI, "CreateDXGIFactory" );
if ( !pCreateDXGIFactory )
{
FreeLibrary( hDXGI );
wprintf( L"ERROR: dxgi.dll missing entry-point\n" );
return -1;
}
}
HRESULT hr = pCreateDXGIFactory( __uuidof( IDXGIFactory ), ( LPVOID* )&pDXGIFactory );
if ( SUCCEEDED(hr) )
{
EnumerateUsingDXGI( pDXGIFactory );
pDXGIFactory->Release();
return 0;
}
FreeLibrary( hDXGI );
return 0;
}