Reputation: 51
It seems all the "Multiple Consoles in C++" questions on this site are either 7 years old and no longer work, or are in C instead of C++. I've searched the web for any APIs for something of that nature. Is there a way specifically to create multiple consoles in C++?
Upvotes: 1
Views: 1557
Reputation: 10827
The documentation here: https://learn.microsoft.com/en-us/windows/console/attachconsole says no you can't do that within a single process.
A process can be attached to at most one console. If the calling process is already attached to a console, the error code returned is ERROR_ACCESS_DENIED (5).
This also repeats the theme: https://learn.microsoft.com/en-us/windows/console/allocconsole
A process can be associated with only one console, so the AllocConsole function fails if the calling process already has a console. A process can use the FreeConsole function to detach itself from its current console, then it can call AllocConsole to create a new console or AttachConsole to attach to another console.
As Remy Lebeau mentioned in a comment, you can however spawn additional child processes each having their own console windows. See the CREATE_NEW_CONSOLE
flag of CreateProcess here: https://learn.microsoft.com/en-us/windows/win32/procthread/process-creation-flags
Upvotes: 2