Bax STAR
Bax STAR

Reputation: 5

In Language Processing, What is making the console window of an exe file?

When a language gets processed into displaying its output, specifically for compiled languages, their code is compiled by a compiler, assembled by an assembler and linked by a linker to create the executable file.

Since the linker is usually the one making the executable, I assumed that it was the one doing the graphical layout of the console window which is what an exe uses to display output, but when I read more about linkers, It never mentioned about creating a console window at some point after or before linking, So it just got me wondering, which one makes the graphical layout of the console window of an executable binary?

Upvotes: -1

Views: 69

Answers (1)

user22405329
user22405329

Reputation: 979

The console window is built in into one of the system services of Windows - that's why all programs have the same console. Before Vista, it was located in csrss.exe. Starting from Vista, it was moved into conhost.exe. Those programs are automatically launched by Windows when the console is required.

Windows will create a console when:

  • Your program explicitly asks for it by calling AllocConsole(). Note, that each process can have only one - the function fails if you already have a console.
  • When the EXE file is loaded, if its header has "Subsystem" field set to "Console".

The last one is indeed controlled by the linker. If you are using Microsoft Linker (link.exe), you can select a subsystem with /SUBSYSTEM command line parameter:

  • Linking your program with /SUBSYSTEM:CONSOLE will automatically create a console, when EXE is loaded.
  • Linking with /SUBSYSTEM:WINDOWS will not create a console (but your program can still create it later with AllocConsole)
  • Linking without /SUBSYSTEM option - the linker will decide automatically. If your program has a function called main or wmain - it will set it to CONSOLE. If you have WinMain or wWinMain instead - it will set WINDOWS.

Upvotes: 2

Related Questions