using System.Runtime.InteropServices; // See https://aka.ms/new-console-template for more information Console.WriteLine("Hello, World!"); var message = "test"; var bufffer = Marshal.StringToHGlobalAnsi(message); Console.WriteLine(bufffer); Console.WriteLine(message.Length); var example = new Lib.MyString() { Data = bufffer, Length = (nuint)message.Length, }; Lib.PrintString(example); var b = Lib.CreateString(); var m2 = Marshal.PtrToStringAnsi(b.Data, (int)b.Length); Console.WriteLine(m2);