修改 WINVER 和 _WIN32_WINNTModifying WINVER and _WIN32_WINNT

Visual C++ 不再支持面向 Windows 95、Windows 98、Windows ME、Windows NT 或 Windows 2000。Visual C++ no longer supports targeting Windows 95, Windows 98, Windows ME, Windows NT or Windows 2000. 如果你的 WINVER_WIN32_WINNT 宏分配给了这些 Windows 版本中的一个,则必须修改宏。If your WINVER or _WIN32_WINNT macros are assigned to one of these versions of Windows, you must modify the macros. 升级使用早期版本的 Visual C++ 创建的项目时,你可能会看到与 WINVER_WIN32_WINNT 宏相关的编译错误(如果这些宏分配给了不再受支持的 Windows 版本)。When you upgrade a project that was created by using an earlier version of Visual C++, you may see compilation errors related to the WINVER or _WIN32_WINNT macros if they are assigned to a version of Windows that is no longer supported.

备注Remarks

若要修改这些宏,请在头文件(例如在创建面向 Windows 的项目时包含的 targetver.h)中添加以下行。To modify the macros, in a header file (for example, targetver.h which is included when you create a project that targets Windows), add the following lines.

#define WINVER 0x0A00  
#define _WIN32_WINNT 0x0A00  

这面向 Windows 10 操作系统。This targets the Windows 10 operating system. 在 Windows 头文件 SDKDDKVer.h(它还定义每个 Windows 版本的宏)中列出了这些值。These values are listed in the Windows header file SDKDDKVer.h, which also defines macros for each Windows version. 应添加 #define 语句,然后才能包括 SDKDDKVer.h。You should add the #define statement before including SDKDDKVer.h. 下面是 Windows 10 版 SDKDDKVer.h(它对每个版本的 Windows 的值进行编码)中的行:Here are the lines from the Windows 10 version of SDKDDKVer.h that encode the values for each version of Windows:

//  
// _WIN32_WINNT version constants  
//  
#define _WIN32_WINNT_NT4                    0x0400 // Windows NT 4.0  
#define _WIN32_WINNT_WIN2K                  0x0500 // Windows 2000  
#define _WIN32_WINNT_WINXP                  0x0501 // Windows XP  
#define _WIN32_WINNT_WS03                   0x0502 // Windows Server 2003  
#define _WIN32_WINNT_WIN6                   0x0600 // Windows Vista  
#define _WIN32_WINNT_VISTA                  0x0600 // Windows Vista  
#define _WIN32_WINNT_WS08                   0x0600 // Windows Server 2008  
#define _WIN32_WINNT_LONGHORN               0x0600 // Windows Vista  
#define _WIN32_WINNT_WIN7                   0x0601 // Windows 7  
#define _WIN32_WINNT_WIN8                   0x0602 // Windows 8  
#define _WIN32_WINNT_WINBLUE                0x0603 // Windows 8.1  
#define _WIN32_WINNT_WINTHRESHOLD           0x0A00 // Windows 10  
#define _WIN32_WINNT_WIN10                  0x0A00 // Windows 10  

如果你查看的 SDKDDKVer.h 的一个副本中没有列出以上所有 Windows 版本,则很可能是由于你正在使用 Windows SDK 的较旧版本。If you don't see all of these versions of Windows listed in a copy of SDKDDKVer.h that you're looking at, you probably are using an older version of the Windows SDK. 默认情况下,Visual Studio 2017 中的 Win32 项目使用 Windows 10 SDK。By default, Win32 projects in Visual Studio 2017 use the Windows 10 SDK.

备注

如果将内部 MFC 头文件包含到应用程序中,则无法保证这些值有效。Values are not guaranteed to work if you include internal MFC headers in your application.

你还可以使用 /D 编译器选项定义此宏。You can also define this macro by using the /D compiler option. 有关详细信息,请参阅 /D (Preprocessor Definitions)For more information, see /D (Preprocessor Definitions).

若要深入了解这些宏的含义,请参阅 使用 Windows 头文件For more information about the meanings of these macros, see Using the Windows Headers.

请参阅See Also

Visual C++ 更改历史记录Visual C++ change history