|
-
March 23rd, 2006, 10:37 PM
#1
ERROR WINDOWS.H already included??
Hey All -
I am writing a win32 dll. I included a class that can access database operations. I included afxdb.h in the headerfile and declared a variable in the header file for CDatabase. When I compile it.. it gives me a error
"WINDOWS.H already included. MFC apps must not #include <windows.h>"
same when I try to include it in the .cpp file (below stdafx.h ) it compiles without errors.
I am trying to research on it online.. no 1 seems to have a solution... but jus very similar problems...!!!
can any one help me around this please????
-
March 23rd, 2006, 11:05 PM
#2
Re: ERROR WINDOWS.H already included??
If r e adding this header file then u need not to include the <windows.h>
try it up.
-
March 24th, 2006, 12:13 AM
#3
Re: ERROR WINDOWS.H already included??
There are a lot of threads that havre already discussed this issue in this forum.....kindly do a search....
- Sreehari
"Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us."
" Everybody is sent to Earth on a purpose. I am so Lagging behind that i won't die." – Calvin
-
March 24th, 2006, 04:19 AM
#4
Re: ERROR WINDOWS.H already included??
If I Helped You, "Rate This Post"
Thanks
Guna
-
March 24th, 2006, 05:41 AM
#5
Re: ERROR WINDOWS.H already included??
 Originally Posted by dude1
I included a class that can access database operations. I included afxdb.h in the headerfile and declared a variable in the header file for CDatabase.
That looks like trouble. Usually, you should avoid as much as possible #including headers in header files. Why are you doing this? Is there any type defined in afxdb.h which you need inside your class definition (for example, because you're deriving from it or including it by value)? Likewise, why did you declare a variable in a header file? This will only work if you declare it as extern, and provide the actual declaration in an implementation file.
-
March 24th, 2006, 09:47 AM
#6
Re: ERROR WINDOWS.H already included??
o well I need to Include the CDatabase variable as a part of the class... Thats the reason I am including it in the header file... I dont understand one thing is.. he same file when included in the .cpp file.. it compiles fine... but when I include in the .h file.. it gives me this error..???
any way i will try removing the windows.h as it is mentioned in other threads
-
March 24th, 2006, 10:00 AM
#7
Re: ERROR WINDOWS.H already included??
 Originally Posted by dude1
o well I need to Include the CDatabase variable as a part of the class... Thats the reason I am including it in the header file...
Are you sure you need an instance of CDatabase in your class - and not just a reference or pointer to it (in that case, a forward declaration will do, and you don't need the header in your header).
 Originally Posted by dude1
I dont understand one thing is.. he same file when included in the .cpp file.. it compiles fine... but when I include in the .h file.. it gives me this error..???
Well, because a header file is usually #included in several compilation units, while a .cpp file makes up it's own compilation unit.
-
March 24th, 2006, 10:02 AM
#8
Re: ERROR WINDOWS.H already included??
I have recently encountered the very same problem. And thanks to it I've spent a very frustrating hour. The problem appeared suddenly after moving a file from one folder in my project into another. Pretty absurd if you come to think about it.
Anyway, in one of my cpp files I was including the file using #include "session.h". After I moved "session.h" the compiler was no longer able to find it in my project's folders but unfortunately a file with a similar name exists in the VS Include folders. That one ends up including "windows.h" and thus generating the error.
The wicked part is that the error was generated before any other more meaningful error such as "undefined symbol XXXX" ( which was defined in my session.h). I failed to understand what happened until I did the following:
- started from the cpp file where the error is reported
- commented all its content except the include directives ( to avoid other errors)
- commented each of the include directives, one at the time, until I found the "h" generating the problem
- continue with that h file by verifying its includes
Even if they all look fine, open them to make sure they are the files you expect.
Hope it helps.
Har Har
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|