[Mono-list] C# bindings and FILE* question

Артем Попов tfwo@mail.ru
Tue, 31 Aug 2004 08:32:32 +0700


On Mon, 2004-08-30 at 16:41 +0200, Antony Lesuisse wrote:
> Jonathan Pryor <jonpryor@vt.edu> [040830]:
> > On Mon, 2004-08-30 at 04:01, ?????????? ?????????? wrote:
> > > Is it possible to pass a Stream object to the C code as FILE* pointer?
> > 
> > No.  They're completely different.  You could P/Invoke into libc for
> > fopen(3), fclose(3), etc., and use IntPtr as a FILE*, if necessary.
> > 
> > > I'd like to wrap some native code that has lots of functions with FILE*-
> > > args and I want to pass at least to kind of Stream from the class
> > > library to them (the Memory Stream and the File Stream)
> > 
> > This isn't possible, even if you were in C.  FILE* doesn't support
> 
> Actually it is possible if you use the GNU libc (linux and cygwin):
> 
> for the generic way see section:
> 
>     12.21.3.2 Custom Stream Hook Functions
>     http://www.delorie.com/gnu/docs/glibc/libc_232.html
> 
> and for simple buffers like MemoryStream:
> 
>     12.21.1 String Streams
>     http://www.delorie.com/gnu/docs/glibc/libc_228.html
> 

This is amazing! However, Mono implementation of MemoryStream does not
use these routines and does even have a FILE*-like handle, so I guess I
still have some c glue to write... -Artem