Create new console from console app? C++

孤街醉人 提交于 2019-12-04 20:24:24

You can't. According to the documentation for AllocConsole:

A process can be associated with only one console, so the AllocConsole function fails if the calling process already has a console.

More info

You can't use CREATE_NEW_PROCESS and DETACHED_PROCESS together. See Process Creation Flags. I think you misunderstand what DETACHED_PROCESS is. From the documentation:

DETACHED_PROCESS

For console processes, the new process does not inherit its parent's console (the default). The new process can call the AllocConsole function at a later time to create a console. For more information, see Creation of a Console.

This value cannot be used with CREATE_NEW_CONSOLE.

A detached process is a process without a console. You can't create a new console for a process that doesn't have a console.

Remove the DETACHED_PROCESS flag from your call, and it should work.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!