glib r6570 - in trunk: . glib



Author: tml
Date: Sun Feb 24 01:07:41 2008
New Revision: 6570
URL: http://svn.gnome.org/viewvc/glib?rev=6570&view=rev

Log:
2008-02-24  Tor Lillqvist  <tml novell com>

	* glib/gutils.h: Mention G_WIN32_DLLMAIN_FOR_DLL_NAME() will be
	deprecated in the future.

	* glib/gutils.c: Drop use of G_WIN32_DLLMAIN_FOR_DLL_NAME(). Use a
	minimal DllMain() instead that just saves the DLL handle.
	(g_win32_get_system_data_dirs_for_module, _glib_get_locale_dir)
	(get_module_share_dir): Use
	g_win32_get_package_installation_directory_of_module().



Modified:
   trunk/ChangeLog
   trunk/glib/gutils.c
   trunk/glib/gutils.h

Modified: trunk/glib/gutils.c
==============================================================================
--- trunk/glib/gutils.c	(original)
+++ trunk/glib/gutils.c	Sun Feb 24 01:07:41 2008
@@ -133,7 +133,18 @@
 
 #ifdef G_PLATFORM_WIN32
 
-G_WIN32_DLLMAIN_FOR_DLL_NAME (static, dll_name)
+static HMODULE glib_dll = NULL;
+
+BOOL WINAPI
+DllMain (HINSTANCE hinstDLL,
+	 DWORD     fdwReason,
+	 LPVOID    lpvReserved)
+{
+  if (fdwReason == DLL_PROCESS_ATTACH)
+      glib_dll = hinstDLL;
+
+  return TRUE;
+}
 
 #endif
 
@@ -2428,7 +2439,7 @@
   static gboolean beenhere = FALSE;
   typedef BOOL (WINAPI *t_GetModuleHandleExA) (DWORD, LPCTSTR, HMODULE *);
   static t_GetModuleHandleExA p_GetModuleHandleExA = NULL;
-  HMODULE hmodule;
+  HMODULE hmodule = NULL;
 
   if (!address)
     return NULL;
@@ -2458,27 +2469,14 @@
 get_module_share_dir (gconstpointer address)
 {
   HMODULE hmodule;
-  gchar *filename = NULL;
-  gchar *p, *retval;
-  wchar_t wfilename[MAX_PATH];
+  gchar *filename;
+  gchar *retval;
 
   hmodule = get_module_for_address (address);
   if (hmodule == NULL)
     return NULL;
 
-  if (GetModuleFileNameW (hmodule, wfilename, G_N_ELEMENTS (wfilename)))
-    filename = g_utf16_to_utf8 (wfilename, -1, NULL, NULL, NULL);
-
-  if (filename == NULL)
-    return NULL;
-
-  if ((p = strrchr (filename, G_DIR_SEPARATOR)) != NULL)
-    *p = '\0';
-
-  p = strrchr (filename, G_DIR_SEPARATOR);
-  if (p && (g_ascii_strcasecmp (p + 1, "bin") == 0))
-    *p = '\0';
-
+  filename = g_win32_get_package_installation_directory_of_module (hmodule);
   retval = g_build_filename (filename, "share", NULL);
   g_free (filename);
 
@@ -2493,6 +2491,7 @@
   static GHashTable *per_module_data_dirs = NULL;
   gchar **retval;
   gchar *p;
+  gchar *exe_root;
       
   if (address)
     {
@@ -2553,13 +2552,20 @@
   if (p)
     g_array_append_val (data_dirs, p);
     
-  p = g_win32_get_package_installation_subdirectory (NULL, dll_name, "share");
-  if (p)
-    g_array_append_val (data_dirs, p);
+  if (glib_dll != NULL)
+    {
+      gchar *glib_root = g_win32_get_package_installation_directory_of_module (glib_dll);
+      p = g_build_filename (glib_root, "share", NULL);
+      if (p)
+	g_array_append_val (data_dirs, p);
+      g_free (glib_root);
+    }
   
-  p = g_win32_get_package_installation_subdirectory (NULL, NULL, "share");
+  exe_root = g_win32_get_package_installation_directory_of_module (NULL);
+  p = g_build_filename (exe_root, "share", NULL);
   if (p)
     g_array_append_val (data_dirs, p);
+  g_free (exe_root);
 
   retval = (gchar **) g_array_free (data_dirs, FALSE);
 
@@ -3149,10 +3155,11 @@
 static gchar *
 _glib_get_locale_dir (void)
 {
-  gchar *install_dir, *locale_dir;
+  gchar *install_dir = NULL, *locale_dir;
   gchar *retval = NULL;
 
-  install_dir = g_win32_get_package_installation_directory (GETTEXT_PACKAGE, dll_name);
+  if (glib_dll != NULL)
+    install_dir = g_win32_get_package_installation_directory_of_module (glib_dll);
 
   if (install_dir)
     {

Modified: trunk/glib/gutils.h
==============================================================================
--- trunk/glib/gutils.h	(original)
+++ trunk/glib/gutils.h	Sun Feb 24 01:07:41 2008
@@ -427,6 +427,12 @@
 G_END_DECLS
 
 /*
+ * This macro will be deprecated in the future. This DllMain() is too
+ * complex. It is recommended to have a DLlMain() that just saves the
+ * handle to the DLL and then use that handle in normal code instead,
+ * for instance passing it to
+ * g_win32_get_package_installation_directory_of_module().
+ *
  * On Windows, this macro defines a DllMain function that stores the
  * actual DLL name that the code being compiled will be included in.
  * STATIC should be empty or 'static'. DLL_NAME is the name of the



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]