none
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)

    Tuesday, March 5, 2013 8:00 AM