shell32 patch 23

Martin Fuchs martin-fuchs at gmx.net
Thu Jan 29 14:14:36 CST 2004


Changelog:

This patch for ShellExecute and similar functions implements the following functionality and bug fixes:

- resolving of shell links including calling of IShellExecuteHook interface
- handle shell links to virtual folders
- call explorer to open shell folders
- expand environment strings in path and command strings
- move "%I" expansion from ShellExecuteEx() into common function SHELL_ArgifyW()
- enumerate all "shell\<verb>\command" entries in the registry instead of searching only for "shell\open\command" entries
- set error code ERROR_DDE_FAIL if the DDE connection failed
- fix handling of %2, %3, ... and lower case format characters in SHELL_ArgifyW()
- fix buffer length usage for RegQueryValueW() calls at various places
  (The buffer length for RegQueryValueW() is given in bytes, not in characters!)
- SHELL_FindExecutable(): use PathFindExtensionA() instead if strrchr()
- ShellExecuteExA(): fix returning of application instance handles


I hope it's not too large - trying to split this into smaller patches will not be very successfull.
(Yes I know - some small parts could be separated out...)



Index: shell32_main.h
===================================================================
RCS file: /home/wine/wine/dlls/shell32/shell32_main.h,v
retrieving revision 1.80
diff -u -p -d -w -b -r1.80 shell32_main.h
--- shell32_main.h 26 Jan 2004 20:13:03 -0000 1.80
+++ shell32_main.h 29 Jan 2004 19:34:47 -0000
@@ -228,8 +228,13 @@ inline static WCHAR * __SHCloneStrAtoW(W
 #define HINSTANCE_32(h16) ((HINSTANCE)(ULONG_PTR)(h16))
 #define HINSTANCE_16(h32) (LOWORD(h32))
 
-typedef UINT (*SHELL_ExecuteW32)(WCHAR *lpCmd, void *env, LPSHELLEXECUTEINFOW sei, BOOL shWait);
-BOOL WINAPI ShellExecuteExW32 (LPSHELLEXECUTEINFOW sei, SHELL_ExecuteW32 execfunc);
+typedef UINT (*SHELL_ExecuteW32)(const WCHAR *lpCmd, void *env, BOOL shWait,
+       LPSHELLEXECUTEINFOW psei, LPSHELLEXECUTEINFOW psei_out);
+
+BOOL WINAPI ShellExecuteExW32(LPSHELLEXECUTEINFOW psei, SHELL_ExecuteW32 execfunc);
+
+UINT SHELL_FindExecutable(LPCWSTR lpPath, LPCWSTR lpFile, LPCWSTR lpOperation,
+                          LPWSTR lpResult, LPWSTR key, void **env, LPITEMIDLIST pidl, LPCWSTR args);
 
 extern WCHAR swShell32Name[MAX_PATH];
 extern char sShell32Name[MAX_PATH];


Index: shlexec.c
===================================================================
RCS file: /home/wine/wine/dlls/shell32/shlexec.c,v
retrieving revision 1.28
diff -u -p -d -w -b -r1.28 shlexec.c
--- shlexec.c 16 Jan 2004 23:06:25 -0000 1.28
+++ shlexec.c 29 Jan 2004 19:34:48 -0000
@@ -47,6 +47,7 @@
 #include "wine/winbase16.h"
 #include "shell32_main.h"
 #include "undocshell.h"
+#include "pidl.h"
 
 #include "wine/debug.h"
 
@@ -54,6 +55,10 @@ WINE_DEFAULT_DEBUG_CHANNEL(exec);
 
 static const WCHAR wszOpen[] = {'o','p','e','n',0};
 static const WCHAR wszExe[] = {'.','e','x','e',0};
+static const WCHAR wszILPtr[] = {':','%','p',0};
+static const WCHAR wszShell[] = {'\\','s','h','e','l','l','\\',0};
+static const WCHAR wszFolder[] = {'F','o','l','d','e','r',0};
+static const WCHAR wszEmpty[] = {0};
 
 
 /***********************************************************************
@@ -70,11 +75,16 @@ static const WCHAR wszExe[] = {'.','e','
  * %L seems to be %1 as long filename followed by the 8+3 variation
  * %S ???
  * %* all following parameters (see batfile)
+ *
+ * FIXME: use 'len'
  */
-static BOOL SHELL_ArgifyW(WCHAR* res, int len, const WCHAR* fmt, const WCHAR* lpFile)
+static BOOL SHELL_ArgifyW(WCHAR* out, int len, const WCHAR* fmt, const WCHAR* lpFile, LPITEMIDLIST pidl, LPCWSTR args)
 {
     WCHAR       xlpFile[1024];
     BOOL        done = FALSE;
+    LPVOID  pv;
+    PWSTR   res = out;
+    PCWSTR  cmd;
 
     while (*fmt)
     {
@@ -86,61 +96,221 @@ static BOOL SHELL_ArgifyW(WCHAR* res, in
             case '%':
                 *res++ = '%';
                 break;
-            case '1':
+
+              case '2':
+              case '3':
+       case '4':
+       case '5':
+              case '6':
+              case '7':
+       case '8':
+       case '9':
+       case '0':
             case '*':
+  if (args)
+  {
+      if (*fmt == '*')
+      {
+   *res++ = '"';
+   while(*args)
+       *res++ = *args++;
+   *res++ = '"';
+      }
+      else
+      {
+   while(*args && !isspace(*args))
+       *res++ = *args++;
+
+   while(isspace(*args))
+       ++args;
+      }
+  }
+  else
+  {
+              case '1':
                 if (!done || (*fmt == '1'))
                 {
+   /*FIXME Is the call to SearchPathW() really needed? We already have separated out the parameter string in args. */
                     if (SearchPathW(NULL, lpFile, wszExe, sizeof(xlpFile)/sizeof(WCHAR), xlpFile, NULL))
+       cmd = xlpFile;
+   else
+       cmd = lpFile;
+
+   /* Add double quotation marks unless we already have them (e.g.: "%1" %* for exefile) */
+   if (res != out && *(res - 1) == '"')
                     {
-                        strcpyW(res, xlpFile);
-                        res += strlenW(xlpFile);
+       strcpyW(res, cmd);
+       res += strlenW(cmd);
                     }
                     else
                     {
-                        strcpyW(res, lpFile);
-                        res += strlenW(lpFile);
+       strcpyW(res, cmd);
+       res += strlenW(cmd);
+   }
                     }
                 }
                 break;
+
             /*
              * IE uses this alot for activating things such as windows media
              * player. This is not verified to be fully correct but it appears
              * to work just fine.
              */
+              case 'l':
             case 'L':
+  if (lpFile) {
                 strcpyW(res,lpFile);
                 res += strlenW(lpFile);
+  }
+                break;
+
+              case 'i':
+              case 'I':
+  if (pidl) {
+      HGLOBAL hmem = SHAllocShared(pidl, ILGetSize(pidl), 0);
+      pv = SHLockShared(hmem, 0);
+      res += sprintfW(res, wszILPtr, pv);
+      SHUnlockShared(pv);
+  }
                 break;
 
             default: FIXME("Unknown escape sequence %%%c\n", *fmt);
             }
+
             fmt++;
             done = TRUE;
         }
         else
             *res++ = *fmt++;
     }
+
     *res = '\0';
+
     return done;
 }
 
+HRESULT SHELL_GetPathFromIDListForExecuteA(LPCITEMIDLIST pidl, LPSTR pszPath, UINT uOutSize)
+{
+    STRRET strret;
+    IShellFolder* desktop;
+
+    HRESULT hr = SHGetDesktopFolder(&desktop);
+
+    if (SUCCEEDED(hr)) {
+ hr = IShellFolder_GetDisplayNameOf(desktop, pidl, SHGDN_FORPARSING, &strret);
+
+ if (SUCCEEDED(hr))
+     StrRetToStrNA(pszPath, uOutSize, &strret, pidl);
+
+ IShellFolder_Release(desktop);
+    }
+
+    return hr;
+}
+
+HRESULT SHELL_GetPathFromIDListForExecuteW(LPCITEMIDLIST pidl, LPWSTR pszPath, UINT uOutSize)
+{
+    STRRET strret;
+    IShellFolder* desktop;
+
+    HRESULT hr = SHGetDesktopFolder(&desktop);
+
+    if (SUCCEEDED(hr)) {
+ hr = IShellFolder_GetDisplayNameOf(desktop, pidl, SHGDN_FORPARSING, &strret);
+
+ if (SUCCEEDED(hr))
+     StrRetToStrNW(pszPath, uOutSize, &strret, pidl);
+
+ IShellFolder_Release(desktop);
+    }
+
+    return hr;
+}
+
+/*************************************************************************
+ * SHELL_ResolveShortCutW [Internal]
+ * read shortcut file at 'wcmd' and fill psei with its content
+ */
+static HRESULT SHELL_ResolveShortCutW(LPWSTR wcmd, LPWSTR wargs, LPWSTR wdir, HWND hwnd, LPCWSTR lpVerb, int* pshowcmd, LPITEMIDLIST* ppidl)
+{
+    IShellFolder* psf;
+
+    HRESULT hr = SHGetDesktopFolder(&psf);
+
+    *ppidl = NULL;
+
+    if (SUCCEEDED(hr)) {
+ LPITEMIDLIST pidl;
+ ULONG l;
+
+     hr = IShellFolder_ParseDisplayName(psf, 0, 0, wcmd, &l, &pidl, 0);
+
+ if (SUCCEEDED(hr)) {
+     IShellLinkW* psl;
+
+     hr = IShellFolder_GetUIObjectOf(psf, NULL, 1, (LPCITEMIDLIST*)&pidl, &IID_IShellLinkW, NULL, (LPVOID*)&psl);
+
+     if (SUCCEEDED(hr)) {
+  hr = IShellLinkW_Resolve(psl, hwnd, 0);
+
+  if (SUCCEEDED(hr)) {
+      hr = IShellLinkW_GetPath(psl, wcmd, MAX_PATH, NULL, SLGP_UNCPRIORITY);
+
+      if (SUCCEEDED(hr)) {
+   if (!*wcmd) {
+       /* We could not translate the PIDL in the shell link into a valid file system path - so return the PIDL instead. */
+       hr = IShellLinkW_GetIDList(psl, ppidl);
+
+       if (SUCCEEDED(hr) && *ppidl) {
+    /* We got a PIDL instead of a file system path - try to translate it. */
+    if (SUCCEEDED(SHELL_GetPathFromIDListW(*ppidl, wcmd, MAX_PATH))) {
+        SHFree(*ppidl);
+        *ppidl = NULL;
+    }
+       }
+   }
+
+   if (SUCCEEDED(hr)) {
+       /* get command line arguments, working directory and display mode if available */
+       IShellLinkW_GetWorkingDirectory(psl, wdir, MAX_PATH);
+       IShellLinkW_GetArguments(psl, wargs, MAX_PATH);
+       IShellLinkW_GetShowCmd(psl, pshowcmd);
+   }
+      }
+  }
+
+  IShellLinkW_Release(psl);
+     }
+
+     SHFree(pidl);
+ }
+
+ IShellFolder_Release(psf);
+    }
+
+    return hr;
+}
+
 /*************************************************************************
  * SHELL_ExecuteW [Internal]
  *
  */
-static UINT SHELL_ExecuteW(WCHAR *lpCmd, void *env, LPSHELLEXECUTEINFOW sei, BOOL shWait)
+static UINT SHELL_ExecuteW(const WCHAR *lpCmd, void *env, BOOL shWait,
+       LPSHELLEXECUTEINFOW psei, LPSHELLEXECUTEINFOW psei_out)
 {
     STARTUPINFOW  startup;
     PROCESS_INFORMATION info;
     UINT retval = 31;
 
-    TRACE("Execute %s from directory %s\n", debugstr_w(lpCmd), debugstr_w(sei->lpDirectory));
-    ZeroMemory(&startup,sizeof(STARTUPINFOW));
+    TRACE("Execute %s from directory %s\n", debugstr_w(lpCmd), debugstr_w(psei->lpDirectory));
+
+    ZeroMemory(&startup, sizeof(startup));
     startup.cb = sizeof(STARTUPINFOW);
     startup.dwFlags = STARTF_USESHOWWINDOW;
-    startup.wShowWindow = sei->nShow;
-    if (CreateProcessW(NULL, lpCmd, NULL, NULL, FALSE, 0,
-                       env, sei->lpDirectory, &startup, &info))
+    startup.wShowWindow = psei->nShow;
+
+    if (CreateProcessW(NULL, (LPWSTR)lpCmd, NULL, NULL, FALSE, 0,
+                       env, *psei->lpDirectory? psei->lpDirectory: NULL, &startup, &info))
     {
         /* Give 30 seconds to the app to come up, if desired. Probably only needed
            when starting app immediately before making a DDE connection. */
@@ -148,10 +318,12 @@ static UINT SHELL_ExecuteW(WCHAR *lpCmd,
             if (WaitForInputIdle( info.hProcess, 30000 ) == -1)
                 WARN("WaitForInputIdle failed: Error %ld\n", GetLastError() );
         retval = 33;
-        if(sei->fMask & SEE_MASK_NOCLOSEPROCESS)
-            sei->hProcess = info.hProcess;
+
+        if (psei->fMask & SEE_MASK_NOCLOSEPROCESS)
+            psei_out->hProcess = info.hProcess;
         else
             CloseHandle( info.hProcess );
+
         CloseHandle( info.hThread );
     }
     else if ((retval = GetLastError()) >= 32)
@@ -160,7 +332,7 @@ static UINT SHELL_ExecuteW(WCHAR *lpCmd,
         retval = ERROR_BAD_FORMAT;
     }
 
-    sei->hInstApp = (HINSTANCE)retval;
+    psei_out->hInstApp = (HINSTANCE)retval;
     return retval;
 }
 
@@ -236,6 +408,7 @@ static BOOL SHELL_TryAppPathW( LPCWSTR s
     static const WCHAR wszKeyAppPaths[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s',
  '\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','A','p','p',' ','P','a','t','h','s','\\',0};
     static const WCHAR wPath[] = {'P','a','t','h',0};
+
     HKEY hkApp = 0;
     WCHAR buffer[1024];
     LONG len;
@@ -248,7 +421,7 @@ static BOOL SHELL_TryAppPathW( LPCWSTR s
     res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, buffer, 0, KEY_READ, &hkApp);
     if (res) goto end;
 
-    len = MAX_PATH;
+    len = MAX_PATH*sizeof(WCHAR);
     res = RegQueryValueW(hkApp, NULL, lpResult, &len);
     if (res) goto end;
     found = TRUE;
@@ -265,6 +438,53 @@ end:
     return found;
 }
 
+static UINT SHELL_FindExecutableByOperation(LPCWSTR lpPath, LPCWSTR lpFile, LPCWSTR lpOperation, LPWSTR key, LPWSTR filetype, LPWSTR command)
+{
+    static const WCHAR wCommand[] = {'\\','c','o','m','m','a','n','d',0};
+
+    LONG commandlen = 256*sizeof(WCHAR);  /* This is the most DOS can handle :) */
+
+    /* Looking for ...buffer\shell\<verb>\command */
+    strcatW(filetype, wszShell);
+    strcatW(filetype, lpOperation);
+    strcatW(filetype, wCommand);
+
+    if (RegQueryValueW(HKEY_CLASSES_ROOT, filetype, command, &commandlen) == ERROR_SUCCESS)
+    {
+ commandlen /= sizeof(WCHAR);
+        if (key) strcpyW(key, filetype);
+#if 0
+        LPSTR tmp;
+        char param[256];
+ LONG paramlen = 256;
+
+        /* FIXME: it seems all Windows version don't behave the same here.
+         * the doc states that this ddeexec information can be found after
+         * the exec names.
+         * on Win98, it doesn't appear, but I think it does on Win2k
+         */
+ /* Get the parameters needed by the application
+    from the associated ddeexec key */
+ tmp = strstr(filetype, "command");
+ tmp[0] = '\0';
+ strcat(filetype, "ddeexec");
+
+ if (RegQueryValueA(HKEY_CLASSES_ROOT, filetype, param, &paramlen) == ERROR_SUCCESS)
+ {
+            strcat(command, " ");
+            strcat(command, param);
+            commandlen += paramlen;
+ }
+#endif
+
+ command[commandlen] = '\0';
+
+ return 33; /* FIXME see SHELL_FindExecutable() */
+    }
+
+    return 31; /* default - 'No association was found' */
+}
+
 /*************************************************************************
  * SHELL_FindExecutable [Internal]
  *
@@ -279,35 +499,35 @@ end:
  *              command (it'll be used afterwards for more information
  *              on the operation)
  */
-static UINT SHELL_FindExecutable(LPCWSTR lpPath, LPCWSTR lpFile, LPCWSTR lpOperation,
-                                 LPWSTR lpResult, LPWSTR key, void **env)
+UINT SHELL_FindExecutable(LPCWSTR lpPath, LPCWSTR lpFile, LPCWSTR lpOperation,
+       LPWSTR lpResult, LPWSTR key, void **env, LPITEMIDLIST pidl, LPCWSTR args)
 {
-    static const WCHAR wShell[] = {'\\','s','h','e','l','l','\\',0};
-    static const WCHAR wCommand[] = {'\\','c','o','m','m','a','n','d',0};
     static const WCHAR wWindows[] = {'w','i','n','d','o','w','s',0};
     static const WCHAR wPrograms[] = {'p','r','o','g','r','a','m','s',0};
     static const WCHAR wExtensions[] = {'e','x','e',' ','p','i','f',' ','b','a','t',' ','c','m','d',' ','c','o','m',0};
+
     WCHAR *extension = NULL; /* pointer to file extension */
     WCHAR wtmpext[5];        /* local copy to mung as we please */
     WCHAR filetype[256];     /* registry name for this filetype */
     LONG  filetypelen = 256; /* length of above */
     WCHAR command[256];      /* command from registry */
-    LONG  commandlen = 256;  /* This is the most DOS can handle :) */
     WCHAR wBuffer[256];      /* Used to GetProfileString */
     UINT  retval = 31;       /* default - 'No association was found' */
     WCHAR *tok;              /* token pointer */
-    WCHAR xlpFile[256] = {0}; /* result of SearchPath */
+    WCHAR xlpFile[256];      /* result of SearchPath */
+    DWORD attribs;           /* file attributes */
 
     TRACE("%s\n", (lpFile != NULL) ? debugstr_w(lpFile) : "-");
 
     lpResult[0] = '\0'; /* Start off with an empty return string */
     if (key) *key = '\0';
 
+    xlpFile[0] = '\0';
+
     /* trap NULL parameters on entry */
-    if ((lpFile == NULL) || (lpResult == NULL) || (lpOperation == NULL))
+    if ((lpFile == NULL) || (lpResult == NULL))
     {
-        WARN("(lpFile=%s,lpResult=%s,lpOperation=%s): NULL parameter\n",
-             debugstr_w(lpFile), debugstr_w(lpOperation), debugstr_w(lpResult));
+        WARN("(lpFile=%s,lpResult=%s): NULL parameter\n", debugstr_w(lpFile), debugstr_w(lpResult));
         return 2; /* File not found. Close enough, I guess. */
     }
 
@@ -324,6 +544,14 @@ static UINT SHELL_FindExecutable(LPCWSTR
         /* Hey, isn't this value ignored?  Why make this call?  Shouldn't we return here?  --dank*/
     }
 
+    attribs = GetFileAttributesW(lpFile);
+    if (attribs!=INVALID_FILE_ATTRIBUTES && (attribs&FILE_ATTRIBUTE_DIRECTORY))
+    {
+ strcpyW(filetype, wszFolder);
+ filetypelen = 6;    /* strlen("Folder") */
+    }
+    else
+    {
     /* First thing we need is the file's extension */
     extension = strrchrW(xlpFile, '.'); /* Assume last "." is the one; */
                                        /* File->Run in progman uses */
@@ -335,7 +563,6 @@ static UINT SHELL_FindExecutable(LPCWSTR
         WARN("Returning 31 - No association\n");
         return 31; /* no association */
     }
-
     /* Make local copy & lowercase it for reg & 'programs=' lookup */
     lstrcpynW(wtmpext, extension, 5);
     CharLowerW(wtmpext);
@@ -387,61 +614,77 @@ static UINT SHELL_FindExecutable(LPCWSTR
     if (RegQueryValueW(HKEY_CLASSES_ROOT, wtmpext, filetype, 
    &filetypelen) == ERROR_SUCCESS)
     {
+     filetypelen /= sizeof(WCHAR);
  filetype[filetypelen] = '\0';
- TRACE("File type: %s\n", debugstr_w(filetype));
+ }
+    }
+
+    if (*filetype)
+    {
+ if (lpOperation)
+ {
+     /* pass the operation string to SHELL_FindExecutableByOperation() */
+     filetype[filetypelen] = '\0';
+     retval = SHELL_FindExecutableByOperation(lpPath, lpFile, lpOperation, key, filetype, command);
+ }
+ else
+ {
+     WCHAR operation[MAX_PATH];
+     HKEY hkey;
 
  /* Looking for ...buffer\shell\lpOperation\command */
- strcatW(filetype, wShell);
- strcatW(filetype, lpOperation);
- strcatW(filetype, wCommand);
+     strcatW(filetype, wszShell);
 
- if (RegQueryValueW(HKEY_CLASSES_ROOT, filetype, command,
-                           &commandlen) == ERROR_SUCCESS)
+     /* enumerate the operation subkeys in the registry and search for one with an associated command */
+     if (RegOpenKeyW(HKEY_CLASSES_ROOT, filetype, &hkey) == ERROR_SUCCESS)
  {
-            if (key) strcpyW(key, filetype);
-#if 0
-            LPWSTR tmp;
-            WCHAR param[256];
-     LONG paramlen = 256;
-            static const WCHAR wSpace[] = {' ',0};
+  int idx = 0;
+  for(;; ++idx)
+  {
+      if (RegEnumKeyW(hkey, idx, operation, MAX_PATH) != ERROR_SUCCESS)
+   break;
 
-            /* FIXME: it seems all Windows version don't behave the same here.
-             * the doc states that this ddeexec information can be found after
-             * the exec names.
-             * on Win98, it doesn't appear, but I think it does on Win2k
-             */
-     /* Get the parameters needed by the application
-        from the associated ddeexec key */
-     tmp = strstrW(filetype, wCommand);
-     tmp[0] = '\0';
-     strcatW(filetype, wDdeexec);
+      filetype[filetypelen] = '\0';
+      retval = SHELL_FindExecutableByOperation(lpPath, lpFile, operation, key, filetype, command);
 
-     if (RegQueryValueW(HKEY_CLASSES_ROOT, filetype, param,
-      &paramlen) == ERROR_SUCCESS)
+      if (retval > 32)
+   break;
+  }
+
+  RegCloseKey(hkey);
+     }
+ }
+
+ if (retval > 32)
      {
-                strcatW(command, wSpace);
-                strcatW(command, param);
-                commandlen += paramlen;
+            SHELL_ArgifyW(lpResult, MAX_PATH, command, xlpFile, pidl, args);
+
+            /* Remove double quotation marks and command line arguments */
+            if (*lpResult == '"')
+            {
+                WCHAR *p = lpResult;
+                while (*(p + 1) != '"')
+                {
+                    *p = *(p + 1);
+                    p++;
      }
-#endif
-            command[commandlen] = '\0';
-            SHELL_ArgifyW(lpResult, 1024 /*FIXME*/, command, xlpFile);
-            retval = 33; /* FIXME see above */
+                *p = '\0';
  }
     }
-    else /* Check win.ini */
+    }
+    else if (extension) /* Check win.ini */
     {
  static const WCHAR wExtensions[] = {'e','x','t','e','n','s','i','o','n','s',0};
- static const WCHAR wEmpty[] = {0};
 
  /* Toss the leading dot */
  extension++;
- if (GetProfileStringW(wExtensions, extension, wEmpty, command, sizeof(command)/sizeof(WCHAR)) > 0)
+ if (GetProfileStringW(wExtensions, extension, wszEmpty, command, sizeof(command)/sizeof(WCHAR)) > 0)
         {
             if (strlenW(command) != 0)
             {
                 strcpyW(lpResult, command);
                 tok = strchrW(lpResult, '^'); /* should be ^.extension? */
+
                 if (tok != NULL)
                 {
                     tok[0] = '\0';
@@ -452,6 +695,7 @@ static UINT SHELL_FindExecutable(LPCWSTR
                         strcatW(lpResult, &tok[5]);
                     }
                 }
+
                 retval = 33; /* FIXME - see above */
             }
         }
@@ -484,12 +728,15 @@ static HDDEDATA CALLBACK dde_cb(UINT uTy
  */
 static unsigned dde_connect(WCHAR* key, WCHAR* start, WCHAR* ddeexec,
                             const WCHAR* lpFile, void *env,
-                            LPSHELLEXECUTEINFOW sei, SHELL_ExecuteW32 execfunc)
+       LPCWSTR szCommandline, LPITEMIDLIST pidl, SHELL_ExecuteW32 execfunc,
+       LPSHELLEXECUTEINFOW psei, LPSHELLEXECUTEINFOW psei_out)
 {
     static const WCHAR wApplication[] = {'\\','a','p','p','l','i','c','a','t','i','o','n',0};
     static const WCHAR wTopic[] = {'\\','t','o','p','i','c',0};
+
     WCHAR *     endkey = key + strlenW(key);
-    WCHAR       app[256], topic[256], ifexec[256], res[256];
+    WCHAR app[256], topic[256], ifexec[256];
+    WCHAR res[1024];
     LONG        applen, topiclen, ifexeclen;
     WCHAR *     exec;
     DWORD       ddeInst = 0;
@@ -499,7 +746,7 @@ static unsigned dde_connect(WCHAR* key, 
     unsigned    ret = 31;
 
     strcpyW(endkey, wApplication);
-    applen = sizeof(app)/sizeof(WCHAR);
+    applen = sizeof(app);   /* buffer length for RegQueryValueW() is in bytes! */
     if (RegQueryValueW(HKEY_CLASSES_ROOT, key, app, &applen) != ERROR_SUCCESS)
     {
         FIXME("default app name NIY %s\n", debugstr_w(key));
@@ -507,7 +754,7 @@ static unsigned dde_connect(WCHAR* key, 
     }
 
     strcpyW(endkey, wTopic);
-    topiclen = sizeof(topic)/sizeof(WCHAR);
+    topiclen = sizeof(topic);
     if (RegQueryValueW(HKEY_CLASSES_ROOT, key, topic, &topiclen) != ERROR_SUCCESS)
     {
         static const WCHAR wSystem[] = {'S','y','s','t','e','m',0};
@@ -528,7 +775,7 @@ static unsigned dde_connect(WCHAR* key, 
     {
         static const WCHAR wIfexec[] = {'\\','i','f','e','x','e','c',0};
         TRACE("Launching '%s'\n", debugstr_w(start));
-        ret = execfunc(start, env, sei, TRUE);
+        ret = execfunc(start, env, TRUE, psei, psei_out);
         if (ret < 32)
         {
             TRACE("Couldn't launch\n");
@@ -538,18 +785,19 @@ static unsigned dde_connect(WCHAR* key, 
         if (!hConv)
         {
             TRACE("Couldn't connect. ret=%d\n", ret);
-            ret = 30; /* whatever */
-            goto error;
+            DdeUninitialize(ddeInst);
+            SetLastError(ERROR_DDE_FAIL);
+            return ret = 30; /* whatever */
         }
         strcpyW(endkey, wIfexec);
-        ifexeclen = sizeof(ifexec)/sizeof(WCHAR);
+        ifexeclen = sizeof(ifexec);
         if (RegQueryValueW(HKEY_CLASSES_ROOT, key, ifexec, &ifexeclen) == ERROR_SUCCESS)
         {
             exec = ifexec;
         }
     }
 
-    SHELL_ArgifyW(res, sizeof(res)/sizeof(WCHAR), exec, lpFile);
+    SHELL_ArgifyW(res, sizeof(res), exec, lpFile, pidl, szCommandline);
     TRACE("%s %s => %s\n", debugstr_w(exec), debugstr_w(lpFile), debugstr_w(res));
 
     ret = (DdeClientTransaction((LPBYTE)res, (strlenW(res) + 1) * sizeof(WCHAR), hConv, 0L, 0,
@@ -563,21 +811,29 @@ static unsigned dde_connect(WCHAR* key, 
 /*************************************************************************
  * execute_from_key [Internal]
  */
-static UINT execute_from_key(LPWSTR key, LPCWSTR lpFile, void *env,
-                             LPSHELLEXECUTEINFOW sei, SHELL_ExecuteW32 execfunc)
+static UINT execute_from_key(LPWSTR key, LPCWSTR lpFile, void *env, LPCWSTR szCommandline,
+        SHELL_ExecuteW32 execfunc,
+        LPSHELLEXECUTEINFOW psei, LPSHELLEXECUTEINFOW psei_out)
 {
-    WCHAR cmd[1024] = {0};
-    LONG cmdlen = 1024;
+    WCHAR cmd[1024];
+    LONG cmdlen = sizeof(cmd);
     UINT retval = 31;
 
+    cmd[0] = '\0';
+
     /* Get the application for the registry */
     if (RegQueryValueW(HKEY_CLASSES_ROOT, key, cmd, &cmdlen) == ERROR_SUCCESS)
     {
  static const WCHAR wCommand[] = {'c','o','m','m','a','n','d',0};
  static const WCHAR wDdeexec[] = {'d','d','e','e','x','e','c',0};
+
         LPWSTR tmp;
-        WCHAR param[256] = {0};
-        LONG paramlen = 256;
+        WCHAR param[256];
+        LONG paramlen = sizeof(param);
+
+ cmdlen /= sizeof(WCHAR);
+
+ param[0] = '\0';
 
         /* Get the parameters needed by the application
            from the associated ddeexec key */
@@ -588,14 +844,14 @@ static UINT execute_from_key(LPWSTR key,
         if (RegQueryValueW(HKEY_CLASSES_ROOT, key, param, &paramlen) == ERROR_SUCCESS)
         {
             TRACE("Got ddeexec %s => %s\n", debugstr_w(key), debugstr_w(param));
-            retval = dde_connect(key, cmd, param, lpFile, env, sei, execfunc);
+            retval = dde_connect(key, cmd, param, lpFile, env, szCommandline, psei->lpIDList, execfunc, psei, psei_out);
         }
         else
         {
             /* Is there a replace() function anywhere? */
             cmd[cmdlen] = '\0';
-            SHELL_ArgifyW(param, sizeof(param)/sizeof(WCHAR), cmd, lpFile);
-            retval = execfunc(param, env, sei, FALSE);
+            SHELL_ArgifyW(param, sizeof(param)/sizeof(WCHAR), cmd, lpFile, psei->lpIDList, szCommandline);
+            retval = execfunc(param, env, FALSE, psei, psei_out);
         }
     }
     else TRACE("ooch\n");
@@ -650,7 +906,7 @@ HINSTANCE WINAPI FindExecutableW(LPCWSTR
         SetCurrentDirectoryW(lpDirectory);
     }
 
-    retval = SHELL_FindExecutable(lpDirectory, lpFile, wszOpen, lpResult, NULL, NULL);
+    retval = SHELL_FindExecutable(lpDirectory, lpFile, wszOpen, lpResult, NULL, NULL, NULL, NULL);
 
     TRACE("returning %s\n", debugstr_w(lpResult));
     if (lpDirectory)
@@ -661,150 +917,307 @@ HINSTANCE WINAPI FindExecutableW(LPCWSTR
 /*************************************************************************
  * ShellExecuteExW32 [Internal]
  */
-BOOL WINAPI ShellExecuteExW32 (LPSHELLEXECUTEINFOW sei, SHELL_ExecuteW32 execfunc)
+BOOL WINAPI ShellExecuteExW32 (LPSHELLEXECUTEINFOW psei, SHELL_ExecuteW32 execfunc)
 {
     static const WCHAR wQuote[] = {'"',0};
     static const WCHAR wSpace[] = {' ',0};
     static const WCHAR wWww[] = {'w','w','w',0};
     static const WCHAR wFile[] = {'f','i','l','e',0};
     static const WCHAR wHttp[] = {'h','t','t','p',':','/','/',0};
-    WCHAR wszApplicationName[MAX_PATH+2],wszCommandline[1024],wszPidl[20],wfileName[MAX_PATH];
-    LPWSTR pos;
+    static const WCHAR wExtLnk[] = {'.','l','n','k',0};
+    static const WCHAR wExplorer[] = {'e','x','p','l','o','r','e','r','.','e','x','e',0};
+
+    WCHAR wszApplicationName[MAX_PATH+2], wszParameters[1024], wfileName[MAX_PATH], wszDir[MAX_PATH];
+    SHELLEXECUTEINFOW sei_tmp; /* modifyable copy of SHELLEXECUTEINFO struct */
     void *env;
-    int gap, len;
-    WCHAR lpstrProtocol[256];
-    LPCWSTR lpFile,lpOperation;
+    WCHAR wszProtocol[256];
+    LPCWSTR lpFile;
     UINT retval = 31;
-    WCHAR wcmd[1024];
-    BOOL done;
+    WCHAR buffer[1024];
+    const WCHAR* ext;
+
+    memcpy(&sei_tmp, psei, sizeof(sei_tmp));
 
     TRACE("mask=0x%08lx hwnd=%p verb=%s file=%s parm=%s dir=%s show=0x%08x class=%s\n",
-            sei->fMask, sei->hwnd, debugstr_w(sei->lpVerb),
-            debugstr_w(sei->lpFile), debugstr_w(sei->lpParameters),
-            debugstr_w(sei->lpDirectory), sei->nShow,
-            (sei->fMask & SEE_MASK_CLASSNAME) ? debugstr_w(sei->lpClass) : "not used");
+            sei_tmp.fMask, sei_tmp.hwnd, debugstr_w(sei_tmp.lpVerb),
+            debugstr_w(sei_tmp.lpFile), debugstr_w(sei_tmp.lpParameters),
+            debugstr_w(sei_tmp.lpDirectory), sei_tmp.nShow,
+            (sei_tmp.fMask & SEE_MASK_CLASSNAME) ? debugstr_w(sei_tmp.lpClass) : "not used");
 
-    sei->hProcess = NULL;
-    ZeroMemory(wszApplicationName,MAX_PATH);
-    if (sei->lpFile)
-        strcpyW(wszApplicationName, sei->lpFile);
+    psei->hProcess = NULL;
 
-    ZeroMemory(wszCommandline,1024);
-    if (sei->lpParameters)
-        strcpyW(wszCommandline, sei->lpParameters);
+    if (sei_tmp.lpFile)
+ strcpyW(wszApplicationName, sei_tmp.lpFile);
+    else
+ *wszApplicationName = '\0';
 
-    if (sei->fMask & (SEE_MASK_INVOKEIDLIST | SEE_MASK_ICON | SEE_MASK_HOTKEY |
+    if (sei_tmp.lpParameters)
+ strcpyW(wszParameters, sei_tmp.lpParameters);
+    else
+ *wszParameters = '\0';
+
+    if (sei_tmp.lpDirectory)
+ strcpyW(wszDir, sei_tmp.lpDirectory);
+    else
+ *wszDir = '\0';
+
+    sei_tmp.lpFile = wszApplicationName;
+    sei_tmp.lpParameters = wszParameters;
+    sei_tmp.lpDirectory = wszDir;
+
+    if (sei_tmp.fMask & (SEE_MASK_ICON | SEE_MASK_HOTKEY |
         SEE_MASK_CONNECTNETDRV | SEE_MASK_FLAG_DDEWAIT |
         SEE_MASK_DOENVSUBST | SEE_MASK_FLAG_NO_UI | SEE_MASK_UNICODE |
         SEE_MASK_NO_CONSOLE | SEE_MASK_ASYNCOK | SEE_MASK_HMONITOR ))
     {
-        FIXME("flags ignored: 0x%08lx\n", sei->fMask);
+        FIXME("flags ignored: 0x%08lx\n", sei_tmp.fMask);
     }
 
     /* process the IDList */
-    if ( (sei->fMask & SEE_MASK_INVOKEIDLIST) == SEE_MASK_INVOKEIDLIST) /*0x0c*/
-    {
-        wszApplicationName[0] = '"';
-        SHGetPathFromIDListW(sei->lpIDList,wszApplicationName + 1);
-        strcatW(wszApplicationName, wQuote);
-        TRACE("-- idlist=%p (%s)\n", sei->lpIDList, debugstr_w(wszApplicationName));
-    }
-    else
-    {
-        if (sei->fMask & SEE_MASK_IDLIST )
+    if (sei_tmp.fMask & SEE_MASK_INVOKEIDLIST) /* 0x0c: includes SEE_MASK_IDLIST */
         {
-     static const WCHAR wI[] = {'%','I',0}, wP[] = {':','%','p',0};
-            pos = strstrW(wszCommandline, wI);
-            if (pos)
+ IShellExecuteHookW* pSEH;
+
+ HRESULT hr = SHBindToParent(sei_tmp.lpIDList, &IID_IShellExecuteHookW, (LPVOID*)&pSEH, NULL);
+
+ if (SUCCEEDED(hr))
             {
-                LPVOID pv;
-                HGLOBAL hmem = SHAllocShared ( sei->lpIDList, ILGetSize(sei->lpIDList), 0);
-                pv = SHLockShared(hmem,0);
-                sprintfW(wszPidl,wP,pv );
-                SHUnlockShared(pv);
+     hr = IShellExecuteHookW_Execute(pSEH, psei);
 
-                gap = strlenW(wszPidl);
-                len = strlenW(pos)-2;
-                memmove(pos+gap,pos+2,len*sizeof(WCHAR));
-                memcpy(pos,wszPidl,gap*sizeof(WCHAR));
+     IShellExecuteHookW_Release(pSEH);
+
+     if (hr == S_OK)
+  return TRUE;
             }
+
+ /* try to translate PIDL directly into the corresponding file system path */
+        if (SUCCEEDED(SHELL_GetPathFromIDListW(sei_tmp.lpIDList, wszApplicationName/*sei_tmp.lpFile*/, sizeof(wszApplicationName)/sizeof(WCHAR))))
+ {
+     sei_tmp.lpIDList = NULL;
+     sei_tmp.fMask &= ~SEE_MASK_INVOKEIDLIST;
         }
+
+        TRACE("-- idlist=%p (%s)\n", sei_tmp.lpIDList, debugstr_w(wszApplicationName));
     }
 
-    if (sei->fMask & (SEE_MASK_CLASSNAME | SEE_MASK_CLASSKEY))
+    if (sei_tmp.fMask & (SEE_MASK_CLASSNAME | SEE_MASK_CLASSKEY))
     {
  /* launch a document by fileclass like 'WordPad.Document.1' */
         /* the Commandline contains 'c:\Path\wordpad.exe "%1"' */
-        /* FIXME: szCommandline should not be of a fixed size. Fixed to 1024, MAX_PATH is way too short! */
-        HCR_GetExecuteCommandW((sei->fMask & SEE_MASK_CLASSKEY) ? sei->hkeyClass : NULL,
-                               (sei->fMask & SEE_MASK_CLASSNAME) ? sei->lpClass: NULL,
-                               (sei->lpVerb) ? sei->lpVerb : wszOpen,
-                               wszCommandline, sizeof(wszCommandline)/sizeof(WCHAR));
+        /* FIXME: wszParameters should not be of a fixed size. Fixed to 1024, MAX_PATH is way too short! */
+        HCR_GetExecuteCommandW((sei_tmp.fMask & SEE_MASK_CLASSKEY)? sei_tmp.hkeyClass: NULL,
+                               (sei_tmp.fMask & SEE_MASK_CLASSNAME)? sei_tmp.lpClass: NULL,
+                               (sei_tmp.lpVerb)? sei_tmp.lpVerb: wszOpen,
+                               wszParameters/*sei_tmp.lpParameters*/, sizeof(wszParameters)/sizeof(WCHAR));
 
         /* FIXME: get the extension of lpFile, check if it fits to the lpClass */
-        TRACE("SEE_MASK_CLASSNAME->'%s', doc->'%s'\n", debugstr_w(wszCommandline), debugstr_w(wszApplicationName));
+        TRACE("SEE_MASK_CLASSNAME->'%s', doc->'%s'\n", debugstr_w(sei_tmp.lpParameters), debugstr_w(sei_tmp.lpFile));
 
-        wcmd[0] = '\0';
-        done = SHELL_ArgifyW(wcmd, sizeof(wcmd)/sizeof(WCHAR), wszCommandline, wszApplicationName);
-        if (!done && wszApplicationName[0])
+        buffer[0] = '\0';
+
+        if (!SHELL_ArgifyW(buffer, sizeof(buffer)/sizeof(WCHAR), sei_tmp.lpParameters, sei_tmp.lpFile, sei_tmp.lpIDList, NULL) && sei_tmp.lpFile[0])
         {
-            strcatW(wcmd, wSpace);
-            strcatW(wcmd, wszApplicationName);
+            strcatW(buffer, wExtLnk);
+            strcatW(buffer, sei_tmp.lpFile);
         }
-        retval = execfunc(wcmd, NULL, sei, FALSE);
+
+        retval = execfunc(buffer, NULL, FALSE, &sei_tmp, psei);
         if (retval > 32)
             return TRUE;
         else
             return FALSE;
     }
 
-    /* We set the default to open, and that should generally work.
-       But that is not really the way the MS docs say to do it. */
-    if (sei->lpVerb == NULL)
-        lpOperation = wszOpen;
+    /* Else, try to execute the filename */
+    TRACE("execute:'%s','%s'\n", debugstr_w(sei_tmp.lpFile), debugstr_w(sei_tmp.lpParameters));
+
+
+    /* resolve shell shortcuts */
+    ext = PathFindExtensionW(sei_tmp.lpFile);
+
+    if (ext && !strcmpiW(ext, wExtLnk)) /* or check for: shell_attribs & SFGAO_LINK */
+    {
+ HRESULT hr = SHELL_ResolveShortCutW((LPWSTR)sei_tmp.lpFile, (LPWSTR)sei_tmp.lpParameters, (LPWSTR)sei_tmp.lpDirectory,
+         sei_tmp.hwnd, sei_tmp.lpVerb?sei_tmp.lpVerb:wszEmpty, &sei_tmp.nShow, (LPITEMIDLIST*)&sei_tmp.lpIDList);
+
+ if (psei->lpIDList)
+     psei->fMask |= SEE_MASK_IDLIST;
+
+ if (SUCCEEDED(hr))
+ {
+     /* repeat IDList processing if needed */
+     if (sei_tmp.fMask & SEE_MASK_IDLIST)
+     {
+  IShellExecuteHookW* pSEH;
+
+  HRESULT hr = SHBindToParent(sei_tmp.lpIDList, &IID_IShellExecuteHookW, (LPVOID*)&pSEH, NULL);
+
+  if (SUCCEEDED(hr))
+  {
+      hr = IShellExecuteHookW_Execute(pSEH, psei);
+
+      IShellExecuteHookW_Release(pSEH);
+
+      if (hr == S_OK)
+   return TRUE;
+  }
+
+  TRACE("-- idlist=%p (%s)\n", debugstr_w(sei_tmp.lpIDList), debugstr_w(sei_tmp.lpFile));
+     }
+ }
+    }
+
+
+    /* Has the IDList not yet been translated? */
+    if (sei_tmp.fMask & SEE_MASK_IDLIST)
+    {
+ /* last chance to translate IDList: now also allow CLSID paths */
+ if (SUCCEEDED(SHELL_GetPathFromIDListForExecuteW(sei_tmp.lpIDList, buffer, sizeof(buffer)))) {
+     if (buffer[0]==':' && buffer[1]==':') {
+  /* open shell folder for the specified class GUID */
+  strcpyW(wszParameters, buffer);
+  strcpyW(wszApplicationName, wExplorer);
+
+  sei_tmp.fMask &= ~SEE_MASK_INVOKEIDLIST;
+     } else if (HCR_GetExecuteCommandW(0, wszFolder, sei_tmp.lpVerb?sei_tmp.lpVerb:wszOpen, buffer, sizeof(buffer))) {
+  SHELL_ArgifyW(wszApplicationName, sizeof(wszApplicationName)/sizeof(WCHAR), buffer, NULL, sei_tmp.lpIDList, NULL);
+
+  sei_tmp.fMask &= ~SEE_MASK_INVOKEIDLIST;
+     }
+ }
+    }
+
+
+    /* expand environment strings */
+
+    if (ExpandEnvironmentStringsW(sei_tmp.lpFile, buffer, MAX_PATH))
+ lstrcpyW(wszApplicationName/*sei_tmp.lpFile*/, buffer);
+
+    if (*sei_tmp.lpParameters)
+        if (ExpandEnvironmentStringsW(sei_tmp.lpParameters, buffer, MAX_PATH))
+     lstrcpyW(wszParameters/*sei_tmp.lpParameters*/, buffer);
+
+    if (*sei_tmp.lpDirectory)
+ if (ExpandEnvironmentStringsW(sei_tmp.lpDirectory, buffer, MAX_PATH))
+     lstrcpyW(wszDir/*sei_tmp.lpDirectory*/, buffer);
+
+
+    /* separate out command line arguments from executable file name */
+    if (!*sei_tmp.lpParameters) {
+ /* If the executable path is quoted, handle the rest of the command line as parameters. */
+ if (sei_tmp.lpFile[0] == '"') {
+     LPWSTR src = wszApplicationName/*sei_tmp.lpFile*/ + 1;
+     LPWSTR dst = wfileName;
+     LPWSTR end;
+
+     /* copy the unquoted executabe path to 'wfileName' */
+     while(*src && *src!='"')
+  *dst++ = *src++;
+
+     *dst = '\0';
+
+     if (*src == '"') {
+  end = ++src;
+
+  while(isspace(*src))
+      ++src;
+     } else
+  end = src;
+
+     /* copy the parameter string to 'wszParameters' */
+     strcpyW(wszParameters, src);
+
+     /* terminate previous command string after the quote character */
+     *end = '\0';
+ }
     else
-        lpOperation = sei->lpVerb;
+ {
+     /* If the executable name is not quoted, we have to use this search loop here,
+        that in CreateProcess() is not sufficient because it does not handle shell links. */
+     WCHAR buffer[MAX_PATH], xlpFile[MAX_PATH];
+     LPWSTR space, s;
 
-    /* Else, try to execute the filename */
-    TRACE("execute:'%s','%s'\n", debugstr_w(wszApplicationName), debugstr_w(wszCommandline));
+     LPWSTR beg = wszApplicationName/*sei_tmp.lpFile*/;
+     for(s=beg; (space=strchrW(s, ' ')); s=space+1) {
+  int idx = space-sei_tmp.lpFile;
+  strncpyW(buffer, sei_tmp.lpFile, idx);
+  buffer[idx] = '\0';
+
+  /*FIXME This finds directory paths if the targeted file name contains spaces. */
+  if (SearchPathW(*sei_tmp.lpDirectory? sei_tmp.lpDirectory: NULL, buffer, wszExe, sizeof(xlpFile), xlpFile, NULL))
+  {
+      /* separate out command from parameter string */
+      LPCWSTR p = space + 1;
+
+      while(isspaceW(*p))
+   ++p;
+
+      strcpyW(wszParameters, p);
+      *space = '\0';
+
+      break;
+  }
+     }
+
+     strcpyW(wfileName, sei_tmp.lpFile);
+ }
+    } else
+ strcpyW(wfileName, sei_tmp.lpFile);
 
-    strcpyW(wfileName, wszApplicationName);
     lpFile = wfileName;
-    if (wszCommandline[0]) {
-        strcatW(wszApplicationName, wSpace);
-        strcatW(wszApplicationName, wszCommandline);
+
+    if (sei_tmp.lpParameters[0]) {
+        strcatW(wszApplicationName/*sei_tmp.lpFile*/, wSpace);
+        strcatW(wszApplicationName/*sei_tmp.lpFile*/, sei_tmp.lpParameters);
     }
 
-    retval = execfunc(wszApplicationName, NULL, sei, FALSE);
+    retval = execfunc(sei_tmp.lpFile, NULL, FALSE, &sei_tmp, psei);
     if (retval > 32)
+    {
+ /* Now, that we have successfully launched a process, we can free the PIDL.
+ It may have been used before for %I command line options. */
+ if (sei_tmp.lpIDList!=psei->lpIDList && sei_tmp.lpIDList)
+     SHFree(sei_tmp.lpIDList);
+
+        TRACE("execfunc: retval=%d psei->hInstApp=%p\n", retval, psei->hInstApp);
         return TRUE;
+    }
 
     /* Else, try to find the executable */
-    wcmd[0] = '\0';
-    retval = SHELL_FindExecutable(sei->lpDirectory, lpFile, lpOperation, wcmd, lpstrProtocol, &env);
+    buffer[0] = '\0';
+    retval = SHELL_FindExecutable(*sei_tmp.lpDirectory? sei_tmp.lpDirectory: NULL, lpFile, sei_tmp.lpVerb, buffer, wszProtocol, &env, sei_tmp.lpIDList, sei_tmp.lpParameters);
+
     if (retval > 32)  /* Found */
     {
         WCHAR wszQuotedCmd[MAX_PATH+2];
-        /* Must quote to handle case where cmd contains spaces, 
+        /* Must quote to handle case where 'buffer' contains spaces, 
          * else security hole if malicious user creates executable file "C:\\Program"
+  *
+  * FIXME: If we don't have set explicitly command line arguments, we must first
+  * split executable path from optional command line arguments. Otherwise we would quote
+  * the complete string with executable path _and_ arguments, which is not what we want.
          */
         strcpyW(wszQuotedCmd, wQuote);
-        strcatW(wszQuotedCmd, wcmd);
+        strcatW(wszQuotedCmd, buffer);
         strcatW(wszQuotedCmd, wQuote);
-        if (wszCommandline[0]) {
+
+        if (*sei_tmp.lpParameters) {
             strcatW(wszQuotedCmd, wSpace);
-            strcatW(wszQuotedCmd, wszCommandline);
+     strcatW(wszQuotedCmd, sei_tmp.lpParameters);
         }
-        TRACE("%s/%s => %s/%s\n", debugstr_w(wszApplicationName), debugstr_w(lpOperation), debugstr_w(wszQuotedCmd), debugstr_w(lpstrProtocol));
-        if (*lpstrProtocol)
-            retval = execute_from_key(lpstrProtocol, wszApplicationName, env, sei, execfunc);
+
+        TRACE("%s/%s => %s/%s\n", debugstr_w(wszApplicationName), debugstr_w(buffer), debugstr_w(wszQuotedCmd), debugstr_w(wszProtocol));
+
+        if (*wszProtocol)
+            retval = execute_from_key(wszProtocol, lpFile, env, sei_tmp.lpParameters, execfunc, &sei_tmp, psei);
         else
-            retval = execfunc(wszQuotedCmd, env, sei, FALSE);
+            retval = execfunc(wszQuotedCmd, env, FALSE, &sei_tmp, psei);
+
         if (env) HeapFree( GetProcessHeap(), 0, env );
     }
     else if (PathIsURLW((LPWSTR)lpFile))    /* File not found, check for URL */
     {
- static const WCHAR wShell[] = {'\\','s','h','e','l','l',0};
+ static const WCHAR wszShell[] = {'\\','s','h','e','l','l',0};
  static const WCHAR wCommand[] = {'\\','c','o','m','m','a','n','d',0};
         LPWSTR lpstrRes;
         INT iSize;
@@ -816,12 +1229,12 @@ BOOL WINAPI ShellExecuteExW32 (LPSHELLEX
             iSize = strlenW(lpFile);
 
         TRACE("Got URL: %s\n", debugstr_w(lpFile));
-        /* Looking for ...protocol\shell\lpOperation\command */
-        strncpyW(lpstrProtocol, lpFile, iSize);
-        lpstrProtocol[iSize] = '\0';
-        strcatW(lpstrProtocol, wShell);
-        strcatW(lpstrProtocol, lpOperation);
-        strcatW(lpstrProtocol, wCommand);
+        /* Looking for ...protocol\shell\<verb>\command */
+        strncpyW(wszProtocol, lpFile, iSize);
+        wszProtocol[iSize] = '\0';
+        strcatW(wszProtocol, wszShell);
+        strcatW(wszProtocol, sei_tmp.lpVerb? sei_tmp.lpVerb: wszOpen);    /*FIXME: enumerate registry subkeys - compare with the loop into SHELL_FindExecutable() */
+        strcatW(wszProtocol, wCommand);
 
         /* Remove File Protocol from lpFile */
         /* In the case file://path/file     */
@@ -830,7 +1243,8 @@ BOOL WINAPI ShellExecuteExW32 (LPSHELLEX
             lpFile += iSize;
             while (*lpFile == ':') lpFile++;
         }
-        retval = execute_from_key(lpstrProtocol, lpFile, NULL, sei, execfunc);
+
+        retval = execute_from_key(wszProtocol, lpFile, NULL, sei_tmp.lpParameters, execfunc, &sei_tmp, psei);
     }
     /* Check if file specified is in the form www.??????.*** */
     else if (!strncmpiW(lpFile, wWww, 3))
@@ -839,16 +1253,22 @@ BOOL WINAPI ShellExecuteExW32 (LPSHELLEX
         WCHAR lpstrTmpFile[256];
         strcpyW(lpstrTmpFile, wHttp);
         strcatW(lpstrTmpFile, lpFile);
-        retval = (UINT)ShellExecuteW(sei->hwnd, lpOperation, lpstrTmpFile, NULL, NULL, 0);
+        retval = (UINT)ShellExecuteW(sei_tmp.hwnd, sei_tmp.lpVerb, lpstrTmpFile, NULL, NULL, 0);
     }
 
+    /* Now we can free the PIDL. It may have been used before for %I command line options. */
+    if (sei_tmp.lpIDList!=psei->lpIDList && sei_tmp.lpIDList)
+ SHFree(sei_tmp.lpIDList);
+
+    TRACE("ShellExecuteExW32 retval=%d\n", retval);
+
     if (retval <= 32)
     {
-        sei->hInstApp = (HINSTANCE)retval;
+        psei->hInstApp = (HINSTANCE)retval;
         return FALSE;
     }
 
-    sei->hInstApp = (HINSTANCE)33;
+    psei->hInstApp = (HINSTANCE)33;
     return TRUE;
 }
 
@@ -930,6 +1350,10 @@ BOOL WINAPI ShellExecuteExA (LPSHELLEXEC
     if (wDirectory) SHFree(wDirectory);
     if (wClass) SHFree(wClass);
 
+    sei->hInstApp = seiW.hInstApp;
+
+    TRACE("ShellExecuteExW(): ret=%d\n", ret);
+
     return ret;
 }
 
@@ -952,7 +1376,6 @@ HINSTANCE WINAPI ShellExecuteW(HWND hwnd
                                LPCWSTR lpParameters, LPCWSTR lpDirectory, INT nShowCmd)
 {
     SHELLEXECUTEINFOW sei;
-    HANDLE hProcess = 0;
 
     TRACE("\n");
     sei.cbSize = sizeof(sei);
@@ -967,7 +1390,7 @@ HINSTANCE WINAPI ShellExecuteW(HWND hwnd
     sei.lpClass = 0;
     sei.hkeyClass = 0;
     sei.dwHotKey = 0;
-    sei.hProcess = hProcess;
+    sei.hProcess = 0;
 
     ShellExecuteExW32 (&sei, SHELL_ExecuteW);
     return sei.hInstApp;


Index: shell.c
===================================================================
RCS file: /home/wine/wine/dlls/shell32/shell.c,v
retrieving revision 1.58
diff -u -p -d -w -b -r1.58 shell.c
--- shell.c 15 Jan 2004 06:13:57 -0000 1.58
+++ shell.c 29 Jan 2004 19:34:47 -0000
@@ -611,13 +611,14 @@ DWORD WINAPI RegEnumKey16( HKEY hkey, DW
 /*************************************************************************
  *           SHELL_Execute16 [Internal]
  */
-static UINT SHELL_Execute16(WCHAR *lpCmd, void* env, LPSHELLEXECUTEINFOW seiW, BOOL shWait)
+static UINT SHELL_Execute16(const WCHAR *lpCmd, void *env, BOOL shWait,
+       LPSHELLEXECUTEINFOW psei, LPSHELLEXECUTEINFOW psei_out)
 {
     UINT ret;
     char sCmd[MAX_PATH];
     WideCharToMultiByte(CP_ACP, 0, lpCmd, -1, sCmd, MAX_PATH, NULL, NULL);
-    ret = WinExec16(sCmd, seiW->nShow);
-    seiW->hInstApp = HINSTANCE_32(ret);
+    ret = WinExec16(sCmd, (UINT16)psei->nShow);
+    psei_out->hInstApp = HINSTANCE_32(ret);
     return ret;
 }
 


--
Martin Fuchs
martin-fuchs at gmx.net




More information about the wine-patches mailing list