PDA

View Full Version : Determine amount of video ram in a GFX card?



czar
26-03-2005, 01:52 AM
Just a quick question. Does anyone know how to determine how much video ram a video card has. e.g. 64meg, 128 meg etc ?

I need to do this in code.

I searched via google but couldn't work it out.

Clootie
26-03-2005, 07:45 PM
1) DirectX - use Direct3D7 interfaces for this
2) more general - use WMI. -- C++ version (http://ofb.net/~wesn/test.cpp)
3) another DirectX - use DXDiag...
again C++ version :roll:

IDxDiagProviderAutoPtr dxDiagProvider;
HRESULT hr = CoCreateInstance(CLSID_DxDiagProvider, 0,
CLSCTX_INPROC_SERVER, IID_IDxDiagProvider, (LPVOID*)&dxDiagProvider);
if (SUCCEEDED(hr))
{
DXDIAG_INIT_PARAMS dxDiagInitParam;
ZeroMemory(&dxDiagInitParam, sizeof(DXDIAG_INIT_PARAMS));

dxDiagInitParam.dwSize =
sizeof(DXDIAG_INIT_PARAMS);
dxDiagInitParam.dwDxDiagHeaderVersion = DXDIAG_DX9_SDK_VERSION;
dxDiagInitParam.bAllowWHQLChecks = FALSE;
dxDiagInitParam.pReserved = 0;

IDxDiagContainerAutoPtr dxDiagRoot;
hr = dxDiagProvider->Initialize(&dxDiagInitParam);
if (SUCCEEDED(hr))
{
hr = dxDiagProvider->GetRootContainer(&dxDiagRoot);
if (SUCCEEDED(hr))
{
// enumerate all display devices until we find the device
identified by mD3DAdapterIdentifier.DeviceIdentifier
IDxDiagContainerAutoPtr dxDispDevices;
hr = dxDiagRoot->GetChildContainer(L"DxDiag_DisplayDevices",
&dxDispDevices);
if (SUCCEEDED(hr))
{
DWORD numDevices = 0;
hr =
dxDispDevices->GetNumberOfChildContainers(&numDevices);
if (SUCCEEDED(hr))
{
for &#40;Uint dev = 0; dev < numDevices; dev++&#41;
&#123;
WCHAR devName&#91;256&#93;;
hr = dxDispDevices->EnumChildContainerNames&#40;dev,
devName, 256&#41;;
if &#40;SUCCEEDED&#40;hr&#41;&#41;
&#123;
IDxDiagContainerAutoPtr dxDispDevice;
hr = dxDispDevices->GetChildContainer&#40;devName,
&dxDispDevice&#41;;
if &#40;SUCCEEDED&#40;hr&#41;&#41;
&#123;
// get this device's GUID, and see if it is
equal to mD3DAdapterIdentifier.DeviceIdentifier
GUID devGUID;
memcpy&#40;&devGUID, &__uuidof&#40;0&#41;, sizeof&#40;GUID&#41;&#41;;

VARIANT v;
VariantInit&#40;&v&#41;;
hr =
dxDispDevice->GetProp&#40;L"szDeviceIdentifier", &v&#41;;
if &#40;SUCCEEDED&#40;hr&#41; && v.vt == VT_BSTR&#41;
&#123;
IIDFromString&#40;v.bstrVal, &devGUID&#41;;
&#125;

VariantClear&#40;&v&#41;;

if &#40;IsEqualGUID&#40;devGUID,
mD3DAdapterIdentifier.DeviceIdentifier&#41;&#41;
&#123;
// parse the display adapter memory string
hr =
dxDispDevice->GetProp&#40;L"szDisplayMemoryEnglish", &v&#41;;
if &#40;SUCCEEDED&#40;hr&#41; && v.vt == VT_BSTR&#41;
&#123;
WCHAR* endPtr = 0;
double adapterRam = wcstod&#40;v.bstrVal,
&endPtr&#41;;
if &#40;endPtr != v.bstrVal&#41;
&#123;
mVideoMemorySize = long&#40;adapterRam&#41;
* 1024 * 1024;
&#125;
&#125;

VariantClear&#40;&v&#41;;

break; // done enumerating devices
&#125;
&#125;
&#125;
&#125;
&#125;
&#125;
&#125;
&#125;
&#125;

czar
26-03-2005, 11:56 PM
It is all Greek to me :?

Thanks, I should be able to use this knowledge to work something out.

I actually do not know any C/C++ code.