I have the following C ++ method:
__ declspec (dllexport) void __stdcall getDoubles (int * count, double ** values); the method selects and fills the double array and sets * calculates the size of the array.
The only way I was able to get this to work through pinvoke is:
[System.Runtime.InteropServices.DllImportAttribute("xx.dll")] public static extern void getDoubles(ref int count, ref System.IntPtr values);
and use:
int count = 0; IntPtr doubles = new IntPtr(); Nappy.getDoubles(ref count, ref doubles); double[] dvs = new double[count]; for(int i = 0;i < count;++{ dvs[i] = (double)Marshal.PtrToStructure(doubles, typeof(System.Double)); doubles = new IntPtr(doubles.ToInt64()+Marshal.SizeOf(typeof(System.Double))); }
the values are in the dvs array Is there a better way to do this without forcing pointer arithmetic in a controlled language ...
c ++ arrays c # pinvoke
zohar
source share