Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Redirecting standard-C stdin, stdout, and stderr after AllocConsole

212 views
Skip to first unread message

Ulrik Petersen

unread,
Sep 9, 1998, 3:00:00 AM9/9/98
to
Hi!

In the excellent sample for writing console-applications that comes with
Visual C++ 4.0, the main() function first frees the console with
FreeConsole(), then allocates a new one with AllocConsole(). A comment
then says something to the effect that standard C I/O with printf etc.
will not work unless one "fixes" the handles. I have searched the
documentation for hours, but couldn't figure out how to do it. Any
suggestions?

What I want is this:

When my Win32 console application starts, I want to create a new
console, then re-size it, then write to it with standard-C printf and
read from it with scanf. I am working with automated translation from
pascal-programs written on a Sparc platform to Win32 programs compiled
with GNU CC (http://www.cygnus.com).

How does one "reconnect" the stdout, stdin, and stderr handles with the
new handles for the new console?

Thanks in advance

Ulrik Petersen
ulr...@daimi.aau.dk

m...@waverider.ca

unread,
Sep 28, 1998, 3:00:00 AM9/28/98
to
A solution to this problem is at the following link:

http://www.codeguru.com/misc/console.shtml

One of the key calls it makes is to ::_open_osfhandle(). This allows you to
associate a C runtime file handle with a windows file handle.

Hope this helps others out there too...

Max

In article <35F65D...@daimi.aau.dk>,


--
Max Leung, mle...@my-dejanews.com
------------------------------------------------
"My clever .sig q

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum

0 new messages