-
-
Save cashlalala/eb96d3f30e81c7a11b9d9c6c55d4a087 to your computer and use it in GitHub Desktop.
Revisions
-
andrewloable created this gist
Jun 23, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ using System; using System.Runtime.InteropServices; using System.Text; namespace GoSharedDLL { class Program { [DllImport("shared.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)] private static extern IntPtr ReturnReversedString(byte[] input); static void Main(string[] args) { var input = Encoding.UTF8.GetBytes("Hello World!"); var resultbytes = ReturnReversedString(input); var output = Marshal.PtrToStringAnsi(resultbytes); Console.WriteLine(output); Console.WriteLine("Press enter to continue..."); Console.ReadLine(); } } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ package main import "C" //export ReturnReversedString func ReturnReversedString(input *C.char) *C.char { str := C.GoString(input) runes := []rune(str) for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 { runes[i], runes[j] = runes[j], runes[i] } retval := string(runes) return C.CString(retval) } func main() {} // compile using go build -o shared.dll -buildmode=c-shared