Click here to Skip to main content
15,943,103 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
A while back I created a 32-bit, dialog-based program in Visual Studio 9. Recently I needed to create a 64-bit version. So I went to the Configuration Manager, selected "<new...>", chose "x64" from the "Type" and "Win32" from the "Copy settings from". This has worked just fine to create 64-bit versions for other, similar programs, so I didn't see any problem.

But for this one program, this doesn't work. If I run the program as Win32, then the CWinApp constructor in appcore.cpp is called first, and then the function AfxWinMain() in winmain.cpp. The program runs fine.

If I select the "x64" type, then for some reason the CWinApp constructor is skipped and AfxWinMain() is called first. This means that AfxGetThread() returns NULL, so I get a null pointer exception at the line:
if (!pThread->InitInstance())

Eventually I found from another article on here that going to the Properties page, going to C/C++ -> Preprocessor -> Preprocessor Definitions, and changing "_WINDOWS" to "_CONSOLE" for the x64 platform makes it work.

So my questions would be: why did this happen for this one program, and not others which are written similarly that have been converted to x64; and why did choosing _CONSOLE fix this?
Updated 17-Apr-12 8:32am
Marius Bancila 17-Apr-12 15:35pm    
CWinApp is called before main, because you have a global variable of that type, and that is instantiated before main is called. Now, is it that the global CWinApp object is declared with some #ifdef conditions?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900