Checking for errors

The WSAGetLastError Function

Description

The WSAGetLastError function retrieves the error code for the last unsuccessful call to a WinSock2 library function. Most WinSock2 library functions indicate failure by returning a particular value, and you have to call the WSAGetLastError function to find out the reason for the failure. The error code returned by this function is not effected by calls to WinSock2 library functions that succeed, or by calling this function to retrieve the error code. An error code of zero means that no WinSock2 library function has failed since you initialized the WinSock2 library (i.e. called the WSAStartUp function), or since you last set the error code to zero by calling the WSASetLastError function.

Declaration

The system include file WinSock2.inc contains the following declaration for the WSAGetLastError function:

function WSAGetLastError : integer;
  external dll='ws2_32.dll';

Arguments

None.

Return Values

See Description.

Reference Information

The authoritative source of information about the WinSock2 library is the Microsoft Developers Network (MSDN). You can access the MSDN on the Microsoft website at msdn.microsoft.com.