HRESULT GetDXVersion( DWORD* pdwDirectXVersion, TCHAR* strDirectXVersion, int cchDirectXVersion ) { bool bGotDirectXVersion = false; // Init values to unknown if( pdwDirectXVersion ) *pdwDirectXVersion = 0; if( strDirectXVersion && cchDirectXVersion > 0 ) strDirectXVersion[0] = 0; DWORD dwDirectXVersionMajor = 0; DWORD dwDirectXVersionMinor = 0; TCHAR cDirectXVersionLetter = ' '; // First, try to use dxdiag's COM interface to get the DirectX version. // The only downside is this will only work on DirectX9 or later. if( SUCCEEDED( GetDirectXVersionViaDxDiag( &dwDirectXVersionMajor, &dwDirectXVersionMinor, &cDirectXVersionLetter ) ) ) bGotDirectXVersion = true; if( !bGotDirectXVersion ) { // Getting the DirectX version info from DxDiag failed, // so most likely we are on DirectX8.x or earlier if( SUCCEEDED( GetDirectXVerionViaFileVersions( &dwDirectXVersionMajor, &dwDirectXVersionMinor, &cDirectXVersionLetter ) ) ) bGotDirectXVersion = true; } // If both techniques failed, then return E_FAIL if( !bGotDirectXVersion ) return E_FAIL; // Set the output values to what we got and return cDirectXVersionLetter = (char)tolower(cDirectXVersionLetter); if( pdwDirectXVersion ) { // If pdwDirectXVersion is non-NULL, then set it to something // like 0x00080102 which would represent DirectX8.1b DWORD dwDirectXVersion = dwDirectXVersionMajor; dwDirectXVersion <<= 8; dwDirectXVersion += dwDirectXVersionMinor; dwDirectXVersion <<= 8; if( cDirectXVersionLetter >= 'a' && cDirectXVersionLetter <= 'z' ) dwDirectXVersion += (cDirectXVersionLetter - 'a') + 1; *pdwDirectXVersion = dwDirectXVersion; } if( strDirectXVersion && cchDirectXVersion > 0 ) { // If strDirectXVersion is non-NULL, then set it to something // like "8.1b" which would represent DirectX8.1b if( cDirectXVersionLetter == ' ' ) StringCchPrintf( strDirectXVersion, cchDirectXVersion, TEXT("%d.%d"), dwDirectXVersionMajor, dwDirectXVersionMinor ); else StringCchPrintf( strDirectXVersion, cchDirectXVersion, TEXT("%d.%d%c"), dwDirectXVersionMajor, dwDirectXVersionMinor, cDirectXVersionLetter ); } return S_OK; }
DWORD GetDXVersion () { DWORD version = 0; bool bGotDirectXVersion = false; // Init values to unknown DWORD dwDirectXVersionMajor = 0; DWORD dwDirectXVersionMinor = 0; TCHAR cDirectXVersionLetter = ' '; // First, try to use dxdiag's COM interface to get the DirectX version. // The only downside is this will only work on DX9 or later. if ( SUCCEEDED( GetDirectXVersionViaDxDiag( &dwDirectXVersionMajor, &dwDirectXVersionMinor, &cDirectXVersionLetter ) ) ) bGotDirectXVersion = true; if ( !bGotDirectXVersion ) { // Getting the DirectX version info from DxDiag failed, // so most likely we are on DX8.x or earlier if( SUCCEEDED( GetDirectXVerionViaFileVersions( &dwDirectXVersionMajor, &dwDirectXVersionMinor, &cDirectXVersionLetter ) ) ) bGotDirectXVersion = true; } // If both techniques failed, then return error if (bGotDirectXVersion) { // Set the output values to what we got and return cDirectXVersionLetter = (char)tolower(cDirectXVersionLetter); // Set version to something like 0x00080102 which would represent DX8.1b version = dwDirectXVersionMajor; version <<= 8; version += dwDirectXVersionMinor; version <<= 8; if( cDirectXVersionLetter >= 'a' && cDirectXVersionLetter <= 'z' ) version += (cDirectXVersionLetter - 'a') + 1; } return (version); }
HRESULT CUtils::GetDXVersionString( CString& strDXVersionString ) { HRESULT hr = GetDirectXVersionViaDxDiag(strDXVersionString); return hr; }