471,598 Members | 1,273 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,598 software developers and data experts.

Console output in a window / text box

Hello,

i've been dealing with this problem whole morning, but havent quite
figured out the solution. The thing is: i have a C# program that calls
a function from a C++ dll. While running, the function uses "cout" a
lot, to print out useful data. Now here is the problem: this data is
being written in an output window and i want to redirect this data to
an application window or a text box. If thats not possible, then the
data should be at least written to a console window, that would come
up, when this function is called.

Any help would be greatly appreciated, thanks

Dec 7 '05 #1
2 3395
Roosty,

You can create a class that derives from TextWriter, overriding the
Write method (that takes a single character) and then having that fire an
event every time a character is written. Then, you can just call SetOut on
the Console class, passing an instance of your TextWriter.

You would then hook to an event on your text writer, which is fired
every time the character is written.

Overriding the Write method that takes a character is the minimum you
would have to do. However, this would result in a good number of events
being fired.

You could override some of the more specific methods, if you wish, for
the sake of performance.

This should capture the results of writing to cout from your unmanaged
DLL, and then you can display them anyway you wish.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Roosty" <ro******@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Hello,

i've been dealing with this problem whole morning, but havent quite
figured out the solution. The thing is: i have a C# program that calls
a function from a C++ dll. While running, the function uses "cout" a
lot, to print out useful data. Now here is the problem: this data is
being written in an output window and i want to redirect this data to
an application window or a text box. If thats not possible, then the
data should be at least written to a console window, that would come
up, when this function is called.

Any help would be greatly appreciated, thanks

Dec 7 '05 #2
Hello Nicholas, thanks for replying so quickly. Well, im quite new to
C# , so would it be too much trouble for you to write the code of
exactly what you mean. I have seen quite a few similar questions, but
none of the answers offered the exact solution code.

Dec 7 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

16 posts views Thread by Chris Maloof | last post: by
6 posts views Thread by Max | last post: by
2 posts views Thread by Boba | last post: by
2 posts views Thread by =?Utf-8?B?TWFuanJlZSBHYXJn?= | last post: by
2 posts views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.