1 #include <mono/jit/jit.h>
2 #include <mono/metadata/environment.h>
6 * Very simple mono embedding example.
8 * gcc -o teste teste.c `pkg-config --cflags --libs mono` -lm
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
);
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
);
36 main(int argc
, char* argv
[]) {
42 fprintf (stderr
, "Please provide an assembly to load\n");
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
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
);