sample fix
[mono.git] / samples / embed / teste.c
1 #include <mono/jit/jit.h>
2
3 /*
4  * Very simple mono embedding example.
5  * Compile with: 
6  *      gcc -o teste teste.c `pkg-config --cflags --libs mono`
7  *      mcs test.cs
8  * Run with:
9  *      ./teste test.exe
10  */
11
12 static MonoString*
13 gimme () {
14         return mono_string_new (mono_domain_get (), "All your monos are belong to us!");
15 }
16
17 int 
18 main(int argc, char* argv[]) {
19         MonoDomain *domain;
20         MonoAssembly *assembly;
21         const char *file;
22         int retval;
23
24         if (argc < 2)
25                 return 1;
26         file = argv [1];
27         /*
28          * mono_jit_init() creates a domain: each assembly is
29          * loaded and run in a MonoDomain.
30          */
31         domain = mono_jit_init (file);
32         /*
33          * We add our special internal call, so that C# code
34          * can call us back.
35          */
36         mono_add_internal_call ("Mono::gimme", gimme);
37         assembly = mono_domain_assembly_open (domain, file);
38         if (!assembly)
39                 return 2;
40         /*
41          * mono_jit_exec() will run the Main() method in the assembly
42          * and return the value.
43          */
44         retval = mono_jit_exec (domain, assembly, argc - 1, argv + 1);
45         mono_jit_cleanup (domain);
46         return retval;
47 }
48