Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

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


Thanks,
Posted
Comments
Matthew Faithfull 15-Mar-13 3:22am    
Add one or more of these '178' errors to your post so we can see what we're really trying to solve.

Have you tried adding the #includes back in one at a time to see which one or more is causing the problem?

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

XML
#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.
 
Share this answer
 
v2
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).
 
Share this answer
 
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.
 
Share this answer
 
thanks from all of you
your solutions were good and applicational.

i solved it through the following method:

just add below precompile definitions :
C++
#ifdef __windows__
#undef __windows__
#endif


and thanks again
 
Share this answer
 
Comments
Jochen Arndt 9-Feb-15 8:16am    
Don't do this!

While this avoids the error message it does not solve the problem and breaks the MFC header file inclusion checks.

The only solution:
Don't include windows.h when using MFC. It will be included by the MFC header files using special mechanisms.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900