@@ -287,27 +287,40 @@ unescape_shellxquote(char_u *p, char_u *escaped)
287287 HINSTANCE
288288vimLoadLib (char * name )
289289{
290- HINSTANCE dll = NULL ;
291- TCHAR old_dir [MAXPATHL ];
290+ HINSTANCE dll = NULL ;
291+ char old_dir [MAXPATHL ];
292292
293293 /* NOTE: Do not use mch_dirname() and mch_chdir() here, they may call
294294 * vimLoadLib() recursively, which causes a stack overflow. */
295295 if (exe_path == NULL )
296296 get_exe_name ();
297- if (exe_path != NULL && GetCurrentDirectory ( MAXPATHL , old_dir ) != 0 )
297+ if (exe_path != NULL )
298298 {
299- /* Change directory to where the executable is, both to make sure we
300- * find a .dll there and to avoid looking for a .dll in the current
301- * directory. */
302- SetCurrentDirectory (exe_path );
303- dll = LoadLibrary (name );
304- SetCurrentDirectory (old_dir );
305- }
306- else
307- {
308- /* We are not able to change directory to where the executable is, try
309- * to load library anyway. */
310- dll = LoadLibrary (name );
299+ #ifdef FEAT_MBYTE
300+ WCHAR old_dirw [MAXPATHL ];
301+
302+ if (GetCurrentDirectoryW (MAXPATHL , old_dirw ) != 0 )
303+ {
304+ /* Change directory to where the executable is, both to make
305+ * sure we find a .dll there and to avoid looking for a .dll
306+ * in the current directory. */
307+ SetCurrentDirectory (exe_path );
308+ dll = LoadLibrary (name );
309+ SetCurrentDirectoryW (old_dirw );
310+ return dll ;
311+ }
312+ /* Retry with non-wide function (for Windows 98). */
313+ if (GetLastError () == ERROR_CALL_NOT_IMPLEMENTED )
314+ #endif
315+ if (GetCurrentDirectory (MAXPATHL , old_dir ) != 0 )
316+ {
317+ /* Change directory to where the executable is, both to make
318+ * sure we find a .dll there and to avoid looking for a .dll
319+ * in the current directory. */
320+ SetCurrentDirectory (exe_path );
321+ dll = LoadLibrary (name );
322+ SetCurrentDirectory (old_dir );
323+ }
311324 }
312325 return dll ;
313326}
0 commit comments