comparison 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
comparison
equal deleted inserted replaced
23001:14f1738a56ae 23003:d591b38e3410
38 { 38 {
39 std::string retval; 39 std::string retval;
40 40
41 std::string bin_dir; 41 std::string bin_dir;
42 42
43 HANDLE h = CreateToolhelp32Snapshot (TH32CS_SNAPMODULE 43 char namebuf[MAX_PATH+1];
44 #if defined (TH32CS_SNAPMODULE32) 44 if (GetModuleFileName (GetModuleHandle (NULL), namebuf, MAX_PATH))
45 | TH32CS_SNAPMODULE32 45 {
46 #endif 46 namebuf[MAX_PATH] = '\0';
47 , 0);
48 47
49 if (h != INVALID_HANDLE_VALUE) 48 std::string exe_name = namebuf;
50 { 49 size_t pos = exe_name.rfind ("\\");
51 MODULEENTRY32 mod_info;
52 50
53 ZeroMemory (&mod_info, sizeof (mod_info)); 51 if (pos != std::string::npos)
54 mod_info.dwSize = sizeof (mod_info); 52 bin_dir = exe_name.substr (0, pos + 1);
55
56 if (Module32First (h, &mod_info))
57 {
58 do
59 {
60 std::string mod_name (mod_info.szModule);
61
62 if (mod_name.find ("octave") != std::string::npos)
63 {
64 bin_dir = mod_info.szExePath;
65
66 if (bin_dir[bin_dir.length () - 1] != '\\')
67 bin_dir.append (1, '\\');
68
69 break;
70 }
71 }
72 while (Module32Next (h, &mod_info));
73 }
74
75 CloseHandle (h);
76 } 53 }
77 54
78 if (! bin_dir.empty ()) 55 if (! bin_dir.empty ())
79 { 56 {
80 size_t pos = bin_dir.rfind ("\\bin\\"); 57 size_t pos = bin_dir.rfind ("\\bin\\");