How do I get the base STDIO FILE * managed by System.IO.FileStream?
I am writing a .NET adapter for a C / C ++ library where the "bar" method takes a standard stdio FILE *. Is it possible to build an interface so that a managed (File) Stream can be passed by a user of managed code? It is not about creating an intermediate buffer and code to exchange data between them. Also does the assumption that bar () is reading only makes things better?
// native code
void bar(FILE*);
// interface for managed code
void foo(System::IO::FileStream^ file)
{
FILE* stdio_handle = ???;
bar(stdio_handle);
}
source to share
Not necessarily a stdio
descriptor. This is a Windows descriptor. I don't think it is FileStream
built on stdio
to have a handle stdio
.
As Mark pointed out and mentioned in the MSDN link, you may need to use the property SafeFileHandle
(if you are using .NET 2.0+) instead of Handle
(which is now deprecated). However, only Handle
available in older versions.
source to share