Changing a Windows App to a Console App in Visual Studio
In Visual Studio there are two kinds of *.exe binaries, a windows application and a console application. A Windows Application is a typical Windows program that has a GUI. Console applications, on the other hand, are supposed to be run from the console (i.e., they are DOS programs). For developers, the main difference is that a windows application's entry point is WinMain(), whereas a console application's entry point is main(). The start-up code is also different, so simply changing the name of the entry point will not change the type of application that is being made.
An elementary mistake to make, is to create a Windows application project when the intention was to create a console application. This mistake results in error messages such as:
MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
When I made this mistake myself, a lengthy search on the internet brought solutions ranging from deleting the project and starting again (not nice at all) through to things that simply do not work. There is a much simpler way to fix this mistake. All that is required is knowing which options/settings to change. The following instructions are for Visual Studio 2008 Express. It will most likely work on other versions of Visual Studio too.
Switching from a Windows App to a Console App
- In the "Solution Explorer" (it should be in the left-hand side-bar), right-click on the project in question and select "properties."
- Under "Configuration Properties," select "Linker->System."
- Change the "SubSystem" option from Windows (circled in red below) to console
- The properties window should now look like:
- Now select "C/C++->Preprocessor," saving the changes if requested
- In the "Preprocessor Definitions," replace the entry "_WINDOWS" (circled in red below) with "_CONSOLE"
- The settings Window should now look like:
- Press"OK" to close the properties window
Articles » Windows Development » Changing a Windows App to a Console App in Visual Studio