ShellExecute initial directory patch.

Rein Klazes rklazes at xs4all.nl
Thu Mar 18 12:37:16 CST 2004


Hi,

This fixes a bug reported on the users list (see subject "Some strange
things with files") where  ShellExecute failed to find the executable.

It turns out (testing on Win2k) that ShellExecute looks for the
executable in the new current directory (if one is specified) and not in
the current directory of the calling process.
That is opposite of what CreateProcess does: it searches the current
directory but not the initial dir. 

Since ShellExecute uses CreateProcess to do the actual job, the current
directory needs to be changed...

Changelog:
	dlls/shell32/	: shlexec.c
	In SHELL_ExecuteW, if a new current directory is specified,
	change to it before calling CreateProcess so that it will find
	the correct executable.

Rein.
-- 
Rein Klazes
rklazes at xs4all.nl
-------------- next part --------------
--- wine/dlls/shell32/shlexec.c	2004-03-18 13:52:10.000000000 +0100
+++ mywine/dlls/shell32/shlexec.c	2004-03-18 14:26:06.000000000 +0100
@@ -135,8 +135,16 @@
     STARTUPINFOW  startup;
     PROCESS_INFORMATION info;
     UINT retval = 31;
+    UINT gcdret = 0;
+    WCHAR curdir[MAX_PATH];
 
     TRACE("Execute %s from directory %s\n", debugstr_w(lpCmd), debugstr_w(psei->lpDirectory));
+    /* ShellExecute specifies the command from psei->lpDirectory
+     * if present. Not from the current dir as CreateProcess does */
+    if( psei->lpDirectory && psei->lpDirectory[0] )
+        if( ( gcdret = GetCurrentDirectoryW( MAX_PATH, curdir)))
+            if( !SetCurrentDirectoryW( psei->lpDirectory))
+                ERR("cannot set directory %s\n", debugstr_w(psei->lpDirectory));
     ZeroMemory(&startup,sizeof(STARTUPINFOW));
     startup.cb = sizeof(STARTUPINFOW);
     startup.dwFlags = STARTF_USESHOWWINDOW;
@@ -165,6 +173,10 @@
     TRACE("returning %u\n", retval);
 
     psei_out->hInstApp = (HINSTANCE)retval;
+    if( gcdret ) 
+        if( !SetCurrentDirectoryW( curdir))
+            ERR("cannot return to directory %s\n", debugstr_w(curdir));
+
     return retval;
 }
 


More information about the wine-patches mailing list