⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 winsockhelper.h

📁 股票分析系统源码
💻 H
字号:
////////////////////////////////////////////////////////////////////////////////
// General utilities : WinSock helper classes
//
// Copyright (c) 2003 by Morning
// http://morningspace.51.net
// mailto:moyingzz@etang.com
//
// Permission to use, copy, modify, distribute and sell this program for any 
// purpose is hereby granted without fee, provided that the above copyright 
// notice appear in all copies and that both that copyright notice and this 
// permission notice appear in supporting documentation.
//
// It is provided "as is" without express or implied warranty.
////////////////////////////////////////////////////////////////////////////////

#ifndef _WINSOCK_HELPER_H_
#define _WINSOCK_HELPER_H_
//
#include <exception>
#include <string>
// #include <winsock2.h>
//
namespace MUtils {

class WinSockException : public std::exception
{
public:

    WinSockException(const std::string message = "")
     : _message(message)
    {
    }

    const char *what() const throw ()
    {
        return _message.c_str();
    }

private:

    std::string _message;
};

class WinSockHelper
{
public:

    WinSockHelper()
    {
        WSADATA wsaData;
        int result = WSAStartup(0x0002, &wsaData);

        if ( result != 0 )
        {
            throw WinSockException("WSAStartup error");
        }

        if ( wsaData.wVersion != 0x0002)
        {
            WSACleanup( );
            throw WinSockException("Winsock version not support");
        }
    }

    ~WinSockHelper() throw()
    {
        WSACleanup();
    }
};

} // namespace MUtils

#endif // _WINSOCK_HELPER_H_

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -