27
_WIN32_WINNT not defined. Defaulting to _WIN32_WINNT_MAXVER (see WinSDKVer.h)

This error keeps popping up during my compilation. It doesn't seem to affect compilation, but how should I get rid of it? Am I risking anything by ignoring it?

Felice Pollano
  • 32,832
  • 9
  • 75
  • 115
User982367637
  • 325
  • 1
  • 3
  • 5

6 Answers6

22

Set it to the oldest Windows Operating System you want your program to run on. The possible values are given in this MSDN article, Using the Windows Headers.

You can define these symbols by using the #define statement in each source file, or by specifying the /D compiler option supported by Visual C++.

For example, to set WINVER in your source file, use the following statement:

 #define WINVER 0x0502    // Windows Server 2003 with SP1, Windows XP with SP2

To set _WIN32_WINNT in your source file, use the following statement:

#define _WIN32_WINNT 0x0502    // Windows Server 2003 with SP1, Windows XP with SP2

To set _WIN32_WINNT using the /D compiler option, use the following command:

cl -c /D_WIN32_WINNT=0x0502 source.cpp
Richard Chambers
  • 16,643
  • 4
  • 81
  • 106
user93353
  • 13,733
  • 8
  • 60
  • 122
19

It is defined for you through WinSDKVer.h. So just define it explicitly on the top of your source code (e.g. in the beginning of stdafx.h) and you will get rid of the warning.

Having it defined to the same value (as compared to _WIN32_WINNT_MAXVER from WinSDKVer.h) is highly unlikely to break anything.

For example, WinSDKVer.h of Windows® Software Development Kit (SDK) for Windows 7 and .NET Framework 3.5 Service Pack 1 contains:

// This list contains the highest version constants supported by content 
// in the Windows SDK.

// [...]
#define _WIN32_WINNT_MAXVER     0x0601
Roman R.
  • 68,205
  • 6
  • 94
  • 158
  • 2
    I'd recommend adding it to StdAfx.h almost at the beginning. Here is a list of values for each OS. http://msdn.microsoft.com/en-us/library/aa383745%28VS.85%29.aspx – Marek May 20 '16 at 09:28
  • `WIN32_WINNT` is defined by default through `sdkddkver.h`, while `WinSDKVer.h` defines `_WIN32_WINNT_MAXVER` and related `MAXVER` macros (which are usually set to the most recent Windows version suppported by that version of the Windows SDK). Defining `_WIN32_WINNT` to a valid value will resolve the warning which User982367637 was asking about. Whether that value should be `_WIN32_WINNT_MAXVER` or an older Windows version depends on whether they want their app to be able to run on older versions of Windows (as noted by the answer from user93353, below). – MikeOnline Jan 22 '20 at 22:36
5

Solving in VS2019

Ways to solve this and a link to possible values to use can be found here in the super answer by user93353 which I used to solve the problem.

https://stackoverflow.com/a/12871547/3070485

However, after reading the solution, I set my compiler option in my IDE which is Visual Studio 2019.

For anyone wanting to set it there quickly and wanting to know the location (as these things change from IDE release to release, or maybe someone is more familiar with another IDE), here is where it went.

enter image description here

Configuration Properties
C/C++
Preprocessor
Preprocessor Definitions
_WIN32_WINNT=0x0502

Ivan
  • 4,383
  • 36
  • 27
2

Note: the #define _WIN32_WINNT must occur before any header file, including "stdafx.h".

Pierre
  • 4,114
  • 2
  • 34
  • 39
  • 6
    @Stonz2 I dunno... [A] The OP complains he's getting a "_WIN32_WINNT not defined" error. [B] I tell him where to define _WIN32_WINNT to get rid of the error (see where he asks "how should I get rid of it?") . [C] Doesn't this sort of help him? – Pierre Oct 03 '14 at 17:44
  • Down-voting. See my answer below. – MikeOnline Jan 13 '20 at 19:23
1

If using MFC: My preferred answer is to include windows.h. But if you are using MFC, you cannot do this*. To avoid defining WINVER in your project, instead you can include sdkddkver.h before afx.h.

#include <sdkddkver.h>
#include <afx.h>

The sdkddkver system header sets WINVER and _WIN32_WINNT so you don't need to add it to your project. This does the same as windows.h for versioning windows SDK/DDK from the system headers.

*if you include windows.h before afx.h you get: #error: WINDOWS.H already included. MFC apps must not #include <Windows.h>

0

#define _WIN32_WINNT and #define WINVER can occur in a header, so long as they occur before including SDKDDKVer.h or any headers from the Windows SDK (in particular Windows.h). Visual Studio VC++ projects typically provide a targetver.h header, where you can include WinSDKVer.h, define _WIN32_WINNT, NTDDI_VERSION and WINVER, and then include SDKDDKVer.h. Comments within this file say:

// If you wish to build your application for a previous Windows platform, include `WinSDKVer.h`
// and set the _WIN32_WINNT macro to the platform you wish to support before including `SDKDDKVer.h`.

The Microsoft article Update WINVER and _WIN32_WINNT goes out of its way to instruct you to define _WIN32_WINNT and WINVER in targetver.h (though it mentions these can be defined using command-line parameters, too).

Note: targetver.h gets included in certain .rc resource files generated by Visual Studio, so this is another reason to fill out the contents of the targetver.h file as described, above.

Note: defining _WIN32_WINNT, NTDDI_VERSION and WINVER using command-line parameters or preprocessor directives within the project's build configurations can also work, but neither takes care of the need to include WinSDKVer.h and SDKDDKVer.h.

Note: when using the Windows 8.1 SDK (or newer), you may also need to define WINAPI_FAMILY in targetver.h depending on the specific Windows platform (server, desktop, phone, store, etc.) you need. See winapifamily.h for details.

Note: In newer Windows SDK versions, the values NTDDI_VERSION, WINVER and _WIN32_IE can be set automatically based on the value you define for _WIN32_WINNT. However, you may want to define a more specific version for NTDDI_VERSION explicitly prior to including SDKDDKVer.h.

MikeOnline
  • 994
  • 11
  • 18