* X11Display.cs: port over jackson's XplatUIX11.cs fix for DND
[mono-project.git] / samples / embed / testi.c
bloba1ea82b633f83efae1aeeb49dd475290bc650e6e
1 #include <mono/interpreter/embed.h>
2 #include <mono/metadata/environment.h>
4 /*
5 * Very simple mint embedding example.
6 * Compile with:
7 * gcc -o testi testi.c `pkg-config --cflags --libs mint` -lm
8 * mcs test.cs
9 * Run with:
10 * ./testi test.exe
13 static MonoString*
14 gimme () {
15 return mono_string_new (mono_domain_get (), "All your monos are belong to us!");
18 typedef struct
20 MonoDomain *domain;
21 const char *file;
22 int argc;
23 char **argv;
24 } MainThreadArgs;
26 static void main_thread_handler (gpointer user_data)
28 MainThreadArgs *main_args=(MainThreadArgs *)user_data;
29 MonoAssembly *assembly;
31 assembly = mono_domain_assembly_open (main_args->domain,
32 main_args->file);
33 if (!assembly)
34 exit (2);
36 * mono_jit_exec() will run the Main() method in the assembly.
37 * The return value needs to be looked up from
38 * System.Environment.ExitCode.
40 mono_interp_exec (main_args->domain, assembly, main_args->argc,
41 main_args->argv);
45 int
46 main(int argc, char* argv[]) {
47 MonoDomain *domain;
48 const char *file;
49 int retval;
50 MainThreadArgs main_args;
52 if (argc < 2){
53 fprintf (stderr, "Please provide an assembly to load\n");
54 return 1;
56 file = argv [1];
58 * mono_jit_init() creates a domain: each assembly is
59 * loaded and run in a MonoDomain.
61 domain = mono_interp_init (file);
63 * We add our special internal call, so that C# code
64 * can call us back.
66 mono_add_internal_call ("MonoEmbed::gimme", gimme);
68 main_args.domain=domain;
69 main_args.file=file;
70 main_args.argc=argc-1;
71 main_args.argv=argv+1;
73 mono_runtime_exec_managed_code (domain, main_thread_handler,
74 &main_args);
76 retval=mono_environment_exitcode_get ();
78 mono_interp_cleanup (domain);
79 return retval;