Creating a second console

Started by
2 comments, last by SirSmokey 18 years, 4 months ago
Ok how do I create a second Win32 console? I've searched on these forums and MSDN and AllocConsole() looks like a good start but it doesn't create another console window, it just uses the one that opens (that is to say when I call FreeConsole() the window closes and the app ends) So how can I create 2 console windows. I would like to use one to display debugging info. Thanks for any help.
Advertisement
A process can only have one console, so unfortunately you cannot make another console.
You can, however, spawn a new process with an attached console and use pipes to send debug information to the second process. The second process could be relatively simple; just something like:
#include <iostream>int main(int, char **) {  std::cout << std::cin.rdbuf();  return 0;}

You could probably modify the code in this article to do the process creation. Just keep in mind that you don't want to set the new pipe handles to be the stdin/stdout of the current process and you'll need to keep at least one handle around to write your debug text to.
Thanks for the article. Unfortunately I can't seem to get it working the way i want, there's som stuff i don't quite understand. Could anybody give me some quick sample code that would just, say, write a string to the second console from the first, something simple like that. If i saw it in action the way i would like, i think i would be ok and be able to take what i need to learn from it. Thanks for any help.

This topic is closed to new replies.

Advertisement