[英]'_WIN32_WINNT' / 'WINVER' : macro redefinition
我有一個VS2015 C++
項目。 應用程序必須在 Windows 7 和 XP 上運行。 所以,我想將_WIN32_WINNT
& WINVER
設置為_WIN32_WINNT_WINXP
。
這是我項目的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>
編譯后,我看到以下警告/錯誤:
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'
因為#include "targetver.h"
包含<sdkddkver.h>
,當構建環境尚未定義常量_WIN32_WINNT和WINVER時,它們已經定義了它們。
實際上,自動生成的targetver.h
告訴您確切的解決方法:
#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>
簡單的解決方案。 只需在包含targetver.h
之前定義這些常量。 您可能必須使用XP的實際文字值,因為您沒有包含用於定義XP的頭文件
像這樣:
// x501 is XP
#define _WIN32_WINNT 0x0501
#define WINVER 0x0501
#include "targetver.h"
#include <windows.h>
嘗試
#include <winsdkver.h>
#undef _WIN32_WINNT
#define _WIN32_WINNT _WIN32_WINNT_WINXP
#include <SDKDDKVer.h>
你 #include <winsdkver.h> 這樣你就可以使用 _WIN32_WIN_WINXP。 但是,您需要 #undef _WIN32_WINNT 因為它是在 <winsdkver.h> 中定義的。 這樣,當您使用 #define _WIN32_WINNT _WIN32_WINNT_WINXP 時,您不會收到 _WIN32_WINNT 警告的重新定義。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.