[gimp/gimp-2-8] windows: Call SetDLLDirectory() in the app



commit 6faa39a3b2e026a8056189fb9b16d5360f3f9a79
Author: Mukund Sivaraman <muks banu com>
Date:   Mon Apr 13 00:17:06 2015 +0530

    windows: Call SetDLLDirectory() in the app
    
    With this patch, there should be no more need to set PATH on Windows
    before running GIMP.
    
    This patch was tested by me and drawoc, but there could be some
    undetected issues lurking. Revert if any problems arise.
    
    (cherry picked from commit 60197c227db92c7cf927927a3b7b2d39aaf622b1)

 app/main.c     |   34 ++++++++++++++++++++++++++++++++++
 libgimp/gimp.c |   34 ++++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+), 0 deletions(-)
---
diff --git a/app/main.c b/app/main.c
index 4bdfa35..f3ddd63 100644
--- a/app/main.c
+++ b/app/main.c
@@ -309,6 +309,40 @@ main (int    argc,
     if (p_SetDllDirectoryA)
       (*p_SetDllDirectoryA) ("");
   }
+
+  /* On Windows, set DLL search path to $INSTALLDIR/bin so that .exe
+     plug-ins in the plug-ins directory can find libgimp and file
+     library DLLs without needing to set external PATH. */
+  {
+    const gchar *install_dir;
+    gchar       *bin_dir;
+    LPWSTR       w_bin_dir;
+    int          n;
+
+    w_bin_dir = NULL;
+    install_dir = gimp_installation_directory ();
+    bin_dir = g_build_filename (install_dir, "bin", NULL);
+
+    n = MultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS,
+                             bin_dir, -1, NULL, 0);
+    if (n == 0)
+      goto out;
+
+    w_bin_dir = g_malloc_n (n + 1, sizeof (wchar_t));
+    n = MultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS,
+                             bin_dir, -1,
+                             w_bin_dir, (n + 1) * sizeof (wchar_t));
+    if (n == 0)
+      goto out;
+
+    SetDllDirectoryW (w_bin_dir);
+
+  out:
+    if (w_bin_dir)
+      g_free (w_bin_dir);
+    g_free (bin_dir);
+  }
+
 #ifndef _WIN64
   {
     typedef BOOL (WINAPI *t_SetProcessDEPPolicy) (DWORD dwFlags);
diff --git a/libgimp/gimp.c b/libgimp/gimp.c
index 0d2c7f7..a5deca8 100644
--- a/libgimp/gimp.c
+++ b/libgimp/gimp.c
@@ -261,6 +261,40 @@ gimp_main (const GimpPlugInInfo *info,
     if (p_SetDllDirectoryA)
       (*p_SetDllDirectoryA) ("");
   }
+
+  /* On Windows, set DLL search path to $INSTALLDIR/bin so that GEGL
+     file operations can find their respective file library DLLs (such
+     as jasper, etc.) without needing to set external PATH. */
+  {
+    const gchar *install_dir;
+    gchar       *bin_dir;
+    LPWSTR       w_bin_dir;
+    int          n;
+
+    w_bin_dir = NULL;
+    install_dir = gimp_installation_directory ();
+    bin_dir = g_build_filename (install_dir, "bin", NULL);
+
+    n = MultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS,
+                             bin_dir, -1, NULL, 0);
+    if (n == 0)
+      goto out;
+
+    w_bin_dir = g_malloc_n (n + 1, sizeof (wchar_t));
+    n = MultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS,
+                             bin_dir, -1,
+                             w_bin_dir, (n + 1) * sizeof (wchar_t));
+    if (n == 0)
+      goto out;
+
+    SetDllDirectoryW (w_bin_dir);
+
+  out:
+    if (w_bin_dir)
+      g_free (w_bin_dir);
+    g_free (bin_dir);
+  }
+
 #ifndef _WIN64
   {
     typedef BOOL (WINAPI *t_SetProcessDEPPolicy) (DWORD dwFlags);


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