Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Version Numbers, Backwards Compatibility, and Windows 10

Version Numbers, Backwards Compatibility, and Windows 10

There is a lot of speculation as to why the next version of Windows will be called “Windows 10”. And while we’ll probably never know what happened behind the closed doors of the marketing department, there are solid technical reasons why it can’t be called “Windows 9”.

To determine if an application can run on a given version of Windows, in full or with limited functionality, most developers check the major and minor version numbers. For example, if your program runs on Windows XP or later you may use this statement:

if (MajorVersion >= 5 && MinorVersion >= 1)

Those of you who worked help desks back in 2006 can probably recognize the error in that code. Windows Vista, which has a version number of 6.0, fails the test. This means many programs ran in either a degraded mode or stopped working entirely, which in turn contributed to Vista’s poor reputation.

Part of the reason Windows 7 was given the version number 6.1 was to suppress this error. And continuing the tradition, Windows 8 and 8.1 were given the numbers 6.2 and 6.3 respectively.

But this isn’t the only mistake that developers have made. A Reddit user going by the handle dndrdndr ran a search for this line of code, which was used to detect Windows 95 and Windows 98:

if (osName.startswith("windows 9"))

According to Search Code, a search engine for open source projects, there are over 4,000 instances of this faulty version checking code. And that’s not counting the untold numbers of commercial and internal applications that may break due to bad version checking.

While writing correct version number checks isn’t hard, the current recommendation from Microsoft is to avoid using GetVersionEx entirely. Instead you can use functions such as IsWindowsXPOrGreater and IsWindowsServer, which are supported all the way back to Windows 2000.

It should be noted that even GetVersionEx was created in response to developers incorrectly checking version numbers. From the documentation for GetVersion,

The GetVersionEx function was developed because many existing applications err when examining the packed DWORD value returned by GetVersion, transposing the major and minor version numbers. GetVersionEx forces applications to explicitly examine each element of version information. VerifyVersionInfo eliminates further potential for error by comparing the required system version with the current system version for you.

Rate this Article