We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Been trying to return a string, not printing it to console, but there seem not to be a way.
I did try 2 different approaches
//export PrintHello2 func PrintHello2(Input *C.char, Output **C.char) int32 { *Output = C.CString(fmt.Sprintf("From DLL: Hello, %s!\n", C.GoString(Input))) return 1 }
and
//export PrintHello4 func PrintHello4(Input *C.char) *C.char{ return C.CString(fmt.Sprintf("From DLL: Hello, %s!\n", C.GoString(Input))) }
I'm calling this code from .net using the following test code
class Program { [DllImport("goDLL.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] public static extern int PrintHello2([In] byte[] data, [MarshalAs(UnmanagedType.I1)] ref SByte[] output); [DllImport("goDLL.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)] public static extern SByte[] PrintHello4(byte[] data); static void Main(string[] args) { string res = "demo"; SByte[] output= { }; Console.WriteLine("PrintHello4 Returns: " + PrintHello4(Encoding.UTF8.GetBytes(res)).Length); Console.WriteLine("PrintHello2 Returns: " + PrintHello2(Encoding.UTF8.GetBytes(res), ref output)); Console.WriteLine("Ref Val changed to: " + output.Length + "\n"); } }
None of the Go function works as expected and program chashes with System.Runtime.InteropServices.MarshalDirectiveException for any of the 2 functions
The text was updated successfully, but these errors were encountered:
My bad, problem was in .net
Solution: https://stackoverflow.com/questions/48208098/using-generated-golang-dll-to-return-string-or-c-char/48227520#48227520
Sorry, something went wrong.
Good to hear there was a solution, I will close the issue now
No branches or pull requests
Been trying to return a string, not printing it to console, but there seem not to be a way.
I did try 2 different approaches
and
I'm calling this code from .net using the following test code
None of the Go function works as expected and program chashes with System.Runtime.InteropServices.MarshalDirectiveException for any of the 2 functions
The text was updated successfully, but these errors were encountered: