#include #include #include #include // Create a console window for out Win32API app if (AllocConsole() == 0) { MessageBox(0, "no console created", "Error", 0); return 1; } // Now this is the hack: // We link the Windows STD_OUTPUT_HANDLE to the DOS stdout handle: int hCrt = _open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT); *stdout = *_fdopen(hCrt, "w"); setvbuf(stdout, NULL, _IONBF, 0); //The old fashion way: printf("Hello Console,"); //woohoo it works! char *buf = "using Win32API now."; DWORD wr = 0; WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), buf, strlen(buf), &wr, NULL); // Cleanup FreeConsole();