Danbias/Code/Network/NetworkDependencies/WinsockFunctions.cpp

44 lines
762 B
C++
Raw Normal View History

#ifndef INCLUDE_WINSOCK_LIB
#define INCLUDE_WINSOCK_LIB
#pragma comment(lib, "ws2_32.lib")
#endif
#include "WinsockFunctions.h"
#include <WinSock2.h>
2013-11-26 13:45:03 +01:00
bool InitWinSock()
{
WSADATA wsaData;
return WSAStartup(MAKEWORD(2, 2), &wsaData) == NO_ERROR;
}
2013-11-26 13:45:03 +01:00
void ShutdownWinSock()
{
WSACleanup();
2013-11-26 13:45:03 +01:00
}
std::wstring GetErrorMessage(int errorCode)
{
LPWSTR lpMessage;
std::wstring retVal(L"Succesful");
2013-12-04 09:36:43 +01:00
DWORD bufLen = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS ,
2013-11-26 13:45:03 +01:00
NULL,
errorCode ,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT) ,
(LPWSTR)&lpMessage,
0 ,
NULL );
2013-12-10 08:32:08 +01:00
2013-11-26 13:45:03 +01:00
if(bufLen)
{
retVal = lpMessage;
LocalFree(lpMessage);
return retVal;
}
2013-11-27 11:28:11 +01:00
//Added this if bufLen is 0
return retVal;
}