I need to get the system host name for which I am using gethostname function
But its failing with error code 10093 which is
Successful WSAStartup not yet performed. Either the application has
not called WSAStartup or WSAStartup failed. The application may be
accessing a socket that the current active task does not own (that is,
trying to share a socket between tasks), or WSACleanup has been called
too many times.
#pragma comment(lib, "Ws2_32.lib")
hostname = '\0';
int err = WSAGetLastError();
if (WSAStartup (MAKEWORD(2,2), &WSAData) != 0)
MessageBox (NULL, TEXT("WSAStartup failed!"), TEXT("Error"), MB_OK);
It is written in the link you posted:
WSAStartupcall must occur before using this function.
WSAStartup, check its return code, if all went well, call