• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1027
  • Last Modified:

afx.h & windows.h conflict

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
BEEjay
Asked:
BEEjay
1 Solution
 
bkrahmerCommented:
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
 
SnurreCommented:
If you are using MFC, you should include the <afxwin.h> instead of including <windows.h>

Thats one thing...

 
0
 
BEEjayAuthor Commented:
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
bkrahmerCommented:
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
 
SnurreCommented:
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
 
bcladdCommented:
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

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now