我想把对话框程序作为服务器,控制台程序作为客户端,谁能给发个示例程序,谢谢了~~
[email protected]
我改孙鑫的老是有问题,谢谢帮忙~

解决方案 »

  1.   

    看孙鑫的代码的话,这个函数AfxSocketInit()是在MFC应用程序下才能用,我的控制台程序能用吗??
      

  2.   

    如果创建控制台程序的时候选择支持MFC就没问题
    不过一般还是直接用API,其实AfxSocketInit基本跟下面代码差不多,不过用的是1.1WORD 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; 
    }
      

  3.   

    控制台支持MFC,就可以使用AfxSocketInit.不然就是用WSAStartup() API好了
      

  4.   

    如果你使用的是vc6.0,通过下列步骤是你的控制台程序支持MFC
    1. 选择Project-》Setting
    2.  弹出Peoject Setting对话框,选择General。 
    3. 在Microsoft Foundation Classes选择Use MFC in a Shared DLL或Use MFC in a Static Library
      

  5.   

    对话框跟控制台有区别么,两者用的通信原理都是一样的 用的底层API也是一样的,难道你想问的是MFC跟控制台之间的区别么,MFC底层也是用API实现的。
      

  6.   

    程序通信的机制都是通过底层api函数进行的阿,而且都是通过消息队列进行消息传递,你也可以把客户端用对话框,服务器端用控制台程序啊!