8

I've got an unmanaged DLL that is writing log messages to standard output. I'm calling this DLL with P-invokes from a WPF app and I need to get the standard output stream log. I've tried Console.SetOut, but that only seems to capture information written using Console.Write, etc.

Anyone have any ideas? I've found similar questions asked elsewhere but they don't have answers.

RandomEngy
  • 14,931
  • 5
  • 70
  • 113
  • Have you considered writing your intermediary native DLL that calls this DLL, captures the stdout and then passes everything back to managed via P/Invoke? – Tamas Czinege Feb 07 '10 at 01:14
  • I guess it's possible. Though it would be really annoying because I'd want to display the data as it came back so it would require polling as well as that extra wrapper library. I'm hoping there's a cleaner way of doing it. – RandomEngy Feb 07 '10 at 03:01

1 Answers1

4

Since you're already calling PInvoke, I guess you wont mind an extra call to SetStdHandle. A similar thread is here Redirect stdout+stderr on a C# Windows service

Community
  • 1
  • 1
Mattias S
  • 4,748
  • 2
  • 17
  • 18
  • I actually did find that after I had asked the question, but sadly it did not work for me. Maybe the fact that this is cross-compiled from MinGW is messing with the output stream somehow. I'll try to get another DLL and see if the build method changes anything. – RandomEngy Feb 09 '10 at 18:53
  • Accepting... turns out my cross-compiled MinGW .dll acts differently. I had to have it capture its own output and call a callback I gave it through Pinvoke. – RandomEngy Mar 13 '10 at 20:17
  • @RandomEngy my C dll is also compiled in MinGW and I'm seeing the same issue. Were you able to find a way to get this working? – Thick_propheT Aug 25 '21 at 04:43
  • @Thick_propheT https://github.com/HandBrake/HandBrake/blob/master/libhb/hb.c Look at hb_register_logger and redirect_thread_func . Also of interest: https://github.com/HandBrake/HandBrake/blob/master/win/CS/HandBrake.Interop/Interop/HbLib/HBDelegates.cs and hb_register_logger pinvoke setup in https://github.com/HandBrake/HandBrake/blob/master/win/CS/HandBrake.Interop/Interop/HbLib/HbFunctions.cs . – RandomEngy Aug 25 '21 at 05:32