Hook the printf outputs

I want to get the printf outputs of a foreign C++ dll in my C# application. Is there a way to install a hook?

The foreign c++ dll is encapsulated via my own C++ dll (interface C++ -> C#). I tried to overwrite printf there - unfortunately without success.

Thank you for any hints.
1. You execute code via a small console executable of your own which include the DLL
2. You launch that console executable hidden from your main application and capture the output via interprocess communication.
can you reassign stdout to another stream and use it? I forget the details on this, so I apologize in advance, but I seem to recall that you could override the streams to use other devices (where a device can just be a buffer you share?!)

https://www.geeksforgeeks.org/io-redirection-c/ maybe?

I do not know if this will work: does the dll use the overridden printf or its own local instance? All I can say is, try it... it isnt much code to test one example maybe?
Last edited on
Registered users can post here. Sign in or register to post.