class Finalized : CriticalFinalizerObject
{
~Finalized()
{
Console.WriteLine("finalized");
}
}
static public class Class1
{
//little hack to use the host as a DLL (and support the host rename)
[UnmanagedCallersOnly]
static void Init(IntPtr textPTr, Int32 textLenght) //the setup
{
var hostName = Marshal.PtrToStringUTF8(textPTr, textLenght);
var assembly = Assembly.GetExecutingAssembly();
DllImportResolver resolver = (string libraryName, Assembly assembly, DllImportSearchPath? searchPath) => {
if (libraryName == "host")
return NativeLibrary.Load(hostName);
return IntPtr.Zero;
};
NativeLibrary.SetDllImportResolver(assembly, resolver);
}
//main loaded by rust side
[UnmanagedCallersOnly]
public static void Main()
{
var finalized = new Finalized(); //pur C# object with a finalizer
var vec = new Vec3I(); //this an unmanaged struct, from rust, just a small test
vec.x = 1;
vec.y = 2;
vec.z = 3;
vec.Print(); //this is bind to rust
}
[UnmanagedCallersOnly]
public static void Cleanup() //recently added cleanup method
{
GC.Collect(); //need else finalizer is never called !
Console.WriteLine("invoking GC right here");
}
}