I have a VS2015 C++ project. app has to run on both Windows 7 and XP. So, I want to set _WIN32_WINNT & WINVER to _WIN32_WINNT_WINXP.
This is how stdafx.h of my project looks like:
stdafx.h
#pragma once
#include "targetver.h"
#define _WIN32_WINNT _WIN32_WINNT_WINXP
#define WINVER _WIN32_WINNT_WINXP
#include <WinSDKVer.h>
// Windows Header Files:
#include <windows.h>
When compiled, I see the following warning/error:
stdafx.h(12): error C2220: warning treated as error - no 'object' file generated
1>stdafx.h(12): warning C4005: '_WIN32_WINNT': macro redefinition
1> C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\include\SDKDDKVer.h(197): note: see previous definition of '_WIN32_WINNT'
1>stdafx.h(13): warning C4005: 'WINVER': macro redefinition
1> C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\include\SDKDDKVer.h(212): note: see previous definition of 'WINVER'
Because the #include "targetver.h" is including <sdkddkver.h> which already defines the constants _WIN32_WINNT and WINVER when they aren't already defined by the build environment.
As a matter of fact, the auto-generated targetver.h tells you exactly how to fix this:
#pragma once
// Including SDKDDKVer.h defines the highest available Windows platform.
// 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.
#include <SDKDDKVer.h>
Simple solution. Just define those constants before the inclusion of targetver.h. You might have to use the actual literal value for XP since you haven't include the header file that defines
Like this:
// x501 is XP
#define _WIN32_WINNT 0x0501
#define WINVER 0x0501
#include "targetver.h"
#include <windows.h>
If 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