As I understand it, in a C++ project:
_WIN32_WINNT
, WINVER
, and NTDDI_VERSION
macros
If I compile my application with the following setup:
v140_xp
(Visual Studio 2015 - Windows XP)StdAfh.h
#include <WinSDKVer.h>
#define _WIN32_WINNT 0x0501
#define WINVER 0x0501
#define NTDDI_VERSION 0x05010000
#include <SDKDDKVer.h>
From what I can tell, it looks like Target Platform Version is an suposed to be an alternative to the _WIN32_WINNT
, WINVER
, and NTDDI_VERSION
macros. The weird thing is, with the above configuration you can set the Target Platform Version to 1
or 99
... and the compiler doesn't generate any errors or warnings.
This this leaves me wondering: What is the Target Platform Version for?
A target platform is the particular platform that your project is built to run on. The target platform is specified in the PlatformTarget build property in a project file. You can change the target platform by using the project property pages or the Configuration Manager in the IDE.
Visual Studio enables you to set up your application builds to target different platforms (processor architectures), such as x86 and x64. For 64-bit platform support for . NET development, see 64-bit applications. Note. Visual Studio runs as a 32-bit application.
Choose the Configuration Manager button to open the Configuration Manager dialog box. In the Active Solution Platform drop-down list, select the <New...> option to open the New Solution Platform dialog box. In the Type or select the new platform drop-down list, select a 64-bit target platform.
In Visual Studio 2015 the Target Platform Version field just sets the version of the Windows SDK to use. See this MSDN article for reference. In Visual Studio 2019, this field has been renamed Windows SDK Version. You still need to set _WIN32_WINNT
, WINVER
, and NTDDI_VERSION
macros, as well as the Platform Toolset field. Taken together they determine the versions of Windows your app can run on.
If your applications need to run on Windows XP, you have to pick a Platform Toolset ending in _xp, select an older Windows SDK Version (you need 7.1A, but picking 7.0 or 8.1 should work; see below), and set _WIN32_WINNT
, WINVER
, and NTDDI_VERSION
macros accordingly. See this Stack Overflow posting for tips on setting these macros and including related SDK headers via targetver.h
.
If building from a Command Prompt with an _xp platform toolset see this Stack Overflow posting for tips on setting the /SUBSYSTEM
linker option and for defining _USING_V110_SDK71_
.
Windows SDKs are backward-compatible, but I haven't yet found a clear reference which lists the oldest version of Windows you can target when building with a given version of the Windows SDK (see EDIT at the bottom of this post). Each SDK lists "System Requirements", but these list the minimum version of Windows needed to develop with the SDK, not the minimum version of Windows that executables built with that SDK can target. The best reference I know of is the sdkddkver.h
header in each of the newer Windows SDKs. Within this header are a list of _WIN32_WINNT version constants. For example, in the Windows 7.1A SDK, sdkddkver.h
defines _WIN32_WINNT_NT4
as the oldest supported Windows platform (but I do not know if this is definitive).
The rest of this answer are notes regarding targeting for native VC++ apps using Visual Studio 2019. These notes may apply to older Visual Studio versions as well.
In Visual Studio 2019, selecting a Platform Toolset which ends in _xp has certain quirks. For v120_xp, the Windows SDK Version field is hidden, but the inherited VC++ Directories will show that the Windows SDK 7.1A directory is specified. For v140_xp and v141_xp platform toolsets, you can pick Windows SDK 7.0 or 8.1 (for either, the inherited VC++ Directories will show that the Windows SDK 7.1A directory is specified).
I am not sure what the difference is - if any - between specifying Windows SDK Version 7.0 or 8.1 when using Platform Toolset v140_xp or v141_xp in Visual Studio 2019.
In Visual Studio 2019, when setting native C++ project properties for a Windows Desktop app, depending on the Platform Toolset you select, the read-only Target Platform field may change to "Windows 10". But this DOES NOT mean your Win32 desktop app will be built as a Universal Windows Platform app. It will still work on older versions of Windows depending on the Platform Toolset, Windows SDK Version and the values for the _WIN32_WINNT
, WINVER
, and NTDDI_VERSION
macros.
Microsoft could update VS2019 so the Target Platform field value would show just "Windows" when setting properties for Win32/desktop projects, regardless of the selected Platform Toolset or Windows SDK Version.
EDIT: See the article A Brief History of Windows SDKs from Chuck Walbourn, Senior Engineer for Xbox at Microsoft, for details regarding backward compatibility of various Windows SDKs.
The following summarizes the differences between the Windows SDK Version & the Platform Toolset configuration properties.
Important: Sometimes this property is referred to as Target Platform Version
Thankfully, this subject has been updated in Microsoft's MSDN. The following was taken directly from C++ project property pages.
this specifies the version of the Windows SDK that your project requires. When you install a C++ Workload by using the Visual Studio installer, the required parts of the Windows SDK are also installed. If you have other Windows SDK versions on your computer, each version of the SDK tools that you have installed appears in the dropdown.
To target Windows 7 or Windows Vista, use the value 8.1, since Windows SDK 8.1 is backward compatible to those platforms. In addition, you should define the appropriate value for _WIN32_WINNT in targetver.h. For Windows 7, that's 0x0601.
For those of you who don't know, any given Windows SDK is [mostly] backwards compatible with older versions of the Windows SDK. For example, you could configure your C++ project with the following:
10
TargetVer.h
to your project that includes the following pre-processor macros:
#define WINVER 0x0603 // Windows 8.1
#define _WIN32_WINNT 0x0603 // Windows 8.1
For more information, please see:
This property specifies the following for your C++ project:
v142
results in the the Visual Studio 2019 compiler being usedv142
indicates that you are using the Visual Studio 2019 C++ library
MSVCRxxx.dll
) during deployment.MSVCR
MS
= MicrosoftV
= VisualC
= C++R
= RedistributableC:\Windows\
C:\Windows\SysWOW64\
_MSC_VER
pre-processor macro.It is worth noting that:
Platform Toolset
is a project level setting (see PlatformToolset
in *.vcxproj
), whereas, the selected Windows SDK Version
is saved elsewhere.Platform Toolset
value can be somewhat confusing because:
v142
) is associated with a Visual Studio release (e.g. Visual Studio 2019)For more information, please see:
_MSC_VER
values and their meaningsIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With