它们是用于定义windows和Internet Explorer版本号的,用于区分不用版本的函数和参数。
在你编译程序时会根据不同的版本系统号,链接不同的函数和参数。
目前的VISUAL C++2015已经不再支持Windows 95, Windows 98, Windows ME, Windows NT or Windows 2000.
这些宏定义出现在SdkDdkVer.h文件中,它将随着不同版本DDK做相应更新。
// _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 |
使用方法有两种,一种是定义头文件,如下列定义将约定最小系统为WIN10
#define WINVER 0x0A00
#define _WIN32_WINNT 0x0A00
另外一种方法是使用/D编译选项,不提。
Visual C/C++早期版本的宏定义如下:
The following table describes the preferred macros used in the Windows header files. If you define NTDDI_VERSION, you must also define _WIN32_WINNT.
Minimum system required | Value for NTDDI_VERSION |
---|---|
Windows 8.1 | NTDDI_WINBLUE (0x06030000) |
Windows 8 | NTDDI_WIN8 (0x06020000) |
Windows 7 | NTDDI_WIN7 (0x06010000) |
Windows Server 2008 | NTDDI_WS08 (0x06000100) |
Windows Vista with Service Pack 1 (SP1) | NTDDI_VISTASP1 (0x06000100) |
Windows Vista | NTDDI_VISTA (0x06000000) |
Windows Server 2003 with Service Pack 2 (SP2) | NTDDI_WS03SP2 (0x05020200) |
Windows Server 2003 with Service Pack 1 (SP1) | NTDDI_WS03SP1 (0x05020100) |
Windows Server 2003 | NTDDI_WS03 (0x05020000) |
Windows XP with Service Pack 3 (SP3) | NTDDI_WINXPSP3 (0x05010300) |
Windows XP with Service Pack 2 (SP2) | NTDDI_WINXPSP2 (0x05010200) |
Windows XP with Service Pack 1 (SP1) | NTDDI_WINXPSP1 (0x05010100) |
Windows XP | NTDDI_WINXP (0x05010000) |
The following tables describe other macros used in the Windows header files.
Minimum system required | Minimum value for _WIN32_WINNT and WINVER |
---|---|
Windows 8.1 | _WIN32_WINNT_WINBLUE (0x0602) |
Windows 8 | _WIN32_WINNT_WIN8 (0x0602) |
Windows 7 | _WIN32_WINNT_WIN7 (0x0601) |
Windows Server 2008 | _WIN32_WINNT_WS08 (0x0600) |
Windows Vista | _WIN32_WINNT_VISTA (0x0600) |
Windows Server 2003 with SP1, Windows XP with SP2 | _WIN32_WINNT_WS03 (0x0502) |
Windows Server 2003, Windows XP | _WIN32_WINNT_WINXP (0x0501) |
Minimum version required | Minimum value of _WIN32_IE |
---|---|
Internet Explorer 10.0 | _WIN32_IE_IE100 (0x0A00) |
Internet Explorer 9.0 | _WIN32_IE_IE90 (0x0900) |
Internet Explorer 8.0 | _WIN32_IE_IE80 (0x0800) |
Internet Explorer 7.0 | _WIN32_IE_IE70 (0x0700) |
Internet Explorer 6.0 SP2 | _WIN32_IE_IE60SP2 (0x0603) |
Internet Explorer 6.0 SP1 | _WIN32_IE_IE60SP1 (0x0601) |
Internet Explorer 6.0 | _WIN32_IE_IE60 (0x0600) |
Internet Explorer 5.5 | _WIN32_IE_IE55 (0x0550) |
Internet Explorer 5.01 | _WIN32_IE_IE501 (0x0501) |
Internet Explorer 5.0, 5.0a, 5.0b | _WIN32_IE_IE50 (0x0500) |
Setting WINVER or _WIN32_WINNT
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: To set _WIN32_WINNT in your source file, use the following statement: To set _WIN32_WINNT using the /D compiler option, use the following command: For information on using the /D compiler option, see . Note that some features introduced in the latest version of Windows may be added to a service pack for a previous version of Windows. Therefore, to target a service pack, you may need to define _WIN32_WINNT with the value for the next major operating system release. For example, the function was introduced in Windows Server 2003 and is conditionally defined if _WIN32_WINNT is 0x0502 or greater. This function was also added to Windows XP with SP1. Therefore, if you were to define _WIN32_WINNT as 0x0501 to target Windows XP, you would miss features that are defined in Windows XP with SP1.
_MSC_VER
_MSC_VER 定义编译器的版本。下面是一些编译器版本的_MSC_VER值:
MS VC++ 12.0 _MSC_VER = 1800 (Visual C++ 2013)
MS VC++ 11.0 _MSC_VER = 1700 (Visual C++ 2012)
MS VC++ 10.0 _MSC_VER = 1600(Visual C++ 2010)
MS VC++ 9.0 _MSC_VER = 1500
MS VC++ 8.0 _MSC_VER = 1400
MS VC++ 7.1 _MSC_VER = 1310
MS VC++ 7.0 _MSC_VER = 1300
MS VC++ 6.0 _MSC_VER = 1200
MS VC++ 5.0 _MSC_VER = 1100
在程序中加入_MSC_VER宏可以根据编译器版本让编译器选择性地编译一段程序。例如一个版本编译器产生的lib文件可能不能被另一个版本的编译器调用,那么在开发应用程序的时候,在该程序的lib调用库中放入多个版本编译器产生的lib文件。在程序中加入_MSC_VER宏,编译器就能够在调用的时根据其版本自动选择可以链接的lib库版本,如下所示。
#if _MSC_VER >= 1400 // for vc8, or vc9
#pragma comment( lib, "SomeLib-vc8-d.lib" )
#else if
#pragma comment( lib, "SomeLib-vc8-r.lib" )
#else if _MSC_VER >= 1310 // for vc71
#pragma comment( lib, "SomeLib-vc71-d.lib" )
#else if
#pragma comment( lib, "SomeLib-vc71-r.lib" )
#else if _MSC_VER >=1200 // for vc6
#ifdef _DEBUG
#pragma comment( lib, "SomeLib-vc6-d.lib" )
#else if
#pragma comment( lib, "SomeLib-vc6-r.lib" )
#endif
#endif