Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / March 2008

Tip: Looking for answers? Try searching our database.

How to capture "printfs" from unmanaged C++

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
barker7@yahoo.com - 12 Mar 2008 21:33 GMT
I posted this to the interop group. I'm reposting to troll for a few
more ideas.

In my managed C# app we capture trace statements and direct them to a
log file using trace listeners. Part of the app uses unmanaged C++
dlls, and unfortunately, the C++ printfs don't get picked up and are
simply printed to the console window.

Is there any way I can capture the output of the printfs and then
redirect them to the same file that the trace listener is writing to?

I do have access to the unmanaged C++ code if the solution involves
not using printfs. The important thing is that the C++ printfs and the
C# trace messages end up in the same file.

One solution from the interop group was to compile the C++ with /clr
and then replace the printfs with Trace.WriteLine(). Any less invasive
techniques. Maybe somehow redirecting the printfs to someplace that
can be picked up by .Net.

Thanks

Mitch
Peter Duniho - 13 Mar 2008 00:32 GMT
> [...]
> Is there any way I can capture the output of the printfs and then
[quoted text clipped - 3 lines]
> not using printfs. The important thing is that the C++ printfs and the
> C# trace messages end up in the same file.

It's been some time now, but my recollection is that the standard CRT has  
a provision for overriding the default stdout stream.  You could do that  
in a single place in the C++ code, and then in that overridding output  
redirect the output back up to the managed log file via the usual managed  
mechanisms.

I apologize for not having the details as to how to redirect stdout from  
within the process but this is, after all, a newsgroup for managed code.  
:)  I assume that if you posted the same question to a forum specifically  
about using C++ and the standard CRT, they'd be able to tell you more  
details.  Or you might be able to find it in the C++ reference docs on  
MSDN.

Pete

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.