INFO: AllocConsole() Necessary to Get Valid Handles

ID: Q89750


The information in this article applies to:
  • Microsoft Win32 Application Programming Interface (API), used with:
    • Microsoft Windows NT versions 3.1, 3.5, 3.51, 4.0
    • Microsoft Windows 2000


SUMMARY

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.

Additional query words:

Keywords : kbprg kbConsole kbFileIO kbKernBase kbNTOS310 kbNTOS350 kbNTOS351 kbNTOS400 kbWinOS2000 kbDSupport kbGrpKernBase
Version : winnt:3.1,3.5,3.51,4.0
Platform : winnt
Issue type : kbinfo


Last Reviewed: January 11, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.