开发者

Redirect stdout+stderr on a C# GUI project

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.


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".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜