Skip to content

Latest commit

 

History

History
27 lines (16 loc) · 1.42 KB

handling-winsock-errors.md

File metadata and controls

27 lines (16 loc) · 1.42 KB
description ms.assetid title ms.topic ms.date
Error Handling in Winsock.
81ed3328-4b15-43dc-88f1-573a4a97d672
Handling Winsock Errors
article
05/31/2018

Handling Winsock Errors

Most Windows Sockets 2 functions do not return the specific cause of an error when the function returns. Some Winsock functions return a value of zero if successful. Otherwise, the value SOCKET_ERROR (-1) is returned and a specific error number can be retrieved by calling the WSAGetLastError function. For Winsock functions that return a handle, a return value of INVALID_SOCKET (0xffff) indicates an error and a specific error number can be retrieved by calling WSAGetLastError. For Winsock functions that return a pointer, a return value of NULL indicates an error and a specific error number can be retrieved by calling the WSAGetLastError function.

A Winsock error code can be converted to an HRESULT for use in a remote procedure call (RPC) using HRESULT_FROM_WIN32. In earlier versions of the Platform Software Development Kit (SDK), HRESULT_FROM_WIN32 was defined as a macro in the Winerror.h header file. In the Microsoft Windows Software Development Kit (SDK), HRESULT_FROM_WIN32 is defined as an inline function in the Winerror.h header file.

Related topics

Windows Sockets Error Codes