Array Parameters when calling exported Go func from C#

Hi

I am trying to call a go func from C# and pass in single array. However I am struggling to enable the called Go function to see it as an array.

In Go.

package main

import “C”

func main() {
}

//export DoInt
func DoInt(dataX []int) int {
return len(dataX)
}

in C# I am importing this way

[DllImport(@“test.dll”, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
public static extern int DoInt(int[] dataX);

And calling it in a function

  int[] bvals = { 1,  6, 8888, 4343, 3};
  int k = GoFunctions.DoInt(bvals);

In C# when I execute the code k is 8888 and within the Go function when I try dataX[0] I cannot access the array elements and the code exits.

Should I be passing a pointer? or reference to the array instead of the array?

Thanks

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.