Due to server problems the website is temporarily offline! Visit http://www.smorgasbordet.com/pellesc/ to download Pelles C.
I have a console window that starts up and runs with my Windows app.I currently have to close the windows app and then close the console also.Is there a way to close the console window through the WM_CLOSE command?I am interested in learning how Pelles makes the console stay active. I used to have to cause the console to stay open by using some kind of read or get command.
How do you get the console window?
...#pragma comment(linker, "-subsystem:console")#pragma comment(linker, "-entry:wWinMainCRTStartup")...
Just use this in GUI program (UNICODE)Code: [Select]...#pragma comment(linker, "-subsystem:console")#pragma comment(linker, "-entry:wWinMainCRTStartup")...
#ifndef NDEBUG//#define TRACE(x) OutputDebugString(x)#define TRACE(x) WriteStdOut((x))void __cdecl WriteStdOut(TCHAR *szTxt){ static HANDLE hStdOut = 0; if (!hStdOut) { AllocConsole(); hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); } WriteConsole(hStdOut, szTxt, lstrlen(szTxt), 0, 0);}#else#define TRACE(x)#endif
TRACE("My TRACE comment\n");
// redirect unbuffered STDIN to the console lStdHandle = (long)GetStdHandle(STD_INPUT_HANDLE); hConHandle = _open_osfhandle(lStdHandle, _O_TEXT | _O_RDONLY); fp = _fdopen( hConHandle, "r" ); *stdin = *fp; setvbuf( stdin, NULL, _IONBF, 0 ); fflush(stdin); //Add Flush
freopen("CONIN$", "r", stdin);freopen("CONOUT$", "w", stdout);freopen("CONOUT$", "w", stderr);
You don't need 6 lines to redirect a stream, 3 will do them all, without having to employ the undefined behaviour of fflush(stdin)
// You must flush the input buffer before using gets. // fflush on input stream is an extension to the C standard
Code: [Select]freopen("CONIN$", "r", stdin);freopen("CONOUT$", "w", stdout);freopen("CONOUT$", "w", stderr);