Drew Hall Drew Hall - 3 days ago 4x
C Question

How do I retrieve an error string from WSAGetLastError()?

I'm porting some sockets code from Linux to Windows.

In Linux, I could use

to convert an errno code into a human-readable string.

MSDN documentation shows equivalent strings for each error code returned from
, but I don't see anything about how to retrieve those strings. Will
work here too?

How can I retrieve human-readable error strings from Winsock?


As the documentation for WSAGetLastError says you can use FormatMessage to obtain a text version of the error message.

You need to set FORMAT_MESSAGE_FROM_SYSTEM in the dwFlags parameter and pass the error code as the dwMessage parameter.