The information in this article applies to:
SUMMARY
To use C Run-time output routines, such as printf(), from a GUI
application, it is necessary to create a console. The Win32 application
programming interface (API) AllocConsole() creates the console. The CRT
routine setvbuf() removes buffering so that output is visible immediately.
This code opens up a new low-level CRT handle to the correct console output
handle, associates a new stream with that low-level handle, and replaces
stdout with that new stream. This process takes care of functions that use
stdout, such as printf(), puts(), and so forth. Use the same procedure for
stdin and stderr.
Note that this code does not correct problems with handles 0, 1, and 2. In fact, due to other complications, it is not possible to correct this, and therefore it is necessary to use stream I/O instead of low-level I/O. MORE INFORMATION
When a GUI application is started with the "start" command, the three
standard OS handles STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, and
STD_ERROR_HANDLE are all "zeroed out" by the console initialization
routines. These three handles are replaced by valid values when the GUI
application calls AllocConsole(). Therefore, once this is done, calling
GetStdHandle() will always return valid handle values. The problem is that
the CRT has already completed initialization before your application gets a
chance to call AllocConsole(); the three low I/O handles 0, 1, and 2 have
already been set up to use the original zeroed out OS handles, so all CRT
I/O is sent to invalid OS handles and CRT output does not appear in the
console. Use the workaround described above to eliminate this problem.
Additional query words: 3.10 3.50 CRT redirect std handles
Keywords : kbConsole kbKernBase kbWinOS2000 kbDSupport kbGrpKernBase |
Last Reviewed: December 30, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |