I\'d like to have a windows application with the following behaviour:
1. if it is started from an existing command line window (cmd.exe) then it writes its stdout to tha
Found out the answer here: http://dslweb.nwnexus.com/~ast/dload/guicon.htm
DWORD ret = AttachConsole(-1);
if (ret != 0) {
HANDLE lStdHandle = GetStdHandle(STD_OUTPUT_HANDLE);
int hConHandle = _open_osfhandle((intptr_t)lStdHandle, 0);
FILE* fp = _fdopen( hConHandle, "w" );
*stdout = *fp;
}
And as for making cmd.exe wait, that doesn't seem possible: http://blogs.msdn.com/b/oldnewthing/archive/2009/01/01/9259142.aspx