I have a problem calling a C DLL function from my C # code. The C DLL has a function that takes a file name ( const char * ), then opens the file, does some work on the content (reads through FILE * ) and writes the result to another file. I would like to optimize it, so the read / write operations on the disk are not performed, since I have a file that will be processed already in the memory stream in my C # application. I have the right to change both ends (C # application and C DLL). The C # application is based on .NET 2.0.
I was thinking of expanding the DLL so that it has a function that accepts and pops out an array of bytes so that I can easily PInvoke it. The output seems easy on the C side - instead of writing to FILE * , I could just store the sequential bytes into an array, but the input seems complicated. I donβt know how to work on the C side with the received byte array, to make it in the memory stream and work with it instead in the physical file stream from this point (I do not want to rewrite the entire DLL to read from the byte array instead of FILE * - I I want most of the internal components of the DLL to remain unchanged, just to wrap it up and configure the inputs / outputs). But actually I donβt know, maybe there is a better idea for this.
So the question is : how to turn an array of bytes in C into (FILE *) without writing it to disk and opening FILE * to read this file? Alternatively : how to transfer a memory stream from C # to PInvoke in a C DLL so that it can be easily recognized on the C side and works with FILE * (again, without a physical disk it writes / reads, only in memory)?
source share