I have developed a MFC dialog based application. Now when I execute this app
from command prompt, I need to write some text back to console.
In console application we achieve this using functions like printf(),
puts(), etc.
Please let me know how do I achieve same in dialog based application since
printf() and other functions are not working here.
Thanks,
Ajay
Take a look at AllocConsole, ReadConsole, and WriteConsole.
Here is an example:
http://www.codeproject.com/KB/cpp/ConsoleAdapter.aspx
AliR.
"Ajay Shinde" <AjayS...@discussions.microsoft.com> wrote in message
news:45748FA7-EEB4-4CFB...@microsoft.com...
Under XP (and presumably later OS's) you can use AttachConsole like
this:
AttachConsole( ATTACH_PARENT_PROCESS );
int hCrt;
FILE *hf;
hCrt = _open_osfhandle( (intptr_t)
GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT );
hf = _fdopen( hCrt, "w" );
*stdout = *hf;
int i = setvbuf( stdout, NULL, _IONBF, 0 );
SetConsoleCtrlHandler( HandlerRoutine, true );
printf( "Hello World\n" );
Under other OS's I'm not aware of how you can do it other than to
cheat by having 2 separate programs - a console one with a .com
extension and a GUI one with a .exe extension. The .com starts first
and can then conditionally run the .exe version.
Dave
So instead of asking how to do something that isn't very good practice, why not ask a
question based on what you are trying to accomplish?
joe
On Fri, 18 Apr 2008 05:59:00 -0700, Ajay Shinde <AjayS...@discussions.microsoft.com>
wrote:
Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm