NO

Author Topic: Tip about using stdout in GUI programs  (Read 3196 times)

Alessio

  • Guest
Tip about using stdout in GUI programs
« on: November 04, 2006, 04:21:43 PM »
Hi,

on help file I've found a function for redirect stdout to a new console window.

Code: [Select]
void RedirectStdOut(void)
{
    CONSOLE_SCREEN_BUFFER_INFO csbi;

    // Try creating a new console window.
    if (!AllocConsole()) return;

    // Set the screen buffer to be larger than normal.
    if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi))
    {
        csbi.dwSize.Y = 1000; // any useful number...
        SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), csbi.dwSize);
    }

    // Redirect "stdout" to the console window.
    fclose(stdout);
    setbuf(stdout, NULL);
    *stdout = *_fdopen(_open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE), 0), "w");
}


Why I can't use

Code: [Select]
freopen("CONOUT$", "w", stdout);

instead of
Code: [Select]
// Redirect "stdout" to the console window.
    fclose(stdout);
    setbuf(stdout, NULL);
    *stdout = *_fdopen(_open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE), 0), "w");


??

It works on another compiler.

Thank you.

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2096
Tip about using stdout in GUI programs
« Reply #1 on: November 04, 2006, 06:17:06 PM »
It should probably work with M$ compiler, but PellesC standard handles are not fully compliant with M$ library.
It is better to be hated for what you are than to be loved for what you are not. - Andre Gide

severach

  • Guest
Tip about using stdout in GUI programs
« Reply #2 on: December 08, 2006, 07:12:00 PM »
Quote from: "frankie"
It should probably work with M$ compiler, but PellesC standard handles are not fully compliant with M$ library.


I'm working on a single #include file that makes Pelles work with MSVCRT.DLL and be compatible with standard handles. It is fairly automated and working for all the quick and dirty console projects I'm making. Anyone want to help push it along?