您的位置:首页 > 移动开发

MFC apps must not #include <windows.h>

2016-06-04 15:06 453 查看
MFC apps must not #include <windows.h>

详细提示:

1>d:\program files (x86)\microsoft visual studio 8\vc\atlmfc\include\afxv_w32.h(16) : fatal error C1189: #error :  WINDOWS.H already included.  MFC apps must not #include <windows.h>

出错位置代码:

#ifdef _WINDOWS_

 #error WINDOWS.H already included.  MFC apps must not #include <windows.h>

#endif

最大的可能是:直接或间接包括afx_w32.h之前,直接或间接包括了windows.h。由于fx_w32.h和windows.h都使用了#pragma once,所以只有第一次include有效。

注意:VC开发环境会定义一个宏_WINDOWS_,和这个没关系,后面多一个下划线。

afxwin.h包括了afx.h,afx.h包括了afxver_.h,afxver_.h包括了afxv_w32.h,简称afxwin.h->afx.h->afxver_.h->afxv_w32.h。

类似的还有:afxmt.h->afx.h->afxver_.h->afxv_w32.h。

解决方案:

尽量不使用windows.h、winsock.h、winsock2.h,而是用afxwin.h和afxsock.h。猜测:前者以win开头,后者以afx开头。

afxsock.h先包括afxwin.h后包括winsock2.h。

验证环境:VC8(VS2005)

如何查看是哪个源文件直接或间接包括了windows.h?

看是在编译那个源文件时,报的错。如果看不清楚,builid->clean一下。

----

>正在编译...

1>testexeDlg.cpp

1>d:\program files (x86)\microsoft visual studio 8\vc\atlmfc\include\afxv_w32.h(16) : fatal error C1189: #error :  WINDOWS.H already included.  MFC apps must not #include <windows.h>

------

说明是testexeDlg.cpp直接或间接包括了windows.h。

已知某个源文件直接或间接包括了windows.h,如何知道此文件?

暂时注释掉此源文件和头文件的有效代码,然后依次注释include语句。

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: