I have an application written in C# and using a DLL written in C After some delegate (function pointer), I managed to call the C function. This function is expected to do a lot of processing on some data, and then return the processed binary data back to C# along with the size of the data.
The prototype of the C# managed function is:
private unsafe delegate void MyCallback (IntPtr cs_buf, Int32 cs_size);
And I call this from my C code as:
void* c_buf = NULL; int c_size = 0; .... some processing here to fill buf and size...... MyCallback (c_buf, c_size);
In C# managed code, I need to call a function from MyCallback that has a prototype:
void foo (byte[] cs_buf, int cs_size)
Now there is no problem with the cs_size value, but what is the correct way to use / transfer the binary buffer from C code to C # code so that it can be used as byte[] in C # code.
If what I am doing is the correct way, what should be the recommended way to convert the received IntPtr cs_buf to byte[] ?
Thanks Vikram
source share