Solved

Fatal Error C1189

Posted on 2009-07-02
20
1,957 Views
Last Modified: 2013-12-14
Hi

I am getting this error

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

This error is not coming on my machine but it is coming when I put the code on other's machine.
0
Comment
Question by:KaranGupta
  • 8
  • 8
  • 4
20 Comments
 
LVL 40

Expert Comment

by:evilrix
ID: 24770398
Do both machines have the same versions of Visual Studio installed?
0
 

Author Comment

by:KaranGupta
ID: 24770452
Yes

0
 
LVL 40

Expert Comment

by:evilrix
ID: 24770479
Same service pack levels too (VS service packs not OS)?
Are you able to do a clean install of VS on a clean machine (recently imaged) to see what happens?
What version of VS are you building with and what service pack level does it have?
Are you able to recreate the issue with a small test program?

Sorry, lots of questions I know but currently there isn't enough info to assist you in diagnosing the issue. :)
0
 

Author Comment

by:KaranGupta
ID: 24770488
Same service pack levels too (VS service packs not OS)?
[Karan]: Yes
Are you able to do a clean install of VS on a clean machine (recently imaged) to see what happens?
[Karan]: At this point of time I can do this
What version of VS are you building with and what service pack level does it have?
[Karan]: VS 2008 with service pack 1
Are you able to recreate the issue with a small test program?
[Karan]: Yes
0
 
LVL 40

Expert Comment

by:evilrix
ID: 24770548
>> Are you able to do a clean install of VS on a clean machine (recently imaged) to see what happens?
>> [Karan]: At this point of time I can do this

Then that might be a good idea, if nothing else it'll show if this is a real issue or just isolated to that one machine

>> Are you able to recreate the issue with a small test program?
>> [Karan]: Yes

Great, can you create a small project that does this and then upload it here?: http://ee-stuff.com/
Just log in using your EE credentials.

More on ee-stuff: http://www.experts-exchange.com/Q_21906270.html

Once you've uploaded the project I can take a look and see if I can get it to build (although I only have access to VS2008 Express so I'm not sure if it'll work given your project seems to use MFC).

0
 

Author Comment

by:KaranGupta
ID: 24770665
Hi

I am sorry I can't post code here due to sensitivity of data.  Can you help me in some other way.
0
 
LVL 40

Expert Comment

by:evilrix
ID: 24770674
>> I am sorry I can't post code here due to sensitivity of data.
Not even a small test program just to recreate the problem? I'm not requesting production code, just a test project.

>> Can you help me in some other way.
Well, not without being able to have some idea of what you're doing, no.
0
 

Author Comment

by:KaranGupta
ID: 24771033
Hi

I have commented the code for windows.h

Now I am getting this error

fatal error C1189: #error :  Your version of the Windows SDK is earlier than 6.0. Try setting the 'WINVER' and '_WIN32_WINNT' definitions in your project to less than 0x0600.
0
 
LVL 40

Expert Comment

by:evilrix
ID: 24771035
>> Now I am getting this error
If you comment out windows.h then everything that relies on it (which is nearly all the Win32 framework) will fail to build. Unless your code uses no Win32 framework (which it must do if you see that error) this is not a viable solution.
0
 

Author Comment

by:KaranGupta
ID: 24771041
Because when I include it I am getting an error <windows.h> is already included


0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 40

Expert Comment

by:evilrix
ID: 24771065
>> Because when I include it I am getting an error <windows.h> is already included
I understand that but that is in one isolated place in the code. If you remove it from the "top level" then everything else that relies on it will fail to build.

You really need to prove if this is a localised issue or not by trying this on a clean machine. If it's a localised issue it's probably a configuration problem on that single machine.
0
 
LVL 39

Assisted Solution

by:itsmeandnobodyelse
itsmeandnobodyelse earned 500 total points
ID: 24771454
>>>> If you comment out windows.h then everything that relies on it will fail to build.

That is only true if the windows.h wasn't already included yet what seems the case here.

Any wizard generated VC project will include the stdafx.h as very first header to support the precompiled header feature. If switched on, the (pre)compiler would not include the stdafx.h and the headers included there but use a precompiled object file from projectname.pch which was compiled via stdafx.cpp (which has no statements beside of including stdafx.h). The stdafx.h would include the AFX subsystem (in case of MFC) and one of the first includes made there is windows.h. That system (what actually is very bad) relies on the order the header files were included, hence any attempt to including windows.h or afxmfc.h a second time was protected by #error statements.

>>>> fatal error C1189: #error :  Your version of the Windows SDK is earlier than 6.0
That normally is due to the _WIN32_WINNT macro is not set.

You can add it to the project settings in the C++ section. add

_WIN32_WINNT=0x0500

to the list of macros already defined for 'preprocessor definitions' (you must do it for all configurations Debug and Release).  0x0500 is W2000, 0x0600 is Win XP, but the first normally is sufficient to overcome the error.
0
 

Author Comment

by:KaranGupta
ID: 24771470
Where to add this

_WIN32_WINNT=0x0500

on every page
0
 
LVL 40

Expert Comment

by:evilrix
ID: 24771485
>> Where to add this?
I really do think this is the wrong way to go. You need to figure out why this is happening. Trying to *hack* it to work isn't a solution and it's likely to just raise other problems!

Again, have you tried this on any other machines apart from the 2 so far? There is a very good chance this is a localised problem on this one machine since it works on the other. If that is the case you are trying to fix the wrong problem. Before you can fix something you really do need to know what is actually broken.
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 24771504
>>>> If it's a localised issue it's probably a configuration problem on that single machine.

Yes and no. The fixed including order and the errors following if not done as required are by design. The only reason why they don't arise very often is that most developers use the wizard or a working project where the issue was solved. The errors regarding wrong SDK version is due to the fact that not all SDK functions were available in the standard configuration (where the header files used - depending on the compiler - last back to 16bit Windows and to Win95/98). But if the project uses a more difficult threading model or uses dlls which were calling Windows NT fuctionality, then the corresponding macros like _WIN32_WINNT must be set correctly to make it work. The WINVER was set by the compiler anyhow. So, if the used compiler is VC6 or younger, the WINVER couldn't be the issue.
0
 
LVL 40

Expert Comment

by:evilrix
ID: 24771531
>> The only reason why they don't arise very often is that most developers use the wizard or a working project where the issue was solved.

But the asker has already confirmed both machines are set up the same, so it should build fine on both. The fact it fails to build on one suggests that machine isn't set up as expected. This is why I suggest setting up a new machine with all the config and prerequisites that are expected. If it also builds on that then the problem is the other machine, if it doesn't it's a code issue.

Anyway, I'll leave you to this since you are more adept to Windows than I (being a prediminantely cross-platform developer).
0
 

Author Comment

by:KaranGupta
ID: 24771584
Hi

One more observation which I want to share with you guys is when I run on machine of some other collegue then after commenting #include <windows.h> from stdafx.h it started working but in some other code it is not
0
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 500 total points
ID: 24771604
>>>> Where to add this
In VC6 it is

Projects - Settings - C++ - Preprocessor definitions

in VC7 or later it is

Projects - Properties - Configuration Properties - C/C++ - PreProcessor - PreProcessor Definitions

In both case add the _WIN32_WINNT=0x0500  to the list of macros already defined there separated by comma (VC6) or semicolon (>= VC7).

>>>> I really do think this is the wrong way to go.

If you would look at the header where the error 1189 was thrown, you'll see a sequence like

// Note: WINDOWS.H already included from AFXV_W32.H
#ifndef NTDDI_LONGHORN
#   define NTDDI_LONGHORN 0x06000000
#   if (WINVER >= 0x0600) || (_WIN32_WINNT >= 0x0600)
#       error Your version of the Windows SDK is earlier than 6.0. Try setting the 'WINVER' and '_WIN32_WINNT'        definitions in your project to less than 0x0600.
#   endif
#endif

So, it comes into that cause the macro NTDDI_LONGHORN wasn't defined (what isn't so wondering as longhorn is Vista) and now checks the windows version to be less than 0x0600 what is Windows Vista.

But when writing this, I see that the error states that the OS *must not be* Vista. So, it seems that your compiler version indeed is not suitable to develop at a VISTA environment.

Can you post the header where this error was thrown?

And what is your compiler and Windows version?



0
 

Author Comment

by:KaranGupta
ID: 24772514
Hi

I changed my mode from debug to release but I now I am getting an error

Unspecified error _argc

Why is it coming
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 24772677
>>>> but I now I am getting an error
It would be better we would have cleared the original question which surely could be answered when you tell me

1. What is your current compiler version?

2. What is the Windows Version you currently are working on?

3. Which header file throws that #error 'Your version of the Windows SDK is earlier than 6.0. Try setting the 'WINVER' and '_WIN32_WINNT''


>>>> Unspecified error _argc

When did you get that error? At compiling or linking?

Note argc is one of the arguments of main function (counter for the number of arguments passed in argv). The underline prefix iss an internal prefix for the linker.

Can you post the full context and text of that message.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now