locked
Marshalling char[][] RRS feed

  • Question

  • C function has char[][] parameter (in and out!)

    How should I call it from C# code?

    func(char[][SOME_SIZE]);


    • Edited by olelukoyya Tuesday, March 5, 2013 1:04 AM
    Tuesday, March 5, 2013 1:03 AM

Answers

  • Try the default marshalling:

    [DllImport("MyDll.dll")]

    static extern void func(sbyte[,] data);

    The data can be allocated like this:

    sbyte[,] data = new sbyte[10, 100];

    where 100 is a sample value of SOME_SIZE.

    The native code should also know the other size – 10.

    The sizes can be also passed as parameters:

    [DllImport("MyDll.dll")]

    static extern void func(sbyte[,] data, int n, int m);

    . . .

    sbyte[,] data = new sbyte[10, 100];

    func(data, data.GetLength(0), data.GetLength(1));

    . . .

    // The native function:

    void func(char * data, int n, int m)

    • Proposed as answer by Mike Feng Wednesday, March 6, 2013 8:28 AM
    • Marked as answer by Mike Feng Wednesday, March 13, 2013 5:11 PM
    Tuesday, March 5, 2013 8:00 AM