Click here to Skip to main content
12,394,971 members (60,590 online)
Rate this:
Please Sign up or sign in to vote.
See more: C++ Visual-Studio
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?
Posted 17-Apr-12 7:57am
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.160721.1 | Last Updated 17 Apr 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100