1 #include <mono/jit/jit.h>
2 #include <mono/metadata/environment.h>
3 #include <mono/utils/mono-publib.h>
7 * Very simple mono embedding example.
9 * gcc -o teste teste.c `pkg-config --cflags --libs mono-2` -lm
17 return mono_string_new (mono_domain_get (), "All your monos are belong to us!");
20 static void main_function (MonoDomain
*domain
, const char *file
, int argc
, char** argv
)
22 MonoAssembly
*assembly
;
24 assembly
= mono_domain_assembly_open (domain
, file
);
28 * mono_jit_exec() will run the Main() method in the assembly.
29 * The return value needs to be looked up from
30 * System.Environment.ExitCode.
32 mono_jit_exec (domain
, assembly
, argc
, argv
);
35 static int malloc_count
= 0;
37 static void* custom_malloc(size_t bytes
)
44 main(int argc
, char* argv
[]) {
50 fprintf (stderr
, "Please provide an assembly to load\n");
55 MonoAllocatorVTable mem_vtable
= {custom_malloc
};
56 mono_set_allocator_vtable (&mem_vtable
);
59 * Load the default Mono configuration file, this is needed
60 * if you are planning on using the dllmaps defined on the
61 * system configuration
63 mono_config_parse (NULL
);
65 * mono_jit_init() creates a domain: each assembly is
66 * loaded and run in a MonoDomain.
68 domain
= mono_jit_init (file
);
70 * We add our special internal call, so that C# code
73 mono_add_internal_call ("MonoEmbed::gimme", gimme
);
75 main_function (domain
, file
, argc
- 1, argv
+ 1);
77 retval
= mono_environment_exitcode_get ();
79 mono_jit_cleanup (domain
);
81 fprintf (stdout
, "custom malloc calls = %d\n", malloc_count
);