致命错误C1189:#error:WINDOWS.H已包含在内。 MFC应用程序不得#include [英] fatal error C1189: #error : WINDOWS.H already included. MFC apps must not #include

查看:1060
本文介绍了致命错误C1189:#error:WINDOWS.H已包含在内。 MFC应用程序不得#include的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在我的项目中包含一些头文件后,它显示以下错误。当我删除这些语句时,它显示的是'178'数字的批量错误。我检查了哪个是那些包括files.Can任何人帮助我如何删除该错误。



Hi,
In my project after including some header files,it is showing the below error.When I removed those statements it is showing a bulk error of '178' numbers.And I checked which are those including files.Can anyone help me how can I remove that error.

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





谢谢,



Thanks,

推荐答案

这可能有助于某人。我从UnitTest项目得到了同样的错误。

我将stdafx.h更改为:



This may help someone. I got the same error from a UnitTest project.
I changed my stdafx.h to this:

#include "targetver.h"

#include <afx.h>
#include <afxwin.h>         // MFC core and standard components

// Headers for CppUnitTest
#include "CppUnitTest.h"

// TODO: reference additional headers your program requires here





...和错误去了。



... and the error went.


以下是我用于#include文件的一些规则,可能对您有所帮助:

- 使用预编译的头文件(#include< ; stdafx.h中>中)。这必须是.cpp文件中的第一个包含。它永远不应该在.h文件中。 [我还经常在多项目环境中将文件重命名为特定于项目的项目(例如,util_stdafx.h),以便在某处不包含错误的文件。您可以选择是否执行此操作...]

- stdafx.h文件包含后应立即与您的.cpp文件对应的#include。这样,.h文件将包含正常工作所需的任何内容。

- 在.cpp文件中包含这两个文件后,包括.cpp文件正常运行所需的任何其他内容。

- 编译器附带的头文件称为稳定头。这些应该是stdafx.h中出现的唯一内容,以及这些头文件使用的#defines(例如WIN3​​2_LEAN_AND_MEAN,_WIN32_WINNT等)。如果你在windows上,那么stdafx.h是唯一你应该看到的地方#include< windows.h>

- 头文件中的第一个非空白非注释行应该是#pragma once或保护块定义(或两者)。
Here are some of the rules I use for #include files which might be helpful to you:
- Use precompiled headers ("#include <stdafx.h>"). This must be the first include in your .cpp file. It should never be in a .h file. [I also routinely rename the file to something project specific (eg. util_stdafx.h) in a multi-project environment so that the wrong file is not included somewhere. You can choose whether or not to do this...]
- Immediately after the stdafx.h file include should be the #include corresponding to your .cpp file. This way, the .h file will #include anything it needs to work properly.
- After these 2 includes in your .cpp file, include anything else needed for the .cpp file to run correctly.
- Header files that come with the compiler are called "Stable headers". These should be the only ones that appear in stdafx.h, along with #defines used by these headers (eg. WIN32_LEAN_AND_MEAN, _WIN32_WINNT etc.). If you are on windows, then stdafx.h is the only place you should see "#include <windows.h>"
- The first non-blank non-comment lines in header files should be either "#pragma once" or guard block definition (or both).


检查`windows.h`可能包含在`stdafx.h`文件中。如果是这样,然后注释`Windows.h`然后检查,错误可能会消失。因为我有同样的问题,我也以同样的方式解决。
Check probably `Windows.h` might be included in your `stdafx.h` file. If so, then comment `Windows.h` and then check, the error may go off. Because I had the same problem I resolve in same way.


这篇关于致命错误C1189:#error:WINDOWS.H已包含在内。 MFC应用程序不得#include的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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