views:

23

answers:

1

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

In Linux, I could use strerror() to convert an errno code into a human-readable string.

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

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

+3  A: 

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.

Charles Bailey
Thanks--I just discovered that myself. I need to remember to look at the online MSDN (vs. the off-line copy installed on my laptop!).
Drew Hall