Hi,
on help file I've found a function for redirect stdout to a new console window.
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
freopen("CONOUT$", "w", stdout);
instead of
// 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.
It should probably work with M$ compiler, but PellesC standard handles are not fully compliant with M$ library.
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?