将 STDIN 与 AllocConsole() 一起使用 [英] Using STDIN with an AllocConsole()

查看:38
本文介绍了将 STDIN 与 AllocConsole() 一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个第三方 dll,我将其加载到不是我的软件中,并且我使用 AllocConsole() 创建标准 Windows CLI 窗口,因此我可以轻松地输出调试消息.

I have a third-party dll that I load into software that isn't mine, and I'm using AllocConsole() to create the standard windows CLI window so I have an easy means of outputting debug messages.

不过,我的问题是它忽略了任何类型的输入.我只是希望能够使用我分配的控制台并让我能够为其提供一些输入.

My problem is though, is that it ignores any kind of input. I just want to be able to use the console I allocated and enable the ability for me to give it some input.

推荐答案

感谢 Ben Voigt,我能够在分配控制台后通过以下方式使控制台接受输入:

Thanks to Ben Voigt, I was able to cause the console to take input after I allocated it by doing:

freopen("CONIN$", "r", stdin); 
freopen("CONOUT$", "w", stdout); 
freopen("CONOUT$", "w", stderr); 

这也会将 stdout 和 strerr 定向到同一个控制台窗口,以防它们由于某种原因被定向到其他地方.

This also directs the stdout and strerr to the same console window, in case they are directed someplace else for some reason.

这篇关于将 STDIN 与 AllocConsole() 一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆