Using WSAStartup to Initialize Winsock

Calling the WSAStartup function initializes the Winsock.dll and a WSADATA structure that contains the details of the Winsock implementation. When an application or DLL has finished using the Winsock.dll, it must call WSACleanup to enable the Winsock.dll to free any resources for the application. For every call to WSAStartup, there must be a call to WSACleanup.

The following code example shows how to use WSAStartup:

if (WSAStartup (MAKEWORD(1,1), &WSAData) != 0) 
{
  MessageBox (NULL, TEXT("WSAStartup failed!"), TEXT("Error"), MB_OK);
  return FALSE;
}

If successful, WSAStartup returns 0. After WSAStartup returns, an application cannot call WSAGetLastError to determine the error value as is normally done with Winsock functions.

The WSADATA structure pointed to by lpWSAData stores Winsock initialization data returned by a call to WSAStartup. WSADATA contains Winsock.dll implementation data. An application or DLL can call WSAStartup repeatedly if it needs to obtain the WSADATA structure data more than once.

The following table show values that WSAStartup assigns to the members of WSADATA.

WSADATA member
Assigned value
wVersion 1.1
wHighVersion 1.1
szDescription NULL string
szSystemStatus NULL string
iMaxSockets 20
iMaxUdpDg 0
lpVendorInfo NULL