我从CSocket继承了一个类,然后运行create(),结果失败了。
请问哪些情况下运行create()会失败?
还有create()是干什么用的?

解决方案 »

  1.   

    在stdafx()里,#include <afxsock.h>
    在initinstance里需要调用afxinitsocket();
    create创建一个socket对象
      

  2.   

    1#include <afxsock.h>2afxinitsocket()
      

  3.   

    1.在stdafx.h文件里,#include <afxsock.h>
    2.在CxxApp的initinstance()里需要调用
    afxinitsocket();
    代码如下:
    BOOL CTestModuleApp::InitInstance()
    {
    //Update by Daniel Zhu
    if (!AfxSocketInit())
    {
    AfxMessageBox(_T("Windows 通信端口初始化失败"));
    return FALSE;
    }
    //AfxMessageBox("Windows 通信端口初始化成功");
        return CWinApp::InitInstance();
    }
      

  4.   

    这是因为你创建工程的时候没有选择Socket支持。
    你按照alphapiao(奉旨灌水钦差)的方法就可以解决
      

  5.   

    CSocket::Create()是建立了一个socket,估计调用的是API函数socket()
    下面是他的错误码
    Error code Meaning 
    WSANOTINITIALISED A successful WSAStartup call must occur before using this function. 
    WSAENETDOWN The network subsystem or the associated service provider has failed. 
    WSAEAFNOSUPPORT The specified address family is not supported. 
    WSAEINPROGRESS A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function. 
    WSAEMFILE No more socket descriptors are available. 
    WSAENOBUFS No buffer space is available. The socket cannot be created. 
    WSAEPROTONOSUPPORT The specified protocol is not supported. 
    WSAEPROTOTYPE The specified protocol is the wrong type for this socket. 
    WSAESOCKTNOSUPPORT The specified socket type is not supported in this address family. 
    建议楼主看MSDN好了!