在VC2005中创建了一个MFC程序,但没有勾选Windows Socket,请问创建完成后还能不能添加了?谢谢!

解决方案 »

  1.   


    可以啊. 这个就是加了个头文件的引用, 如下,#include <afxsock.h> // MFC socket extensions
      

  2.   

    up。。也可以在StdAfx.h
    添加#include <WINSOCK2.H>
    #pragma comment(lib, "ws2_32.lib")
      

  3.   

    AfxSocketInit()加载的1.1的
    如果你要加载更高版本的socket,就必须手动添加了
    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 later    */
    /* 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; 
    }
     
    /* The WinSock DLL is acceptable. Proceed. */
      

  4.   

    如果对MFC自带的SOCKET不满意还可以自己引用winsock2.h ... ...自己动手封装套接字