[libpeas: 1/2] Windows: use DLL handle to get module dir



commit b5dcc0e19049a7102b1932d49c117a509d61adaf
Author: Tom Schoonjans <Tom Schoonjans diamond ac uk>
Date:   Wed Dec 18 11:22:09 2019 +0000

    Windows: use DLL handle to get module dir

 libpeas/peas-dirs.c | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)
---
diff --git a/libpeas/peas-dirs.c b/libpeas/peas-dirs.c
index eca5611..7cb08e2 100644
--- a/libpeas/peas-dirs.c
+++ b/libpeas/peas-dirs.c
@@ -29,6 +29,27 @@
 #include "peas-utils-osx.h"
 #endif
 
+#ifdef G_OS_WIN32
+// inspired by gobject-introspection...
+
+#include <libloaderapi.h>
+
+static HMODULE libpeas_dll = NULL;
+
+#ifdef DLL_EXPORT
+
+BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved);
+
+BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
+{
+  if (fdwReason == DLL_PROCESS_ATTACH)
+    libpeas_dll = hinstDLL;
+  return TRUE;
+}
+
+#endif
+#endif
+
 gchar *
 peas_dirs_get_data_dir (void)
 {
@@ -37,7 +58,7 @@ peas_dirs_get_data_dir (void)
 #ifdef G_OS_WIN32
   gchar *win32_dir;
 
-  win32_dir = g_win32_get_package_installation_directory_of_module (NULL);
+  win32_dir = g_win32_get_package_installation_directory_of_module (libpeas_dll);
 
   data_dir = g_build_filename (win32_dir, "share", "libpeas-1.0", NULL);
   g_free (win32_dir);
@@ -58,7 +79,7 @@ peas_dirs_get_lib_dir (void)
 #ifdef G_OS_WIN32
   gchar *win32_dir;
 
-  win32_dir = g_win32_get_package_installation_directory_of_module (NULL);
+  win32_dir = g_win32_get_package_installation_directory_of_module (libpeas_dll);
 
   lib_dir = g_build_filename (win32_dir, "lib", "libpeas-1.0", NULL);
   g_free (win32_dir);
@@ -98,7 +119,7 @@ peas_dirs_get_locale_dir (void)
 #ifdef G_OS_WIN32
   gchar *win32_dir;
 
-  win32_dir = g_win32_get_package_installation_directory_of_module (NULL);
+  win32_dir = g_win32_get_package_installation_directory_of_module (libpeas_dll);
 
   locale_dir = g_build_filename (win32_dir, "share", "locale", NULL);
 


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