NO

Author Topic: Tip about using stdout in GUI programs  (Read 2554 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: 1774
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.

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?