9
votes


I get an error when trying to compile a small c++ program
Error 87 fatal error C1189: #error : WINDOWS.H already included. MFC apps must not #include c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxv_w32.h 16

I made sure that the windows.h was not included in any of the project files I have. I am using a visual studio 2008 IDE

Any reason why ?

6

6 Answers

15
votes

reason why is because something is including Windows.h: the compiler is not lying to you.

Go to project Properties->Configuration Properties->C/C++->Advanced and set Show Includes to Yes. Then build, and the compiler will show you a list with every included file found, and in the order it finds it, hereby telling you which file eventually includes windows.h

9
votes

try and include afxcoll.h before stdafx.h. I had the same problem and it fixed it. See http://social.msdn.microsoft.com/forums/en-US/vcgeneral/thread/2ab6862f-0d90-467a-b283-f62f6aef96fe/ for the original discussion.

3
votes
#include "afxwin.h"         // MFC core and standard components
#include "afxext.h"         // MFC extensions

Adding these to my stdafx.h file sorted out that error..hope this helps someone else.

1
votes

Visual Studio by default will defile your program with a precompiled headers file, which may contain something which includes something which includes windows.h . Be sure to check in there.

1
votes

In your project go to Configuration Properties->C/C++ -> Precompiled Headers. Make sure the Precompiled Header setting is set to Use(/Yu).

This setting "Enables creation or use of a precompiled header during the build".

0
votes

The problem I had was the "stdafx.h" file is being included in the "StdAfx.h" file, and the file name in Configuration Properties->C/C++ ->Precompiled Headers was never updated from "stdafx.h" to "StdAfx.h".