views:

64

answers:

1

I have an array of arrays that I want to pass into a DLL. I am running into the error "There is no marshaling support for nested arrays."

I can pass a single array in fine but if I stack them up it fails. I need/want a "safe" way of passing in the array of arrays.

private static extern int PrintStuff(string[][] someStringsInGroups, int numberOfGroups, int[] lengthSetsInGroups);

EDIT: I am also willing, with enough discouragement and anguish, to accept a solution involving marshaling.

+1  A: 

You could convert the double array to a single array. This can be done by keeping width and height variables, and accessing the indices as such:

string atXY = someStringsInSingleArray[(y * width) + x];

the array can be converted as such:

string * array = new string[width * height];

for (unsigned int y = 0; y < height; ++y) { for (unsigned int x = 0; x < width; ++x) {

  array[(y * width) + x] = someStringsInGroups[x][y];

}

}

// (pass single array to dll)

delete [] array;

Rantaak
To generalize that idea, you can put your 2D array into any serializable form - like a 1D array, or even a string.
Matt Ball
I have serialized some data in a int array before and even did some strut casting on the C++ side so you could read what your were assigning the data to (o[i].value v.s. o[i][7]). When a string is passed into a DLL it is marshaled with a Null on the end of it. If I serialize it my self I will have to add those in. Not a big deal, but the code as it is makes the techs around me squirm. The other requirement is that all code be "safe" in C#. Another solution would be to actually martial the data manully :(
JustSmith