Neither of them worked for me, they only work when I set the SUBSYSTEM to Console, and define entry point as 'int main' instead of 'WinMain'. So I ended of doing this:
|  1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 | typedef void (WindowsLogFn)(const char*);
static WindowsLogFn* windowsLog;
static void windowsLogConsole(const char* msg)
{
	HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
	DWORD written; // ignored
	char* t = (char*)msg;
	DWORD len = 0;
	while (*t != 0) { t++; len++; }
	WriteConsoleA(hOut, msg, len, &written, 0);
}
void log(const char* cstr)
{
	windowsLog(cstr);
	windowsLog("\n");
}
// entry point
if(IsDebuggerPresent())
{
	windowsLog = OutputDebugStringA;
}
else
{
	AllocConsole();
	windowsLog = windowsLogConsole;
}
// others
 |