6 #include "mono/metadata/assembly.h"
7 #include "mono/metadata/class.h"
8 #include "mono/metadata/object.h"
9 #include "mono/metadata/tabledefs.h"
10 #include "mono/io-layer/wapi.h"
17 gpointer FindWindowExW (gpointer hwndParent, gpointer hwndChildAfter,
18 const char *classw, const char *window);
20 gpointer HeapAlloc (gpointer unused1, gint32 unused2, gint32 nbytes);
21 gpointer HeapCreate (gint32 flags, gint32 initial_size, gint32 max_size);
22 gboolean HeapSetInformation (gpointer handle, gpointer heap_info_class,
23 gpointer heap_info, gint32 head_info_length);
25 gboolean HeapQueryInformation (gpointer handle, gpointer heap_info_class,
26 gpointer heap_info, gint32 head_info_length, gint32 *ret_length);
28 gpointer HeapAlloc (gpointer handle, gint32 flags, gint32 nbytes);
29 gpointer HeapReAlloc (gpointer handle, gint32 flags, gpointer mem, gint32 nbytes);
30 gint32 HeapSize (gpointer handle, gint32 flags, gpointer mem);
31 gboolean HeapFree (gpointer handle, gint32 flags, gpointer mem);
32 gboolean HeapValidate (gpointer handle, gpointer mem);
33 gboolean HeapDestroy (gpointer handle);
34 gpointer GetProcessHeap (void);
36 static FnPtr functions [] = {
37 { "FindWindowExW", NULL }, /* user32 */
39 #define NFUNCTIONS (sizeof (functions)/sizeof (FnPtr))
41 static int swf_registered;
44 compare_names (const void *key, const void *p)
46 FnPtr *ptr = (FnPtr *) p;
47 return strcmp (key, ptr->fname);
51 get_function (const char *name)
55 ptr = bsearch (name, functions, NFUNCTIONS, sizeof (FnPtr),
59 g_warning ("Function '%s' not not found.", name);
67 supportw_register_delegate (const char *function_name, void *fnptr)
71 g_return_val_if_fail (function_name && fnptr, FALSE);
73 ptr = bsearch (function_name, functions, NFUNCTIONS, sizeof (FnPtr),
77 g_warning ("Function '%s' not supported.", function_name);
85 #define M_ATTRS (METHOD_ATTRIBUTE_PUBLIC | METHOD_ATTRIBUTE_STATIC)
87 register_assembly (const char *name, int *registered)
89 /* we can't use mono or wapi funcions in a support lib */
91 MonoAssembly *assembly;
92 MonoImageOpenStatus status;
101 assembly = mono_assembly_load_with_partial_name (name, &status);
102 if (assembly == NULL) {
103 g_warning ("Cannot load assembly '%s'.", name);
107 image = mono_assembly_get_image (assembly);
108 klass = mono_class_from_name (image, name, "LibSupport");
110 g_warning ("Cannot load class %s.LibSupport", name);
111 mono_assembly_close (assembly);
115 method = mono_class_get_method_from_name_flags (klass, "Register", 0, M_ATTRS);
117 g_warning ("Cannot load method Register from klass %s.LibSupport", name);
118 mono_assembly_close (assembly);
123 mono_runtime_invoke (method, NULL, NULL, &exc);
125 mono_assembly_close (assembly);
126 mono_print_unhandled_exception (exc);
130 mono_assembly_close (assembly);
142 register_assembly ("System.Windows.Forms", &swf_registered);
143 for (i = 0; i < NFUNCTIONS; i++) {
144 FnPtr *ptr = &functions [i];
145 if (ptr->fnptr == NULL)
146 g_warning ("%s wasn't registered.", ptr->fname);
151 FindWindowExW (gpointer hwndParent, gpointer hwndChildAfter, const char *classw, const char *window)
153 typedef gpointer (*func_type) (gpointer hwndParent, gpointer hwndChildAfter,
154 const char *classw, const char *window);
155 static func_type func;
157 g_return_val_if_fail (register_assembly ("System.Windows.Forms", &swf_registered), NULL);
159 func = (func_type) get_function ("FindWindowExW");
161 return func (hwndParent, hwndChildAfter, classw, window);
164 /* begin Heap* functions */
166 HeapCreate (gint32 flags, gint32 initial_size, gint32 max_size)
168 return (gpointer) 0xDEADBEEF;
172 HeapSetInformation (gpointer handle, gpointer heap_info_class, gpointer heap_info,
173 gint32 head_info_length)
179 HeapQueryInformation (gpointer handle, gpointer heap_info_class, gpointer heap_info,
180 gint32 head_info_length, gint32 *ret_length)
187 HeapAlloc (gpointer handle, gint32 flags, gint32 nbytes)
189 return g_malloc0 (nbytes);
193 HeapReAlloc (gpointer handle, gint32 flags, gpointer mem, gint32 nbytes)
195 return g_realloc (mem, nbytes);
199 HeapSize (gpointer handle, gint32 flags, gpointer mem)
205 HeapFree (gpointer handle, gint32 flags, gpointer mem)
212 HeapValidate (gpointer handle, gpointer mem)
218 HeapDestroy (gpointer handle)
227 return (gpointer) 0xDEADBEEF;
229 /* end Heap* functions */