- if (FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
- code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&buf, 0, NULL))
- {
- ret = g_utf16_to_utf8 (buf, wcslen(buf), NULL, NULL, NULL);
- LocalFree (buf);
- } else {
- g_assert_not_reached ();
- }
- return ret;
-}
-
-static gpointer
-w32_find_symbol (MonoDl *module, const gchar *symbol_name)
-{
- HMODULE *modules;
- DWORD buffer_size = sizeof (HMODULE) * 1024;
- DWORD needed, i;
- gpointer proc = NULL;
-
- /* get the symbol directly from the specified module */
- if (!module->main_module)
- return GetProcAddress (module->handle, symbol_name);
-
- /* get the symbol from the main module */
- proc = GetProcAddress (module->handle, symbol_name);
- if (proc != NULL)
- return proc;
-
- /* get the symbol from the loaded DLLs */
- modules = (HMODULE *) g_malloc (buffer_size);
- if (modules == NULL)
- return NULL;
-
- if (!EnumProcessModules (GetCurrentProcess (), modules,
- buffer_size, &needed)) {
- g_free (modules);
- return NULL;
- }
-
- /* check whether the supplied buffer was too small, realloc, retry */
- if (needed > buffer_size) {
- g_free (modules);
-
- buffer_size = needed;
- modules = (HMODULE *) g_malloc (buffer_size);
-
- if (modules == NULL)
- return NULL;
-
- if (!EnumProcessModules (GetCurrentProcess (), modules,
- buffer_size, &needed)) {
- g_free (modules);
- return NULL;
- }
- }
-
- for (i = 0; i < needed / sizeof (HANDLE); i++) {
- proc = GetProcAddress (modules [i], symbol_name);
- if (proc != NULL) {
- g_free (modules);
- return proc;
- }
- }
-
- g_free (modules);
- return NULL;
-}
-
-
-static gpointer
-w32_load_module (const char* file, int flags)
-{
- gpointer hModule = NULL;
- if (file) {
- gunichar2* file_utf16 = g_utf8_to_utf16 (file, strlen (file), NULL, NULL, NULL);
- guint last_sem = SetErrorMode (SEM_FAILCRITICALERRORS);
- guint32 last_error = 0;
-
- hModule = LoadLibrary (file_utf16);
- if (!hModule)
- last_error = GetLastError ();
-
- SetErrorMode (last_sem);
- g_free (file_utf16);
-
- if (!hModule)
- SetLastError (last_error);
- } else {
- hModule = GetModuleHandle (NULL);
- }
- return hModule;
-}
-#endif