Click here to Skip to main content
15,867,330 members
Articles / Programming Languages / C++
Article

Windows version requirements macros

Rate me:
Please Sign up or sign in to vote.
4.50/5 (6 votes)
1 Jun 20051 min read 57.7K   329   15   13
Operating system version requirements to the corresponding values for the currently running version of the system.

Introduction

The GetVersion function returns the current version number of the operating system. If the function succeeds, the return value is a DWORD value that contains the major and minor version numbers of the operating system in the low order word, and information about the operating system platform in the high order word.

For all platforms, the low order word contains the version number of the operating system. The low-order byte of this word specifies the major version number, in hexadecimal notation. The high-order byte specifies the minor version (revision) number, in hexadecimal notation.

In the table, you can find the examples for several Windows platforms:

Windows version numbers table

Often programmers need to get the currently running version of the system. The code in this article will show you how to identify the Windows platforms.

Macros definition

Windows version macros compare operating system version requirements to the corresponding values for the currently running version of the system. This enables you to easily determine the presence of a required set of operating system version conditions.

//Windows version macros

#define WinVerMajor()        LOBYTE(LOWORD(GetVersion()))
#define WinVerMinor()        HIBYTE(LOWORD(GetVersion()))

#define IsWinVerNTs()        (GetVersion() < 0x80000000)
#define IsWinVerNT351Plus()  (IsWinVerNTs() && WinVerMajor() >= 3)
#define IsWinVerNT4Plus()    (IsWinVerNTs() && WinVerMajor() > 3)
#define IsWinVer98Plus()     (LOWORD(GetVersion()) != 4)
#define IsWinVerMEPlus()     (WinVerMajor() >= 5 || WinVerMinor() > 10)
#define IsWinVer2000Plus()   (WinVerMajor() >= 5)
#define IsWinVerXPPlus()     (WinVerMajor() >= 5 && LOWORD(GetVersion()) != 5)

If the currently running operating system satisfies the specified requirements, the return value is a nonzero value. If the current system does not satisfy the requirements, the return value is zero.

Windows version numbers table

Using the macros

These examples will show you how easilyy you can use the macros in your applications:

// Example 1:
if (IsWinVerMEPlus())
{
    printf("If you can see this message you" 
           " are running Windows ME or higher! \n");
}
else
{
    printf("If you can see this message you are running Windows 95 or 98! \n");
}

// Example 2:
if (IsWinVerXPPlus())
{
    // Jun-01-2005
    printf("If you can see this message you are running Windows XP or 2003! \n");
}

// Example 3:
if (IsWinVer2000Plus())
{
    printf("Your operating system supports the opacity" 
           " and transparency color key of a layered window! \n");
}

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Slovakia Slovakia
Wink | ;-)

Comments and Discussions

 
GeneralMacro does not work Pin
bantisk8-Aug-06 21:22
bantisk8-Aug-06 21:22 
AnswerRe: Macro does not work Pin
Dalibor Drzik22-Aug-06 1:48
Dalibor Drzik22-Aug-06 1:48 
GeneralRe: Macro does not work Pin
bantisk23-Aug-06 0:57
bantisk23-Aug-06 0:57 
QuestionWhy are you using macros? Pin
Don Clugston1-Jun-05 20:42
Don Clugston1-Jun-05 20:42 
AnswerRe: Why are you using macros? Pin
Dalibor Drzik2-Jun-05 0:15
Dalibor Drzik2-Jun-05 0:15 
GeneralRe: Why are you using macros? Pin
Anonymous2-Jun-05 15:18
Anonymous2-Jun-05 15:18 
GeneralRe: Why are you using macros? Pin
Dalibor Drzik3-Jun-05 12:08
Dalibor Drzik3-Jun-05 12:08 
GeneralRe: Why are you using macros? Pin
F5Tiger14-Jun-05 21:18
F5Tiger14-Jun-05 21:18 
In macros, arguments must ALWAYS be used with parenthesis:

#define sqr(x) (x)*(x)
sqr(3 + 5) - you expect 8 and result = 64
real result (3 + 5) * (3 + 5) = 64
GeneralRe: Why are you using macros? Pin
Dalibor Drzik18-Jun-05 0:01
Dalibor Drzik18-Jun-05 0:01 
GeneralRe: Why are you using macros? Pin
Don Clugston5-Jun-05 22:04
Don Clugston5-Jun-05 22:04 
GeneralRe: Why are you using macros? Pin
Dalibor Drzik6-Jun-05 3:15
Dalibor Drzik6-Jun-05 3:15 
GeneralRe: Why are you using macros? Pin
Pablo Aliskevicius7-Jun-05 20:07
Pablo Aliskevicius7-Jun-05 20:07 
GeneralRe: Why are you using macros? Pin
Dalibor Drzik9-Jun-05 2:30
Dalibor Drzik9-Jun-05 2:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.