if ( argc > 1 ) { if ( strstr(argv[1], "/h") ) { AllocConsole(); AttachConsole(ATTACH_PARENT_PROCESS); SetConsoleTitle(L"Boom!"); DWORD out = 0; HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); WriteConsole(hStdOut, L"eee", 3, &out, 0); Sleep(5000); FreeConsole(); // } }
void CreateConsoleLog(const char *winTitle){ AllocConsole(); SetConsoleTitle(winTitle); int hConHandle; long lStdHandle; FILE *fp; // redirect unbuffered STDOUT to the console lStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE); hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); fp = _fdopen( hConHandle, "w" ); *stdout = *fp; setvbuf( stdout, NULL, _IONBF, 0 ); // redirect unbuffered STDIN to the console lStdHandle = (long)GetStdHandle(STD_INPUT_HANDLE); hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); fp = _fdopen( hConHandle, "r" ); *stdin = *fp; setvbuf( stdin, NULL, _IONBF, 0 ); // redirect unbuffered STDERR to the console lStdHandle = (long)GetStdHandle(STD_ERROR_HANDLE); hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); fp = _fdopen( hConHandle, "w" ); *stderr = *fp; setvbuf( stderr, NULL, _IONBF, 0 );}