On Thu, Sep 12, 2002 at 08:38:09PM +1000, Michael Beach wrote:
Recently I've been using WINE to run a Win32 exe which needs to load certain DLLs which are located in the same directory as the exe. I was most perplexed when I found that this worked initially, but when I moved the exe and DLLs to a different directory it stopped working ie WINE would refuse to start the exe, claiming that it was unable to load the required DLLs.
After some debugging, I discovered that the critical factor was the length of the pathname to the exe, when it passed a certain length it stopped working. However this length was way short of the MAX_PATH value of 260.
Ah, cool finding !
static BOOL DIR_TryModulePath( LPCWSTR name, DOS_FULL_NAME *full_name, BOOL win32 ) {
- /* FIXME: for now, GetModuleFileNameW can't return more */
- /* than OFS_MAXPATHNAME. This may change with Win32. */
- WCHAR bufferW[OFS_MAXPATHNAME];
WCHAR bufferW[MAX_PATH]; LPWSTR p;
if (!win32)
@@ -727,13 +725,13 @@ if (!GetCurrentTask()) return FALSE; if (!GetModuleFileName16( GetCurrentTask(), buffer, sizeof(buffer) )) return FALSE;
MultiByteToWideChar(CP_ACP, 0, buffer, -1, bufferW, OFS_MAXPATHNAME);
} else {MultiByteToWideChar(CP_ACP, 0, buffer, -1, bufferW, MAX_PATH);
- if (!GetModuleFileNameW( 0, bufferW, OFS_MAXPATHNAME ) )
- if (!GetModuleFileNameW( 0, bufferW, MAX_PATH ) ) return FALSE; } if (!(p = strrchrW( bufferW, '\' ))) return FALSE;
- if (OFS_MAXPATHNAME - (++p - bufferW) <= strlenW(name)) return FALSE;
- if (MAX_PATH - (++p - bufferW) <= strlenW(name)) return FALSE; strcpyW( p, name ); return DOSFS_GetFullName( bufferW, TRUE, full_name );
Argl, why does this code use the buffer size contants instead of sizeof(variable) !? I suggest we always specify buffer length constants only *once*, namely at creation of the buffer. Not doing so can be potentially very harmful if we decide to change the buffer length and then manage to forget one or more length constants...
Maybe you could even also fix that "weirdness" in our code ?
Thanks ! :)