4
votes

I created an MFC application from visual studio 2008 MFC Application template. The problem is that I want to show a console in execution and not the window created by default MFC Application template ( like the one shown when we choose Win32 Console Application template).

Can anyone please tell me how could ! display a console instead of window in an MFC application?

4
Change the subsystem or call AllocConsoleta.speot.is
Do you really need it to be an MFC application? If you want a console instead of windows, just create a Console application and you are set.Gorpik

4 Answers

4
votes

When you create a new Win32 Console application, the wizard has a checkbox to add common header files for MFC - check it.

This isn't very commonly done because there isn't much of MFC that's useful in a console application. You won't be running MFC's application message pump so a lot of things just won't work.

4
votes

In your stdafx.h (before vs2019) or pch.h (vs2019) :

#ifdef _UNICODE
#pragma comment(linker, "/entry:wWinMainCRTStartup /subsystem:console") 
#else
#pragma comment(linker, "/entry:WinMainCRTStartup /subsystem:console")
#endif
0
votes

You can change the project's subsystem to console, when the MFC application windows running and also a console running.

If you want only a console running, create a console project instead.

0
votes

Change project settings from Linker > System > SubSystem to "CONSOLE" instead of "WINDOWS".

Also if you want to attach console in your windows application then use "Editbin" utility from Visual Studio Tools. It is located in \VC\bin\editbin.exe

editbin.exe /SUBSYSTEM:CONSOLE YourApplicationPath.exe

This will attach console in you windows application.