I was looking at some code and they had this line: #define WINVER 0x0501
in stdafx.h
file? Why do you need to define WINVER
? How does it affect your code? Can someone please explain?

- 58,567
- 58
- 222
- 373

- 1,437
- 4
- 20
- 28
4 Answers
WINVER determines the minimum platform SDK required to build your application, which in turn will determine at compile time which routines are found by the headers.
You can use this to verify, at compile time, that your application will work on Windows 2000 (0x0500), for example, or on Windows XP (0x0501).
MSDN's page on Modifying WINVER and _WIN32_WINNT goes into this in more detail.

- 1,317
- 2
- 15
- 30

- 554,122
- 78
- 1,158
- 1,373
-
1Newer versions of Visual Studio include a _Target Platform Version_ property for C++ projects. Moving forward, is this intended to be the replacement for explicitly defining `WINVER` in source code? – Pressacco Sep 09 '16 at 15:02
WINVER defines the minimum Windows system the program can run on. There's a more detailed explanation at MSDN. What #define WINVER 0x0501
means is that the program requires Windows XP or Server 2003 to run, and that it therefore can use Windows functionality up through that release.

- 1,317
- 2
- 15
- 30

- 56,304
- 9
- 91
- 158
WINVER means Windows Version. In a nutshell, if you're building for a particular version of Windows, some APIs are available that are not available on previous versions.

- 56,086
- 21
- 82
- 121
By defining WINVER
macro you unhide a set of functions specific to a certain Windows version. For instance, if you define it as #define WINVER 0x0502
you will not able to use TaskDialog which is available only in Windows Vista. For more detail you could read the Using the Windows Headers article in MSDN.

- 1,317
- 2
- 15
- 30

- 97,037
- 24
- 136
- 212