Skip to main content
GameDev.net gamedev.net
🔒 Locked

How come when I include atlbase.h I get...

Started by chadsxe Dec 15, 2009 at 4:47 PM 9 replies 3k views
Original Post
chadsxe
chadsxe
I feel dumb for asking this but when ever I include atlbase.h I get... fatal error C1189: #error : Need to include strsafe.h after tchar.h I am not using strsafe or tchar at all in my program. I am just trying to use atlbase. I googled and other people have had the problem but have not found a solution. It obviosuly has to do with the order of includes but I for the life of me can't figure out what system header (not mine) is messing this up. If it helps I am using DirectX and DirectShow. Regards Chad
SiCrane
SiCrane
Did you try #including tchar.h before atlbase.h ?
chadsxe
chadsxe
Quote:
Original post by SiCrane
Did you try #including tchar.h before atlbase.h ?


Sure did. The more I look into the more people I find who had the issue. Most response to there querys are along the lines of "You are mixing up your include order". I have checked mutliple times and have yet to find the reason.

Regards

Chad
Codeka
Codeka
Quote:
Original post by chadsxe
Sure did. The more I look into the more people I find who had the issue. Most response to there querys are along the lines of "You are mixing up your include order". I have checked mutliple times and have yet to find the reason.
You could start by, I don't know... showing us your #includes...
chadsxe
chadsxe
This is my precompile

// Standard Includes
#include
#include
#include
#include
#include
//#include ? have moved up and down this list.

// Boost Includes
#include
#include
#include
#include
#include
#include

// DirectX includes
#include
#include


Then in the header where it is neede

#include "DeviceEnumeration.h" // This has nothing in it
#include
#include
//#include ? have moved up and down this list.
chadsxe
chadsxe
Quote:
Original post by ApochPiQ
Erm, wait... are you #including the header from both your PCH and another header?


I was under the impression you are not to include your precompile header inside other headers. Only .cpp files. This led me to believe that in order to gain some functionality in headers I had to inlude what was needed per header.

Regards

Chad
ApochPiQ
ApochPiQ
OK, time for a crash course in how C++ headers work [smile]

When you #include a file, you're not doing anything magical - what happens is the compiler reads the #included file, and basically pastes it into the original file in place of the #include line. You could literally use copy/paste to put the header in your .cpp file (or wherever you #include it from) and end up with the same result.

A precompiled header is nothing more than the same thing, except already processed by the compiler so it works a bit faster. You're still relying on the same basic copy/paste operation under the surface.

Since all of your .cpp files (by default, anyways) rely on the PCH, you #include the PCH at the top of each file. This is, once again, equivalent to copying and pasting the raw PCH header file into the top of your .cpp file.

Bottom line: once you have #included something in your PCH, it is automatically available to every .cpp file that #includes that PCH. There is no need to #include anything twice, and in fact, double includes often cause weird problems.

I don't think the fatal error you mentioned in the original post will be fixed by removing your duplicate headers, but at the very least you can probably clean your code up quite a bit by trimming things back.
chadsxe
chadsxe
Quote:
Original post by ApochPiQ
Since all of your .cpp files (by default, anyways) rely on the PCH, you #include the PCH at the top of each file. This is, once again, equivalent to copying and pasting the raw PCH header file into the top of your .cpp file.
I think your missing the point that I am not talking about .cpp file and including a header that is already in the PCH. I am talking about .h files that need access to other .h files in order to know variable types. If you take notice in my post above I state that the second set of Includes is in .h file. If I take those out then there is no way for the class decleration inside that .h file to know some of the variable types it is using.

Unless I am misunderstanding what you are saying?

In regards to my orginal issue I need to inlcude #include in my header in order to declare a variable ot the type CComPtr.

Regards

Chad
SiCrane
SiCrane
Think about it. Your other headers will always be included in a .cpp file eventually. Since each and every one of your .cpp files will include the PCH as the very first header that means that each and every header can assume that the headers in the PCH are already included.

In other news, I notice a distinct lack of tchar.h in your includes.
chadsxe
chadsxe
Quote:
Original post by SiCrane
Think about it. Your other headers will always be included in a .cpp file eventually. Since each and every one of your .cpp files will include the PCH as the very first header that means that each and every header can assume that the headers in the PCH are already included.

In other news, I notice a distinct lack of tchar.h in your includes.


Thought about and figured it out. I apologize for the confusion.

None the less my solution had to do with a little bit more then I was leading on. The program I was trying to get it working is compiling as a static lib. The program that is using that lib is what did not realize what it was looking at. So I had to include it in that one as well.

Regards

Chad

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.