I’m trying to access a function in a DLL from C# that I compiled in C++ with the signature:
Code:bool DecodeJpeg(byte* arrayPointer, int arrayLength, byte* &newArray)
How would I go about passing the information from C# if I want to pass a simple array pointer and then use newArray as the data I want returned from the function?
From what I have been reading I will be trying this:
I’m concerned with the way the array will be passed to the DLL and how the memory that will be allocated in the DLL will be handled when it is passed back into my C# code. Will just a pointer be adequate to access the data? How will it be affected by garbage collection?Code:bool DecodeFile(byte* arrayPointer, int arrayLength, byte* &newArray) Byte[] someArray; Byte* rp; //open a file, and assign enough memory to the array to hold the file int len = someArray.length(); fixed(byte* bp = someArray) { DecodeFile(bp, len, rp) }
Because of my use of a reference and a pointer in the C++ code I think I should use the out statement in the signature in C#. Is this correct? E.g.:
Thanks for any information you have.Code:public static extern bool DecodeFile(byte* data, int len, out byte* fileMap);




Reply With Quote