private static void PrintLibArgs(LibArgs libArgs) { string message = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? Marshal.PtrToStringUni(libArgs.Message) : Marshal.PtrToStringUTF8(libArgs.Message); Console.WriteLine($"-- message: {message}"); Console.WriteLine($"-- number: {libArgs.Number}"); }
public static int Hello(IntPtr arg, int argLength) { if (argLength < System.Runtime.InteropServices.Marshal.SizeOf(typeof(LibArgs))) { return(1); } LibArgs libArgs = Marshal.PtrToStructure <LibArgs>(arg); Console.WriteLine($"Hello, world! from {nameof(Lib)} [count: {s_CallCount++}]"); PrintLibArgs(libArgs); return(0); }
private static void InitAltVAssembly(Assembly altVNetAssembly, LibArgs libArgs, AssemblyLoadContext resourceAssemblyLoadContext, string resourceName) { foreach (var type in altVNetAssembly.GetTypes()) { switch (type.Name) { case "ModuleWrapper": type.GetMethod("MainWithAssembly", BindingFlags.Public | BindingFlags.Static)?.Invoke(null, new object[] { libArgs.ServerPointer, libArgs.ResourcePointer, resourceAssemblyLoadContext }); break; case "HostWrapper": try { type.GetMethod("SetStartTracingDelegate", BindingFlags.Public | BindingFlags.Static) ?.Invoke( null, new object[] { new Action <string, string>(StartTracing) }); type.GetMethod("SetStopTracingDelegate", BindingFlags.Public | BindingFlags.Static)?.Invoke( null, new object[] { new Action(StopTracing) }); type.GetMethod("SetImportDelegate", BindingFlags.Public | BindingFlags.Static)?.Invoke( null, new object[] { new ImportDelegate(Import) }); type.GetMethod("SetExportDelegate", BindingFlags.Public | BindingFlags.Static)?.Invoke( null, new object[] { new Action <string, object>((key, value) => { Export(resourceName, key, value); }) }); var traceSizeChangeDelegate = (Action <long>)type.GetMethod("GetTraceSizeChangeDelegate", BindingFlags.Public | BindingFlags.Static)?.Invoke( null, new object[] { }); TraceSizeChangeDelegates[resourceName] = traceSizeChangeDelegate; } catch (Exception exception) { Console.WriteLine( "Consider updating the AltV.Net nuget package and AltV.Net.Host.dll to be able to access all csharp-module features."); Console.WriteLine(exception); } break; } } }
public static int Hello(IntPtr arg, int argLength) { if (argLength < System.Runtime.InteropServices.Marshal.SizeOf(typeof(LibArgs))) { return(1); } LibArgs libArgs = Marshal.PtrToStructure <LibArgs>(arg); string message = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? Marshal.PtrToStringUni(libArgs.Message) : Marshal.PtrToStringUTF8(libArgs.Message); Console.WriteLine($"Hello, world! from {nameof(Lib)} [count: {s_CallCount++}]"); Console.WriteLine($"-- message: {message}"); Console.WriteLine($"-- number: {libArgs.Number}"); return(0); }
public static void CustomEntryPoint(LibArgs libArgs) { string message = Marshal.PtrToStringUni(libArgs.Message); switch (libArgs.Number) { case 0: Startup(); break; case 1: break; case 2: break; case 3: break; case 4: break; case 5: break; case -1: Console.WriteLine("Unknown operation"); break; } }
public static void CustomEntryPointUnmanaged(LibArgs libArgs) { CustomEntryPoint(libArgs); }
public static void CustomEntryPoint(LibArgs libArgs) { Console.WriteLine($"Hello, world! from {nameof(CustomEntryPoint)} in {nameof(Lib)}"); PrintLibArgs(libArgs); }