I am making a DLL in C++ to use in C#. I need to transfer a array list from C# to C++ vector. The array will look like
[][]
[][]
.
.
I referred to this answer for marshaling List to vector link. It worked for one dimension array. But for list of array which gives a nested array gives an error "There is no marshaling support for nested arrays".
My code looks like this on C# end,
[DllImport("./x64/Debug/Test.dll")]
public static extern void analysis([MarshalAs(UnmanagedType.LPArray)] double[][] values, int len);
static void Main(string[] args)
{
List<double[]> lst = new List<double[]>();
lst.Add(new double[] { 1.2, 1.3 });
lst.Add(new double[] { 2.3, 2.4 });
lst.Add(new double[] { 3.4, 3.5 });
analysis(lst.ToArray(), lst.Count);
}
And on C++ end,
extern "C" __declspec(dllexport) void __cdecl analysis(double* values[], int len)
{
using namespace std;
vector<array<double,2>> ind(values, values + len);
int n = ind.size();
for (int i = 0; i < n; i++)
{
cout << ind[i][0] << ind[i][1] << endl;
}
}
Also, I am not sure I wrote the vector constructor correctly. I would very much appreciate some help.