Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

This function gets the error status for the last operation that failed.

Syntax

int WSAGetLastError(void);

Parameters

None.

Return Value

The return value indicates the error code for this thread's last Windows Sockets operation that failed. For a list of error codes, see Winsock Error Codes.

Remarks

This function returns the last network error that occurred. When a particular Windows Sockets function indicates that an error has occurred, this function should be called to retrieve the appropriate error code. This error code can be different from the error code obtained from getsockopt (Windows Sockets)SO_ERROR, which is socket-specific because WSAGetLastErroris for all thread-specific sockets.

A successful function call, or a call to WSAGetLastError, does not reset the error code. To reset the error code, use the WSASetLastErrorfunction call with iErrorset to zero. A getsockoptSO_ERROR also resets the error code to zero.

The WSAGetLastErrorfunction should not be used to check for an error code on receipt of an asynchronous message. In this case, the error code is passed in the lParamparameter of the message, and this can differ from the value returned by WSAGetLastError.

Requirements

Header winsock2.h
Library Ws2.lib
Windows Embedded CE Windows CE 1.0 and later
Windows Mobile Windows Mobile Version 5.0 and later

See Also