"Fossies" - the Fresh Open Source Software Archive

Member "AutoHotkey_L-1.1.33.09/source/os_version.cpp" (8 May 2021, 7072 Bytes) of package /windows/misc/AutoHotkey_L-1.1.33.09.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "os_version.cpp" see the Fossies "Dox" file reference documentation.

    1 
    2 ///////////////////////////////////////////////////////////////////////////////
    3 //
    4 // AutoIt
    5 //
    6 // Copyright (C)1999-2003:
    7 //      - Jonathan Bennett <jon@hiddensoft.com>
    8 //      - Others listed at http://www.autoitscript.com/autoit3/docs/credits.htm
    9 //
   10 // This program is free software; you can redistribute it and/or modify
   11 // it under the terms of the GNU General Public License as published by
   12 // the Free Software Foundation; either version 2 of the License, or
   13 // (at your option) any later version.
   14 //
   15 ///////////////////////////////////////////////////////////////////////////////
   16 //
   17 // os_version.cpp
   18 //
   19 // A standalone class for easy checking of the OS version.
   20 //
   21 ///////////////////////////////////////////////////////////////////////////////
   22 
   23 
   24 // Includes
   25 #include "stdafx.h" // pre-compiled headers
   26 
   27 #ifndef _MSC_VER                                // Includes for non-MS compilers
   28     #include <windows.h>
   29 #endif
   30 
   31 #include "os_version.h"
   32 
   33 #pragma warning(disable: 4996) // Ignore GetVersionEx deprecation.
   34 
   35 /*
   36 OSVERSIONINFO structure details
   37 ===============================
   38 
   39 dwOSVersionInfoSize
   40 Specifies the size, in bytes, of this data structure. Set this member to sizeof(OSVERSIONINFO)
   41 before calling the GetVersionEx function.
   42 
   43 dwMajorVersion
   44 Identifies the major version number of the operating system as follows. Operating System Value
   45 Windows 95              4
   46 Windows 98              4
   47 Windows Me              4
   48 Windows NT 3.51         3
   49 Windows NT 4.0          4
   50 Windows 2000/XP/2003    5
   51 Windows Vista/7         6
   52 
   53 dwMinorVersion
   54 Identifies the minor version number of the operating system as follows. Operating System Value
   55 Windows 95          0
   56 Windows 98          10
   57 Windows Me          90
   58 Windows NT 3.51     51
   59 Windows NT 4.0      0
   60 Windows 2000        0
   61 Windows XP          1
   62 Windows 2003        2
   63 Windows Vista       0 (probably 0 for all Vista variants)
   64 Windows 7           1
   65 
   66 dwBuildNumber
   67 Windows NT/2000: Identifies the build number of the operating system.
   68 Windows 95/98: Identifies the build number of the operating system in the low-order word.
   69 The high-order word contains the major and minor version numbers.
   70 
   71 dwPlatformId
   72 Identifies the operating system platform. This member can be one of the following values. Value Platform
   73 VER_PLATFORM_WIN32s         Win32s on Windows 3.1.
   74 VER_PLATFORM_WIN32_WINDOWS  Windows 95, Windows 98, or Windows Me.
   75 VER_PLATFORM_WIN32_NT       Windows NT 3.51, Windows NT 4.0, Windows 2000, Windows XP, Windows Vista or Windows 7.
   76 
   77 szCSDVersion
   78 Windows NT/2000, Whistler: Contains a null-terminated string, such as "Service Pack 3",
   79 that indicates the latest Service Pack installed on the system. If no Service Pack has
   80 been installed, the string is empty.
   81 Windows 95/98/Me: Contains a null-terminated string that indicates additional version
   82 information. For example, " C" indicates Windows 95 OSR2 and " A" indicates Windows 98 SE.
   83 
   84 */
   85 
   86 
   87 ///////////////////////////////////////////////////////////////////////////////
   88 // Init()
   89 ///////////////////////////////////////////////////////////////////////////////
   90 
   91 void OS_Version::Init(void)
   92 {
   93     typedef int (WINAPI * GetVersionType)(OSVERSIONINFOW *Info);
   94     static GetVersionType _RtlGetVersion = (GetVersionType)GetProcAddress(GetModuleHandle(_T("ntdll.dll")), "RtlGetVersion");
   95 
   96     // Get details of the OS we are running on
   97     m_OSvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW);
   98     if (_RtlGetVersion)
   99         _RtlGetVersion(&m_OSvi);
  100     else
  101         GetVersionExW(&m_OSvi);
  102 
  103     // Populate Major and Minor version numbers
  104     m_dwMajorVersion    = m_OSvi.dwMajorVersion;
  105     m_dwMinorVersion    = m_OSvi.dwMinorVersion;
  106     m_dwBuildNumber     = m_OSvi.dwBuildNumber;
  107 
  108     // Compose human-readable version number.
  109     _sntprintf(m_szVersion, _countof(m_szVersion)-1, _T("%u.%u.%u"), m_dwMajorVersion, m_dwMinorVersion, m_dwBuildNumber);
  110     m_szVersion[_countof(m_szVersion)-1] = '\0'; // For the slim chance that it's too long to fit in the buffer (and therefore wasn't null-terminated).
  111 
  112     /* // AutoHotkey: This is disabled because we never use it.
  113     
  114     int     i;
  115     int     nTemp;
  116     
  117     // Get CSD information
  118     nTemp = (int)_tcslen(m_OSvi.szCSDVersion);
  119 
  120     if (nTemp > 0)
  121     {
  122         //  strip trailing
  123         for (i=nTemp-1; i>0; i--)
  124         {
  125             if (m_OSvi.szCSDVersion[i] != ' ') 
  126                 break;
  127             m_OSvi.szCSDVersion[i] = '\0';
  128         }
  129 
  130         //  strip leading
  131         nTemp = i;
  132         for (i=0; i<nTemp; i++)
  133         {
  134             if (m_OSvi.szCSDVersion[i] != ' ') 
  135                 break;
  136         }
  137         _tcscpy(m_szCSDVersion, &m_OSvi.szCSDVersion[i]);
  138     }
  139     else
  140         m_szCSDVersion[0] = '\0';               // No CSD info, make it blank to avoid errors
  141     */
  142 
  143     // Set all options to false by default
  144 #ifdef CONFIG_WIN9X
  145     m_bWinNT    = false;
  146     m_bWin9x    = false;
  147 
  148     m_bWin95    = false;    m_bWin95orLater     = false;
  149     m_bWin98    = false;    m_bWin98orLater     = false;
  150     m_bWinMe    = false;    m_bWinMeorLater     = false;
  151 #endif
  152 #ifdef CONFIG_WINNT4
  153     m_bWinNT4   = false;    m_bWinNT4orLater    = false;
  154 #endif
  155 #ifdef CONFIG_WIN2K
  156     m_bWin2000  = false;    m_bWin2000orLater   = false;    m_bWinXPorLater = false;
  157 #endif
  158     m_bWinXP    = false;
  159     m_bWin2003  = false;
  160     m_bWinVista = false;    m_bWinVistaOrLater  = false;
  161     m_bWin7     = false;    m_bWin7OrLater      = false;
  162     m_bWin8     = false;
  163 
  164 #ifdef CONFIG_WIN9X
  165     // Work out if NT or 9x
  166     if (m_OSvi.dwPlatformId == VER_PLATFORM_WIN32_NT)
  167     {
  168         // Windows NT
  169         m_bWinNT = true;
  170 #endif
  171 
  172         switch (m_dwMajorVersion)
  173         {
  174 #ifdef CONFIG_WINNT4
  175             case 4:                             // NT 4
  176                 m_bWinNT4 = true;
  177                 m_bWinNT4orLater = true;
  178                 break;
  179 #endif
  180 
  181             case 5:                             // Win2000 / XP
  182 #ifdef CONFIG_WINNT4
  183                 m_bWinNT4orLater = true;
  184 #endif
  185 #ifdef CONFIG_WIN2K
  186                 m_bWin2000orLater = true;
  187                 if ( m_dwMinorVersion == 0 )    // Win2000
  188                     m_bWin2000 = true;
  189                 else // minor is 1 (XP), 2 (2003), or beyond.
  190 #endif
  191                 {
  192 #ifdef CONFIG_WIN2K
  193                     m_bWinXPorLater = true;
  194 #endif
  195                     if ( m_dwMinorVersion == 1 )
  196                         m_bWinXP = true;
  197                     else if ( m_dwMinorVersion == 2 )
  198                         m_bWin2003 = true;
  199                     //else it's something later than XP/2003, so there is nothing more to be done.
  200                 }
  201                 break;
  202             case 6:
  203                 if (m_dwMinorVersion == 0)
  204                     m_bWinVista = true;
  205                 else {
  206                     m_bWin7OrLater = true;
  207                     if (m_dwMinorVersion == 1)
  208                         m_bWin7 = true;
  209                     else if (m_dwMinorVersion == 2)
  210                         m_bWin8 = true;
  211                     else if (m_dwMinorVersion == 3)
  212                         m_bWin8_1 = true;
  213                 }
  214                 m_bWinVistaOrLater = true;
  215 #ifdef CONFIG_WIN2K
  216                 m_bWinXPorLater = true;
  217                 m_bWin2000orLater = true;
  218 #endif
  219 #ifdef CONFIG_WINNT4
  220                 m_bWinNT4orLater = true;
  221 #endif
  222                 break;
  223             default:
  224                 if (m_dwMajorVersion > 6)
  225                 {
  226                     m_bWin7OrLater = true;
  227                     m_bWinVistaOrLater = true;
  228 #ifdef CONFIG_WIN2K
  229                     m_bWinXPorLater = true;
  230                     m_bWin2000orLater = true;
  231 #endif
  232 #ifdef CONFIG_WINNT4
  233                     m_bWinNT4orLater = true;
  234 #endif
  235                 }
  236                 break;
  237 
  238         } // End Switch
  239 #ifdef CONFIG_WIN9X
  240     }
  241     else
  242     {
  243         // Windows 9x -- all major versions = 4
  244         m_bWin9x = true;
  245         m_bWin95orLater = true;
  246         m_dwBuildNumber = (WORD) m_OSvi.dwBuildNumber;  // Build number in lower word on 9x
  247 
  248         switch ( m_dwMinorVersion )
  249         {
  250             case 0:                             // 95
  251                 m_bWin95 = true;
  252                 break;
  253 
  254             case 10:                            // 98
  255                 m_bWin98 = m_bWin98orLater = true;
  256                 break;
  257 
  258             case 90:                            // ME
  259                 m_bWinMe =  m_bWinMeorLater = m_bWin98orLater = true;
  260                 break;
  261         } // End Switch
  262     } // End If
  263 #endif
  264 
  265 } // Init()
  266