自动初始化 winsock
#pragma once
#ifdef _WIN32
#include <WinSock2.h>
#pragma comment(lib,"ws2_32.lib")
//typedef unsigned char BYTE;
//typedef unsigned short WORD;
//#define MAKEWORD(a, b) ((WORD) (((BYTE) (a)) | ((WORD) ((BYTE) (b))) << 8))
#endif // !_WIN32
class CWinSockInit
{
public:
CWinSockInit(BYTE minorVer = 2, BYTE majorVer = 2)
{
#ifdef _WIN32
WSADATA wsaData;
WORD sockVersion = MAKEWORD(minorVer, majorVer);
if (::WSAStartup(sockVersion, &wsaData) != 0)
{
exit(0);
}
#endif
}
inline ~CWinSockInit()
{
#ifdef _WIN32
::WSACleanup();
#endif
}
};