Created
June 23, 2019 05:48
-
-
Save andrewloable/afa1c683701cec18c4530f6a91692e0b to your computer and use it in GitHub Desktop.
Use a library compiled in Go in c# (.net)
This file contains 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 characters
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(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You should mark exporting method with comment above
//export [Some name]
No space after //