diff options
author | Gonzalo Paniagua Javier <gonzalo.mono@gmail.com> | 2005-06-30 02:38:30 +0400 |
---|---|---|
committer | Gonzalo Paniagua Javier <gonzalo.mono@gmail.com> | 2005-06-30 02:38:30 +0400 |
commit | 05381e2173ba106ef1b85c444dd8956c7a2b7dbe (patch) | |
tree | f67be991379a0dd2f62adb9621995729bf7b8eb2 /support | |
parent | b3da602a5a08d94ae2d90cdec38985bd08583528 (diff) |
2005-06-29 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* supportw.c:
* supportw.h:
* Makefile.am: new library intended to provide often P/Invoked windows
API functions not present in io-layer.
svn path=/trunk/mono/; revision=46736
Diffstat (limited to 'support')
-rw-r--r-- | support/ChangeLog | 7 | ||||
-rw-r--r-- | support/Makefile.am | 10 | ||||
-rw-r--r-- | support/supportw.c | 215 | ||||
-rw-r--r-- | support/supportw.h | 12 |
4 files changed, 243 insertions, 1 deletions
diff --git a/support/ChangeLog b/support/ChangeLog index c19f3efa5e7..4371e4cb8b1 100644 --- a/support/ChangeLog +++ b/support/ChangeLog @@ -1,3 +1,10 @@ +2005-06-29 Gonzalo Paniagua Javier <gonzalo@ximian.com> + + * supportw.c: + * supportw.h: + * Makefile.am: new library intended to provide often P/Invoked windows + API functions not present in io-layer. + 2005-06-29 Jonathan Pryor <jonpryor@vt.edu> * map.c: Handle Syslog-related changes (SyslogFacility isn't a diff --git a/support/Makefile.am b/support/Makefile.am index 468cf03b403..1d0c6f17e2d 100644 --- a/support/Makefile.am +++ b/support/Makefile.am @@ -1,4 +1,4 @@ -lib_LTLIBRARIES= libMonoPosixHelper.la +lib_LTLIBRARIES= libMonoPosixHelper.la libsupportw.la INCLUDES = \ $(GLIB_CFLAGS) \ @@ -69,6 +69,14 @@ libMonoPosixHelper_la_LIBADD = \ # libMonoPosixHelper_la_LDFLAGS = -no-undefined -version-info 1:0:1 libMonoPosixHelper_la_LDFLAGS = -no-undefined -avoid-version +libsupportw_la_SOURCES = \ + supportw.c \ + supportw.h + +libsupportw_la_LIBADD = \ + $(top_builddir)/mono/io-layer/libwapi.la \ + $(top_builddir)/mono/mini/libmono.la + # # Use this target to refresh the values in map.[ch] # diff --git a/support/supportw.c b/support/supportw.c new file mode 100644 index 00000000000..512d21732f0 --- /dev/null +++ b/support/supportw.c @@ -0,0 +1,215 @@ +#include <glib.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include "supportw.h" +#include "mono/metadata/assembly.h" +#include "mono/metadata/class.h" +#include "mono/metadata/object.h" +#include "mono/metadata/tabledefs.h" +#include "mono/io-layer/wapi.h" + +typedef struct { + const char *fname; + void *fnptr; +} FnPtr; + +gpointer FindWindowExW (gpointer hwndParent, gpointer hwndChildAfter, + const char *classw, const char *window); + +gpointer HeapAlloc (gpointer unused1, gint32 unused2, gint32 nbytes); +gpointer HeapCreate (gint32 flags, gint32 initial_size, gint32 max_size); +gboolean HeapSetInformation (gpointer handle, gpointer heap_info_class, + gpointer heap_info, gint32 head_info_length); + +gboolean HeapQueryInformation (gpointer handle, gpointer heap_info_class, + gpointer heap_info, gint32 head_info_length, gint32 *ret_length); + +gpointer HeapAlloc (gpointer handle, gint32 flags, gint32 nbytes); +gpointer HeapReAlloc (gpointer handle, gint32 flags, gpointer mem, gint32 nbytes); +gint32 HeapSize (gpointer handle, gint32 flags, gpointer mem); +gboolean HeapFree (gpointer handle, gint32 flags, gpointer mem); +gboolean HeapValidate (gpointer handle, gpointer mem); +gpointer GetProcessHeap (void); + +static FnPtr functions [] = { + { "FindWindowExW", NULL }, /* user32 */ +}; +#define NFUNCTIONS (sizeof (functions)/sizeof (FnPtr)) + +static int swf_registered; + +static int +compare_names (const void *key, const void *p) +{ + FnPtr *ptr = (FnPtr *) p; + return strcmp (key, ptr->fname); +} + +static gpointer +get_function (const char *name) +{ + FnPtr *ptr; + + ptr = bsearch (name, functions, NFUNCTIONS, sizeof (FnPtr), + compare_names); + + if (ptr == NULL) { + g_warning ("Function '%s' not not found.", name); + return NULL; + } + + return ptr->fnptr; +} + +gboolean +supportw_register_delegate (const char *function_name, void *fnptr) +{ + FnPtr *ptr; + + g_return_val_if_fail (function_name && fnptr, FALSE); + + ptr = bsearch (function_name, functions, NFUNCTIONS, sizeof (FnPtr), + compare_names); + + if (ptr == NULL) { + g_warning ("Function '%s' not supported.", function_name); + return FALSE; + } + + ptr->fnptr = fnptr; + return TRUE; +} + +#define M_ATTRS (METHOD_ATTRIBUTE_PUBLIC | METHOD_ATTRIBUTE_STATIC) +static gboolean +register_assembly (const char *name, int *registered) +{ + MonoAssembly *assembly; + MonoImageOpenStatus status; + MonoImage *image; + MonoClass *klass; + MonoMethod *method; + MonoObject *exc; + + if (*registered) + return TRUE; + + assembly = mono_assembly_load_with_partial_name (name, &status); + if (assembly == NULL) { + g_warning ("Cannot load assembly '%s'.", name); + return FALSE; + } + + image = mono_assembly_get_image (assembly); + klass = mono_class_from_name (image, name, "LibSupport"); + if (klass == NULL) { + g_warning ("Cannot load class %s.LibSupport", name); + mono_assembly_close (assembly); + return FALSE; + } + + method = mono_class_get_method_from_name_flags (klass, "Register", 0, M_ATTRS); + if (klass == NULL) { + g_warning ("Cannot load method Register from klass %s.LibSupport", name); + mono_assembly_close (assembly); + return FALSE; + } + + exc = NULL; + mono_runtime_invoke (method, NULL, NULL, &exc); + if (exc != NULL) { + mono_assembly_close (assembly); + mono_print_unhandled_exception (exc); + return FALSE; + } + *registered = 1; + mono_assembly_close (assembly); + return TRUE; +} + +void +supportw_test_all () +{ + int i; + + register_assembly ("System.Windows.Forms", &swf_registered); + for (i = 0; i < NFUNCTIONS; i++) { + FnPtr *ptr = &functions [i]; + if (ptr->fnptr == NULL) + g_warning ("%s wasn't registered.", ptr->fname); + } +} + +gpointer +FindWindowExW (gpointer hwndParent, gpointer hwndChildAfter, const char *classw, const char *window) +{ + typedef gpointer (*func_type) (gpointer hwndParent, gpointer hwndChildAfter, + const char *classw, const char *window); + static func_type func; + + g_return_val_if_fail (register_assembly ("System.Windows.Forms", &swf_registered), NULL); + if (func == NULL) + func = (func_type) get_function ("FindwindowExW"); + + return func (hwndParent, hwndChildAfter, classw, window); +} + +gpointer +HeapCreate (gint32 flags, gint32 initial_size, gint32 max_size) +{ + return (gpointer) 0xDEADBEEF; +} + +gboolean +HeapSetInformation (gpointer handle, gpointer heap_info_class, gpointer heap_info, + gint32 head_info_length) +{ + return TRUE; +} + +gboolean +HeapQueryInformation (gpointer handle, gpointer heap_info_class, gpointer heap_info, + gint32 head_info_length, gint32 *ret_length) +{ + *ret_length = 0; + return TRUE; +} + +gpointer +HeapAlloc (gpointer handle, gint32 flags, gint32 nbytes) +{ + return g_malloc0 (nbytes); +} + +gpointer +HeapReAlloc (gpointer handle, gint32 flags, gpointer mem, gint32 nbytes) +{ + return g_realloc (mem, nbytes); +} + +gint32 +HeapSize (gpointer handle, gint32 flags, gpointer mem) +{ + return 0; +} + +gboolean +HeapFree (gpointer handle, gint32 flags, gpointer mem) +{ + g_free (mem); + return TRUE; +} + +gboolean +HeapValidate (gpointer handle, gpointer mem) +{ + return TRUE; +} + +gpointer +GetProcessHeap () +{ + return (gpointer) 0xDEADBEEF; +} + diff --git a/support/supportw.h b/support/supportw.h new file mode 100644 index 00000000000..2f186e2a9e4 --- /dev/null +++ b/support/supportw.h @@ -0,0 +1,12 @@ +#ifndef __SUPPORTW_H +#define __SUPPORTW_H + +G_BEGIN_DECLS + +gboolean supportw_register_delegate (const char *function_name, void *fnptr); +void supportw_test_all (void); + +G_END_DECLS + +#endif /* __SUPPORTW_H */ + |