WSAStartup

Initializes the Windows Sockets API library.

Syntax

int WSAStartup(
  WORD                 wVersionRequested,
  LPWSADATA            lpWSAData
);
                

Parameters

  • wVersionRequested

    [in] The version of the Windows Sockets API specification that the calling application requests. The high byte of the word is the minor version number; the low byte is the major version number.

  • lpWSAData

    [out] A pointer to a WSADATA structure that receives details about the Windows Sockets implementation.

Return Value

  • If the function succeeds, the return value is zero. Otherwise, the return value is one of the Windows Sockets error codes.

Remarks

The WSAStartup function must be the first Windows Sockets function called by any application or DLL that uses the Windows Sockets API. It is used to load the Windows Sockets DLL and perform the necessary initializations for the Winsock environment.

The wVersionRequested parameter specifies the Winsock version that an application can support. The Winsock DLL checks if it supports the requested version, or a version that is backward compatible. If it does, it returns an information structure in lpWSAData and returns zero.

Applications should generally request the highest version of the Winsock specification that they can support. For example, to request Winsock version 2.2, the application should set wVersionRequested to MAKEWORD(2, 2).

If an application needs to support multiple versions, it can make multiple calls to WSAStartup with different version numbers. However, each call must be matched by a corresponding call to WSACleanup.

After a successful call to WSAStartup, an application must call WSACleanup before it terminates. Failure to do so can result in the termination of the entire process.

Requirements

Header: winsock2.h (include winsock.h for older versions)

Library: Ws2_32.lib

Minimum supported client: Windows 2000 Professional

Minimum supported server: Windows 2000 Server

DLL: Ws2_32.dll