output to console from MFC

Started by
3 comments, last by GameDev.net 17 years, 4 months ago
I have an MDI utility that I've built with MFC (VC8) which I now also want to be able to use from the command line. I have added code to handle command line arguments with the help of CCommandLineInfo. But I can't find anything helpful about how to output text to the same console. I mostly need it to display error messages. I don't want to use a MessageBox when I run the program from the command line. Also how do I exit the program with an error code so that a batch file running the program can catch it?
Advertisement
Here is an article on Code Project about openning an cmd window and printing to it. Hope it helps.

http://www.codeproject.com/debug/oleconsolewindow.asp
Unfortunately I have already seen that page and it doesn't help. That code opens a new console and outputs to it. I want to output to the console that started the program.
Quote:Original post by Decept
Unfortunately I have already seen that page and it doesn't help. That code opens a new console and outputs to it. I want to output to the console that started the program.
printf() or cout should do the trick.

As for exiting with an error code, I seem to recall there's a file (MyApp.cpp or something) which has a WinMain-like function in it. You should modify that to return an error code instead of 0.
MFC overrides console output...
I had found this article while I was using VC++6, but it may still work with VC++2005: http://www.codeproject.com/cpp/EditBin.asp

all you have to do is:
EditBin MyProgram.exe /SUBSYSTEM:CONSOLE

This topic is closed to new replies.

Advertisement