Partager via


Winsock and the new SDK Headers

As you may have noticed in the recent Vista CTP SDK, the Winsock headers have undergone some changes. First, instead of a couple monolithic files (winsock2.h and mswsock.h), they have been split into a number of smaller files for ease of maintenance as well as for use by other components that don't necessarily load Winsock but need to use some of its defines. For example, device drivers that need protocol and structure definitions might only include ws2def.h instead of winsock2.h which pulls in a bunch of conflicting SDK definitions (since the driver already pulls in DDK definitions).

The other major change is header versioning. Recently all the Windows header files have been versioned to only define constants, structures, and APIs if the source is explicitly compiled for a Windows OS version that supports those definitions.  This allows developers to use one set of headers that can be compiled for any target Windows OS. Unfortunately, this also means if you don't define _WIN32_WINNT at all, many of the definitions are not declared at all.

The good news is the downloadable SDK does set this define according to the target OS selected when running under the SDK environment. However, Visual Studio does not set this define. Therefore if your build environment of choice is VS, you may need to set this define in your project in order to compile correctly for your targeted OS.

To target a project for Vista, _WIN32_WINNT should be set to 0x0600. For a complete list of OS target version numbers, see the following KB article:

https://msdn.microsoft.com/library/default.asp?url=/library/en-us/winprog/winprog/using_the_windows_headers.asp

-Anthony Jones (AJones)