Using STDIN with an AllocConsole()

Nowayz picture Nowayz · Jan 26, 2012 · Viewed 12.6k times · Source

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.

Answer

Nowayz picture Nowayz · Jan 28, 2012

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); 

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