FAQ Where did my console output go?

J

jacob navia

One of the many questions asked by people is that even if they write
into standard output, the output doesn't show in the screen. This
happens in windows systems since quite a long time.

To avoid this, you should open a console before outputting anything
into standard output. You do this with

void AllocConsole(void);

When you do not want to use the console any more (and you do not
want the ugly black window hanging around) you just do:
BOOL WINAPI FreeConsole(void);

The operating system opens up a console for all programs that
have the bit of "console application" set in the executable. That is
why you do NOT needto open a console for those programs. Programs
that need this are only programs that were compiled with the
"subsystem windows" bit set.

-------------------------------------------------------------------

You find this off topic for clc?

You can go to hell. There, you can complain to the boss.

You find me obnoxious?

You can go to heaven and complain there to the boss.
 
K

Kenny McCormack

One of the many questions asked by people is that even if they write
into standard output, the output doesn't show in the screen. This
happens in windows systems since quite a long time.

To avoid this, you should open a console before outputting anything
into standard output. You do this with

void AllocConsole(void);

Some additional points:
1) (As noted by others) You don't need any of this if you "just want
standard C" and want to appease the topicality police. You just
compiler your program as a console mode app and pretend that the
last 25 years of progress in OS functionality didn't happen.
2) (And therefore) You really only need this when you want to use
Windows qua Windows and also want Old World "standard I/O" as well.
3) I seem to remember that early Windows compilers had a way to
automatically "Windows-ize" stdio programs - i.e., it would open up
a Windows-y window for you and direct stdout there (and also had a
facility for reading the keyboard). I don't know if current
compilers support this. If so, this would be the best advice for
would-be C programmers working under Windows.
4) I think there's a little more to it than just AllocConsole() - having
been there and done that, as they say. You also have to do
GetStandardHandle() and jump through a couple of other hoops.
 
E

Eric Sosman

jacob said:
You can go to hell. There, you can complain to the boss.

Your recent descent from obnoxiousness to deliberate
offensiveness forces another action on me.
 
J

jacob navia

Eric said:
Your recent descent from obnoxiousness to deliberate
offensiveness forces another action on me.

yes?

Go ahead
do whatever you feel like
 
K

Keith Thompson

jacob navia said:
void AllocConsole(void);
[...]

That is not the correct declaration for AllocConsole. According to
Microsoft's own online documentation, the correct declaration is

BOOL WINAPI AllocConsole(void);

Presumably BOOL is some Boolean type (most likely not _Bool, since I
understand Microsoft's compiler doesn't support C99). My guess is
that WINAPI is some sort of macro or extension that specifies
something about the calling convention.

Richard Heathfield pointed out in another thread that the declaration
is incorrect; if he hadn't, I would have assumed you had gotten it
right. If you post Windows-specific information here in comp.lang.c,
and you happen to get something wrong, it's very likely that nobody
will correct your error. If, on the other hand, you had posted to,
say, comp.os.ms-windows.programmer.win32, then your information could
have been checked by other people who actually use AllocConsole.

Getting the declaration for AllocConsole wrong isn't a huge deal. We
all make mistakes; I certainly do. Posting such information *here*,
however, runs a substantial risk of misleading people.

This is why we have different newsgroups.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top