1,众所周知使用CAsyncSocket类需要预编译头文件afxsock.h,并且使用函数AfxSocketInit()对Winsock对象进行初始化,请问CAsyncSocket类指定的是什么版本的Winsock?是不是1.1的?
2,如果使用Winsock2则要预编译头文件Winsock2.h,我在参考一些资料的时候发现,程序使用的是CAsyncSocket类,而在成员函数GetIP()中通过WSAStartup()直接指定了Winsock版本为2.0,根本没有预编译头文件Winsock2.h啊,是否存在某种情况使用Winsock2也不必预编译头文件Winsock2.h?3Q

解决方案 »

  1.   

    afxsock.h内容如下:// This is a part of the Microsoft Foundation Classes C++ library.
    // Copyright (C) Microsoft Corporation
    // All rights reserved.
    //
    // This source code is only intended as a supplement to the
    // Microsoft Foundation Classes Reference and related
    // electronic documentation provided with the library.
    // See these sources for detailed information regarding the
    // Microsoft Foundation Classes product.#ifndef __AFXSOCK_H__
    #define __AFXSOCK_H__#pragma once#ifdef _AFX_NO_SOCKET_SUPPORT
    #error Windows Sockets classes not supported in this library variant.
    #endif#ifndef __AFXWIN_H__
    #include <afxwin.h>
    #endif#if _WIN32_WINNT >= 0x0502
    #include <atlsocket.h>
    #else
        #include <winsock2.h>
        #include <mswsock.h>
    #endif  // _WIN32_WINNT#ifndef _WINSOCK2API_
    #ifdef _WINSOCKAPI_
    #error MFC requires use of Winsock2.h
    #endif
    #endif#ifdef _AFX_MINREBUILD
    #pragma component(minrebuild, off)
    #endif#ifndef _AFX_NOFORCE_LIBS/////////////////////////////////////////////////////////////////////////////
    // Win32 libraries#pragma comment(lib, "wsock32.lib")#endif //!_AFX_NOFORCE_LIBS/////////////////////////////////////////////////////////////////////////////#ifdef _AFX_PACKING
    #pragma pack(push, _AFX_PACKING)
    #endif