WSACleanup返回SOCKET_ERROR, GetLastError() = 10091, network subsystem unavailable..why??

解决方案 »

  1.   

    问题描述的不太清楚,查看一下在相应的Winsock的库你添加到工程了没有?
    即在Project/Settings/Object/library modules下面加入了Ws2_32.lib 库。
      

  2.   

    #include <winsock2.h>#pragma comment (lib,"ws2_32.lib")/************************************************************************
    * Use global object to auto init & clearup.
    ************************************************************************/
    class AutoInitNetLib
    {
    public:
    AutoInitNetLib();
    ~AutoInitNetLib();
    static AutoInitNetLib g_autoInitLib;
    };
    AutoInitNetLib AutoInitNetLib::g_autoInitLib;AutoInitNetLib::AutoInitNetLib()
    {
    WSADATA wsaData;
    int Ret = 0;
    if ((Ret = WSAStartup(MAKEWORD(2,2), &wsaData)) != 0)
    {
    // NOTE: Since Winsock failed to load we cannot use 
    // WSAGetLastError to determine the specific error for
    // why it failed. Instead we can rely on the return 
    // status of WSAStartup.
    CString msg;
    msg.Format("WSAStartup failed with error %d\n", Ret);
    #ifdef _WINDOWS
    AfxMessageBox(msg, MB_OK | MB_ICONERROR);
    #else // _WINDOWS
    printf(msg);
    #endif // _WINDOWS
    }}
    AutoInitNetLib::~AutoInitNetLib()
    {
    WSACleanup();
    }//
    在~AutoInitNetLib()调用WSACleanup()返回SOCKET_ERROR,虽然貌似可以不管他??
      

  3.   

    调用WSAStartup和WSACleanup不是在同一线程吧???
      

  4.   

    AutoInitNetLib() 
    ~AutoInitNetLib() 我加了 TRACE("ThreadID=0x%x\n", GetCurrentThreadId());, 线程id是一样的.