diff src/shared-fcns.h @ 23003:d591b38e3410 stable

Use GetModuleFileName for getting octave path in windows (bug #48671) * src/shared-fcns.h (w32_get_octave_home): Use GetModuleFileName instead of Module32First/Next scan.
author John D
date Thu, 05 Jan 2017 09:37:16 -0500
parents 2bc07741efa0
children 71f19f38cbad e8d64dce0afd
line wrap: on
line diff
--- a/src/shared-fcns.h	Wed Jan 04 11:19:00 2017 +0100
+++ b/src/shared-fcns.h	Thu Jan 05 09:37:16 2017 -0500
@@ -40,39 +40,16 @@
 
   std::string bin_dir;
 
-  HANDLE h = CreateToolhelp32Snapshot (TH32CS_SNAPMODULE
-#if defined (TH32CS_SNAPMODULE32)
-                                       | TH32CS_SNAPMODULE32
-#endif
-                                       , 0);
-
-  if (h != INVALID_HANDLE_VALUE)
+  char namebuf[MAX_PATH+1];
+  if (GetModuleFileName (GetModuleHandle (NULL), namebuf, MAX_PATH))
     {
-      MODULEENTRY32 mod_info;
-
-      ZeroMemory (&mod_info, sizeof (mod_info));
-      mod_info.dwSize = sizeof (mod_info);
+      namebuf[MAX_PATH] = '\0';
 
-      if (Module32First (h, &mod_info))
-        {
-          do
-            {
-              std::string mod_name (mod_info.szModule);
-
-              if (mod_name.find ("octave") != std::string::npos)
-                {
-                  bin_dir = mod_info.szExePath;
+      std::string exe_name = namebuf; 
+      size_t pos = exe_name.rfind ("\\");
 
-                  if (bin_dir[bin_dir.length () - 1] != '\\')
-                    bin_dir.append (1, '\\');
-
-                  break;
-                }
-            }
-          while (Module32Next (h, &mod_info));
-        }
-
-      CloseHandle (h);
+      if (pos != std::string::npos)
+        bin_dir = exe_name.substr (0, pos + 1);
     }
 
   if (! bin_dir.empty ())