Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Windows and Console application

Tags:

visual-c++

What differences are there between Windows and Console applications ?

When creating a new project in Visual C++ , it asks to choose either of the above .

like image 805
Rakesh Agarwal Avatar asked Feb 22 '09 13:02

Rakesh Agarwal


People also ask

What is the difference between Windows application and console application?

A Windows form application is an application that has a graphical user interface(GUI) like the Visual C# IDE. A console program on the other hand is a text application. There are not fancy controls like buttons or textboxes in a console application and they are run from the command prompt.

What is difference between console application and web application?

Console applications are light weight programs run inside the command prompt (DOS) window. They are commonly used for test applications. Windows Applications are form based standard Windows desktop applications for common day to day tasks.

What is meant by console application?

An application that uses the command line for input and output rather than a graphical interface (GUI). For example, utility programs that perform a single function or that run in the background are often written as console apps.

What are Windows application?

A program that is written to run under the Microsoft Windows operating system, also called a "Windows app." All 32-bit Windows applications run in the 32-bit and 64-bit versions of Windows. All 64-bit applications require 64-bit Windows, which is the standard on new Windows computers and tablets.


2 Answers

The sole difference is that a console application always spawns a console if it isn't started from one (or the console is actively suppressed on startup). A windows application, on the other hand, does not spawn a console. It can still attach to an existant console or create a new one using AllocConsole.

This makes Windows applications better suited for GUI applications or background applications because you usually don't want to have a terminal window created for those.

On a more technical note, the only difference between a Console and a Windows executable is one byte in the PE header of the exe file. Toggling this byte manually (e.g. using a hex editor) converts the application type. This is a well-published hack that is used to create console applications in VB6 (where this type of application was not explicitly supported).

To determine and change the subsystem type of an application, you need to read parts of the PE header. The address of the subsystem data is not fixed though, because it's part of the optional file header whose position is determined by an address stored in the DOS file header (in the member e_lfanew). This address actually points to the _IMAGE_NT_HEADERS record which, in turn, includes the IMAGE_OPTIONAL_HEADER32 structure. This has an int161) member called Subsystem. The member's value is 2 for a Windows application and 3 for a console application. Other subsystems exist (in particular, POSIX and kernel). I've written a small VB6 application to change the subsystem of an application, which can be downloaded from ActiveVB as source code.

The PE format isn't very well documented but this document may serve as an introduction: Peering Inside the PE: A Tour of the Win32 Portable Executable File Format.


1) This doesn't really contradict my claim that only one byte differs: the most significant byte of this member is always 0. Only the least significant byte changes.

like image 165
Konrad Rudolph Avatar answered Sep 17 '22 06:09

Konrad Rudolph


Besides the difference mentioned by Konrad, console and Windows applications behave differently when called interactively from the command prompt:

When you start a console application, the command prompt doesn't return until the console application exits. When you start a windows application, the command returns immediately.

This is not true for batch files; they will always wait until the application exits. (You can always use the start command to start an application without waiting.)

like image 30
oefe Avatar answered Sep 20 '22 06:09

oefe