0

I have a unmanaged dll (C++) which I can't change.
How can I get result of STDOUT from this dll to my C# GUI project ? for example DLL have void like this:

__declspec(dllexport) void PrintMsg();

void PrintMsg()
{
cout << "Some text" << endl ;
}

I find this solution Redirect stdout+stderr on a C# Windows service , but all redirected data write to file, I need recive stdout without save to output file, the best option get output in a variable.

If possible, tell me how.

Thanks.

Community
  • 1
  • 1
user497447
  • 43
  • 2
  • 7
  • 1
    What does this have to do with C++ and VB.NET? – Seth Carnegie Aug 04 '11 at 23:07
  • Sorry, I forgte this solution http://stackoverflow.com/questions/5510285/c-net-gui-application-native-library-console-stdout-redirection-via-anonymo very good way ideal for me, but work only one time, and not answered why :( – user497447 Aug 04 '11 at 23:07
  • Seth, I have a unmanaged dll for streaming stock prices and main programm written in .net – user497447 Aug 04 '11 at 23:11
  • OK, but remove the tags that are unnecessary, like VB.NET and C++, because it doesn't really matter what languages your unmanaged dll were written in, or VB.NET just because it's .NET. – Seth Carnegie Aug 04 '11 at 23:13
  • also, your question is unclear. void methods do not have results, so did you just want to redirect stdout for your program? – Seth Carnegie Aug 04 '11 at 23:16
  • 1
    Seth, thanks for the comments, I changed the question to a more correct and remove some tags. Yes you right, I need to redirect STDOUT from dll to my .NET program. – user497447 Aug 04 '11 at 23:23
  • yeah, apparently you need a native handle to use `SetStdHandle`. Is using a file and just reading it after output is written an option? – Seth Carnegie Aug 04 '11 at 23:51

1 Answers1

0

I believe you should be able to call CreateFile() and pass it a name unique to your applicaton (NOT A FILENAME) to create a "device". You'll have to do it twice actually, one for "writing" and one for "reading", and then use SetStdHandle and redirect stdout to the "writing" handle. You should then be able to use the "reading" handle to read in everything sent to stdout. I've never tried this, so you'll have to look up exactly how to make an arbitrary communications "device".

Mooing Duck
  • 64,318
  • 19
  • 100
  • 158