Windows console

Well, I have a simple question, at least I hope it is simple. For some time I was interested in the win32 console. Our teacher told us that the Windows console is for DOS and real-mode emulation only. Well, I know this is not true because DOS applications are launched by an emulator that uses the console to output the output. Another thing I found out is that the console is built into Windows with NT. Well. But I could not find how actually console programs written to use the console. I use Visual C ++ for programming (well, for learning). So, the only thing I need to do to use the console is to select a console project. At first, I thought that Windows was deciding whether to launch the application in the console or trying to start the application in window mode. So I created a win32 program and tried printf (). Well, I could not compile it. I know that by definition printf () prints text or variables in stdout. I also found that stdout is a console interface for output. But I could not find what actually is.

So, basically, what I want to ask is where is the difference between a console application and a win32 application. I thought that windows start the console when it receives a command from the console-family functions. But apparently this does not happen, so there should be some code that actually manages the windows to create the console interface.

And the second question: when the console is created, how does Windows recognize which console terminal is used for any application? I mean, what is it really stdout? Is this a memory area or some kind of window procedure called? Thank you

+4
source share
2 answers

When you connect the Win32 application, you choose whether it will be Windows or the console. In the console case, the console window will be highlighted automatically (or, if the parent process has one, it will be reused).

However, a Windows application (such as a GUI) may also display a console window, just call the AllocConsole API.

Testing the application may not compile for a number of reasons, the error message should tell you if you need to:

  • include "stdio.h"
  • refers to the CRT library (C Run Time)
  • something else.

Usually, if you select a console application in a new project for a Win32 project, these things should just work, otherwise you need to choose the right compilation and link options.

+2
source

To answer your second question, stdout on Windows maps to the HANDLE returned by GetStdHandle(STD_OUTPUT_HANDLE) , which defaults to CONOUT$ . You can access this by calling CreateFile("CONOUT$", ...) if you are so prone.

0
source

Source: https://habr.com/ru/post/1306277/


All Articles