//------------------------------------------------------------------------ // Get the property at pContainer by name // Decode the VARIANT property to a string and return the string HRESULT DXDiagNVUtil::GetProperty( IDxDiagContainer * pContainer, LPCWSTR property_name, wstring * out_value ) { HRESULT hr = S_OK; FAIL_IF_NULL( pContainer ); FAIL_IF_NULL( property_name ); FAIL_IF_NULL( out_value ); WCHAR wszPropValue[256]; VARIANT var; VariantInit( &var ); hr = pContainer->GetProp( property_name, &var ); if( SUCCEEDED(hr) ) { // Switch according to the type. There's 4 different types: switch( var.vt ) { case VT_UI4: swprintf( wszPropValue, L"%d", var.ulVal ); break; case VT_I4: swprintf( wszPropValue, L"%d", var.lVal ); break; case VT_BOOL: swprintf( wszPropValue, L"%s", (var.boolVal) ? L"true" : L"false" ); break; case VT_BSTR: wcsncpy( wszPropValue, var.bstrVal, 255 ); wszPropValue[255] = 0; break; } // copy string to the output string (*out_value) = wszPropValue; } else { FMsgW(L"GetProperty( cont, prop, val ) Couldn't get prop [%s]\n", property_name ); //char mbBuf[512]; //wcstombs( mbBuf, property_name, 512 ); //FMsg("GetProperty( cont, prop, val ) Couldn't get prop [%s]\n", mbBuf ); } VariantClear( &var ); return( hr ); }
HRESULT DXDiagNVUtil::ListAllDXDiagPropertyNames( IDxDiagContainer * pDxDiagContainer, WCHAR* wszParentName ) { // Recurse through all properties and child properties, // outputting their names via OutputDebugString(..) // Start this by calling with the root IDxDiagContainer and a NULL string ptr. // // This function can take a while to complete. // // Adapted from DXSDK example file DxDiagOutput.cpp HRESULT hr = S_OK; FAIL_IF_NULL( pDxDiagContainer ); DWORD dwPropCount; DWORD dwPropIndex; WCHAR wszPropName[256]; DWORD dwChildCount; DWORD dwChildIndex; WCHAR wszChildName[256]; IDxDiagContainer* pChildContainer = NULL; const bool bGetPropertyValue = false; hr = pDxDiagContainer->GetNumberOfProps( &dwPropCount ); if( SUCCEEDED(hr) ) { // Print each property in this container for( dwPropIndex = 0; dwPropIndex < dwPropCount; dwPropIndex++ ) { hr = pDxDiagContainer->EnumPropNames( dwPropIndex, wszPropName, 256 ); if( SUCCEEDED( hr ) ) { if( bGetPropertyValue ) { wstring propval; hr = GetProperty( pDxDiagContainer, wszPropName, & propval ); FMsgW(L"%35s : prop \"%s\" = %s\n", wszParentName, wszPropName, propval.c_str() ); } else { // otherwise, just list the property name and parent container info FMsgW(L"%35s : prop \"%s\"\n", wszParentName, wszPropName ); } } } } // Recursivly call this function for each of its child containers hr = pDxDiagContainer->GetNumberOfChildContainers( &dwChildCount ); if( SUCCEEDED(hr) ) { for( dwChildIndex = 0; dwChildIndex < dwChildCount; dwChildIndex++ ) { hr = pDxDiagContainer->EnumChildContainerNames( dwChildIndex, wszChildName, 256 ); if( SUCCEEDED(hr) ) { hr = pDxDiagContainer->GetChildContainer( wszChildName, &pChildContainer ); if( SUCCEEDED(hr) ) { // wszFullChildName isn't needed but is used for text output WCHAR wszFullChildName[256]; // Append child name to parent and pass down in the recursion // as full parent name. if( wszParentName ) swprintf( wszFullChildName, L"%s.%s", wszParentName, wszChildName ); else swprintf( wszFullChildName, L"%s", wszChildName ); // recurse ListAllDXDiagPropertyNames( pChildContainer, wszFullChildName ); SAFE_RELEASE( pChildContainer ); } } } } return( hr ); }
/*------------------------------------------------------------------ Retrieve various data through the IDxDiagContainer interface. The DXDiagNVUtil class provides a few convenient wrapper functions, and direct querries using the IDxDiagContainer COM object names are also supported. For a list of all the container and property COM object names, call ListAllDXDiagPropertyNames(..) ------------------------------------------------------------------*/ HRESULT GetGPUAndSystemInfo::GetData() { HRESULT hr = S_OK; //---------------------------------------------------------------------------- hr = m_DXDiagNVUtil.InitIDxDiagContainer(); MSG_AND_RET_VAL_IF( FAILED(hr), "Couldn't initialize DXDiagNVUtil!\n", hr ); wstring wstr; // Get the computer's machine name: m_DXDiagNVUtil.GetProperty( L"DxDiag_SystemInfo", L"szMachineNameEnglish", &wstr ); m_strMachineName = m_DXDiagNVUtil.WStringToString( &wstr ); FMsg("\n\n"); FMsg("------------------------------------------------------------------------\n"); FMsgW(L"machine name: %s\n", wstr.c_str() ); // Get info about physcial memory: m_DXDiagNVUtil.GetPhysicalMemoryInMB( & m_fSystemPhysicalMemoryMB ); FMsg("physical memory: %g MB\n", m_fSystemPhysicalMemoryMB ); // Get info about logical disks IDxDiagContainer * pContainer, *pChild; DWORD dwNumDisks; hr = m_DXDiagNVUtil.GetChildContainer( L"DxDiag_LogicalDisks", & pContainer ); if( SUCCEEDED(hr)) { pContainer->GetNumberOfChildContainers( & dwNumDisks ); wstring drive, space; FMsgW(L"logical disks: %d\n", dwNumDisks ); for( DWORD n=0; n < dwNumDisks; n++ ) { hr = m_DXDiagNVUtil.GetChildByIndex( pContainer, n, &pChild ); if( SUCCEEDED(hr) ) { m_DXDiagNVUtil.GetProperty( pChild, L"szDriveLetter", &drive ); m_DXDiagNVUtil.GetProperty( pChild, L"szFreeSpace", &space ); FMsgW(L" %s Free space = %s\n", drive.c_str(), space.c_str() ); SAFE_RELEASE( pChild ); } } SAFE_RELEASE( pContainer ); } FMsg("------------------------------------------------------------------------\n"); m_DXDiagNVUtil.GetDirectXVersion( &m_dwDXVersionMajor, &m_dwDXVersionMinor, &m_cDXVersionLetter ); FMsg("DirectX Version: %d.%d%c\n", m_dwDXVersionMajor, m_dwDXVersionMinor, m_cDXVersionLetter ); hr = m_DXDiagNVUtil.GetNumDisplayDevices( & m_dwNumDisplayDevices ); MSG_AND_RET_VAL_IF( FAILED(hr), "Couldn't GetNumDisplayDevices()\n", hr ); FMsg("Num Display Devices: %d\n", m_dwNumDisplayDevices ); string str; // for( DWORD dev=0; dev < m_dwNumDisplayDevices; dev ++ ) if( m_dwNumDisplayDevices > 0 ) { DWORD dev = 0; // get info from display devices m_DXDiagNVUtil.GetDisplayDeviceDescription( dev, & m_wstrDeviceDesc ); m_DXDiagNVUtil.GetDisplayDeviceNVDriverVersion( dev, & m_fDriverVersion ); m_DXDiagNVUtil.GetDisplayDeviceMemoryInMB( dev, & m_nDeviceMemoryMB ); // report the info via OutputDebugString FMsgW(L"Device %d Description: %s\n", dev, m_wstrDeviceDesc.c_str() ); FMsg( "Device %d Driver version: %g\n", dev, m_fDriverVersion ); FMsg( "Device %d Physical mem: %d MB\n", dev, m_nDeviceMemoryMB ); // Get info about AGP memory: wstring wstrAGPEnabled, wstrAGPExists, wstrAGPStatus; hr = m_DXDiagNVUtil.GetDisplayDeviceAGPMemoryStatus( dev, &wstrAGPEnabled, &wstrAGPExists, &wstrAGPStatus ); if( SUCCEEDED(hr)) { // create a string from the AGP status strings m_strAGPStatus = ""; str = m_DXDiagNVUtil.WStringToString( &wstrAGPEnabled ); m_strAGPStatus += "AGP Enabled = "; m_strAGPStatus += str; m_strAGPStatus += ", "; str = m_DXDiagNVUtil.WStringToString( &wstrAGPExists ); m_strAGPStatus += "AGP Exists = "; m_strAGPStatus += str; m_strAGPStatus += ", "; str = m_DXDiagNVUtil.WStringToString( &wstrAGPStatus ); m_strAGPStatus += "AGP Status = "; m_strAGPStatus += str; } FMsg("%s\n", m_strAGPStatus.c_str() ); wstring wstrNotes, wstrTestD3D9; m_DXDiagNVUtil.GetProperty( L"DxDiag_DisplayDevices", L"0", L"szTestResultD3D9English", &wstrTestD3D9 ); m_DXDiagNVUtil.GetProperty( L"DxDiag_DisplayDevices", L"0", L"szNotesEnglish", &wstrNotes ); str = m_DXDiagNVUtil.WStringToString( &wstrTestD3D9 ); FMsg("Device 0 szTestResultD3D9English = \"%s\"\n", str.c_str() ); str = m_DXDiagNVUtil.WStringToString( &wstrNotes ); FMsg("Device 0 szNotesEnglish = \"%s\"\n", str.c_str() ); } m_DXDiagNVUtil.GetDebugLevels( & m_wstrDxDebugLevels ); FMsg("DirectX Debug Levels:\n"); FMsgW(L"%s\n", m_wstrDxDebugLevels.c_str() ); // ListAllDXDiagPropertyNames() is slow // It prints out all nodes, child nodes, properties and their values // m_DXDiagNVUtil.ListAllDXDiagPropertyNames(); // Use a call like that below to print out a specific node and it's children. // For example, to list all the display device property names. /* m_DXDiagNVUtil.GetChildContainer( L"DxDiag_DisplayDevices", &pContainer ); m_DXDiagNVUtil.ListAllDXDiagPropertyNames( pContainer, L"DxDiag_DisplayDevices" ); SAFE_RELEASE( pContainer ); // */ m_DXDiagNVUtil.FreeIDxDiagContainer(); return( hr ); }