Danbias/Code/Network/NetworkDependencies/WinsockFunctions.cpp

39 lines
663 B
C++
Raw Normal View History

#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 );
if(bufLen)
{
retVal = lpMessage;
LocalFree(lpMessage);
return retVal;
}
2013-11-27 11:28:11 +01:00
//Added this if bufLen is 0
return retVal;
}