I have following c++ code:
int nCount[5] = {0, 1, 2, 3, 4};
return &nCount[0];
I am receiving this code in C# P/Invoke layer with following code:
[DllImport(@"/sharedlibrary.so",CallingConvention = CallingConvention.Cdecl)]
public extern static IntPtr read_array_adapter();
Which works well. But when I run c# code below:
int[] result = new int[5];
Marshal.Copy(ptr, result, 0, 5);
It populates the array result with some random large numbers which looks like below:
int[]{1663918692,1852139884,1970351988,1936417641,244554078}
which has no relation with my original array in C++ which looks like {0,1,2,3,4} Any idea what Marshal.Copy
may be doing to populate these kind of results?