stdout/iobuf - managed code equivalent

N

noel.phillips

Hi,

I am porting a C++ console application to managed C++ dll - for now
basically wrapping it in a class. The console app has the option to
write to a file or stdout using fwrite.

So, how do I bridge the managed gap? I really want to be able to pass
a BinaryStream to the managed C++ code from the calling C# code...can
this be done, and how do I go about modifying the C++ code to handle
it?

Any pointers would be appreciated...

Many thanks,
Noel
 
G

Guest

Hi,

I am porting a C++ console application to managed C++ dll - for now
basically wrapping it in a class. The console app has the option to
write to a file or stdout using fwrite.

So, how do I bridge the managed gap? I really want to be able to pass
a BinaryStream to the managed C++ code from the calling C# code...can
this be done, and how do I go about modifying the C++ code to handle
it?

Any pointers would be appreciated...

Many thanks,
Noel

By common sense, stdin etc are text, not binary?

If you really need to pipeline binary objects, have look at the Monad,
aka "power shell"
http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx

--PA
 
B

Ben Voigt

Hi,

I am porting a C++ console application to managed C++ dll - for now
basically wrapping it in a class. The console app has the option to
write to a file or stdout using fwrite.

So, how do I bridge the managed gap? I really want to be able to pass
a BinaryStream to the managed C++ code from the calling C# code...can
this be done, and how do I go about modifying the C++ code to handle
it?

If it's determined to use fwrite, then you will have to capture the data
with a pipe. A combination of _pipe, _fdopen will give you a FILE* that the
existing code can fwrite to. Then you can either wrap the other end of the
pipe in a BinaryStream and give that to your C# code, or else read from the
pipe, writing into the BinaryStream provided by the C# code.

But fwrite's interface is so simple, you should probably just
#define fwrite streamwrite
and write your own size_t streamwrite( const void * buffer, size_t size,
size_t count, FILE * stream ) function that puts the data where you want it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top