0

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.

1 Answer 1

1

Try use json. In c#:

string jsonString = JsonSerializer.Serialize(lst);

Then in C++ unserialize.

Sign up to request clarification or add additional context in comments.

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.