SDK的使用有些需要注意的地方:例如Microsoft Platform SDK, August 2001 Edition版本的SDK,他的目标系统是Microsoft Windows® 95, Microsoft Windows NT® 4.0, Microsoft Windows® 98, Microsoft Windows Millennium Edition (Windows Me), Microsoft Windows 2000, Microsoft Windows XP, and Microsoft Windows .NET Server 。 如果你写的程序准备在Win 95上运行,但是使用了Win 98才有的特性,那么该程序在Win 95上运行时就会出问题。 所以SDK必须对程序的目标平台加以评估,决定是否可以提供相应功能给用户。 SDK通过宏来实现这个目标,给不同的系统定义不同的数字,这样你在VC中用宏定义程序的目标运行平台,SDK根据你的定义决定开放哪些功能。 SDK使用下面的方法决定提供哪些功能:
Guard StatementMeaning#if _WIN32_WINNT >= 0x0400Windows NT 4.0 and later. It is not implemented in Windows 95.#if _WIN32_WINDOWS >= 0x0410Windows 98. The image may not run on Windows 95. #if _WIN32_WINDOWS >= 0x0490Windows Me. The image may not run on Windows 95/98, Windows NT, or Windows 2000.#if _WIN32_WINNT >= 0x0500Windows 2000. The image may not run on Windows 95/98 or Windows NT.#if _WIN32_WINNT >= 0x0501Windows XP. The image may not run on Windows 95/98, Windows NT, Windows Me, or Windows 2000.#if _WIN32_IE >= 0x0300Internet Explorer 3.0 and later.#if _WIN32_IE >= 0x0400Internet Explorer 4.0 and later.#if _WIN32_IE >= 0x0401Internet Explorer 4.01 and later.#if _WIN32_IE >= 0x0500Internet Explorer 5.0 and later.#if _WIN32_IE >= 0x0501Internet Explorer 5.01 and later.#if _WIN32_IE >= 0x0560Internet Explorer 6.0 and later #if _WIN32_IE >= 0x0600Internet Explorer 6.0 and later平台定义如下,需要在代码中加上下面某个宏定义指定你的目标平台是哪个:
Minimum System RequiredMacros to DefineWindows 95 and Windows NT 4.0WINVER=0x0400Windows 98 and Windows NT 4.0_WIN32_WINDOWS=0x0410 and WINVER=0x0400Windows NT 4.0_WIN32_WINNT=0x0400 and WINVER=0x0400Windows 98_WIN32_WINDOWS=0x0410Windows 2000_WIN32_WINNT=0x0500 and WINVER=0x0500Windows Me_WIN32_WINDOWS=0x0490Windows XP and Windows .NET Server_WIN32_WINNT=0x0501 and WINVER=0x0501Internet Explorer 3.0, 3.01, 3.02_WIN32_IE=0x0300Internet Explorer 4.0_WIN32_IE=0x0400Internet Explorer 4.01_WIN32_IE=0x0401Internet Explorer 5.0, 5.0a, 5.0b_WIN32_IE=0x0500Internet Explorer 5.01, 5.5_WIN32_IE=0x0501Internet Explorer 6.0_WIN32_IE=0x0560 or_WIN32_IE=0x0600
例如:Win98之前的系统不提供多显示器相关APISDK中有相应的定义,表示只有Win 98以上的系统可以使用下面的内容:#if(WINVER >= 0x0500) #define SM_XVIRTUALSCREEN 76 #define SM_YVIRTUALSCREEN 77 #define SM_CXVIRTUALSCREEN 78 #define SM_CYVIRTUALSCREEN 79 #define SM_CMONITORS 80 #define SM_SAMEDISPLAYFORMAT 81 #endif /* WINVER >= 0x0500 */
如果你的程序打算在Win95上运行,程序定义了 #define WINVER=0x0400。那么使用SM_CMONITORS时,编译器就会报错,说找不到该符号。 提示: 使用了Windows宏,如果编译器报告找不到定义,那么可能就是SDK对你定义的目标系统不提供支持,你需要在程序中提高你目标系统的定义,例如#define WINVER 0x0500,这样就可以使用编译通过了!