Quote: "Is there a way to have a console window open in tier 2 to log to while the game is running?"
Yes.
Here's an example class that sets it up so that std::cout is directed to the console.
Console.h
#include <windows.h>
#include <string>
#include <assert.h>
#include <cstdio>
#include <io.h>
#include <fcntl.h>
#ifndef _CONSOLE_H_
#define _CONSOLE_H_
class Console
{
public:
Console(const std::string& name);
//get handle,etc etc
HWND getHandle();
void positionConsole(int top,int left);
private:
};
#endif
Console.cpp
Console::Console(const std::string& name)
{
AllocConsole();
SetConsoleTitle(name.c_str());
//need to redirect stdin/stdout/stderr
int hConHandle;
long lStdHandle;
CONSOLE_SCREEN_BUFFER_INFO coninfo;
FILE *fp;
// set the screen buffer to be big enough to let us scroll text
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE),&coninfo);
coninfo.dwSize.Y = 100;
SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE),coninfo.dwSize);
// 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 );
// make cout, wcout, cin, wcin, wcerr, cerr, wclog and clog
// point to console as well
std::ios::sync_with_stdio();
}
HWND Console::getHandle()
{
return GetConsoleWindow();
}
void Console::positionConsole(int top,int left)
{
MoveWindow(getHandle(),left,top,600,400,FALSE);
}