Reputation: 928
I need to call a c++ function from c#.
c++ function is
BOOL Usb_GetDevicesList(int &iNbDevices, char aszDeviceName[][128]);
I tried
[DllImport("UsbComm.dll", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern int Usb_GetDevicesList(int iNbDevices, out byte[][] aszDeviceName);
I got error
Cannot marshal 'parameter #2': There is no marshaling support for nested arrays.
Please help me in converting this c++ function to C#.
Upvotes: 1
Views: 348
Reputation: 3295
You can just flatten the 2D array to a single dimensional one and then pass it.
flattened_array[(y * width) + x] = source[x][y];
Refer to this answer
Upvotes: 1