2.19.3
[platform/upstream/glib.git] / gmodule / gmodule-win32.c
index 882ee7b..98d3fb9 100644 (file)
@@ -30,6 +30,7 @@
 /* 
  * MT safe
  */
+#include "config.h"
 
 #include <stdio.h>
 #include <windows.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);
 }
 
@@ -56,16 +71,20 @@ _g_module_open (const gchar *file_name,
                gboolean     bind_local)
 {
   HINSTANCE handle;
+  wchar_t *wfilename;
 #ifdef G_WITH_CYGWIN
   gchar tmp[MAX_PATH];
 
   cygwin_conv_to_win32_path(file_name, tmp);
   file_name = tmp;
 #endif
-  
-  handle = LoadLibrary (file_name);
+  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;
 }
@@ -85,7 +104,7 @@ _g_module_close (gpointer handle,
 {
   if (handle != null_module_handle)
     if (!FreeLibrary (handle))
-      set_error ();
+      set_error ("");
 }
 
 static gpointer
@@ -214,7 +233,7 @@ _g_module_symbol (gpointer     handle,
     p = GetProcAddress (handle, symbol_name);
 
   if (!p)
-    set_error ();
+    set_error ("");
 
   return p;
 }
@@ -230,14 +249,28 @@ _g_module_build_path (const gchar *directory,
   if (directory && *directory)
     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, 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
 }