?
Solved

afx.h & windows.h conflict

Posted on 2003-03-23
7
Medium Priority
?
1,001 Views
Last Modified: 2007-12-19
hello,

I am using Visula C++ 6.0.

When compiling my program I get the following error message:
#error :  WINDOWS.H already included.  MFC apps must not #include <windows.h>

But if I remove the #incude <windows.h> statement in the "stdafx.h" file, I get a link error: cannot open file "nafxcwd.lib".
This is because, I think, somewhere in a project I use, I include "afx.h". But when I compile that project seperately, it compiles without any problems.

Can someone help me?
0
Comment
Question by:BEEjay
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 2

Expert Comment

by:bkrahmer
ID: 8192665
I would suggest checking the project settings.  In the general tab of the settings, what is MFC set to?  If you are linking to other libraries, make sure all of the code is compiled with the same Code Generation Settings (c/c++ tab.)  

brian
0
 
LVL 2

Expert Comment

by:Snurre
ID: 8194223
If you are using MFC, you should include the <afxwin.h> instead of including <windows.h>

Thats one thing...

 
0
 

Author Comment

by:BEEjay
ID: 8194505
Sorry, I mixed two problems. I'll rewrite my prblem:

I have a working console project that uses MFC. It reads and writes images. Now I want to use a window to draw output images to, instead of writing it to a file.
I've never used MFC before, so I don't know how to do this.
To avoid MFC, I've made a new project: 'Win32 Application-A typical Hello World Application'. Now, I want to use the class containing the image information from the console application. Is this possible?
When I use the console project directly (adding the ImageClass.h in Stdafx.h from the new project), I get the error: windows.h already included.
When I remove #include <windows.h> from the stdafx.h, I get the error: cannot open file "nafxcwd.lib", and some other link errors.

I hope I've posed my question better this time.


 
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Accepted Solution

by:
bkrahmer earned 300 total points
ID: 8200029
Yeah, you can't do it that way.  There are specific settings embedded in the project which are causing you problems.  Regardless if you know MFC or not, I would suggest creating a new Win32 MFC project, and go from there.  At least your compiling and linking flags should be correct that way.

brian
0
 
LVL 2

Expert Comment

by:Snurre
ID: 8202071
If you what to use WinAPI insted of MFC you will be needing to re-write all of you classes that's uses any MFC stuff, so I would say like bkrahmer, that you would need to use an MFC project instead...

But I would recomend you to rewrite all the classes into WinAPI instead.
0
 
LVL 11

Expert Comment

by:bcladd
ID: 9544065
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answerd: Points to bkrahmer

Please leave any comments here within the next seven days. Experts: Silence
means you don't care.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

-bcl (bcladd)
EE Cleanup Volunteer

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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++.
Suggested Courses

770 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