Skip to content

Commit fb1f68e

Browse files
committed
Always pass a full path name to LoadLibraryEx(). Fixes some Windows 9x problems. As discussed on python-dev
1 parent b4bbcd7 commit fb1f68e

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

Python/dynload_win.c

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -163,24 +163,21 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
163163

164164
#ifdef MS_WIN32
165165
{
166-
HINSTANCE hDLL;
166+
HINSTANCE hDLL = NULL;
167167
char pathbuf[260];
168-
if (strchr(pathname, '\\') == NULL &&
169-
strchr(pathname, '/') == NULL)
170-
{
171-
/* Prefix bare filename with ".\" */
172-
char *p = pathbuf;
173-
*p = '\0';
174-
_getcwd(pathbuf, sizeof pathbuf);
175-
if (*p != '\0' && p[1] == ':')
176-
p += 2;
177-
sprintf(p, ".\\%-.255s", pathname);
178-
pathname = pathbuf;
179-
}
180-
/* Look for dependent DLLs in directory of pathname first */
181-
/* XXX This call doesn't exist in Windows CE */
182-
hDLL = LoadLibraryEx(pathname, NULL,
183-
LOAD_WITH_ALTERED_SEARCH_PATH);
168+
LPTSTR dummy;
169+
/* We use LoadLibraryEx so Windows looks for dependent DLLs
170+
in directory of pathname first. However, Windows95
171+
can sometimes not work correctly unless the absolute
172+
path is used. If GetFullPathName() fails, the LoadLibrary
173+
will certainly fail too, so use its error code */
174+
if (GetFullPathName(pathname,
175+
sizeof(pathbuf),
176+
pathbuf,
177+
&dummy))
178+
/* XXX This call doesn't exist in Windows CE */
179+
hDLL = LoadLibraryEx(pathname, NULL,
180+
LOAD_WITH_ALTERED_SEARCH_PATH);
184181
if (hDLL==NULL){
185182
char errBuf[256];
186183
unsigned int errorCode;

0 commit comments

Comments
 (0)