monostub.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #include <mono/jit/jit.h>
  2. #include <stdio.h>
  3. //
  4. // The Mono and WINE header files have overlapping definitions in the
  5. // header files. Since we are only using a few functions and definitions
  6. // define them here to avoid conflicts.
  7. //
  8. // these are defined in jit.h
  9. // typedef long LONG;
  10. // typedef unsigned long DWORD;
  11. // typedef unsigned short WORD;
  12. // typedef UINT HANDLE;
  13. // typedef HINSTANCE HMODULE;
  14. #define __stdcall __attribute__((__stdcall__))
  15. #define CALLBACK __stdcall
  16. #define WINAPI __stdcall
  17. #define PASCAL __stdcall
  18. typedef int INT;
  19. typedef unsigned int UINT;
  20. typedef char CHAR;
  21. typedef CHAR *LPSTR;
  22. typedef const CHAR *LPCSTR;
  23. typedef UINT WPARAM;
  24. typedef LONG LPARAM;
  25. typedef LONG LRESULT;
  26. typedef WORD ATOM;
  27. typedef void* HWND;
  28. typedef void* HINSTANCE;
  29. typedef void* HICON;
  30. typedef void* HCURSOR;
  31. typedef void* HBRUSH;
  32. typedef LRESULT (CALLBACK *WNDPROC) (HWND, UINT, WPARAM, LPARAM);
  33. typedef struct
  34. {
  35. UINT style;
  36. WNDPROC lpfnWndProc;
  37. INT cbClsExtra;
  38. INT cbWndExtra;
  39. HINSTANCE hInstance;
  40. HICON hIcon;
  41. HCURSOR hCursor;
  42. HBRUSH hbrBackground;
  43. LPCSTR lpszMenuName;
  44. LPCSTR lpszClassName;
  45. } WNDCLASSA;
  46. ATOM WINAPI RegisterClassA (const WNDCLASSA *);
  47. HMODULE WINAPI GetModuleHandleA (LPCSTR);
  48. INT WINAPI MessageBoxExA (HWND, LPCSTR, LPCSTR, UINT, WORD);
  49. HINSTANCE applicationInstance = NULL;
  50. // register WNDCLASS for use in embeded application, this is a work around
  51. // for Bugzilla item #29548
  52. int PASCAL MonoRegisterClass (UINT style, WNDPROC lpfnWndProc, INT cbClsExtra,
  53. INT cbWndExtra, HINSTANCE hInstance, HICON hIcon,
  54. HCURSOR hCursor, HBRUSH hbrBackground,
  55. LPCSTR lpszMenuName, LPCSTR lpszClassName)
  56. {
  57. WNDCLASSA wc;
  58. int retval = 0;
  59. wc.lpszClassName = lpszClassName;
  60. wc.lpfnWndProc = lpfnWndProc;
  61. wc.style = style;
  62. wc.hInstance = applicationInstance;
  63. wc.hIcon = hIcon;
  64. wc.hCursor = hCursor;
  65. wc.hbrBackground = hbrBackground;
  66. wc.lpszMenuName = lpszMenuName;
  67. wc.cbClsExtra = cbClsExtra;
  68. wc.cbWndExtra = cbWndExtra;
  69. retval = RegisterClassA (&wc);
  70. return retval;
  71. }
  72. int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  73. LPSTR lpszCmdLine, int nCmdShow)
  74. {
  75. MonoDomain *domain = NULL;
  76. MonoAssembly *assembly = NULL;
  77. int retval = 0;
  78. applicationInstance = hInstance;
  79. printf ("initializing JIT engine\n");
  80. domain = mono_jit_init (lpszCmdLine);
  81. printf ("opening assembly\n");
  82. assembly = mono_domain_assembly_open (domain, lpszCmdLine);
  83. if (!assembly){
  84. printf("error opening assembly\n");
  85. return 1;
  86. }
  87. printf ("executing assembly\n");
  88. retval = mono_jit_exec (domain, assembly, 0, 0);
  89. printf ("calling JIT cleanup\n");
  90. mono_jit_cleanup (domain);
  91. return retval;
  92. }