Console Applications

Click here to change the theme.

A console program is one that can be written using only functions and language features that are compatible with the C or C++ standard. If a program uses the standard exclusively, then it can be compiled for any operating system that has a compiler for the standard. This is can be very important. It is therefore very useful to be familiar with the standard. I think that functions such as "cout" are a separate standard but whether they are part of the C++ standard or are a separate standard, they are worth knowing. There are actually two types of console programs; 16-bit and 32-bit. A 16-bit program is a true DOS program. A 32-bit console program is a Windows program that can be compatible with other operating systems at the source code level if it does not have any direct calls to Windows.

A console application is not a Windows GUI application. Something to understand that is highly relevant is that according to the C and C++ standard all programs have a "main" function. A Windows GUI application has a "WinMain" function instead of a "main" function; 16-bit DOS programs and 32-bit console programs have a "main" function. Also Windows GUI applications can be either 16-bit or 32-bit.

16-Bit DOS Applications

A 16-Bit DOS application uses DOS functions but cannot call Windows functions directly. DOS is called using software interrupts, which is a processor instruction. Software interrupts are prohibited in 32-bit Windows programs.

32-Bit Console Applications

A 32-Bit console application cannot issue a software interrupt and therefore cannot call DOS directly. A 32-Bit console application calls Windows directly for most anything that DOS would be used for. Often a 32-Bit console application relies entirely on C runtime library functions and/or the C++ Standard Classes and other features within the standards. There are also extensions to the standards that are compiler-dependent that can be used without using Windows directly. However those functions call Windows but not DOS.

Windows GUI Applications

A Windows GUI program is not compatible with the C++ standard; that is, a Windows GUI program will only work in a Windows environment. A GUI program however can use Windows windows easier than a console program can. Most Windows programmers would say that a GUI program is a "Windows" program whereas a console program is not, but I am not aware of Microsoft saying that.

I am simplifying things to make it easier to understand, but the truth is that a console program can do most everything a GUI program can do and a GUI program can do most everything a console program can do; it is just a matter of knowing how to do them. If anyone were to try to explain the differences between the two types and still be totally accurate about what each can do then it would get really difficult to understand the differences.

Technical Comments

A DOS program must be built using a 16-bit compiler and a 16-bit linker. Microsoft Visual C++ (VC) version 1.52c is the latest version of VC that is 16-bit. For 32-bit programs a console program is specified using the Subsystem option of the Linker Options. The Subsystem option has many subsystems types that can be specified but only "CONSOLE" and "WINDOWS" are commonly used. When the "CONSOLE" environment is specified a console application is created and when the "WINDOWS" environment is specified a Windows GUI application is created. See /SUBSYSTEM (Specify Subsystem) for an online copy of the Linker Subsystem option in the MSDN. The GetBinaryType function can be used to determine what Subsystem was specified for an executable. I have a sample console program that uses the GetBinaryType function in Getting Executable Type.

If you wish to use Standard I/O in a GUI program then you must first attach a console. I think that is a function documented with the other console functions. Next, look at Microsoft Knowledge Base (KB) Article "Calling CRT Output Routines from a GUI Application" (Q105305).