locked
Can't include afxsock.h if WINVER 0x400 RRS feed

  • Question

  • Trying to compile a project converted to VS2005 from 6.0.  Defining WINVER to 0x400 to allow win9x.  including afxsock.h gives many errors, pasting first few:

     

    J:\Microsoft Visual Studio 8\VC\atlmfc\include\atlsocket.inl(116) : error C2065: 'IPPROTO_IPV6' : undeclared identifier

    J:\Microsoft Visual Studio 8\VC\atlmfc\include\afxsock.h(381) : error C2065: 'SOCKADDR_STORAGE' : undeclared identifier

    J:\Microsoft Visual Studio 8\VC\atlmfc\include\afxsock.h(381) : error C2146: syntax error : missing ';' before identifier 'sockAddr'

    J:\Microsoft Visual Studio 8\VC\atlmfc\include\afxsock.h(381) : error C2065: 'sockAddr' : undeclared identifier

    J:\Microsoft Visual Studio 8\VC\atlmfc\include\afxsock.h(382) : error C2070: ''unknown-type'': illegal sizeof operand

    J:\Microsoft Visual Studio 8\VC\atlmfc\include\afxsock.h(384) : error C2070: ''unknown-type'': illegal sizeof operand

     

    Many more as well.

    If I set WINVER to 0x501, the errors go away.

    Is there a way to still target win9x platforms and use afxsock.h?

    Thanks!

    Friday, May 5, 2006 7:45 PM

Answers

  • Hi,

    Do you have Windows SDK for Vista installed by any chance? Because setting winver to 0x400 for VS2005 works just fine on my desktop. VS2005 ships Win2k3 SP1 PSDK and it supports targeting 0x400. However Windows SDK took a change recently (before Feb CTP) where most of headers were updated to check for 0x500 because as of today Windows SDK supports targetting of Win2k and newer OSes only.

    Nikola

    Friday, May 5, 2006 10:52 PM

All replies

  • Hi,

    Do you have Windows SDK for Vista installed by any chance? Because setting winver to 0x400 for VS2005 works just fine on my desktop. VS2005 ships Win2k3 SP1 PSDK and it supports targeting 0x400. However Windows SDK took a change recently (before Feb CTP) where most of headers were updated to check for 0x500 because as of today Windows SDK supports targetting of Win2k and newer OSes only.

    Nikola

    Friday, May 5, 2006 10:52 PM
  • Thanks, that was it exactly!

    Cheers

    Monday, May 8, 2006 6:08 PM
  •  

    You have it already working I guess :-), looking at the date of this topic.

    But for the others searching for the solution.

     

    By default only Windows XP still compiles...

    You have to help it a little to compile for windows 2000.

     

    Just open c:\program files\microsoft sdks\windows\v6.1\include\ws2def.h in VisualStudio.

     

    Press Control + 'G' to bring up the 'Go to line' dialog, and type 312, to jump to line 312

     

    Modify :

    #if(_WIN32_WINNT >= 0x0600)

    typedef SOCKADDR_STORAGE_LH SOCKADDR_STORAGE;

    typedef SOCKADDR_STORAGE *PSOCKADDR_STORAGE, FAR *LPSOCKADDR_STORAGE;

    #elif (_WIN32_WINNT >= 0x0501)

    typedef SOCKADDR_STORAGE_XP SOCKADDR_STORAGE;

    typedef SOCKADDR_STORAGE *PSOCKADDR_STORAGE, FAR *LPSOCKADDR_STORAGE;

    #endif

     

    Into:

    #if(_WIN32_WINNT >= 0x0600)

    typedef SOCKADDR_STORAGE_LH SOCKADDR_STORAGE;

    typedef SOCKADDR_STORAGE *PSOCKADDR_STORAGE, FAR *LPSOCKADDR_STORAGE;

    #elif (_WIN32_WINNT >= 0x0500) // Windows 2000 also please

    typedef SOCKADDR_STORAGE_XP SOCKADDR_STORAGE;

    typedef SOCKADDR_STORAGE *PSOCKADDR_STORAGE, FAR *LPSOCKADDR_STORAGE;

    #endif

     

    And line 406 from:

    #if(_WIN32_WINNT >= 0x0501)

    IPPROTO_IPV6 = 41, // IPv6 header

    IPPROTO_ROUTING = 43, // IPv6 Routing header

    IPPROTO_FRAGMENT = 44, // IPv6 fragmentation header

    IPPROTO_ESP = 50, // encapsulating security payload

    IPPROTO_AH = 51, // authentication header

    IPPROTO_ICMPV6 = 58, // ICMPv6

    IPPROTO_NONE = 59, // IPv6 no next header

    IPPROTO_DSTOPTS = 60, // IPv6 Destination options

    #endif//(_WIN32_WINNT >= 0x0501)

     

    to:

     

    #if(_WIN32_WINNT >= 0x0500) // Windows 2000

    IPPROTO_IPV6 = 41, // IPv6 header

    IPPROTO_ROUTING = 43, // IPv6 Routing header

    IPPROTO_FRAGMENT = 44, // IPv6 fragmentation header

    IPPROTO_ESP = 50, // encapsulating security payload

    IPPROTO_AH = 51, // authentication header

    IPPROTO_ICMPV6 = 58, // ICMPv6

    IPPROTO_NONE = 59, // IPv6 no next header

    IPPROTO_DSTOPTS = 60, // IPv6 Destination options

    #endif//(_WIN32_WINNT >= 0x0500)

     

    It seems to work OK :-)

     

    Tuesday, August 7, 2007 6:48 PM
  •  Nikola Dudar - MSFT (old name) wrote:

    Hi,

    Do you have Windows SDK for Vista installed by any chance? Because setting winver to 0x400 for VS2005 works just fine on my desktop. VS2005 ships Win2k3 SP1 PSDK and it supports targeting 0x400. However Windows SDK took a change recently (before Feb CTP) where most of headers were updated to check for 0x500 because as of today Windows SDK supports targetting of Win2k and newer OSes only.

    Nikola

     

    Looks more like the made it working for Windows XP.

    But we still need to maintain older/ancient operating systems like Windows 2000

    Tuesday, August 7, 2007 6:54 PM
  • Just include two header files.

    #include <winsock2.h>
    #include <ws2tcpip.h>

    it will get solved... 

    I have search many  quesiton but there was no proper answer... Thus i try this and it works.. check if it work for you...

    Thursday, March 1, 2012 8:56 AM