4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
11 Problem: Win32: may be loading .dll from the wrong directory.
12 Solution: Go to the Vim executable directory when opening a library.
13 Files: src/gui_w32.c, src/if_lua.c, src/if_mzsch.c, src/if_perl.xs,
14 src/if_python.c, src/if_python3.c, src/if_ruby.c, src/mbyte.c,
15 src/os_mswin.c, src/os_win32.c, src/proto/os_win32.pro
18 *** ../vim-7.3.033/src/gui_w32.c 2010-08-15 21:57:25.000000000 +0200
19 --- src/gui_w32.c 2010-10-22 21:49:27.000000000 +0200
23 /* try and load the user32.dll library and get the entry points for
24 * multi-monitor-support. */
25 ! if ((user32_lib = LoadLibrary("User32.dll")) != NULL)
27 pMonitorFromWindow = (TMonitorFromWindow)GetProcAddress(user32_lib,
31 /* try and load the user32.dll library and get the entry points for
32 * multi-monitor-support. */
33 ! if ((user32_lib = vimLoadLib("User32.dll")) != NULL)
35 pMonitorFromWindow = (TMonitorFromWindow)GetProcAddress(user32_lib,
42 ! hLibImm = LoadLibrary("imm32.dll");
50 ! hLibImm = vimLoadLib("imm32.dll");
54 *** ../vim-7.3.033/src/if_lua.c 2010-08-15 21:57:28.000000000 +0200
55 --- src/if_lua.c 2010-10-22 21:49:39.000000000 +0200
58 # define symbol_from_dll dlsym
59 # define close_dll dlclose
61 ! # define load_dll LoadLibrary
62 # define symbol_from_dll GetProcAddress
63 # define close_dll FreeLibrary
66 # define symbol_from_dll dlsym
67 # define close_dll dlclose
69 ! # define load_dll vimLoadLib
70 # define symbol_from_dll GetProcAddress
71 # define close_dll FreeLibrary
73 *** ../vim-7.3.033/src/if_mzsch.c 2010-08-15 21:57:32.000000000 +0200
74 --- src/if_mzsch.c 2010-10-22 21:49:53.000000000 +0200
80 ! hMzSch = LoadLibrary(sch_dll);
81 ! hMzGC = LoadLibrary(gc_dll);
89 ! hMzSch = vimLoadLib(sch_dll);
90 ! hMzGC = vimLoadLib(gc_dll);
94 *** ../vim-7.3.033/src/if_perl.xs 2010-08-15 21:57:30.000000000 +0200
95 --- src/if_perl.xs 2010-10-22 21:53:06.000000000 +0200
98 #define close_dll dlclose
100 #define PERL_PROC FARPROC
101 ! #define load_dll LoadLibrary
102 #define symbol_from_dll GetProcAddress
103 #define close_dll FreeLibrary
106 #define close_dll dlclose
108 #define PERL_PROC FARPROC
109 ! #define load_dll vimLoadLib
110 #define symbol_from_dll GetProcAddress
111 #define close_dll FreeLibrary
113 *** ../vim-7.3.033/src/if_python.c 2010-08-15 21:57:28.000000000 +0200
114 --- src/if_python.c 2010-10-22 21:49:57.000000000 +0200
117 # define close_dll dlclose
118 # define symbol_from_dll dlsym
120 ! # define load_dll LoadLibrary
121 # define close_dll FreeLibrary
122 # define symbol_from_dll GetProcAddress
125 # define close_dll dlclose
126 # define symbol_from_dll dlsym
128 ! # define load_dll vimLoadLib
129 # define close_dll FreeLibrary
130 # define symbol_from_dll GetProcAddress
132 *** ../vim-7.3.033/src/if_python3.c 2010-08-15 21:57:28.000000000 +0200
133 --- src/if_python3.c 2010-10-22 21:50:01.000000000 +0200
136 # define close_dll dlclose
137 # define symbol_from_dll dlsym
139 ! # define load_dll LoadLibrary
140 # define close_dll FreeLibrary
141 # define symbol_from_dll GetProcAddress
144 # define close_dll dlclose
145 # define symbol_from_dll dlsym
147 ! # define load_dll vimLoadLib
148 # define close_dll FreeLibrary
149 # define symbol_from_dll GetProcAddress
151 *** ../vim-7.3.033/src/if_ruby.c 2010-09-29 13:02:48.000000000 +0200
152 --- src/if_ruby.c 2010-10-22 21:50:04.000000000 +0200
155 # define symbol_from_dll dlsym
156 # define close_dll dlclose
158 ! # define load_dll LoadLibrary
159 # define symbol_from_dll GetProcAddress
160 # define close_dll FreeLibrary
163 # define symbol_from_dll dlsym
164 # define close_dll dlclose
166 ! # define load_dll vimLoadLib
167 # define symbol_from_dll GetProcAddress
168 # define close_dll FreeLibrary
170 *** ../vim-7.3.033/src/mbyte.c 2010-09-18 13:36:41.000000000 +0200
171 --- src/mbyte.c 2010-10-22 21:50:09.000000000 +0200
175 if (hIconvDLL != 0 && hMsvcrtDLL != 0)
177 ! hIconvDLL = LoadLibrary(DYNAMIC_ICONV_DLL);
178 if (hIconvDLL == 0) /* sometimes it's called libiconv.dll */
179 ! hIconvDLL = LoadLibrary(DYNAMIC_ICONV_DLL_ALT);
181 ! hMsvcrtDLL = LoadLibrary(DYNAMIC_MSVCRT_DLL);
182 if (hIconvDLL == 0 || hMsvcrtDLL == 0)
184 /* Only give the message when 'verbose' is set, otherwise it might be
187 if (hIconvDLL != 0 && hMsvcrtDLL != 0)
189 ! hIconvDLL = vimLoadLib(DYNAMIC_ICONV_DLL);
190 if (hIconvDLL == 0) /* sometimes it's called libiconv.dll */
191 ! hIconvDLL = vimLoadLib(DYNAMIC_ICONV_DLL_ALT);
193 ! hMsvcrtDLL = vimLoadLib(DYNAMIC_MSVCRT_DLL);
194 if (hIconvDLL == 0 || hMsvcrtDLL == 0)
196 /* Only give the message when 'verbose' is set, otherwise it might be
197 *** ../vim-7.3.033/src/os_mswin.c 2010-08-15 21:57:29.000000000 +0200
198 --- src/os_mswin.c 2010-10-22 22:03:26.000000000 +0200
202 BOOL fRunTimeLinkSuccess = FALSE;
204 // Get a handle to the DLL module.
206 hinstLib = LoadLibrary(libname);
208 + hinstLib = vimLoadLib(libname);
211 // If the handle is valid, try to get the function address.
212 if (hinstLib != NULL)
213 *** ../vim-7.3.033/src/os_win32.c 2010-10-13 20:37:37.000000000 +0200
214 --- src/os_win32.c 2010-10-23 13:16:55.000000000 +0200
217 static int suppress_winsize = 1; /* don't fiddle with console */
224 ! static int did_set_PATH = FALSE;
226 if (exe_name == NULL)
228 /* store the name of the executable, may be used for $VIM */
229 ! GetModuleFileName(NULL, temp, 255);
231 exe_name = FullName_save((char_u *)temp, FALSE);
234 ! if (!did_set_PATH && exe_name != NULL)
239 ! /* Append our starting directory to $PATH, so that when doing "!xxd"
240 ! * it's found in our starting directory. Needed because SearchPath()
241 ! * also looks there. */
242 ! p = mch_getenv("PATH");
243 ! newpath = alloc((unsigned)(STRLEN(p) + STRLEN(exe_name) + 2));
244 ! if (newpath != NULL)
246 ! STRCPY(newpath, p);
247 ! STRCAT(newpath, ";");
248 ! vim_strncpy(newpath + STRLEN(newpath), exe_name,
249 ! gettail_sep(exe_name) - exe_name);
250 ! vim_setenv((char_u *)"PATH", newpath);
254 ! did_set_PATH = TRUE;
258 #if defined(DYNAMIC_GETTEXT) || defined(PROTO)
260 static int suppress_winsize = 1; /* don't fiddle with console */
263 + static char_u *exe_path = NULL;
268 ! char temp[MAXPATHL];
271 if (exe_name == NULL)
273 /* store the name of the executable, may be used for $VIM */
274 ! GetModuleFileName(NULL, temp, MAXPATHL - 1);
276 exe_name = FullName_save((char_u *)temp, FALSE);
279 ! if (exe_path == NULL && exe_name != NULL)
281 ! exe_path = vim_strnsave(exe_name, gettail_sep(exe_name) - exe_name);
282 ! if (exe_path != NULL)
284 ! /* Append our starting directory to $PATH, so that when doing
285 ! * "!xxd" it's found in our starting directory. Needed because
286 ! * SearchPath() also looks there. */
287 ! p = mch_getenv("PATH");
288 ! if (STRLEN(p) + STRLEN(exe_path) + 2 < MAXPATHL);
292 ! STRCAT(temp, exe_path);
293 ! vim_setenv((char_u *)"PATH", temp);
300 + * Load library "name".
303 + vimLoadLib(char *name)
305 + HINSTANCE dll = NULL;
306 + char old_dir[MAXPATHL];
308 ! if (exe_path == NULL)
310 ! if (exe_path != NULL && mch_dirname(old_dir, MAXPATHL) == OK)
312 ! /* Change directory to where the executable is, both to make sure we
313 ! * find a .dll there and to avoid looking for a .dll in the current
315 ! mch_chdir(exe_path);
316 ! dll = LoadLibrary(name);
317 ! mch_chdir(old_dir);
322 #if defined(DYNAMIC_GETTEXT) || defined(PROTO)
325 static char *null_libintl_bindtextdomain(const char *, const char *);
326 static char *null_libintl_bind_textdomain_codeset(const char *, const char *);
328 ! static HINSTANCE hLibintlDLL = 0;
329 char *(*dyn_libintl_gettext)(const char *) = null_libintl_gettext;
330 char *(*dyn_libintl_textdomain)(const char *) = null_libintl_textdomain;
331 char *(*dyn_libintl_bindtextdomain)(const char *, const char *)
333 static char *null_libintl_bindtextdomain(const char *, const char *);
334 static char *null_libintl_bind_textdomain_codeset(const char *, const char *);
336 ! static HINSTANCE hLibintlDLL = NULL;
337 char *(*dyn_libintl_gettext)(const char *) = null_libintl_gettext;
338 char *(*dyn_libintl_textdomain)(const char *) = null_libintl_textdomain;
339 char *(*dyn_libintl_bindtextdomain)(const char *, const char *)
344 /* Load gettext library (libintl.dll) */
345 ! hLibintlDLL = LoadLibrary(libname != NULL ? libname : GETTEXT_DLL);
348 ! char_u dirname[_MAX_PATH];
350 ! /* Try using the path from gvim.exe to find the .dll there. */
352 ! STRCPY(dirname, exe_name);
353 ! STRCPY(gettail(dirname), GETTEXT_DLL);
354 ! hLibintlDLL = LoadLibrary((char *)dirname);
360 ! EMSG2(_(e_loadlib), GETTEXT_DLL);
366 for (i = 0; libintl_entry[i].name != NULL
367 && libintl_entry[i].ptr != NULL; ++i)
371 /* Load gettext library (libintl.dll) */
372 ! hLibintlDLL = vimLoadLib(libname != NULL ? libname : GETTEXT_DLL);
378 ! EMSG2(_(e_loadlib), GETTEXT_DLL);
383 for (i = 0; libintl_entry[i].name != NULL
384 && libintl_entry[i].ptr != NULL; ++i)
387 * Seems like a lot of overhead to load/unload ADVAPI32.DLL each
388 * time we verify security...
390 ! advapi_lib = LoadLibrary("ADVAPI32.DLL");
391 if (advapi_lib != NULL)
393 pSetNamedSecurityInfo = (PSNSECINFO)GetProcAddress(advapi_lib,
395 * Seems like a lot of overhead to load/unload ADVAPI32.DLL each
396 * time we verify security...
398 ! advapi_lib = vimLoadLib("ADVAPI32.DLL");
399 if (advapi_lib != NULL)
401 pSetNamedSecurityInfo = (PSNSECINFO)GetProcAddress(advapi_lib,
402 *** ../vim-7.3.033/src/proto/os_win32.pro 2010-08-15 21:57:28.000000000 +0200
403 --- src/proto/os_win32.pro 2010-10-22 22:05:35.000000000 +0200
408 + HINSTANCE vimLoadLib __ARGS((char *name));
409 int dyn_libintl_init __ARGS((char *libname));
410 void dyn_libintl_end __ARGS((void));
411 void PlatformId __ARGS((void));
412 *** ../vim-7.3.033/src/version.c 2010-10-22 22:13:47.000000000 +0200
413 --- src/version.c 2010-10-23 13:55:21.000000000 +0200
417 { /* Add new patch number below this line */
423 This is the polymorph virus! Follow these instructions carefully:
424 1. Send this message to everybody you know.
425 2. Format your harddisk.
426 Thank you for your cooperation in spreading the most powerful virus ever!
428 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
429 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
430 \\\ download, build and distribute -- http://www.A-A-P.org ///
431 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///