rsk82
rsk82

Reputation: 29377

I've created a new console in win32 window-only app, console is created but nothing gets print on it

this code is compiled with -mwindows under gcc , there is no winapi error message.

#include <windows.h>
#include <stdio.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPTSTR, int nCmdShow) {
  AllocConsole();
  printf("%s\n", "sample text");
  return 0;
}

Result is that console is black empty, no text, no error message.

Upvotes: 0

Views: 179

Answers (1)

Mats Petersson
Mats Petersson

Reputation: 129314

Use:

freopen("CONOUT$", "wb", stdout);

to reopen the stdout after you have created the console. If you plan on using it for input too, then you need:

freopen("CONIN$", "rb", stdin);

and stderr may need opening too:

freopen("CONOUT$", "wb", stderr);

Upvotes: 1

Related Questions