zoukankan      html  css  js  c++  java
  • 解决Winsock2.h和afxsock.h定义冲突的办法

    如果我们在工程中使用了afxsock.h,但在其它的地方又加了些 使用winsock2.h,哈哈,VC会告诉你一大堆错误,大意就是有定义重复,该怎么解决?

    由于MFC的SOCKET类使用的是Winsock1.1,而Winsock2.h是2.0的版本,两个版本中的一些定义就会出现冲突,解决的方式就是在stdafx.h中先定义winsock2.h,然后在定义afxsock.h

    使用时还需要加载库文件:#pragma comment(lib, "ws2_32.lib")

    #if !defined(AFX_STDAFX_H__57EF9120_2A16_4B54_9878_0A0B41C2B505__INCLUDED_) #define AFX_STDAFX_H__57EF9120_2A16_4B54_9878_0A0B41C2B505__INCLUDED_

    #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000

    #define VC_EXTRALEAN   // Exclude rarely-used stuff from Windows headers

    #include <afxwin.h>          // MFC core and standard components #include <afxext.h>          // MFC extensions #include <afxdisp.h>         // MFC Automation classes #include <afxdtctl.h>   // MFC support for Internet Explorer 4 Common Controls #ifndef _AFX_NO_AFXCMN_SUPPORT #include <afxcmn.h>    // MFC support for Windows Common Controls #endif // _AFX_NO_AFXCMN_SUPPORT

    #include <Winsock2.h> #include <afxsock.h>   // MFC socket extensions

    //{{AFX_Insert_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line.

    #endif // !defined(AFX_STDAFX_H__57EF9120_2A16_4B54_9878_0A0B41C2B505__INCLUDED_)

  • 相关阅读:
    好久没有上来,发布几个日志类
    这些天很忙,写一个类似防火墙的东西在WINSOCK2 SPI上做DLL,终于把问题解决了,现提供完整C++项目下载
    Flask学习之搭建环境
    年底总结前序
    3月13日的合照一张
    我也是个张三
    读《广州的一场春梦》有感
    四期合照,纪念小杨离开
    深夜的伤感
    随感,未写先累
  • 原文地址:https://www.cnblogs.com/xiaxiaosheng/p/3221420.html
Copyright © 2011-2022 走看看