CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Mar 2006
    Posts
    40

    Question 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????

  2. #2
    Join Date
    Mar 2006
    Location
    Hyderabad
    Posts
    50

    Thumbs up 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.

  3. #3
    Join Date
    Oct 2005
    Location
    Bangalore
    Posts
    1,051

    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

  4. #4
    Join Date
    Jun 2005
    Location
    Tirunelveli-Tamil Nadu-India
    Posts
    354

    Smile Re: ERROR WINDOWS.H already included??

    If I Helped You, "Rate This Post"

    Thanks
    Guna

  5. #5
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815

    Re: ERROR WINDOWS.H already included??

    Quote 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.

  6. #6
    Join Date
    Mar 2006
    Posts
    40

    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

  7. #7
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815

    Re: ERROR WINDOWS.H already included??

    Quote 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).

    Quote 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.

  8. #8
    Join Date
    Aug 2002
    Location
    Cluj-Napoca,Romania
    Posts
    3,496

    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
  •  





Click Here to Expand Forum to Full Width

Featured