關於_WIN32_WINNT

來源:互聯網
上載者:User

本打算瞭解一下纖程內容,在試圖使用
ConvertThreadToFiber的時候,編譯總是出錯,提示資訊如下:error C2065:
'ConvertThreadToFiber' : undeclared
identifier,編譯器告訴我“函數未聲明”。於是轉而查看MSDN,有內容如下:

Requirements:

Windows NT/2000: Requires Windows NT 3.51 SP3 or later.
Windows 95/98: Requires Windows 98.
Header: Declared in Winbase.h; include Windows.h.
Library: Use Kernel32.lib.  

但明明已經#include
<Windows.h>了。不得已,又經Windows.h進入Winbase.h中,查看源碼,見聲明之前有條件編譯語
句:#if(_WIN32_WINNT >=
0x0400),由此發現我的程式並沒有聲明宏_WIN32_WINNT。最終在StdAfx.h檔案的#include
<windows.h>語句之前添加語句:

#define _WIN32_WINNT 0x0400

編譯通過。

理解_WIN32_WINNT的作用:

需要你自已在stdafx.h標頭檔中定義。編譯器根據此宏來確定windows的版本,如果你需要使用高版本的WIN32函數,只有你定義了此宏後才能使用
    
Windows   XP                                      _WIN32_WINNT>=0x0501    
Windows   2000                                   _WIN32_WINNT>=0x0500    
Windows   NT   4.0                               _WIN32_WINNT>=0x0400    
Windows   Me                                      _WIN32_WINDOWS=0x0490    
Windows   98                                      _WIN32_WINDOWS>=0x0410    
Internet   Explorer   6.0                         _WIN32_IE>=0x0600    
Internet   Explorer   5.01,   5.5                _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

PS:當然也可以在程式的C++的前置處理器中設定。

------------------------------------------------------------------------

MSDN中的描述

Using   the   SDK   Headers  
   
  This   version   of  
the   Microsoft&reg;   Platform   SDK   enables   you   to   create
  applications   that   run   on   Microsoft   Windows&reg;   95,  
Microsoft   Windows   NT&reg;   4.0,   Windows&reg;   98,  
Windows   Millennium   Edition   (Windows   Me),   Windows   2000,  
Windows   XP,   and   Windows   .NET   Server   2003   family.   You  
can   also   create   64-bit   applications.   The   header   files  
use   data   types   that   allow   you   to   build   both   32-   and
  64-bit   versions   of   your   application   from   a   single  
source   code   base.   For   more   information,   see   Getting  
Ready   for   64-bit   Windows.  
   
   
 
Microsoft&reg;   Visual   C++&reg;   includes   content   from
  the   edition   of   the   Platform   SDK   that   was   current   at
  the   time   Visual   C++   was   released.   Therefore,   if   you  
install   the   latest   Platform   SDK,   you   may   end   up   with
  multiple   versions   of   the   same   header   files   on   your  
computer.   To   ensure   that   you   are   using   the   latest  
version   of   the   SDK   header   files,   follow   the   directions
  included   in   Installing   the   Platform   SDK   with   Visual  
Studio.   Otherwise,   you   will   receive   the   following   error  
when   compiling   code   that   uses   features   that   were  
introduced   after   Visual   C++   was   released:   error   C2065:  
undeclared   identifier.  
   
  Certain   functions   that
  depend   on   a   particular   version   of   Windows   are  
declared   using   conditional   code.   This   enables   you   to  
use   the   compiler   to   detect   whether   your   application  
uses   functions   that   are   not   supported   on   its   target  
version(s)   of   Windows.   To   compile   an   application   that  
uses   these   functions,   you   must   define   the   appropriate  
macros.   Otherwise,   you   will   receive   the   C2065   error  
message.   The   following   table   indicates   the   macros   you  
must   define   to   target   each   system.  
   
  Minimum   system   required   Macros   to   define    
  Windows   .NET   Server   2003   family   _WIN32_WINNT>=0x0502    
  Windows   XP   _WIN32_WINNT>=0x0501    
  Windows   2000   _WIN32_WINNT>=0x0500    
  Windows   NT   4.0   _WIN32_WINNT>=0x0400    
  Windows   Me   _WIN32_WINDOWS=0x0490    
  Windows   98   _WIN32_WINDOWS>=0x0410    
  Internet   Explorer   6.0   _WIN32_IE>=0x0600    
  Internet   Explorer   5.01,   5.5   _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    
   
   
  For   example,   to   use   the   features   specifically   marked  
for   Windows   2000   in   the   header   files,   you   need   to  
explicitly   define   _WIN32_WINNT   as   0x0500   or   greater.   You
  can   define   the   symbols   using   the   #define   statement   in
  each   source   file,   or   by   specifying   the  
/D_WIN32_WINNT=0x0500   compiler   option   supported   by   Visual  
C++.  
   
  Visual   C++   6.0:     To   specify  
compiler   options,   go   to   the   Projects   menu   and   click  
Settings,   then   select   the   C/C++   tab.  
   
  Visual   C++   7.0:     To   specify   compiler   options,   go   to   the   Projects   menu   and   click   Properties.  
   
  The   macros   in   Win32.mak   can   help   you   define   the  
correct   macros.   The   value   of   _WIN32_WINNT   depends   on  
the   platform   you   choose   to   target.   For   more  
information,   see   Building   Applications   Using   Win32.mak.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.