Article ID: 950688 - Last Review: March 21, 2008 - Revision: 1.1

You may get compilation errors for afxsock.h

System TipThis article applies to a different operating system than the one you are using. Article content that may not be relevant to you is disabled.
Expand all | Collapse all
Source: Microsoft Support

RAPID PUBLISHING

RAPID PUBLISHING ARTICLES PROVIDE INFORMATION DIRECTLY FROM WITHIN THE MICROSOFT SUPPORT ORGANIZATION. THE INFORMATION CONTAINED HEREIN IS CREATED IN RESPONSE TO EMERGING OR UNIQUE TOPICS, OR IS INTENDED SUPPLEMENT OTHER KNOWLEDGE BASE INFORMATION.

Action

Compile/ Build VC++ projects that use afxsock.h header file and have defined _WIN32_WINNT less than 0x0501.

Result

Build fails with the following errors :



Error 1 error C2065: 'IPPROTO_IPV6' : undeclared identifier c:\program files (x86)\microsoft visual studio 8\vc\atlmfc\include\atlsocket.inl 130
Error 2 error C2065: 'SOCKADDR_STORAGE' : undeclared identifier c:\program files (x86)\microsoft visual studio 8\vc\atlmfc\include\afxsock.h 381
Error 3 error C2146: syntax error : missing ';' before identifier 'sockAddr' c:\program files (x86)\microsoft visual studio 8\vc\atlmfc\include\afxsock.h 381
Error 4 error C2065: 'sockAddr' : undeclared identifier c:\program files (x86)\microsoft visual studio 8\vc\atlmfc\include\afxsock.h 381
Error 5 error C2070: ''unknown-type'': illegal sizeof operand c:\program files (x86)\microsoft visual studio 8\vc\atlmfc\include\afxsock.h 382
Error 6 error C2070: ''unknown-type'': illegal sizeof operand c:\program files (x86)\microsoft visual studio 8\vc\atlmfc\include\afxsock.h 384
Error 7 error C2227: left of '->sin_port' must point to class/struct/union/generic type c:\program files (x86)\microsoft visual studio 8\vc\atlmfc\include\afxsock.h 394
Error 8 error C2146: syntax error : missing ';' before identifier 'sockAddr' c:\program files (x86)\microsoft visual studio 8\vc\atlmfc\include\afxsock.h 402
Error 9 error C2070: ''unknown-type'': illegal sizeof operand c:\program files (x86)\microsoft visual studio 8\vc\atlmfc\include\afxsock.h 403
Error 10 error C2070: ''unknown-type'': illegal sizeof operand c:\program files (x86)\microsoft visual studio 8\vc\atlmfc\include\afxsock.h 405
Error 11 error C2227: left of '->sin_port' must point to class/struct/union/generic type c:\program files (x86)\microsoft visual studio 8\vc\atlmfc\include\afxsock.h 415
Error 12 error C2146: syntax error : missing ';' before identifier 'sockAddr' c:\program files (x86)\microsoft visual studio 8\vc\atlmfc\include\afxsock.h 423
Error 13 error C2070: ''unknown-type'': illegal sizeof operand c:\program files (x86)\microsoft visual studio 8\vc\atlmfc\include\afxsock.h 424
Error 14 error C2070: ''unknown-type'': illegal sizeof operand c:\program files (x86)\microsoft visual studio 8\vc\atlmfc\include\afxsock.h 426
Error 15 error C2227: left of '->sin_port' must point to class/struct/union/generic type c:\program files (x86)\microsoft visual studio 8\vc\atlmfc\include\afxsock.h 436
Error 16 error C2146: syntax error : missing ';' before identifier 'sockAddrSelf' c:\program files (x86)\microsoft visual studio 8\vc\atlmfc\include\afxsock.h 450
Error 17 error C2065: 'sockAddrSelf' : undeclared identifier c:\program files (x86)\microsoft visual studio 8\vc\atlmfc\include\afxsock.h 450
Error 18 error C2070: ''unknown-type'': illegal sizeof operand c:\program files (x86)\microsoft visual studio 8\vc\atlmfc\include\afxsock.h 451
Error 19 error C2070: ''unknown-type'': illegal sizeof operand c:\program files (x86)\microsoft visual studio 8\vc\atlmfc\include\afxsock.h 453
Error 20 error C2228: left of '.ss_family' must have class/struct/union c:\program files (x86)\microsoft visual studio 8\vc\atlmfc\include\afxsock.h 470

Cause

Project has defined _WIN32_WINNT macro value less than minimum recommended for the Operating System, and Windows XP SP2 is minimum required for these structures.

For example, if you set _WIN32_WINNT to 0x0500 or less, you will get the listed errors.

Resolution

Change the preprocessor definition to a version higher or equal to the minimum recommended.
See Using the Windows Headers (http://msdn2.microsoft.com/en-us/library/aa383745.aspx)  for values to use.

If it is inherited from project defaults or parent project uncheck the following settings :
Project->Properties-> Configuration Properties->C/C++->Preprocessor->Preprocessor Definitions->inherit from parent or project defaults.

More Information

See also
SOCKADDR_STORAGE Structure (http://msdn2.microsoft.com/en-us/library/ms740504.aspx)

Note :
The WINVER and _WIN32_WINNT macros are legacy macros. You can also use the new macros starting with NTDDI_* ( for example NTDDI_VISTASP1 for Windows Vista SP1 ) (http://msdn2.microsoft.com/en-us/library/ms740504.aspx)

DISCLAIMER

MICROSOFT AND/OR ITS SUPPLIERS MAKE NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY, RELIABILITY OR ACCURACY OF THE INFORMATION CONTAINED IN THE DOCUMENTS AND RELATED GRAPHICS PUBLISHED ON THIS WEBSITE (THE “MATERIALS”) FOR ANY PURPOSE. THE MATERIALS MAY INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS AND MAY BE REVISED AT ANY TIME WITHOUT NOTICE.

TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, MICROSOFT AND/OR ITS SUPPLIERS DISCLAIM AND EXCLUDE ALL REPRESENTATIONS, WARRANTIES, AND CONDITIONS WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO REPRESENTATIONS, WARRANTIES, OR CONDITIONS OF TITLE, NON INFRINGEMENT, SATISFACTORY CONDITION OR QUALITY, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, WITH RESPECT TO THE MATERIALS.

APPLIES TO
  • Microsoft Visual Studio 2005 Express Edition
  • Microsoft Visual Studio 2005 Professional Edition
  • Microsoft Visual Studio 2005 Standard Edition
  • Microsoft Visual Studio 2005 Team Edition for Software Developers
  • Microsoft Visual Studio 2005 Team Edition for Software Architects
  • Microsoft Visual Studio 2005 Team Suite
Keywords: 
kbnomt kbrapidpub KB950688