文章类型: VC&C++
关键词: VC,_WIN32_WINDOWS,_WIN32_WINNT,WINVER,宏定义
内容摘要: _WIN32_WINDOWS、_WIN32_WINNT、WINVER等宏定义

VC中的_WIN32_WINDOWS、_WIN32_WINNT、WINVER等宏定义

2019/4/26 16:04:17    来源:apple    阅读:

它们是用于定义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 requiredValue for NTDDI_VERSION
Windows 8.1NTDDI_WINBLUE (0x06030000)
Windows 8NTDDI_WIN8 (0x06020000)
Windows 7NTDDI_WIN7 (0x06010000)
Windows Server 2008NTDDI_WS08 (0x06000100)
Windows Vista with Service Pack 1 (SP1)NTDDI_VISTASP1 (0x06000100)
Windows VistaNTDDI_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 2003NTDDI_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 XPNTDDI_WINXP (0x05010000)
 The following tables describe other macros used in the Windows header files.
Minimum system requiredMinimum 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 requiredMinimum 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

#ifdef _DEBUG

#pragma comment( lib, "SomeLib-vc8-d.lib" )

#else if

#pragma comment( lib, "SomeLib-vc8-r.lib" )

#endif

#else if _MSC_VER >= 1310 // for vc71

#ifdef _DEBUG

#pragma comment( lib, "SomeLib-vc71-d.lib" )

#else if

#pragma comment( lib, "SomeLib-vc71-r.lib" )

#endif

#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

↑ 上一篇文章:VC中判断操作系统版本 关键词:VC,判断,操作系统,版本 发布日期:2019/4/26 14:48:42
↓ 下一篇文章:SQLiteOpenHelper与SQLiteDatabase的使用 关键词:SQLiteOpenHelper,SQLiteDatab.. 发布日期:2019/4/30 9:39:16
相关文章:
如何将bmp格式的图片转换成8位256色且保证不失真呢 关键词:VC,ps,将,bmp图片,转换,8位,256色,不失真,faststone,image,vie.. 发布日期:2016-08-10 16:28
VC中的SetFont()修改字体大小及样式的问题 关键词:VC,SetFont,修改,字体,大小,样式 发布日期:2018-12-05 15:45
VC中,出现oxc0000005 读取位置oxddddddddd 时发生访问冲突,0xcccccccc、0xcdcdcdcd和 0xfeeefeee 异常值说明 关键词:VC,oxc0000005,读取,位置,oxddddddddd,0x0000000,发生,访问,.. 发布日期:2018-07-27 10:58
相关目录:.NETVC&C++JAVA
我要评论
正在加载评论信息......