Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "C"
  5. "fmt"
  6. )
  7.  
  8. func main() {}
  9.  
  10. //export Test
  11. func Test(str *C.char) {
  12. fmt.Println("Hello from within Go")
  13. fmt.Println(fmt.Sprintf("A message from Go: %s", C.GoString(str)))
  14. }
  15.  
  16. using System;
  17. using System.Runtime.InteropServices;
  18.  
  19. namespace test
  20. {
  21. class Program
  22. {
  23. static void Main(string[] args)
  24. {
  25. Console.WriteLine("Hello");
  26. Console.WriteLine(GoFunctions.Test("world"));
  27. Console.WriteLine("Goodbye.");
  28. }
  29. }
  30.  
  31.  
  32. static class GoFunctions
  33. {
  34. [DllImport(@<path to test.dll>, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
  35. public static extern string Test(GoString str);
  36. }
  37. }
  38.  
  39. go build -buildmode=c-shared -o test.dll <path to go file>
  40.  
  41. Hello from within Go
  42. A message from Go: w
  43.  
  44. panic: runtime error: growslice: cap out of range
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement