日期:2014-05-17  浏览次数:20978 次

error C2664: “bind”: 不能将参数 1 从“sockaddr_in”转换为“SOCKET”
如题,这个错误不知道怎么修改。是我要自己重新重载=?还是该怎么解决?在google 上没有找到解决办法。大神们帮忙!

------解决方案--------------------
你参数传错了
------解决方案--------------------
给你一个例子:
C/C++ code
    WSADATA wsaData;
    SOCKET ServerSocket;
    SOCKET NewSocket;
    SOCKADDR_IN ServerAddr;
    SOCKADDR_IN ClientAddr;
    int ClientAddrLen;
    int ServerPort = 4000;
    char ReceiveBuffer[1024];
    int Result;
    int ReceiveLen;
    if ((Result = WSAStartup(MAKEWORD(2, 2), &wsaData)) != 0)
    {
        printf("WSAStartup failed with error %d\n", Result);
        return ;
    }
    ServerSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    if (ServerSocket < 0)
    {
        printf("socket failed with error %d\n", WSAGetLastError());
        return ;
    }
    //memset(&ServerAddr, 0, sizeof(ServerAddr));
    ServerAddr.sin_family = AF_INET;
    ServerAddr.sin_port = htons(ServerPort);
    ServerAddr.sin_addr.s_addr = htonl(INADDR_ANY);
    //ServerAddr.sin_addr.s_addr = inet_addr("202.11.11.1" );
    Result = bind(ServerSocket, (SOCKADDR*) &ServerAddr, sizeof(ServerAddr));
    if (Result < 0)
    {
        printf("bind failed with error %d\n", WSAGetLastError());
        return ;
    }