Use wide char API if available, and store dll name in UTF-8.
authorTor Lillqvist <tml@novell.com>
Thu, 7 Apr 2005 23:46:38 +0000 (23:46 +0000)
committerTor Lillqvist <tml@src.gnome.org>
Thu, 7 Apr 2005 23:46:38 +0000 (23:46 +0000)
2005-04-08  Tor Lillqvist  <tml@novell.com>

* glib/gutils.h (G_WIN32_DLLMAIN_FOR_DLL_NAME): Use wide char API
if available, and store dll name in UTF-8.

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-8
glib/gutils.h

index 7bc0276..cf0df3d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2005-04-08  Tor Lillqvist  <tml@novell.com>
+
+       * glib/gutils.h (G_WIN32_DLLMAIN_FOR_DLL_NAME): Use wide char API
+       if available, and store dll name in UTF-8.
+
 2005-04-05  Matthias Clasen  <mclasen@redhat.com>
 
        * glib/gfileutils.c (get_contents_stdio): Avoid memory 
index 7bc0276..cf0df3d 100644 (file)
@@ -1,3 +1,8 @@
+2005-04-08  Tor Lillqvist  <tml@novell.com>
+
+       * glib/gutils.h (G_WIN32_DLLMAIN_FOR_DLL_NAME): Use wide char API
+       if available, and store dll name in UTF-8.
+
 2005-04-05  Matthias Clasen  <mclasen@redhat.com>
 
        * glib/gfileutils.c (get_contents_stdio): Avoid memory 
index 7bc0276..cf0df3d 100644 (file)
@@ -1,3 +1,8 @@
+2005-04-08  Tor Lillqvist  <tml@novell.com>
+
+       * glib/gutils.h (G_WIN32_DLLMAIN_FOR_DLL_NAME): Use wide char API
+       if available, and store dll name in UTF-8.
+
 2005-04-05  Matthias Clasen  <mclasen@redhat.com>
 
        * glib/gfileutils.c (get_contents_stdio): Avoid memory 
index 7bc0276..cf0df3d 100644 (file)
@@ -1,3 +1,8 @@
+2005-04-08  Tor Lillqvist  <tml@novell.com>
+
+       * glib/gutils.h (G_WIN32_DLLMAIN_FOR_DLL_NAME): Use wide char API
+       if available, and store dll name in UTF-8.
+
 2005-04-05  Matthias Clasen  <mclasen@redhat.com>
 
        * glib/gfileutils.c (get_contents_stdio): Avoid memory 
index 5ba1ad8..27de963 100644 (file)
@@ -367,24 +367,38 @@ G_END_DECLS
 #ifndef G_PLATFORM_WIN32
 # define G_WIN32_DLLMAIN_FOR_DLL_NAME(static, dll_name)
 #else
-# define G_WIN32_DLLMAIN_FOR_DLL_NAME(static, dll_name)                           \
-static char *dll_name;                                                    \
-                                                                          \
-BOOL WINAPI                                                               \
-DllMain (HINSTANCE hinstDLL,                                              \
-        DWORD     fdwReason,                                              \
-        LPVOID    lpvReserved)                                            \
-{                                                                         \
-  char bfr[1000];                                                         \
-  switch (fdwReason)                                                      \
-    {                                                                     \
-    case DLL_PROCESS_ATTACH:                                              \
-      GetModuleFileName ((HMODULE) hinstDLL, bfr, sizeof (bfr));          \
-      dll_name = g_path_get_basename (bfr);                               \
-      break;                                                              \
-    }                                                                     \
-                                                                          \
-  return TRUE;                                                            \
+# define G_WIN32_DLLMAIN_FOR_DLL_NAME(static, dll_name)                        \
+static char *dll_name;                                                 \
+                                                                       \
+BOOL WINAPI                                                            \
+DllMain (HINSTANCE hinstDLL,                                           \
+        DWORD     fdwReason,                                           \
+        LPVOID    lpvReserved)                                         \
+{                                                                      \
+  wchar_t wcbfr[1000];                                                 \
+  char cpbfr[1000];                                                    \
+  char *tem;                                                           \
+  switch (fdwReason)                                                   \
+    {                                                                  \
+    case DLL_PROCESS_ATTACH:                                           \
+      if (GetVersion () < 0x80000000)                                  \
+       {                                                               \
+         GetModuleFileNameW ((HMODULE) hinstDLL, wcbfr, G_N_ELEMENTS (wcbfr)); \
+         tem = g_utf16_to_utf8 (wcbfr, -1, NULL, NULL, NULL);          \
+         dll_name = g_path_get_basename (tem);                         \
+         g_free (tem);                                                 \
+       }                                                               \
+      else                                                             \
+       {                                                               \
+         GetModuleFileNameA ((HMODULE) hinstDLL, cpbfr, G_N_ELEMENTS (cpbfr)); \
+         tem = g_locale_to_utf8 (cpbfr, -1, NULL, NULL, NULL);         \
+         dll_name = g_path_get_basename (tem);                         \
+         g_free (tem);                                                 \
+       }                                                               \
+      break;                                                           \
+    }                                                                  \
+                                                                       \
+  return TRUE;                                                         \
 }
 #endif /* G_PLATFORM_WIN32 */