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

Jonathan Gilbert 2a5gjx302@sneakemail.com
Tue, 31 Aug 2004 14:17:23 -0400


At 07:54 AM 30/08/2004 -0400, Jonathan Pryor	 wrote:
>On Mon, 2004-08-30 at 04:01, =D0=90=D1=80=D1=82=D0=B5=D0=BC =D0=9F=D0=BE=
=D0=BF=D0=BE=D0=B2 wrote:
>> 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)
>
[snip]
>This is one of the reasons why C++ introduced iostreams (that, and to
>have type-safe I/O of class objects without needing extra casts).
>
>Consequently, if you want to read data written to a FILE*, you have to
>use a temporary file first, and then read the file afterward.

There is one other possibility: make your own version of fopen(), fread(),
etc., using your own polymorphic structure and mono_runtime_invoke calls to
call back into a Stream if the handle is based on one. I've used this
approach myself to write highly-generic C code that could, e.g., open a
block of memory like a file.

Jonathan