Windows 控制台

发布于 2024-08-27 15:52:13 字数 650 浏览 8 评论 0原文

好吧,我有一个简单的问题,至少我希望它简单。我对 win32 控制台很感兴趣一段时间。我们的老师告诉我们,Windows 控制台仅用于 DOS 和实模式模拟目的。嗯,我知道这不是真的,因为 DOS 应用程序是由模拟器运行的,模拟器仅使用控制台来显示输出。我了解到的另一件事是,从 NT 开始,控制台就内置于 Windows 中。出色地。但我找不到的是,控制台程序实际上是如何编写来使用 console.log 的。我使用 Visual C++ 进行编程(嗯,是为了学习)。因此,使用控制台我唯一需要做的就是选择控制台项目。我首先认为 Windows 决定是在控制台中运行应用程序还是尝试在窗口模式下运行应用程序。所以我创建了win32程序并尝试了printf()。好吧,我无法编译它。我知道根据定义 printf() 将文本或变量打印到标准输出。我还发现stdout是输出的控制台接口。但是,我找不到标准输出实际上是什么。

所以,基本上我想问的是,控制台应用程序和 win32 应用程序之间的区别在哪里。我认为Windows在从“console-family”函数获取命令时启动控制台。但显然事实并非如此,因此必须有一些代码实际命令 Windows 创建控制台界面。

第二个问题是,当创建控制台时,Windows如何识别哪个控制台终端用于哪个应用程序?我的意思是,标准输出实际上是什么?它是内存中的一个区域,还是被调用的某个 Windows 例程?谢谢。

Well, I have a simple question, at least I hope its simple. I was interested in win32 console for a while. Our teacher told us, that windows console is just for DOS and real mode emulation purposes. Well, I know it is not true, becouse DOS applications are runned by emulator which only uses console to display output. Another thing I learned is that console is built into Windows since NT. Well. But what I could not find is, how actually are console programs written to use console. I use Visual C++ for programming (well, for learning). So, the only thing I need to do for using console is select console project. I first thought that windows decides wheather it run app in console or tries to run app in window mode. So I created win32 program and tried printf(). Well, I could not compile it. I know that by definition printf() prints text or variables to stdout. I also found that stdout is the console interface for output. But, I could not find what actually stdout is.

So, basicly what I want to ask is, where is the difference between console app and win32 app. I thought that windows starts console when it gets command from "console-family" functions. But obvisously it does not, so there must be some code that actually commands windows to create console interface.

And the second question is, when the console is created, how does windows recognize which console terminal is used for what app? I mean, what actually is stdout? Is it a area in memory , or some windows routine that is called? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜唯美灬不弃 2024-09-03 15:52:13

当您链接 Win32 应用程序时,您可以选择它是 Windows 还是控制台。在控制台情况下,将自动分配一个控制台窗口(或者,如果父进程有一个控制台窗口,则重复使用)。

然而,Windows(即GUI)应用程序也可以显示控制台窗口,只需调用AllocConsole API。

您的测试应用程序可能由于多种原因而无法编译,错误消息应该告诉您是否需要:

  • 包含“stdio.h”
  • 引用CRT(C运行时)库
  • 或其他内容。

通常,如果您在 Win32 项目的新项目向导中选择控制台应用程序,这些东西应该可以正常工作,否则您需要选择正确的编译和链接选项。

When you link a Win32 application you select whether it is Windows or Console. In the console case a console window will be allocated automatically (or, if the parent process has one, reused).

However a Windows (i.e. GUI) application can also show a console Window, just call the AllocConsole API.

You test application might fail to compile for a number of reasons, the error message should tell you whether you need to:

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

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

平生欢 2024-09-03 15:52:13

要回答你的第二个问题,Windows 中的 stdout 映射到 GetStdHandle(STD_OUTPUT_HANDLE) 返回的 HANDLE,默认情况下映射到 CONOUT$。如果您愿意,可以通过调用 CreateFile("CONOUT$", ...) 来访问它。

To answer your second question, stdout in Windows is mapped to the HANDLE returned by GetStdHandle(STD_OUTPUT_HANDLE) which is by default mapped to CONOUT$. You can access that by calling CreateFile("CONOUT$", ...) if you are so inclined.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文