public static void RegisterHandlers(AllHandlers handlers) { var size = System.Runtime.InteropServices.Marshal.SizeOf(typeof(AllHandlers)); IntPtr ptr = Marshal.AllocHGlobal(size); Marshal.StructureToPtr(handlers, ptr, false); NativeFunctions.RegisterHandlers(ptr, (uint)size); Marshal.FreeHGlobal(ptr); }
public static void RegisterHandlers(AllHandlers handlers) { _handlers = handlers; var size = Marshal.SizeOf(typeof(AllHandlers)); IntPtr ptr = Marshal.AllocHGlobal(size); Marshal.StructureToPtr(_handlers, ptr, false); NativeFunctions.RegisterHandlers(ptr, (uint)size); Marshal.FreeHGlobal(ptr); }
public static bool Init(IntPtr arg, int argLength) { if (arg == (IntPtr)0) { Console.WriteLine("Received NULL bootstrap structure"); return(false); } int expectedLength = Marshal.SizeOf(typeof(Internal.BootstrapArgs)); if (argLength < expectedLength) { Console.WriteLine($"Received bootstrap structure too small - actual={argLength}, expected={expectedLength}"); return(false); } if (argLength > expectedLength) { Console.WriteLine($"WARNING: Received bootstrap structure bigger than expected - actual={argLength}, expected={expectedLength}"); Console.WriteLine($" This usually means that native code version is ahead of the managed code"); } NativeFunctions = Marshal.PtrToStructure <Internal.BootstrapArgs>(arg); AllHandlers handlers; handlers.MainLoop = MainLoopHandler; handlers.RunScript = RunScriptHandler; handlers.Closure = ClosureHandler; var size = Marshal.SizeOf(typeof(AllHandlers)); IntPtr ptr = Marshal.AllocHGlobal(size); Marshal.StructureToPtr(handlers, ptr, false); NativeFunctions.RegisterHandlers(ptr, (uint)size); Marshal.FreeHGlobal(ptr); return(true); }