Fatal Error C1189

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.
KaranGuptaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

evilrixSenior Software Engineer (Avast)Commented:
Do both machines have the same versions of Visual Studio installed?
0
KaranGuptaAuthor Commented:
Yes

0
evilrixSenior Software Engineer (Avast)Commented:
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
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

KaranGuptaAuthor Commented:
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
evilrixSenior Software Engineer (Avast)Commented:
>> 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
KaranGuptaAuthor Commented:
Hi

I am sorry I can't post code here due to sensitivity of data.  Can you help me in some other way.
0
evilrixSenior Software Engineer (Avast)Commented:
>> 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
KaranGuptaAuthor Commented:
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
evilrixSenior Software Engineer (Avast)Commented:
>> 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
KaranGuptaAuthor Commented:
Because when I include it I am getting an error <windows.h> is already included


0
evilrixSenior Software Engineer (Avast)Commented:
>> 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
itsmeandnobodyelseCommented:
>>>> 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
KaranGuptaAuthor Commented:
Where to add this

_WIN32_WINNT=0x0500

on every page
0
evilrixSenior Software Engineer (Avast)Commented:
>> 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
itsmeandnobodyelseCommented:
>>>> 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
evilrixSenior Software Engineer (Avast)Commented:
>> 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
KaranGuptaAuthor Commented:
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
itsmeandnobodyelseCommented:
>>>> 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
KaranGuptaAuthor Commented:
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
itsmeandnobodyelseCommented:
>>>> 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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.