Created
October 2, 2017 20:40
-
-
Save LivingInSyn/3f80d2bef2d7b9c7aa8e1efa277f80db to your computer and use it in GitHub Desktop.
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.Collections.Generic; | |
using System.Linq; | |
using System.Runtime.InteropServices; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace rust_dll_poc | |
{ | |
[StructLayout(LayoutKind.Sequential)] | |
public struct SampleStruct | |
{ | |
public Int16 field_one; | |
public Int32 field_two; | |
public IntPtr string_field; | |
} | |
class Program | |
{ | |
[DllImport("our_rust.dll")] | |
private static extern SampleStruct get_simple_struct(); | |
[DllImport("our_rust.dll")] | |
private static extern SampleStruct free_string(); | |
[DllImport("our_rust.dll")] | |
private static extern Int32 add_numbers(Int32 number1, Int32 number2); | |
static void Main(string[] args) | |
{ | |
var simple_struct = get_simple_struct(); | |
Console.WriteLine(simple_struct.field_one); | |
Console.WriteLine(simple_struct.field_two); | |
Console.WriteLine(Marshal.PtrToStringAnsi(simple_struct.string_field)); | |
free_string(); | |
var addedNumbers = add_numbers(10, 5); | |
Console.WriteLine(addedNumbers); | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment