Trying to create console with AllocConsole()

Started by
8 comments, last by M4573R 15 years, 2 months ago
I'm creating a console window with AllocConsole(), and MSDN says it sets up the standard handles; but when I use printf or cout nothing is printed. Whats the deal? Thanks
Advertisement
You will have to redirect all of the output streams as well. Here is a GameDev post that provides a complete solution for doing this [wink]

You also must include:
#include <fcntl.h>
#include <io.h>
Awesome! Thanks for the reply so early in the morning. Now I have to put this is a new thread don't I... :(
Quote:Original post by M4573R
Awesome! Thanks for the reply so early in the morning. Now I have to put this is a new thread don't I... :(


Nope, all you do is call the code from any thread you want, that's it. It is very easy to use and requires no extra work!

For some reason my link got messed up, this post was the one I was trying to link to. Weird, GD is messing up my links, either way it is mfawcett's reply that I was pointing to.
Instead of redirecting the streams, you can include <conio.h> and use _cprintf()
But if I don't want my game to freeze while accepting input, it needs to be in its own thread. Right?
Handling input doesn't inherently require a new thread. In particular, using window messages for input works in the same thread as the message loop.
Window messages? Like win32 popup boxes?
Things like WM_KEYDOWN, WM_CHAR, etc.
It would be waaaaaaay easier if I could just have the window sitting there waiting with cin.

This topic is closed to new replies.

Advertisement