如何解决错误c1190:MFC需要使用Winsock2.h? [英] How to solve error c1190 : MFC requires to use Winsock2.h ?

查看:711
本文介绍了如何解决错误c1190:MFC需要使用Winsock2.h?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以allah的名义



大家好



i使用visual C ++ 2008和i'一个包含c和c ++代码的项目。



项目正常工作但是当我向项目添加.cpp和.h文件时,项目



in the name of allah

hi everyone

i work with visual C++ 2008 and i'm a project that contains the c and c++ code together.

the project worked correctly but when i add a .cpp and a .h file to the project, the project

errors the c1189 : MFC requires to use winsock2.h









查看.cpp和.h文件中的代码是否正确,因为当我将这些文件添加到另一个mfc项目时会有效,



但是当添加到我的项目时会发生这个错误。



你能告诉我是什么问题是什么?



我的.h文件的第一部分如下:



___





.

look the codes in the .cpp and .h files are correctly because when i add these files to another mfc project will work,

but when add to my project this error will happen.

can you tell me what the problem is?

first part of the my .h file is like below :

___

#pragma once

#ifdef _WINDOWS_
#undef _WINDOWS_
#endif

#include <Afx.h>
#include <afxwin.h>
#include <atlimage.h>
#include <math.h>





___



另外我需要使用CWnd和CS tring和CImage,...我的项目中的类,因为这包括afxwin.h(用于CWnd)和atlimage.h(用于CImage)和....



所以我必须这样做,不是吗?



剩余部分.h文件是:



___





___

in addition i need to use the CWnd and CString and CImage ,... Classes in my project, because of this include the afxwin.h(for CWnd) and atlimage.h(for CImage) and ....

so i have to do these, don't i?

remaining part of .h file is :

___

class Object{
public:
    CImage Image;
    short int x,y;
};

class Theme : public CWnd{
private:
    
protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

public:
    CWnd  *Parent;
    CPoint cursor;
    bool drag;
    CString path,imagepath;
    char DialogMove;//0==top to center - 1==center to top - 2==center to down - 3==down to center
    char code,sb;//code = 0=main page - sb=show button=1=ascedung,-1=desceding;
    short int iimage,bstart,bend,//i = index of images-b = index of buttons
    ib;//ib=index of button for clicking and do code
    short int w, h,D;
    float ani_p, ani_max;
    bool ani,mousec;
    CRect WRect,rdesktop;
    CDC *cdc;
    short int lani;
    HWND hwndani;
    Object *Image;
    CRect *Rect;
    bool *BEnable;//enable of buttons-1 = enable
    unsigned char ButtonCount,ImageCount,SysButtonCount;
    bool Transparent;
    int EndMsg;//0=WM_CLOSE        1=PostMessage(IDOK)

    void GotoPage(unsigned char PageNo,unsigned char BStart,unsigned char BEnd);
    void ClearRect(short i,short j,COLORREF color);
    bool IsIn(CPoint point,CRect rect);
    bool IsInRect(CPoint point,CRect rect,CRect Rectangle);
    void Center2Top(int);
    void Top2Center();
    void Down2Center();
    void Center2Down();
    bool AddImage(unsigned char Index,CString ImagePath,unsigned short int X,short int Y);
    void AddButton(unsigned char Index,CRect rectangle,bool enable);
    void DrawImages(unsigned char alpha,int IImage);
    //Theme(unsigned char imagecount,unsigned char buttoncount,unsigned char sysbuttoncount);
    void Init(unsigned char imagecount,unsigned char buttoncount,unsigned char sysbuttoncount);
    ~Theme(void);
    bool CreateTheme(CRect rect,CWnd *parent,unsigned short int W,unsigned short int H,bool transparent);
    afx_msg void OnPaint();
    afx_msg void OnTimer(UINT_PTR nIDEvent);
    afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
    afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
    
    DECLARE_MESSAGE_MAP()
};





___



之后



在我的.cpp文件中我编写了函数体。



所以问题出在哪里?



非常感谢





感谢



___

after that

in my .cpp file i wrote the body of functions.

so where the problem is?

thanks alot


thanks

推荐答案

包含 afxsock.h 并且之前已包含 winsock.h 时会发生此错误。



使用MFC应用程序时,不应包含 windows.h winsock.h 。只需包含必要的MFC(afx *)头文件。它们将包括 windows.h winsock2.h 包含在 afxsock.h 中。



对于非MFC应用程序,您必须在 windows.h 之前包含 winsock2.h ,因为其中包含 winsock.h ,这会阻止 winsock2.h 被加载。



因为您使用MFC,请检查所有源文件和头文件,并删除 windows的所有内容。 h winsock.h 。如果您使用外部库(不是来自Microsoft)或源模块包含包含这些文件的头文件,这可能会很棘手。比你必须注释掉头文件中的内容。



对于源模块,可能需要在那里添加包含。



[更新]

从头文件中删除这些行:

This error occurs when including afxsock.h and winsock.h has been included before.

With MFC apps you should not include windows.h or winsock.h. Just include the necessary MFC (afx*) header files. They will include windows.h and winsock2.h is included by afxsock.h.

For non MFC apps, you must include winsock2.h before windows.h because that includes winsock.h which prevents winsock2.h from being loaded.

Because you use MFC, check all your source and header files and remove all inclusions of windows.h and winsock.h. This might be tricky if you use external libraries (not from Microsoft) or source modules with header files that have these files included. Than you must comment out the inclusion in the header files.

In the case of source modules it may be than necessary to add the includes there.

[UPDATE]
Remove these lines from your header file:
#ifdef _WINDOWS_
#undef _WINDOWS_
#endif



他们打破了Windows包含文件的错误检查。特别是使用MFC时不得包含 windows.h 的错误。


这篇关于如何解决错误c1190:MFC需要使用Winsock2.h?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆