tags:

views:

78

answers:

3

So,

I've got this code I'm trying to update. It was written for visual studio 6, and I'm trying to get it to compile in visual studio 2010.

In stdafx.h, it includes afx.h and afxwin.h and a few other things necessary for the program to work. Notably, there's usage of CString in other header files.

At the top of the includes in stdafx.h, I added in a #pragma message, to verify that it was being compiled first. There's one at the top of the header file which throws the error, as well. I can see from the compiler output that stdafx.h was being compiled first, so that's good.

However, there was the error. (CString wasn't being recognized as a type.) So, I decided to make sure that it got through all of the includes. So, I put another #pragma message after #include and that message is not printed.

Does that mean is not actually being included?

+1  A: 

Your explanation is a little hard to follow, but I think you're running into the differences between normal compilation and pre-compiled headers.

With pre-compiled headers, the compiler processes the first file normally (the new project wizard sets up stdafx.cpp for this). After processing the include file (typically stdafx.h) set in project options for pre-compilation control, the compiler saves its state to a .pch file.

For every other file, the compiler skims over the file without any processing, just looking for the include file. Then it reads the .pch file, loads the saved state, and continues parsing and compiling normally.

One consequence of this design is that any lines above #include "stdafx.h" in stdafx.cpp become part of the state and are seen by all other files. And lines above #include "stdafx.h" in other files are simply ignored.

Ben Voigt
Beat me to it. What I think you're saying is that you're printing a message from stdafx.h and you don't see this message printed when you compile a file that's including stdafx.h: that's because it's not recompiling stdafx.h again, it's picking up the saved state from when it compiled stdafx.cpp. You should see the message in the stdafx.cpp file.
Rup
I've got it figured out, now. It was due to changes in CString since VS 6. Thanks.
Colin DeClue
A: 

The problem had to do with using typedef with CString. Post VS 6, that's not possible. I just changed references by hand, and it compiles now.

Colin DeClue
Edit your original post don't post an answer ... 'tis just the local etiquette :)
Goz
A: 

Passing my comment to an answer.

CString in VS 6 times was a class and it changed afterwards to be a template. Maybe it has something to due with that?

The problem had to do with using typedef with CString. Post VS 6, that's not possible. I just changed references by hand, and it compiles now.

smink