* X11Display.cs: port over jackson's XplatUIX11.cs fix for DND
[mono-project.git] / samples / embed / teste.c
blobd6a7b8381a18e7c6899ef76ea1df2681bee5f011
1 #include <mono/jit/jit.h>
2 #include <mono/metadata/environment.h>
3 #include <stdlib.h>
5 /*
6 * Very simple mono embedding example.
7 * Compile with:
8 * gcc -o teste teste.c `pkg-config --cflags --libs mono` -lm
9 * mcs test.cs
10 * Run with:
11 * ./teste test.exe
14 static MonoString*
15 gimme () {
16 return mono_string_new (mono_domain_get (), "All your monos are belong to us!");
19 static void main_function (MonoDomain *domain, const char *file, int argc, char** argv)
21 MonoAssembly *assembly;
23 assembly = mono_domain_assembly_open (domain, file);
24 if (!assembly)
25 exit (2);
27 * mono_jit_exec() will run the Main() method in the assembly.
28 * The return value needs to be looked up from
29 * System.Environment.ExitCode.
31 mono_jit_exec (domain, assembly, argc, argv);
35 int
36 main(int argc, char* argv[]) {
37 MonoDomain *domain;
38 const char *file;
39 int retval;
41 if (argc < 2){
42 fprintf (stderr, "Please provide an assembly to load");
43 return 1;
45 file = argv [1];
48 * Load the default Mono configuration file, this is needed
49 * if you are planning on using the dllmaps defined on the
50 * system configuration
52 mono_config_parse (NULL);
54 * mono_jit_init() creates a domain: each assembly is
55 * loaded and run in a MonoDomain.
57 domain = mono_jit_init (file);
59 * We add our special internal call, so that C# code
60 * can call us back.
62 mono_add_internal_call ("MonoEmbed::gimme", gimme);
64 main_function (domain, file, argc - 1, argv + 1);
66 retval = mono_environment_exitcode_get ();
68 mono_jit_cleanup (domain);
69 return retval;