I/O Stream and MFC Control Integration

B

Bugenhagen

Hello

I'm attempting to develop an application using MFC. In the application, I
would like to integrate a previously written C program that uses 'printf' to
display information to the user. What I want to do is instead of printing to
a console, print to a window in my MFC application. I've been trying to
research how to do this and the information I've found so far leads me to
believe that I can achieve this by manipulating I/O streams and buffers.
However, I'm having trouble finding a good example. My inquiry is two-fold.
1. What's the best way to redirect the input and output stream of a console
application to an MFC application? 2. Assuming I figure that out, what is
the best MFC control to use specifically to display output from the I/O
stream? I'm thinking of using a Static Text control but there may be a
better one.

TIA
 
W

William DePalo [MVP VC++]

Bugenhagen said:
I'm attempting to develop an application using MFC. In the application, I
would like to integrate a previously written C program that uses 'printf' to
display information to the user. What I want to do is instead of printing to
a console, print to a window in my MFC application. I've been trying to
research how to do this and the information I've found so far leads me to
believe that I can achieve this by manipulating I/O streams and buffers.
However, I'm having trouble finding a good example. My inquiry is two-fold.

1. What's the best way to redirect the input and output stream of a console
application to an MFC application? 2.

Best is oh so subjective and the world is oh so relative. :)

One thing that people often do is redirect the standard output device to a
pipe. With this scheme the MFC application creates a pipe and issues a read
(perhaps async - aka overlappped). Then when the unsuspecting C application
does a printf, the text is written to a pipe which the MFC application
reads.

There is a knowledge base article

http://support.microsoft.com/?id=Q190351

which discusses the technique in the context of parent and child processes.
In your environment the MFC application would be the parent. The technique
is as old as the hills as the pipe is the basis of "component object model"
as found on 'nix, 'nux, and 'pux platforms. :)
Assuming I figure that out, what is
the best MFC control to use specifically to display output from the I/O
stream? I'm thinking of using a Static Text control but there may be a
better one.

If you need help here, try a UI group. I would expect that an edit control
or a rich-edit control might be a better fit.

Regards,
Will
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top