|
Sujet : [C++] Comment savoir sous quel OS on tourne ?? |
| TheJackal |
Code :
- BOOL bIsWindowsVersionOK( DWORD dwWin9xMajor, DWORD dwWin9xMinor,
- DWORD dwWinNTMajor, DWORD dwWinNTMinor, WORD wWinNTSPMajor )
- {
- OSVERSIONINFO osvi;
- // Initialize the OSVERSIONINFO structure.
- ZeroMemory( &osvi, sizeof( osvi ) );
- osvi.dwOSVersionInfoSize = sizeof( osvi );
- GetVersionEx( &osvi ); // Assume this function succeeds.
- // Split code paths for NT and Win9x
- if( osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS )
- {
- // Check the major version.
- if( osvi.dwMajorVersion > dwWin9xMajor )
- return TRUE;
- else if( osvi.dwMajorVersion == dwWin9xMajor )
- {
- // Check the minor version.
- if( osvi.dwMinorVersion >= dwWin9xMinor )
- return TRUE;
- }
- }
- else if( osvi.dwPlatformId == VER_PLATFORM_WIN32_NT )
- {
- // Check the major version.
- if( osvi.dwMajorVersion > dwWinNTMajor )
- return TRUE;
- else if( osvi.dwMajorVersion == dwWinNTMajor )
- {
- // Check the minor version.
- if( osvi.dwMinorVersion > dwWinNTMinor )
- return TRUE;
- else if( osvi.dwMinorVersion == dwWinNTMinor )
- {
- // Check the service pack.
- DWORD dwServicePack = 0;
- if( osvi.szCSDVersion )
- {
- _stscanf( osvi.szCSDVersion,
- _T("Service Pack %d" ),
- &dwServicePack );
- }
- return ( dwServicePack >= wWinNTSPMajor );
- }
- }
- }
- return FALSE;
- }
|
source: MSDN News |