diff options
author | Gerald Combs <gerald@wireshark.org> | 2010-08-27 19:24:44 +0000 |
---|---|---|
committer | Gerald Combs <gerald@wireshark.org> | 2010-08-27 19:24:44 +0000 |
commit | 5aae07254f8000c6f7b40fbe14e2287800e9f38e (patch) | |
tree | 235461f9dab517e630204934e4527b6eeced52d6 /wsutil | |
parent | 9d96012b57cfea4b309ce9ed00d729b73062cc2f (diff) | |
download | wireshark-5aae07254f8000c6f7b40fbe14e2287800e9f38e.tar.gz wireshark-5aae07254f8000c6f7b40fbe14e2287800e9f38e.tar.bz2 wireshark-5aae07254f8000c6f7b40fbe14e2287800e9f38e.zip |
Forward-port r33953.
Move the SetDllDirectory calls to ws_init_dll_search_path. If
SetDllDirectory fails, pass the Wireshark program path to
SetCurrentDirectory.
svn path=/trunk/; revision=33958
Diffstat (limited to 'wsutil')
-rw-r--r-- | wsutil/file_util.c | 22 | ||||
-rw-r--r-- | wsutil/file_util.h | 7 | ||||
-rw-r--r-- | wsutil/libwsutil.def | 1 |
3 files changed, 30 insertions, 0 deletions
diff --git a/wsutil/file_util.c b/wsutil/file_util.c index 160272c0bf..2695d98170 100644 --- a/wsutil/file_util.c +++ b/wsutil/file_util.c @@ -43,6 +43,7 @@ #include <windows.h> #include <errno.h> #include <wchar.h> +#include <tchar.h> /*#include <direct.h>*/ #include <io.h> @@ -474,6 +475,27 @@ init_dll_load_paths() { return FALSE; } +gboolean +ws_init_dll_search_path() { + gboolean dll_dir_set = FALSE; + wchar_t *program_path_w; + + typedef BOOL (*SetDllDirectoryHandler)(LPCTSTR); + SetDllDirectoryHandler PSetDllDirectory; + + if (PSetDllDirectory = (SetDllDirectoryHandler) GetProcAddress(GetModuleHandle(_T("kernel32.dll")), "SetDllDirectoryW")) { + dll_dir_set = PSetDllDirectory(_T("")); + } + + if (!dll_dir_set && init_dll_load_paths()) { + program_path_w = g_utf8_to_utf16(program_path, -1, NULL, NULL, NULL); + SetCurrentDirectory(program_path_w); + g_free(program_path_w); + } + + return dll_dir_set; +} + /* * Internally g_module_open uses LoadLibrary on Windows and returns an * HMODULE cast to a GModule *. However there's no guarantee that this diff --git a/wsutil/file_util.h b/wsutil/file_util.h index 3427d417ad..798cea9261 100644 --- a/wsutil/file_util.h +++ b/wsutil/file_util.h @@ -100,6 +100,13 @@ extern FILE * ws_stdio_freopen (const gchar *filename, const gchar *mode, FILE * /* DLL loading */ +/** Try to remove the current directory from the DLL search path. + * SetDllDirectory is tried, then SetCurrentDirectory(program_dir) + * + * @return TRUE if we were able to call SetDllDirectory, FALSE otherwise. + */ +gboolean ws_init_dll_search_path(); + /** Load a DLL using LoadLibrary. * Only the system and program directories are searched. * diff --git a/wsutil/libwsutil.def b/wsutil/libwsutil.def index a0cafe95fc..e0e0202187 100644 --- a/wsutil/libwsutil.def +++ b/wsutil/libwsutil.def @@ -18,6 +18,7 @@ ws_stdio_remove ws_stdio_rename ws_stdio_stat ws_stdio_unlink +ws_init_dll_search_path ws_load_library ws_module_open |