BOOL CompareString( LPCTSTR lpLeft, LPCTSTR lpRight, LPCTSTR sOpt, BOOL& bResult ) { INT nRet = 0; if(IsVersionString(lpLeft) && IsVersionString(lpRight)) { LARGE_INTEGER llLeft, llRight; llLeft = ParseVersion(lpLeft); llRight = ParseVersion(lpRight); nRet = CompareLargeInts(llLeft, llRight); } else { nRet = _tcsicmp(lpLeft, lpRight); } return EvalCompareResult(nRet, sOpt, bResult); }
BOOL CompareVersion( const LARGE_INTEGER &v1, const LARGE_INTEGER &v2, LPCTSTR sOpt, BOOL &bResult ) { INT nRet = CompareLargeInts(v1, v2); return EvalCompareResult(nRet, sOpt, bResult); }
//----------------------------------------------------------------------------- // Name: GetDirectXVerionViaFileVersions() // Desc: Tries to get the DirectX version by looking at DirectX file versions //----------------------------------------------------------------------------- HRESULT GetDirectXVerionViaFileVersions( DWORD* pdwDirectXVersionMajor, DWORD* pdwDirectXVersionMinor, TCHAR* pcDirectXVersionLetter ) { ULARGE_INTEGER llFileVersion; TCHAR szPath[512]; TCHAR szFile[512]; BOOL bFound = false; if( GetSystemDirectory( szPath, MAX_PATH ) != 0 ) { szPath[MAX_PATH-1]=0; // Switch off the ddraw version _tcscpy( szFile, szPath ); _tcscat( szFile, TEXT("\\ddraw.dll") ); if( SUCCEEDED( GetFileVersion( szFile, &llFileVersion ) ) ) { if( CompareLargeInts( llFileVersion, MakeInt64( 4, 2, 0, 95 ) ) >= 0 ) // Win9x version { // flle is >= DX1.0 version, so we must be at least DX1.0 if( pdwDirectXVersionMajor ) *pdwDirectXVersionMajor = 1; if( pdwDirectXVersionMinor ) *pdwDirectXVersionMinor = 0; if( pcDirectXVersionLetter ) *pcDirectXVersionLetter = TEXT(' '); bFound = true; } if( CompareLargeInts( llFileVersion, MakeInt64( 4, 3, 0, 1096 ) ) >= 0 ) // Win9x version { // flle is is >= DX2.0 version, so we must DX2.0 or DX2.0a (no redist change) if( pdwDirectXVersionMajor ) *pdwDirectXVersionMajor = 2; if( pdwDirectXVersionMinor ) *pdwDirectXVersionMinor = 0; if( pcDirectXVersionLetter ) *pcDirectXVersionLetter = TEXT(' '); bFound = true; } if( CompareLargeInts( llFileVersion, MakeInt64( 4, 4, 0, 68 ) ) >= 0 ) // Win9x version { // flle is is >= DX3.0 version, so we must be at least DX3.0 if( pdwDirectXVersionMajor ) *pdwDirectXVersionMajor = 3; if( pdwDirectXVersionMinor ) *pdwDirectXVersionMinor = 0; if( pcDirectXVersionLetter ) *pcDirectXVersionLetter = TEXT(' '); bFound = true; } } // Switch off the d3drg8x.dll version _tcscpy( szFile, szPath ); _tcscat( szFile, TEXT("\\d3drg8x.dll") ); if( SUCCEEDED( GetFileVersion( szFile, &llFileVersion ) ) ) { if( CompareLargeInts( llFileVersion, MakeInt64( 4, 4, 0, 70 ) ) >= 0 ) // Win9x version { // d3drg8x.dll is the DX3.0a version, so we must be DX3.0a or DX3.0b (no redist change) if( pdwDirectXVersionMajor ) *pdwDirectXVersionMajor = 3; if( pdwDirectXVersionMinor ) *pdwDirectXVersionMinor = 0; if( pcDirectXVersionLetter ) *pcDirectXVersionLetter = TEXT('a'); bFound = true; } } // Switch off the ddraw version _tcscpy( szFile, szPath ); _tcscat( szFile, TEXT("\\ddraw.dll") ); if( SUCCEEDED( GetFileVersion( szFile, &llFileVersion ) ) ) { if( CompareLargeInts( llFileVersion, MakeInt64( 4, 5, 0, 155 ) ) >= 0 ) // Win9x version { // ddraw.dll is the DX5.0 version, so we must be DX5.0 or DX5.2 (no redist change) if( pdwDirectXVersionMajor ) *pdwDirectXVersionMajor = 5; if( pdwDirectXVersionMinor ) *pdwDirectXVersionMinor = 0; if( pcDirectXVersionLetter ) *pcDirectXVersionLetter = TEXT(' '); bFound = true; } if( CompareLargeInts( llFileVersion, MakeInt64( 4, 6, 0, 318 ) ) >= 0 ) // Win9x version { // ddraw.dll is the DX6.0 version, so we must be at least DX6.0 if( pdwDirectXVersionMajor ) *pdwDirectXVersionMajor = 6; if( pdwDirectXVersionMinor ) *pdwDirectXVersionMinor = 0; if( pcDirectXVersionLetter ) *pcDirectXVersionLetter = TEXT(' '); bFound = true; } if( CompareLargeInts( llFileVersion, MakeInt64( 4, 6, 0, 436 ) ) >= 0 ) // Win9x version { // ddraw.dll is the DX6.1 version, so we must be at least DX6.1 if( pdwDirectXVersionMajor ) *pdwDirectXVersionMajor = 6; if( pdwDirectXVersionMinor ) *pdwDirectXVersionMinor = 1; if( pcDirectXVersionLetter ) *pcDirectXVersionLetter = TEXT(' '); bFound = true; } } // Switch off the dplayx.dll version _tcscpy( szFile, szPath ); _tcscat( szFile, TEXT("\\dplayx.dll") ); if( SUCCEEDED( GetFileVersion( szFile, &llFileVersion ) ) ) { if( CompareLargeInts( llFileVersion, MakeInt64( 4, 6, 3, 518 ) ) >= 0 ) // Win9x version { // ddraw.dll is the DX6.1 version, so we must be at least DX6.1a if( pdwDirectXVersionMajor ) *pdwDirectXVersionMajor = 6; if( pdwDirectXVersionMinor ) *pdwDirectXVersionMinor = 1; if( pcDirectXVersionLetter ) *pcDirectXVersionLetter = TEXT('a'); bFound = true; } } // Switch off the ddraw version _tcscpy( szFile, szPath ); _tcscat( szFile, TEXT("\\ddraw.dll") ); if( SUCCEEDED( GetFileVersion( szFile, &llFileVersion ) ) ) { if( CompareLargeInts( llFileVersion, MakeInt64( 4, 7, 0, 700 ) ) >= 0 ) // Win9x version { // TODO: find win2k version // ddraw.dll is the DX7.0 version, so we must be at least DX7.0 if( pdwDirectXVersionMajor ) *pdwDirectXVersionMajor = 7; if( pdwDirectXVersionMinor ) *pdwDirectXVersionMinor = 0; if( pcDirectXVersionLetter ) *pcDirectXVersionLetter = TEXT(' '); bFound = true; } } // Switch off the dinput version _tcscpy( szFile, szPath ); _tcscat( szFile, TEXT("\\dinput.dll") ); if( SUCCEEDED( GetFileVersion( szFile, &llFileVersion ) ) ) { if( CompareLargeInts( llFileVersion, MakeInt64( 4, 7, 0, 716 ) ) >= 0 ) // Win9x version { // ddraw.dll is the DX7.0 version, so we must be at least DX7.0a if( pdwDirectXVersionMajor ) *pdwDirectXVersionMajor = 7; if( pdwDirectXVersionMinor ) *pdwDirectXVersionMinor = 0; if( pcDirectXVersionLetter ) *pcDirectXVersionLetter = TEXT('a'); bFound = true; } } // Switch off the ddraw version _tcscpy( szFile, szPath ); _tcscat( szFile, TEXT("\\ddraw.dll") ); if( SUCCEEDED( GetFileVersion( szFile, &llFileVersion ) ) ) { if( (HIWORD(llFileVersion.HighPart) == 4 && CompareLargeInts( llFileVersion, MakeInt64( 4, 8, 0, 400 ) ) >= 0) || // Win9x version (HIWORD(llFileVersion.HighPart) == 5 && CompareLargeInts( llFileVersion, MakeInt64( 5, 1, 2258, 400 ) ) >= 0) ) // Win2k/WinXP version { // ddraw.dll is the DX8.0 version, so we must be at least DX8.0 or DX8.0a (no redist change) if( pdwDirectXVersionMajor ) *pdwDirectXVersionMajor = 8; if( pdwDirectXVersionMinor ) *pdwDirectXVersionMinor = 0; if( pcDirectXVersionLetter ) *pcDirectXVersionLetter = TEXT(' '); bFound = true; } } _tcscpy( szFile, szPath ); _tcscat( szFile, TEXT("\\d3d8.dll")); if( SUCCEEDED( GetFileVersion( szFile, &llFileVersion ) ) ) { if( (HIWORD(llFileVersion.HighPart) == 4 && CompareLargeInts( llFileVersion, MakeInt64( 4, 8, 1, 881 ) ) >= 0) || // Win9x version (HIWORD(llFileVersion.HighPart) == 5 && CompareLargeInts( llFileVersion, MakeInt64( 5, 1, 2600, 881 ) ) >= 0) ) // Win2k/WinXP version { // d3d8.dll is the DX8.1 version, so we must be at least DX8.1 if( pdwDirectXVersionMajor ) *pdwDirectXVersionMajor = 8; if( pdwDirectXVersionMinor ) *pdwDirectXVersionMinor = 1; if( pcDirectXVersionLetter ) *pcDirectXVersionLetter = TEXT(' '); bFound = true; } if( (HIWORD(llFileVersion.HighPart) == 4 && CompareLargeInts( llFileVersion, MakeInt64( 4, 8, 1, 901 ) ) >= 0) || // Win9x version (HIWORD(llFileVersion.HighPart) == 5 && CompareLargeInts( llFileVersion, MakeInt64( 5, 1, 2600, 901 ) ) >= 0) ) // Win2k/WinXP version { // d3d8.dll is the DX8.1a version, so we must be at least DX8.1a if( pdwDirectXVersionMajor ) *pdwDirectXVersionMajor = 8; if( pdwDirectXVersionMinor ) *pdwDirectXVersionMinor = 1; if( pcDirectXVersionLetter ) *pcDirectXVersionLetter = TEXT('a'); bFound = true; } } _tcscpy( szFile, szPath ); _tcscat( szFile, TEXT("\\mpg2splt.ax")); if( SUCCEEDED( GetFileVersion( szFile, &llFileVersion ) ) ) { if( CompareLargeInts( llFileVersion, MakeInt64( 6, 3, 1, 885 ) ) >= 0 ) // Win9x/Win2k/WinXP version { // quartz.dll is the DX8.1b version, so we must be at least DX8.1b if( pdwDirectXVersionMajor ) *pdwDirectXVersionMajor = 8; if( pdwDirectXVersionMinor ) *pdwDirectXVersionMinor = 1; if( pcDirectXVersionLetter ) *pcDirectXVersionLetter = TEXT('b'); bFound = true; } } _tcscpy( szFile, szPath ); _tcscat( szFile, TEXT("\\dpnet.dll")); if( SUCCEEDED( GetFileVersion( szFile, &llFileVersion ) ) ) { if( (HIWORD(llFileVersion.HighPart) == 4 && CompareLargeInts( llFileVersion, MakeInt64( 4, 9, 0, 134 ) ) >= 0) || // Win9x version (HIWORD(llFileVersion.HighPart) == 5 && CompareLargeInts( llFileVersion, MakeInt64( 5, 2, 3677, 134 ) ) >= 0) ) // Win2k/WinXP version { // dpnet.dll is the DX8.2 version, so we must be at least DX8.2 if( pdwDirectXVersionMajor ) *pdwDirectXVersionMajor = 8; if( pdwDirectXVersionMinor ) *pdwDirectXVersionMinor = 2; if( pcDirectXVersionLetter ) *pcDirectXVersionLetter = TEXT(' '); bFound = true; } } _tcscpy( szFile, szPath ); _tcscat( szFile, TEXT("\\d3d9.dll")); if( SUCCEEDED( GetFileVersion( szFile, &llFileVersion ) ) ) { // File exists, but be at least DX9 if( pdwDirectXVersionMajor ) *pdwDirectXVersionMajor = 9; if( pdwDirectXVersionMinor ) *pdwDirectXVersionMinor = 0; if( pcDirectXVersionLetter ) *pcDirectXVersionLetter = TEXT(' '); bFound = true; } } if( !bFound ) { // No DirectX installed if( pdwDirectXVersionMajor ) *pdwDirectXVersionMajor = 0; if( pdwDirectXVersionMinor ) *pdwDirectXVersionMinor = 0; if( pcDirectXVersionLetter ) *pcDirectXVersionLetter = TEXT(' '); } return S_OK; }