Как в GUI приложении открыть консоль и назначить stdin,stdout,stderr
|
#include <windows.h> #include <stdio.h> #include <io.h> #include <fcntl.h>
BOOL CreateConsole(void) { FreeConsole(); //на всякий случай if ( AllocConsole() ) { int hCrt = _open_osfhandle((long) GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT); *stdout = *(::_fdopen(hCrt, "w")); ::setvbuf(stdout, NULL, _IONBF, 0); *stderr = *(::_fdopen(hCrt, "w")); ::setvbuf(stderr, NULL, _IONBF, 0); return TRUE; }return FALSE; }
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { CreateConsole(); printf("WinMain with Console test\n");
MSG msg; while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return TRUE; } |