INFO: AllocConsole() Necessary to Get Valid Handles

ID: Q89750

The information in this article applies to:

If a graphical user interface (GUI) application redirects a standard handle, such as stderr or stdout, and then spawns a child process, the output of the child process will not be seen unless the AllocConsole() application programming interface (API) is called by the parent before spawning the child.

If an application spawns a child process without calling AllocConsole() first, then a new console output window is created for the child. The child's console window appears on the screen and the GUI application is not be able to control this window (for example, it cannot minimize the child window). In addition, users can terminate the child process by choosing Close from the console window's Control (system) menu. This causes users to think that only the window is closed, when in actuality, the entire application is terminated. This can cause the user to lose data in the console window.

Keywords          : kbprg kbConsole kbKernBase kbGrpKernBase 
Version           : 3.1 3.5 3.51 4.0
Issue type        : kbinfo

Last Reviewed: May 9, 1997