1. 程式人生 > >error C2065錯誤帶來的作業系統版本問題

error C2065錯誤帶來的作業系統版本問題

Windows新版API往往需要檢測系統版本,方便執行不同的API函式,這在vs2008之後的版本似乎更加加強了,這裡查閱了資料,看了一下系統巨集定義,希望對大家進行軟體特別是進行作業系統識別是有好處。

新版本的API,或者控制元件的新特性(比如新版的ComCtl32.dll)的時候,你可能會得到“error C2065: undeclared identifier.“這個錯誤。原因是這些功能是依賴於你的作業系統的版本的。而你的標頭檔案中的定義並不是最新的。(對於MFC,就是stdafx.h)下面詳細列舉了每個Windows版本對應的NTDDI_VERSION_WIN32_WINNTWINVER

_WIN32_IE這些巨集。

The following table describes the preferred macros in use by the Windows header files.

Minimum system required                Macros to define
Windows Server 2008                     NTDDI_VERSION >= NTDDI_LONGHORN
Windows Vista                                NTDDI_VERSION >= NTDDI_VISTA
Windows Server 2003 SP1                 NTDDI_VERSION >= NTDDI_WS03SP1
Windows Server 2003                     NTDDI_VERSION >= NTDDI_WS03
Windows XP SP2                          NTDDI_VERSION >= NTDDI_WINXPSP2
Windows XP SP1                          NTDDI_VERSION >= NTDDI_WINXPSP1
Windows XP                                  NTDDI_VERSION >= NTDDI_WINXP
Windows 2000 SP4                        NTDDI_VERSION >= NTDDI_WIN2KSP4
Windows 2000 SP3                        NTDDI_VERSION >= NTDDI_WIN2KSP3
Windows 2000 SP2                        NTDDI_VERSION >= NTDDI_WIN2KSP2
Windows 2000 SP1                        NTDDI_VERSION >= NTDDI_WIN2KSP1
Windows 2000                                NTDDI_VERSION >= NTDDI_WIN2K

The following table describes the legacy macros in use by the Windows header files.

Minimum system required                 Macros to define
Windows Server 2008                      _WIN32_WINNT>=0x0600
                                                         WINVER>=0x0600
 
Windows Vista                            _WIN32_WINNT>=0x0600
                                                     WINVER>=0x0600
 
Windows Server 2003                      _WIN32_WINNT>=0x0502
                                                          WINVER>=0x0502
 
Windows XP                               _WIN32_WINNT>=0x0501
                                                       WINVER>=0x0501
 
Windows 2000                             _WIN32_WINNT>=0x0500
                                                      WINVER>=0x0500
 
Windows NT 4.0                           _WIN32_WINNT>=0x0400
                                                       WINVER>=0x0400
 
Windows Me                               _WIN32_WINDOWS=0x0500
                                                       WINVER>=0x0500
 
Windows 98                               _WIN32_WINDOWS>=0x0410
                                                   WINVER>=0x0410
 
Windows 95                               _WIN32_WINDOWS>=0x0400
                                                    WINVER>=0x0400
 
Internet Explorer 7.0                        _WIN32_IE>=0x0700
Internet Explorer 6.0 SP2                 _WIN32_IE>=0x0603
Internet Explorer 6.0 SP1                 _WIN32_IE>=0x0601
Internet Explorer 6.0                        _WIN32_IE>=0x0600
Internet Explorer 5.5                         _WIN32_IE>=0x0550
Internet Explorer 5.01                        _WIN32_IE>=0x0501
Internet Explorer 5.0, 5.0a, 5.0b          _WIN32_IE>=0x0500
Internet Explorer 4.01                       _WIN32_IE>=0x0401
Internet Explorer 4.0                          _WIN32_IE>=0x0400
Internet Explorer 3.0, 3.01, 3.02        _WIN32_IE>=0x0300 

後附一個科學上網利器,大家懂得!