I'd like to have my program (a GUI application) create a console and just
send it a certain output to be displayed.
I don't want to have to code an application that (started by my GUI
application) creates a console, receives the output and prints it but I'd
like to use a standard console application (cmd.exe under winnt/2000 or
command.exe under win9x) and just have it display the output.
Can this be accomplished and how?
Thx.
Regards,
Bob Rock
"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken
"Bob Rock" <nospam.yet_ano...@hotmail.com> wrote in message
news:a0q6nr$ml01i$1...@ID-98646.news.dfncis.de...
You might be better off having a console app that creates windows rather
than a GUI app that has to AllocConsole(). I've never played with
AllocConsole(). Maybe you will get the same thing either way. All I know is
if you have a console app that happens to create windows, it will all work
fine. But if you may not always want to have the console window, you will
want to go the AllocConsole() route.
Look into:
stdio.h
_pipe
popen
Old UNIX tricks. Boy, UNIX has all the answers :)
--
http://www.pc-tools.net/
Windows, Linux & UNIX software
Q105305 - "INFO: Calling CRT Output Routines from a GUI Application"
Regards,
Bob Rock
"Margaret" <marg...@example.com> wrote in message
news:27p13ukfb23ul3e6h...@4ax.com...
> "Bob Rock" <nospam.yet_ano...@hotmail.com>
> hmmm...I mightn't understand your question correctly.
> What happens if you simply include conio.h and call,
> e.g., printf()?
>
> Margaret
Is AllocConsole() of any use?
That way, AllocConsole() returns a file handle, and you can write to that
handle to print, or read from it to get input.
Sometimes when debugging Windows programs I find it convenient to send debug
statements to a console.
The hack below defines the two functions I use to accomplish that -
getConsole() and closeConsole(). The former allocates a console and wires it
to the standard output device. The latter frees it. The console is not
reference counted - multiple get operations return the same console, a
single close deletes it.
Note that it makes printf() work by using the technique described in the kb
article to which Igor directed you. I'm not sure whether that operation is
sufficient to insure that cout would work as well. So in C++ modules I do
something like this:
ostream_withassign cout = getConsole();
cout << "Hello, world";
That seems to work for me.
Regards,
Will
#include <afx.h>
#include <io.h>
#include <stdio.h>
#include <fstream.h>
filebuf *pfb = 0;
ostream_withassign console = 0;
ostream_withassign getConsole()
{
int fd;
FILE *fp;
HANDLE hCon;
if ( console == 0 )
{
// Allocate a console
AllocConsole();
// Make printf happy
hCon = GetStdHandle(STD_OUTPUT_HANDLE);
fd = _open_osfhandle(reinterpret_cast<long>(hCon), 0);
fp = _fdopen(fd, "w");
*stdout = *fp;
setvbuf(stdout, NULL, _IONBF, 0);
// Make cout happy
pfb = new filebuf(fd);
console = pfb;
}
return console;
}
void closeConsole(ostream_withassign ostr)
{
delete pfb;
console = 0;
FreeConsole();
}
ftp://ftp.flipcode.com/cotd/zxlog.zip
regards
Chr. Jensen
"Bob Rock" <nospam.yet_ano...@hotmail.com> wrote in message
news:a0sl2d$mqmo2$1...@ID-98646.news.dfncis.de...