/*
* MT safe
*/
+#include "config.h"
#include <stdio.h>
#include <windows.h>
-#ifdef __MSVC__
#include <tlhelp32.h>
-#else
-
-/* The w32api headers supplied with the mingw gcc don't have
- * tlhelp32.h. We really only need the MODULEENTRY32 struct and the
- * TH32CS_SNAPMODULE value, so provide them here.
- */
-
-#define MAX_MODULE_NAME32 255
-
-typedef struct
-{
- DWORD dwSize;
- DWORD th32ModuleID;
- DWORD th32ProcessID;
- DWORD GlblcntUsage;
- DWORD ProccntUsage;
- BYTE *modBaseAddr;
- DWORD modBaseSize;
- HMODULE hModule;
- char szModule[MAX_MODULE_NAME32 + 1];
- char szExePath[MAX_PATH];
-} MODULEENTRY32;
-#define TH32CS_SNAPMODULE 8
+#ifdef G_WITH_CYGWIN
+#include <sys/cygwin.h>
#endif
static void
-set_error (void)
+set_error (const gchar *format,
+ ...)
{
- gchar *error = g_win32_error_message (GetLastError ());
+ gchar *error;
+ gchar *detail;
+ gchar *message;
+ va_list args;
- g_module_set_error (error);
+ error = g_win32_error_message (GetLastError ());
+
+ va_start (args, format);
+ detail = g_strdup_vprintf (format, args);
+ va_end (args);
+
+ message = g_strconcat (detail, error, NULL);
+
+ g_module_set_error (message);
+ g_free (message);
+ g_free (detail);
g_free (error);
}
/* --- functions --- */
static gpointer
_g_module_open (const gchar *file_name,
- gboolean bind_lazy)
+ gboolean bind_lazy,
+ gboolean bind_local)
{
HINSTANCE handle;
-
- handle = LoadLibrary (file_name);
+ wchar_t *wfilename;
+#ifdef G_WITH_CYGWIN
+ gchar tmp[MAX_PATH];
+
+ cygwin_conv_to_win32_path(file_name, tmp);
+ file_name = tmp;
+#endif
+ wfilename = g_utf8_to_utf16 (file_name, -1, NULL, NULL, NULL);
+
+ handle = LoadLibraryW (wfilename);
+ g_free (wfilename);
+
if (!handle)
- set_error ();
+ set_error ("`%s': ", file_name);
return handle;
}
{
if (handle != null_module_handle)
if (!FreeLibrary (handle))
- set_error ();
+ set_error ("");
}
static gpointer
p = GetProcAddress (handle, symbol_name);
if (!p)
- set_error ();
+ set_error ("");
return p;
}
const gchar *module_name)
{
gint k;
-
+
k = strlen (module_name);
+
if (directory && *directory)
- if (k > 4 && g_strcasecmp (module_name + k - 4, ".dll") == 0)
- return g_strconcat (directory, "\\", module_name, NULL);
+ if (k > 4 && g_ascii_strcasecmp (module_name + k - 4, ".dll") == 0)
+ return g_strconcat (directory, G_DIR_SEPARATOR_S, module_name, NULL);
+#ifdef G_WITH_CYGWIN
+ else if (strncmp (module_name, "lib", 3) == 0 || strncmp (module_name, "cyg", 3) == 0)
+ return g_strconcat (directory, G_DIR_SEPARATOR_S, module_name, ".dll", NULL);
+ else
+ return g_strconcat (directory, G_DIR_SEPARATOR_S, "cyg", module_name, ".dll", NULL);
+#else
+ else if (strncmp (module_name, "lib", 3) == 0)
+ return g_strconcat (directory, G_DIR_SEPARATOR_S, module_name, ".dll", NULL);
else
- return g_strconcat (directory, "\\", module_name, ".dll", NULL);
- else if (k > 4 && g_strcasecmp (module_name + k - 4, ".dll") == 0)
+ return g_strconcat (directory, G_DIR_SEPARATOR_S, "lib", module_name, ".dll", NULL);
+#endif
+ else if (k > 4 && g_ascii_strcasecmp (module_name + k - 4, ".dll") == 0)
return g_strdup (module_name);
+#ifdef G_WITH_CYGWIN
+ else if (strncmp (module_name, "lib", 3) == 0 || strncmp (module_name, "cyg", 3) == 0)
+ return g_strconcat (module_name, ".dll", NULL);
else
+ return g_strconcat ("cyg", module_name, ".dll", NULL);
+#else
+ else if (strncmp (module_name, "lib", 3) == 0)
return g_strconcat (module_name, ".dll", NULL);
+ else
+ return g_strconcat ("lib", module_name, ".dll", NULL);
+#endif
}