The Windows Sockets WSAGetLastError function gets the error status for the last operation that failed.
int WSAGetLastError (void);
The WSAGetLastError 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 SO_ERROR, which is socket-specific since WSAGetLastError is 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 WSASetLastError function call with iError set to zero. A getsockopt SO_ERROR also resets the error code to zero.
The WSAGetLastError function should not be used to check for an error value on receipt of an asynchronous message. In this case, the error value is passed in the lParam field of the message, and this can differ from the value returned by WSAGetLastError.
The return value indicates the error code for this thread's last Windows Sockets operation that failed.
Windows NT: Yes
Windows: Yes
Windows CE: Use version 1.0 and later.
Header: Declared in winsock2.h.
Import Library: Link with ws2_32.lib.