Pelles C forum

Pelles C => General discussions => Topic started by: Alessio on November 04, 2006, 04:21:43 PM

Title: Tip about using stdout in GUI programs
Post by: Alessio 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.
Title: Tip about using stdout in GUI programs
Post by: frankie 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.
Title: Tip about using stdout in GUI programs
Post by: severach 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?