FAQ Where did my console output go?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jacob navia

    FAQ Where did my console output go?

    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(vo id);

    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(voi d);

    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.

    --
    jacob navia
    jacob at jacob point remcomp point fr
    logiciels/informatique

  • Kenny McCormack

    #2
    Re: FAQ Where did my console output go?

    In article <gehp6b$lsc$2@a ioe.org>, jacob navia <jacob@nospam.o rgwrote:
    >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(vo id);
    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
    GetStandardHand le() and jump through a couple of other hoops.

    Comment

    • Eric Sosman

      #3
      Re: FAQ Where did my console output go?

      jacob navia wrote:
      >
      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.

      --
      Eric Sosman
      esosman@ieee-dot-org.invalid

      Comment

      • jacob navia

        #4
        Re: FAQ Where did my console output go?

        Eric Sosman wrote:
        jacob navia wrote:
        >>
        >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.
        >
        yes?

        Go ahead
        do whatever you feel like


        --
        jacob navia
        jacob at jacob point remcomp point fr
        logiciels/informatique

        Comment

        • Keith Thompson

          #5
          Re: FAQ Where did my console output go?

          jacob navia <jacob@nospam.c omwrites:
          [...]
          void AllocConsole(vo id);
          [...]

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

          BOOL WINAPI AllocConsole(vo id);

          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.program mer.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.

          --
          Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
          Nokia
          "We must do something. This is something. Therefore, we must do this."
          -- Antony Jay and Jonathan Lynn, "Yes Minister"

          Comment

          • Lassie

            #6
            Re: FAQ Where did my console output go?


            "Eric Sosman" <esosman@ieee-dot-org.invalidschr eef in bericht
            news:gei3ar$btt $1@registered.m otzarella.org.. .
            jacob navia wrote:
            >>
            >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.
            you are touching yourself now?


            Comment

            Working...