How can I pass an std..fstream or equivalent from C# through CLI to an unmanaged C++ DLL?

Rough application outline:

  • C# application reads a binary file from a database
  • Unmanaged C++ dll is used to "decode" this file and return the information contained therein
  • I can modify any of the C# code. The CLI wrapper is the only portion of the C++ side that I can modify.

I'm currently saving the binary file to disk and passing the path of it to the CLI wrapper where it is opened as an fstream. This is fine for test purposes, but won't work for production for obvious reasons.

I've also looked into passing a byte array to the DLL but I was not able to find a way to convert that to an fstream other than with GlobalAlloc, which I would prefer not to use.

Edit
Report