本人在做一程序设计时,遇到以下麻烦:  
在调用WSAStartup(WORD  wVersionRequested,&WSAData)时,它说那WSAData非法表示,但我不知道如何改,如果你知道的话,请回答好吗?  
还有,在用到recv(SOCKET  s,char  FAR  *buf,int  len,int  flags),我在这里的flags是用NOT_FLAG_SET写,但它说我没有定义,我想问一问,我是不是要把flags写成0???

解决方案 »

  1.   

    WORD wVersionRequested;
    WSADATA wsaData;
    int err;
     
    wVersionRequested = MAKEWORD( 2, 2 );
     
    err = WSAStartup( wVersionRequested, &wsaData );
    if ( err != 0 ) {
        /* Tell the user that we could not find a usable */
        /* WinSock DLL.                                  */
        return;
    }
     
    /* Confirm that the WinSock DLL supports 2.2.*/
    /* Note that if the DLL supports versions greater    */
    /* than 2.2 in addition to 2.2, it will still return */
    /* 2.2 in wVersion since that is the version we      */
    /* requested.                                        */
     
    if ( LOBYTE( wsaData.wVersion ) != 2 ||
            HIBYTE( wsaData.wVersion ) != 2 ) {
        /* Tell the user that we could not find a usable */
        /* WinSock DLL.                                  */
        WSACleanup( );
        return; 
    }
      

  2.   

    Header: Declared in Winsock2.h.
      Library: Use Ws2_32.lib.
      

  3.   

    #include "winsock2.h"并在object->setting->linking:object/library modules中加入:wsock32.lib
      

  4.   

    WSAData是表示的一个数据类型,你需要声明一个
    WSAData data;flags你用0好了
      

  5.   

    第2个问题:你可以把flag设置为0。还有两个值是MSG_OOB,MSG_PEEK.0表试没有特殊的行为,一般可以设置成0。关于MSG_OOB是用于带外数据传输中的,什么是带外数据你要看一下相关的文档。