mono-api-embedding.html 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <h2>Embedding Mono</h2>
  2. <h4><a name="api:mono_jit_init">mono_jit_init</a></h4>
  3. <h4><a name="api:mono_set_dirs">mono_set_dirs</a></h4>
  4. <h4><a name="api:mono_runtime_exec_main">mono_runtime_exec_main</a></h4>
  5. <h4><a name="api:mono_runtime_exec_managed_code">mono_runtime_exec_managed_code</a></h4>
  6. <h4><a name="api:mono_jit_cleanup">mono_jit_cleanup</a></h4>
  7. <h4><a name="api:mono_set_defaults">mono_set_defaults</a></h4>
  8. <h3>Internal Calls</h3>
  9. <p>The Mono runtime provides two mechanisms to expose C code
  10. to the CIL universe: internal calls and native C
  11. code. Internal calls are tightly integrated with the runtime,
  12. and have the least overhead, as they use the same data types
  13. that the runtime uses.
  14. <p>The other option is to use the Platform Invoke (P/Invoke)
  15. to call C code from the CIL universe, using the standard
  16. P/Invoke mechanisms.
  17. <p>To register an internal call, use this call you use the
  18. <tt>mono_add_internal_call</tt> routine.
  19. <h4>Data Marshalling</h4>
  20. <p>Managed objects are represented as <tt>MonoObject*</tt>
  21. types. Those objects that the runtime consumes directly have
  22. more specific C definitions (for example strings are of type
  23. <tt>MonoString *</tt>, delegates are of type
  24. <tt>MonoDelegate*</tt> but they are still <tt>MonoObject
  25. *</tt>s).
  26. <p>As of Mono 1.2.x types defined in mscorlib.dll do not have
  27. their fields reordered in any way. But other libraries might
  28. have their fields reordered. In these cases, Managed
  29. structures and objects have the same layout in the C# code as
  30. they do in the unmanaged world.
  31. <p>Structures defined outside corlib must have a specific
  32. StructLayout definition, and have it set as sequential if you
  33. plan on accessing these fields directly from C code.
  34. <p><b>Important</B> Internal calls do not provide support for
  35. marshalling structures. This means that any API calls that
  36. take a structure (excluding the system types like int32,
  37. int64, etc) must be passed as a pointer, in C# this means
  38. passing the value as a "ref" or "out" parameter.
  39. <h4><a name="api:mono_add_internal_call">mono_add_internal_call</a></h4>
  40. <h3>Mono Runtime Configuration</h3>
  41. <p>Certain features of the Mono runtime, like DLL mapping, are
  42. available through a configuration file that is loaded at
  43. runtime. The default Mono implementation loads the
  44. configuration file from <tt>$sysconfig/mono/config</tt>
  45. (typically this is <tt>/etc/mono/config</tt>).
  46. <p>See the <tt>mono-config(5)</tt> man page for more details
  47. on what goes in this file.
  48. <p>The following APIs expose this functionality:
  49. <h4><a name="api:mono_config_parse">mono_config_parse</a></h4>
  50. <h4><a name="api:mono_config_parse_memory">mono_config_parse_memory</a></h4>
  51. <h3>Function Pointers</h3>
  52. <p>To wrap a function pointer into something that the Mono
  53. runtime can consume, you should use the mono_create_ftnptr.
  54. This is only important if you plan on running on the IA64
  55. architecture. Otherwise you can just use the function
  56. pointer address.
  57. <h4><a name="api:mono_create_ftnptr">mono_create_ftnptr</a></h4>