ntdll/tests: Fix a few function prototypes in the registry test.
[wine/multimedia.git] / dlls / shell32 / shlexec.c
bloba81cada91fed264816a0946c06e83a00b7fb6484
1 /*
2 * Shell Library Functions
4 * Copyright 1998 Marcus Meissner
5 * Copyright 2002 Eric Pouech
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
23 #include "wine/port.h"
25 #include <stdlib.h>
26 #include <string.h>
27 #include <stdarg.h>
28 #include <stdio.h>
29 #ifdef HAVE_UNISTD_H
30 # include <unistd.h>
31 #endif
32 #include <ctype.h>
33 #include <assert.h>
35 #define COBJMACROS
37 #include "windef.h"
38 #include "winbase.h"
39 #include "winerror.h"
40 #include "winreg.h"
41 #include "winuser.h"
42 #include "shlwapi.h"
43 #include "ddeml.h"
45 #include "shell32_main.h"
46 #include "pidl.h"
47 #include "shresdef.h"
49 #include "wine/debug.h"
51 WINE_DEFAULT_DEBUG_CHANNEL(exec);
53 static const WCHAR wszOpen[] = {'o','p','e','n',0};
54 static const WCHAR wszExe[] = {'.','e','x','e',0};
55 static const WCHAR wszILPtr[] = {':','%','p',0};
56 static const WCHAR wszShell[] = {'\\','s','h','e','l','l','\\',0};
57 static const WCHAR wszFolder[] = {'F','o','l','d','e','r',0};
58 static const WCHAR wszEmpty[] = {0};
60 #define SEE_MASK_CLASSALL (SEE_MASK_CLASSNAME | SEE_MASK_CLASSKEY)
62 typedef UINT_PTR (*SHELL_ExecuteW32)(const WCHAR *lpCmd, WCHAR *env, BOOL shWait,
63 const SHELLEXECUTEINFOW *sei, LPSHELLEXECUTEINFOW sei_out);
66 /***********************************************************************
67 * SHELL_ArgifyW [Internal]
69 * this function is supposed to expand the escape sequences found in the registry
70 * some diving reported that the following were used:
71 * + %1, %2... seem to report to parameter of index N in ShellExecute pmts
72 * %1 file
73 * %2 printer
74 * %3 driver
75 * %4 port
76 * %I address of a global item ID (explorer switch /idlist)
77 * %L seems to be %1 as long filename followed by the 8+3 variation
78 * %S ???
79 * %* all following parameters (see batfile)
82 static BOOL SHELL_ArgifyW(WCHAR* out, int len, const WCHAR* fmt, const WCHAR* lpFile, LPITEMIDLIST pidl, LPCWSTR args, DWORD* out_len)
84 WCHAR xlpFile[1024];
85 BOOL done = FALSE;
86 BOOL found_p1 = FALSE;
87 PWSTR res = out;
88 PCWSTR cmd;
89 DWORD used = 0;
91 TRACE("%p, %d, %s, %s, %p, %p\n", out, len, debugstr_w(fmt),
92 debugstr_w(lpFile), pidl, args);
94 while (*fmt)
96 if (*fmt == '%')
98 switch (*++fmt)
100 case '\0':
101 case '%':
102 used++;
103 if (used < len)
104 *res++ = '%';
105 break;
107 case '2':
108 case '3':
109 case '4':
110 case '5':
111 case '6':
112 case '7':
113 case '8':
114 case '9':
115 case '0':
116 case '*':
117 if (args)
119 if (*fmt == '*')
121 used++;
122 if (used < len)
123 *res++ = '"';
124 while(*args)
126 used++;
127 if (used < len)
128 *res++ = *args++;
129 else
130 args++;
132 used++;
133 if (used < len)
134 *res++ = '"';
136 else
138 while(*args && !isspace(*args))
140 used++;
141 if (used < len)
142 *res++ = *args++;
143 else
144 args++;
147 while(isspace(*args))
148 ++args;
150 break;
152 /* else fall through */
153 case '1':
154 if (!done || (*fmt == '1'))
156 /*FIXME Is the call to SearchPathW() really needed? We already have separated out the parameter string in args. */
157 if (SearchPathW(NULL, lpFile, wszExe, sizeof(xlpFile)/sizeof(WCHAR), xlpFile, NULL))
158 cmd = xlpFile;
159 else
160 cmd = lpFile;
162 used += strlenW(cmd);
163 if (used < len)
165 strcpyW(res, cmd);
166 res += strlenW(cmd);
169 found_p1 = TRUE;
170 break;
173 * IE uses this a lot for activating things such as windows media
174 * player. This is not verified to be fully correct but it appears
175 * to work just fine.
177 case 'l':
178 case 'L':
179 if (lpFile) {
180 used += strlenW(lpFile);
181 if (used < len)
183 strcpyW(res, lpFile);
184 res += strlenW(lpFile);
187 found_p1 = TRUE;
188 break;
190 case 'i':
191 case 'I':
192 if (pidl) {
193 INT chars = 0;
194 /* %p should not exceed 8, maybe 16 when looking forward to 64bit.
195 * allowing a buffer of 100 should more than exceed all needs */
196 WCHAR buf[100];
197 LPVOID pv;
198 HGLOBAL hmem = SHAllocShared(pidl, ILGetSize(pidl), 0);
199 pv = SHLockShared(hmem, 0);
200 chars = sprintfW(buf, wszILPtr, pv);
201 if (chars >= sizeof(buf)/sizeof(WCHAR))
202 ERR("pidl format buffer too small!\n");
203 used += chars;
204 if (used < len)
206 strcpyW(res,buf);
207 res += chars;
209 SHUnlockShared(pv);
211 found_p1 = TRUE;
212 break;
214 default:
216 * Check if this is an env-variable here...
219 /* Make sure that we have at least one more %.*/
220 if (strchrW(fmt, '%'))
222 WCHAR tmpBuffer[1024];
223 PWSTR tmpB = tmpBuffer;
224 WCHAR tmpEnvBuff[MAX_PATH];
225 DWORD envRet;
227 while (*fmt != '%')
228 *tmpB++ = *fmt++;
229 *tmpB++ = 0;
231 TRACE("Checking %s to be an env-var\n", debugstr_w(tmpBuffer));
233 envRet = GetEnvironmentVariableW(tmpBuffer, tmpEnvBuff, MAX_PATH);
234 if (envRet == 0 || envRet > MAX_PATH)
236 used += strlenW(tmpBuffer);
237 if (used < len)
239 strcpyW( res, tmpBuffer );
240 res += strlenW(tmpBuffer);
243 else
245 used += strlenW(tmpEnvBuff);
246 if (used < len)
248 strcpyW( res, tmpEnvBuff );
249 res += strlenW(tmpEnvBuff);
253 done = TRUE;
254 break;
256 /* Don't skip past terminator (catch a single '%' at the end) */
257 if (*fmt != '\0')
259 fmt++;
262 else
264 used ++;
265 if (used < len)
266 *res++ = *fmt++;
267 else
268 fmt++;
272 *res = '\0';
273 TRACE("used %i of %i space\n",used,len);
274 if (out_len)
275 *out_len = used;
277 return found_p1;
280 static HRESULT SHELL_GetPathFromIDListForExecuteW(LPCITEMIDLIST pidl, LPWSTR pszPath, UINT uOutSize)
282 STRRET strret;
283 IShellFolder* desktop;
285 HRESULT hr = SHGetDesktopFolder(&desktop);
287 if (SUCCEEDED(hr)) {
288 hr = IShellFolder_GetDisplayNameOf(desktop, pidl, SHGDN_FORPARSING, &strret);
290 if (SUCCEEDED(hr))
291 StrRetToStrNW(pszPath, uOutSize, &strret, pidl);
293 IShellFolder_Release(desktop);
296 return hr;
299 /*************************************************************************
300 * SHELL_ExecuteW [Internal]
303 static UINT_PTR SHELL_ExecuteW(const WCHAR *lpCmd, WCHAR *env, BOOL shWait,
304 const SHELLEXECUTEINFOW *psei, LPSHELLEXECUTEINFOW psei_out)
306 STARTUPINFOW startup;
307 PROCESS_INFORMATION info;
308 UINT_PTR retval = SE_ERR_NOASSOC;
309 UINT gcdret = 0;
310 WCHAR curdir[MAX_PATH];
311 DWORD dwCreationFlags;
312 const WCHAR *lpDirectory = NULL;
314 TRACE("Execute %s from directory %s\n", debugstr_w(lpCmd), debugstr_w(psei->lpDirectory));
316 /* make sure we don't fail the CreateProcess if the calling app passes in
317 * a bad working directory */
318 if (psei->lpDirectory && psei->lpDirectory[0])
320 DWORD attr = GetFileAttributesW(psei->lpDirectory);
321 if (attr != INVALID_FILE_ATTRIBUTES && attr & FILE_ATTRIBUTE_DIRECTORY)
322 lpDirectory = psei->lpDirectory;
325 /* ShellExecute specifies the command from psei->lpDirectory
326 * if present. Not from the current dir as CreateProcess does */
327 if( lpDirectory )
328 if( ( gcdret = GetCurrentDirectoryW( MAX_PATH, curdir)))
329 if( !SetCurrentDirectoryW( lpDirectory))
330 ERR("cannot set directory %s\n", debugstr_w(lpDirectory));
331 ZeroMemory(&startup,sizeof(STARTUPINFOW));
332 startup.cb = sizeof(STARTUPINFOW);
333 startup.dwFlags = STARTF_USESHOWWINDOW;
334 startup.wShowWindow = psei->nShow;
335 dwCreationFlags = CREATE_UNICODE_ENVIRONMENT;
336 if (psei->fMask & SEE_MASK_NO_CONSOLE)
337 dwCreationFlags |= CREATE_NEW_CONSOLE;
338 if (CreateProcessW(NULL, (LPWSTR)lpCmd, NULL, NULL, FALSE, dwCreationFlags, env,
339 lpDirectory, &startup, &info))
341 /* Give 30 seconds to the app to come up, if desired. Probably only needed
342 when starting app immediately before making a DDE connection. */
343 if (shWait)
344 if (WaitForInputIdle( info.hProcess, 30000 ) == WAIT_FAILED)
345 WARN("WaitForInputIdle failed: Error %d\n", GetLastError() );
346 retval = 33;
347 if (psei->fMask & SEE_MASK_NOCLOSEPROCESS)
348 psei_out->hProcess = info.hProcess;
349 else
350 CloseHandle( info.hProcess );
351 CloseHandle( info.hThread );
353 else if ((retval = GetLastError()) >= 32)
355 TRACE("CreateProcess returned error %ld\n", retval);
356 retval = ERROR_BAD_FORMAT;
359 TRACE("returning %lu\n", retval);
361 psei_out->hInstApp = (HINSTANCE)retval;
362 if( gcdret )
363 if( !SetCurrentDirectoryW( curdir))
364 ERR("cannot return to directory %s\n", debugstr_w(curdir));
366 return retval;
370 /***********************************************************************
371 * SHELL_BuildEnvW [Internal]
373 * Build the environment for the new process, adding the specified
374 * path to the PATH variable. Returned pointer must be freed by caller.
376 static void *SHELL_BuildEnvW( const WCHAR *path )
378 static const WCHAR wPath[] = {'P','A','T','H','=',0};
379 WCHAR *strings, *new_env;
380 WCHAR *p, *p2;
381 int total = strlenW(path) + 1;
382 BOOL got_path = FALSE;
384 if (!(strings = GetEnvironmentStringsW())) return NULL;
385 p = strings;
386 while (*p)
388 int len = strlenW(p) + 1;
389 if (!strncmpiW( p, wPath, 5 )) got_path = TRUE;
390 total += len;
391 p += len;
393 if (!got_path) total += 5; /* we need to create PATH */
394 total++; /* terminating null */
396 if (!(new_env = HeapAlloc( GetProcessHeap(), 0, total * sizeof(WCHAR) )))
398 FreeEnvironmentStringsW( strings );
399 return NULL;
401 p = strings;
402 p2 = new_env;
403 while (*p)
405 int len = strlenW(p) + 1;
406 memcpy( p2, p, len * sizeof(WCHAR) );
407 if (!strncmpiW( p, wPath, 5 ))
409 p2[len - 1] = ';';
410 strcpyW( p2 + len, path );
411 p2 += strlenW(path) + 1;
413 p += len;
414 p2 += len;
416 if (!got_path)
418 strcpyW( p2, wPath );
419 strcatW( p2, path );
420 p2 += strlenW(p2) + 1;
422 *p2 = 0;
423 FreeEnvironmentStringsW( strings );
424 return new_env;
428 /***********************************************************************
429 * SHELL_TryAppPathW [Internal]
431 * Helper function for SHELL_FindExecutable
432 * @param lpResult - pointer to a buffer of size MAX_PATH
433 * On entry: szName is a filename (probably without path separators).
434 * On exit: if szName found in "App Path", place full path in lpResult, and return true
436 static BOOL SHELL_TryAppPathW( LPCWSTR szName, LPWSTR lpResult, WCHAR **env)
438 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',
439 '\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','A','p','p',' ','P','a','t','h','s','\\',0};
440 static const WCHAR wPath[] = {'P','a','t','h',0};
441 HKEY hkApp = 0;
442 WCHAR buffer[1024];
443 LONG len;
444 LONG res;
445 BOOL found = FALSE;
447 if (env) *env = NULL;
448 strcpyW(buffer, wszKeyAppPaths);
449 strcatW(buffer, szName);
450 res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, buffer, 0, KEY_READ, &hkApp);
451 if (res) goto end;
453 len = MAX_PATH*sizeof(WCHAR);
454 res = RegQueryValueW(hkApp, NULL, lpResult, &len);
455 if (res) goto end;
456 found = TRUE;
458 if (env)
460 DWORD count = sizeof(buffer);
461 if (!RegQueryValueExW(hkApp, wPath, NULL, NULL, (LPBYTE)buffer, &count) && buffer[0])
462 *env = SHELL_BuildEnvW( buffer );
465 end:
466 if (hkApp) RegCloseKey(hkApp);
467 return found;
470 static UINT SHELL_FindExecutableByOperation(LPCWSTR lpOperation, LPWSTR key, LPWSTR filetype, LPWSTR command, LONG commandlen)
472 static const WCHAR wCommand[] = {'\\','c','o','m','m','a','n','d',0};
473 HKEY hkeyClass;
474 WCHAR verb[MAX_PATH];
476 if (RegOpenKeyExW(HKEY_CLASSES_ROOT, filetype, 0, 0x02000000, &hkeyClass))
477 return SE_ERR_NOASSOC;
478 if (!HCR_GetDefaultVerbW(hkeyClass, lpOperation, verb, sizeof(verb)/sizeof(verb[0])))
479 return SE_ERR_NOASSOC;
480 RegCloseKey(hkeyClass);
482 /* Looking for ...buffer\shell\<verb>\command */
483 strcatW(filetype, wszShell);
484 strcatW(filetype, verb);
485 strcatW(filetype, wCommand);
487 if (RegQueryValueW(HKEY_CLASSES_ROOT, filetype, command,
488 &commandlen) == ERROR_SUCCESS)
490 commandlen /= sizeof(WCHAR);
491 if (key) strcpyW(key, filetype);
492 #if 0
493 LPWSTR tmp;
494 WCHAR param[256];
495 LONG paramlen = sizeof(param);
496 static const WCHAR wSpace[] = {' ',0};
498 /* FIXME: it seems all Windows version don't behave the same here.
499 * the doc states that this ddeexec information can be found after
500 * the exec names.
501 * on Win98, it doesn't appear, but I think it does on Win2k
503 /* Get the parameters needed by the application
504 from the associated ddeexec key */
505 tmp = strstrW(filetype, wCommand);
506 tmp[0] = '\0';
507 strcatW(filetype, wDdeexec);
508 if (RegQueryValueW(HKEY_CLASSES_ROOT, filetype, param,
509 &paramlen) == ERROR_SUCCESS)
511 paramlen /= sizeof(WCHAR);
512 strcatW(command, wSpace);
513 strcatW(command, param);
514 commandlen += paramlen;
516 #endif
518 command[commandlen] = '\0';
520 return 33; /* FIXME see SHELL_FindExecutable() */
523 return SE_ERR_NOASSOC;
526 /*************************************************************************
527 * SHELL_FindExecutable [Internal]
529 * Utility for code sharing between FindExecutable and ShellExecute
530 * in:
531 * lpFile the name of a file
532 * lpOperation the operation on it (open)
533 * out:
534 * lpResult a buffer, big enough :-(, to store the command to do the
535 * operation on the file
536 * key a buffer, big enough, to get the key name to do actually the
537 * command (it'll be used afterwards for more information
538 * on the operation)
540 static UINT SHELL_FindExecutable(LPCWSTR lpPath, LPCWSTR lpFile, LPCWSTR lpOperation,
541 LPWSTR lpResult, int resultLen, LPWSTR key, WCHAR **env, LPITEMIDLIST pidl, LPCWSTR args)
543 static const WCHAR wWindows[] = {'w','i','n','d','o','w','s',0};
544 static const WCHAR wPrograms[] = {'p','r','o','g','r','a','m','s',0};
545 static const WCHAR wExtensions[] = {'e','x','e',' ','p','i','f',' ','b','a','t',' ','c','m','d',' ','c','o','m',0};
546 WCHAR *extension = NULL; /* pointer to file extension */
547 WCHAR filetype[256]; /* registry name for this filetype */
548 LONG filetypelen = sizeof(filetype); /* length of above */
549 WCHAR command[1024]; /* command from registry */
550 WCHAR wBuffer[256]; /* Used to GetProfileString */
551 UINT retval = SE_ERR_NOASSOC;
552 WCHAR *tok; /* token pointer */
553 WCHAR xlpFile[256]; /* result of SearchPath */
554 DWORD attribs; /* file attributes */
556 TRACE("%s\n", debugstr_w(lpFile));
558 if (!lpResult)
559 return ERROR_INVALID_PARAMETER;
561 xlpFile[0] = '\0';
562 lpResult[0] = '\0'; /* Start off with an empty return string */
563 if (key) *key = '\0';
565 /* trap NULL parameters on entry */
566 if (!lpFile)
568 WARN("(lpFile=%s,lpResult=%s): NULL parameter\n",
569 debugstr_w(lpFile), debugstr_w(lpResult));
570 return ERROR_FILE_NOT_FOUND; /* File not found. Close enough, I guess. */
573 if (SHELL_TryAppPathW( lpFile, lpResult, env ))
575 TRACE("found %s via App Paths\n", debugstr_w(lpResult));
576 return 33;
579 if (SearchPathW(lpPath, lpFile, wszExe, sizeof(xlpFile)/sizeof(WCHAR), xlpFile, NULL))
581 TRACE("SearchPathW returned non-zero\n");
582 lpFile = xlpFile;
583 /* Hey, isn't this value ignored? Why make this call? Shouldn't we return here? --dank*/
586 attribs = GetFileAttributesW(lpFile);
587 if (attribs!=INVALID_FILE_ATTRIBUTES && (attribs&FILE_ATTRIBUTE_DIRECTORY))
589 strcpyW(filetype, wszFolder);
591 else
593 /* Did we get something? Anything? */
594 if (xlpFile[0]==0)
596 TRACE("Returning SE_ERR_FNF\n");
597 return SE_ERR_FNF;
599 /* First thing we need is the file's extension */
600 extension = strrchrW(xlpFile, '.'); /* Assume last "." is the one; */
601 /* File->Run in progman uses */
602 /* .\FILE.EXE :( */
603 TRACE("xlpFile=%s,extension=%s\n", debugstr_w(xlpFile), debugstr_w(extension));
605 if (extension == NULL || extension[1]==0)
607 WARN("Returning SE_ERR_NOASSOC\n");
608 return SE_ERR_NOASSOC;
611 /* Three places to check: */
612 /* 1. win.ini, [windows], programs (NB no leading '.') */
613 /* 2. Registry, HKEY_CLASS_ROOT\<filetype>\shell\open\command */
614 /* 3. win.ini, [extensions], extension (NB no leading '.' */
615 /* All I know of the order is that registry is checked before */
616 /* extensions; however, it'd make sense to check the programs */
617 /* section first, so that's what happens here. */
619 /* See if it's a program - if GetProfileString fails, we skip this
620 * section. Actually, if GetProfileString fails, we've probably
621 * got a lot more to worry about than running a program... */
622 if (GetProfileStringW(wWindows, wPrograms, wExtensions, wBuffer, sizeof(wBuffer)/sizeof(WCHAR)) > 0)
624 CharLowerW(wBuffer);
625 tok = wBuffer;
626 while (*tok)
628 WCHAR *p = tok;
629 while (*p && *p != ' ' && *p != '\t') p++;
630 if (*p)
632 *p++ = 0;
633 while (*p == ' ' || *p == '\t') p++;
636 if (strcmpiW(tok, &extension[1]) == 0) /* have to skip the leading "." */
638 strcpyW(lpResult, xlpFile);
639 /* Need to perhaps check that the file has a path
640 * attached */
641 TRACE("found %s\n", debugstr_w(lpResult));
642 return 33;
643 /* Greater than 32 to indicate success */
645 tok = p;
649 /* Check registry */
650 if (RegQueryValueW(HKEY_CLASSES_ROOT, extension, filetype,
651 &filetypelen) == ERROR_SUCCESS)
653 filetypelen /= sizeof(WCHAR);
654 if (filetypelen == sizeof(filetype)/sizeof(WCHAR))
655 filetypelen--;
656 filetype[filetypelen] = '\0';
657 TRACE("File type: %s\n", debugstr_w(filetype));
659 else
661 *filetype = '\0';
665 if (*filetype)
667 /* pass the operation string to SHELL_FindExecutableByOperation() */
668 retval = SHELL_FindExecutableByOperation(lpOperation, key, filetype, command, sizeof(command));
670 if (retval > 32)
672 DWORD finishedLen;
673 SHELL_ArgifyW(lpResult, resultLen, command, xlpFile, pidl, args, &finishedLen);
674 if (finishedLen > resultLen)
675 ERR("Argify buffer not large enough.. truncated\n");
677 /* Remove double quotation marks and command line arguments */
678 if (*lpResult == '"')
680 WCHAR *p = lpResult;
681 while (*(p + 1) != '"')
683 *p = *(p + 1);
684 p++;
686 *p = '\0';
688 else
690 /* Truncate on first space */
691 WCHAR *p = lpResult;
692 while (*p != ' ' && *p != '\0')
693 p++;
694 *p='\0';
698 else /* Check win.ini */
700 static const WCHAR wExtensions[] = {'e','x','t','e','n','s','i','o','n','s',0};
702 /* Toss the leading dot */
703 extension++;
704 if (GetProfileStringW(wExtensions, extension, wszEmpty, command, sizeof(command)/sizeof(WCHAR)) > 0)
706 if (strlenW(command) != 0)
708 strcpyW(lpResult, command);
709 tok = strchrW(lpResult, '^'); /* should be ^.extension? */
710 if (tok != NULL)
712 tok[0] = '\0';
713 strcatW(lpResult, xlpFile); /* what if no dir in xlpFile? */
714 tok = strchrW(command, '^'); /* see above */
715 if ((tok != NULL) && (strlenW(tok)>5))
717 strcatW(lpResult, &tok[5]);
720 retval = 33; /* FIXME - see above */
725 TRACE("returning %s\n", debugstr_w(lpResult));
726 return retval;
729 /******************************************************************
730 * dde_cb
732 * callback for the DDE connection. not really useful
734 static HDDEDATA CALLBACK dde_cb(UINT uType, UINT uFmt, HCONV hConv,
735 HSZ hsz1, HSZ hsz2, HDDEDATA hData,
736 ULONG_PTR dwData1, ULONG_PTR dwData2)
738 TRACE("dde_cb: %04x, %04x, %p, %p, %p, %p, %08lx, %08lx\n",
739 uType, uFmt, hConv, hsz1, hsz2, hData, dwData1, dwData2);
740 return NULL;
743 /******************************************************************
744 * dde_connect
746 * ShellExecute helper. Used to do an operation with a DDE connection
748 * Handles both the direct connection (try #1), and if it fails,
749 * launching an application and trying (#2) to connect to it
752 static unsigned dde_connect(const WCHAR* key, const WCHAR* start, WCHAR* ddeexec,
753 const WCHAR* lpFile, WCHAR *env,
754 LPCWSTR szCommandline, LPITEMIDLIST pidl, SHELL_ExecuteW32 execfunc,
755 const SHELLEXECUTEINFOW *psei, LPSHELLEXECUTEINFOW psei_out)
757 static const WCHAR wApplication[] = {'\\','a','p','p','l','i','c','a','t','i','o','n',0};
758 static const WCHAR wTopic[] = {'\\','t','o','p','i','c',0};
759 WCHAR regkey[256];
760 WCHAR * endkey = regkey + strlenW(key);
761 WCHAR app[256], topic[256], ifexec[256], res[256];
762 LONG applen, topiclen, ifexeclen;
763 WCHAR * exec;
764 DWORD ddeInst = 0;
765 DWORD tid;
766 DWORD resultLen;
767 HSZ hszApp, hszTopic;
768 HCONV hConv;
769 HDDEDATA hDdeData;
770 unsigned ret = SE_ERR_NOASSOC;
771 BOOL unicode = !(GetVersion() & 0x80000000);
773 strcpyW(regkey, key);
774 strcpyW(endkey, wApplication);
775 applen = sizeof(app);
776 if (RegQueryValueW(HKEY_CLASSES_ROOT, regkey, app, &applen) != ERROR_SUCCESS)
778 WCHAR command[1024], fullpath[MAX_PATH];
779 static const WCHAR wSo[] = { '.','s','o',0 };
780 int sizeSo = sizeof(wSo)/sizeof(WCHAR);
781 LPWSTR ptr = NULL;
782 DWORD ret = 0;
784 /* Get application command from start string and find filename of application */
785 if (*start == '"')
787 strcpyW(command, start+1);
788 if ((ptr = strchrW(command, '"')))
789 *ptr = 0;
790 ret = SearchPathW(NULL, command, wszExe, sizeof(fullpath)/sizeof(WCHAR), fullpath, &ptr);
792 else
794 LPWSTR p,space;
795 for (p=(LPWSTR)start; (space=strchrW(p, ' ')); p=space+1)
797 int idx = space-start;
798 memcpy(command, start, idx*sizeof(WCHAR));
799 command[idx] = '\0';
800 if ((ret = SearchPathW(NULL, command, wszExe, sizeof(fullpath)/sizeof(WCHAR), fullpath, &ptr)))
801 break;
803 if (!ret)
804 ret = SearchPathW(NULL, start, wszExe, sizeof(fullpath)/sizeof(WCHAR), fullpath, &ptr);
807 if (!ret)
809 ERR("Unable to find application path for command %s\n", debugstr_w(start));
810 return ERROR_ACCESS_DENIED;
812 strcpyW(app, ptr);
814 /* Remove extensions (including .so) */
815 ptr = app + strlenW(app) - (sizeSo-1);
816 if (strlenW(app) >= sizeSo &&
817 !strcmpW(ptr, wSo))
818 *ptr = 0;
820 ptr = strrchrW(app, '.');
821 assert(ptr);
822 *ptr = 0;
825 strcpyW(endkey, wTopic);
826 topiclen = sizeof(topic);
827 if (RegQueryValueW(HKEY_CLASSES_ROOT, regkey, topic, &topiclen) != ERROR_SUCCESS)
829 static const WCHAR wSystem[] = {'S','y','s','t','e','m',0};
830 strcpyW(topic, wSystem);
833 if (unicode)
835 if (DdeInitializeW(&ddeInst, dde_cb, APPCMD_CLIENTONLY, 0L) != DMLERR_NO_ERROR)
836 return 2;
838 else
840 if (DdeInitializeA(&ddeInst, dde_cb, APPCMD_CLIENTONLY, 0L) != DMLERR_NO_ERROR)
841 return 2;
844 hszApp = DdeCreateStringHandleW(ddeInst, app, CP_WINUNICODE);
845 hszTopic = DdeCreateStringHandleW(ddeInst, topic, CP_WINUNICODE);
847 hConv = DdeConnect(ddeInst, hszApp, hszTopic, NULL);
848 exec = ddeexec;
849 if (!hConv)
851 static const WCHAR wIfexec[] = {'\\','i','f','e','x','e','c',0};
852 TRACE("Launching %s\n", debugstr_w(start));
853 ret = execfunc(start, env, TRUE, psei, psei_out);
854 if (ret <= 32)
856 TRACE("Couldn't launch\n");
857 goto error;
859 hConv = DdeConnect(ddeInst, hszApp, hszTopic, NULL);
860 if (!hConv)
862 TRACE("Couldn't connect. ret=%d\n", ret);
863 DdeUninitialize(ddeInst);
864 SetLastError(ERROR_DDE_FAIL);
865 return 30; /* whatever */
867 strcpyW(endkey, wIfexec);
868 ifexeclen = sizeof(ifexec);
869 if (RegQueryValueW(HKEY_CLASSES_ROOT, regkey, ifexec, &ifexeclen) == ERROR_SUCCESS)
871 exec = ifexec;
875 SHELL_ArgifyW(res, sizeof(res)/sizeof(WCHAR), exec, lpFile, pidl, szCommandline, &resultLen);
876 if (resultLen > sizeof(res)/sizeof(WCHAR))
877 ERR("Argify buffer not large enough, truncated\n");
878 TRACE("%s %s => %s\n", debugstr_w(exec), debugstr_w(lpFile), debugstr_w(res));
880 /* It's documented in the KB 330337 that IE has a bug and returns
881 * error DMLERR_NOTPROCESSED on XTYP_EXECUTE request.
883 if (unicode)
884 hDdeData = DdeClientTransaction((LPBYTE)res, (strlenW(res) + 1) * sizeof(WCHAR), hConv, 0L, 0,
885 XTYP_EXECUTE, 30000, &tid);
886 else
888 DWORD lenA = WideCharToMultiByte(CP_ACP, 0, res, -1, NULL, 0, NULL, NULL);
889 char *resA = HeapAlloc(GetProcessHeap(), 0, lenA);
890 WideCharToMultiByte(CP_ACP, 0, res, -1, resA, lenA, NULL, NULL);
891 hDdeData = DdeClientTransaction( (LPBYTE)resA, lenA, hConv, 0L, 0,
892 XTYP_EXECUTE, 10000, &tid );
893 HeapFree(GetProcessHeap(), 0, resA);
895 if (hDdeData)
896 DdeFreeDataHandle(hDdeData);
897 else
898 WARN("DdeClientTransaction failed with error %04x\n", DdeGetLastError(ddeInst));
899 ret = 33;
901 DdeDisconnect(hConv);
903 error:
904 DdeUninitialize(ddeInst);
906 return ret;
909 /*************************************************************************
910 * execute_from_key [Internal]
912 static UINT_PTR execute_from_key(LPCWSTR key, LPCWSTR lpFile, WCHAR *env, LPCWSTR szCommandline,
913 LPCWSTR executable_name,
914 SHELL_ExecuteW32 execfunc,
915 LPSHELLEXECUTEINFOW psei, LPSHELLEXECUTEINFOW psei_out)
917 static const WCHAR wCommand[] = {'c','o','m','m','a','n','d',0};
918 static const WCHAR wDdeexec[] = {'d','d','e','e','x','e','c',0};
919 WCHAR cmd[256], param[1024], ddeexec[256];
920 LONG cmdlen = sizeof(cmd), ddeexeclen = sizeof(ddeexec);
921 UINT_PTR retval = SE_ERR_NOASSOC;
922 DWORD resultLen;
923 LPWSTR tmp;
925 TRACE("%s %s %s %s %s\n", debugstr_w(key), debugstr_w(lpFile), debugstr_w(env),
926 debugstr_w(szCommandline), debugstr_w(executable_name));
928 cmd[0] = '\0';
929 param[0] = '\0';
931 /* Get the application from the registry */
932 if (RegQueryValueW(HKEY_CLASSES_ROOT, key, cmd, &cmdlen) == ERROR_SUCCESS)
934 TRACE("got cmd: %s\n", debugstr_w(cmd));
936 /* Is there a replace() function anywhere? */
937 cmdlen /= sizeof(WCHAR);
938 if (cmdlen >= sizeof(cmd)/sizeof(WCHAR))
939 cmdlen = sizeof(cmd)/sizeof(WCHAR)-1;
940 cmd[cmdlen] = '\0';
941 SHELL_ArgifyW(param, sizeof(param)/sizeof(WCHAR), cmd, lpFile, psei->lpIDList, szCommandline, &resultLen);
942 if (resultLen > sizeof(param)/sizeof(WCHAR))
943 ERR("Argify buffer not large enough, truncating\n");
946 /* Get the parameters needed by the application
947 from the associated ddeexec key */
948 tmp = strstrW(key, wCommand);
949 assert(tmp);
950 strcpyW(tmp, wDdeexec);
952 if (RegQueryValueW(HKEY_CLASSES_ROOT, key, ddeexec, &ddeexeclen) == ERROR_SUCCESS)
954 TRACE("Got ddeexec %s => %s\n", debugstr_w(key), debugstr_w(ddeexec));
955 if (!param[0]) strcpyW(param, executable_name);
956 retval = dde_connect(key, param, ddeexec, lpFile, env, szCommandline, psei->lpIDList, execfunc, psei, psei_out);
958 else if (param[0])
960 TRACE("executing: %s\n", debugstr_w(param));
961 retval = execfunc(param, env, FALSE, psei, psei_out);
963 else
964 WARN("Nothing appropriate found for %s\n", debugstr_w(key));
966 return retval;
969 /*************************************************************************
970 * FindExecutableA [SHELL32.@]
972 HINSTANCE WINAPI FindExecutableA(LPCSTR lpFile, LPCSTR lpDirectory, LPSTR lpResult)
974 HINSTANCE retval;
975 WCHAR *wFile = NULL, *wDirectory = NULL;
976 WCHAR wResult[MAX_PATH];
978 if (lpFile) __SHCloneStrAtoW(&wFile, lpFile);
979 if (lpDirectory) __SHCloneStrAtoW(&wDirectory, lpDirectory);
981 retval = FindExecutableW(wFile, wDirectory, wResult);
982 WideCharToMultiByte(CP_ACP, 0, wResult, -1, lpResult, MAX_PATH, NULL, NULL);
983 SHFree( wFile );
984 SHFree( wDirectory );
986 TRACE("returning %s\n", lpResult);
987 return retval;
990 /*************************************************************************
991 * FindExecutableW [SHELL32.@]
993 * This function returns the executable associated with the specified file
994 * for the default verb.
996 * PARAMS
997 * lpFile [I] The file to find the association for. This must refer to
998 * an existing file otherwise FindExecutable fails and returns
999 * SE_ERR_FNF.
1000 * lpResult [O] Points to a buffer into which the executable path is
1001 * copied. This parameter must not be NULL otherwise
1002 * FindExecutable() segfaults. The buffer must be of size at
1003 * least MAX_PATH characters.
1005 * RETURNS
1006 * A value greater than 32 on success, less than or equal to 32 otherwise.
1007 * See the SE_ERR_* constants.
1009 * NOTES
1010 * On Windows XP and 2003, FindExecutable() seems to first convert the
1011 * filename into 8.3 format, thus taking into account only the first three
1012 * characters of the extension, and expects to find an association for those.
1013 * However other Windows versions behave sanely.
1015 HINSTANCE WINAPI FindExecutableW(LPCWSTR lpFile, LPCWSTR lpDirectory, LPWSTR lpResult)
1017 UINT_PTR retval = SE_ERR_NOASSOC;
1018 WCHAR old_dir[1024];
1020 TRACE("File %s, Dir %s\n", debugstr_w(lpFile), debugstr_w(lpDirectory));
1022 lpResult[0] = '\0'; /* Start off with an empty return string */
1023 if (lpFile == NULL)
1024 return (HINSTANCE)SE_ERR_FNF;
1026 if (lpDirectory)
1028 GetCurrentDirectoryW(sizeof(old_dir)/sizeof(WCHAR), old_dir);
1029 SetCurrentDirectoryW(lpDirectory);
1032 retval = SHELL_FindExecutable(lpDirectory, lpFile, wszOpen, lpResult, MAX_PATH, NULL, NULL, NULL, NULL);
1034 TRACE("returning %s\n", debugstr_w(lpResult));
1035 if (lpDirectory)
1036 SetCurrentDirectoryW(old_dir);
1037 return (HINSTANCE)retval;
1040 /* FIXME: is this already implemented somewhere else? */
1041 static HKEY ShellExecute_GetClassKey( const SHELLEXECUTEINFOW *sei )
1043 LPCWSTR ext = NULL, lpClass = NULL;
1044 LPWSTR cls = NULL;
1045 DWORD type = 0, sz = 0;
1046 HKEY hkey = 0;
1047 LONG r;
1049 if (sei->fMask & SEE_MASK_CLASSALL)
1050 return sei->hkeyClass;
1052 if (sei->fMask & SEE_MASK_CLASSNAME)
1053 lpClass = sei->lpClass;
1054 else
1056 ext = PathFindExtensionW( sei->lpFile );
1057 TRACE("ext = %s\n", debugstr_w( ext ) );
1058 if (!ext)
1059 return hkey;
1061 r = RegOpenKeyW( HKEY_CLASSES_ROOT, ext, &hkey );
1062 if (r != ERROR_SUCCESS )
1063 return hkey;
1065 r = RegQueryValueExW( hkey, NULL, 0, &type, NULL, &sz );
1066 if ( r == ERROR_SUCCESS && type == REG_SZ )
1068 sz += sizeof (WCHAR);
1069 cls = HeapAlloc( GetProcessHeap(), 0, sz );
1070 cls[0] = 0;
1071 RegQueryValueExW( hkey, NULL, 0, &type, (LPBYTE) cls, &sz );
1074 RegCloseKey( hkey );
1075 lpClass = cls;
1078 TRACE("class = %s\n", debugstr_w(lpClass) );
1080 hkey = 0;
1081 if ( lpClass )
1082 RegOpenKeyW( HKEY_CLASSES_ROOT, lpClass, &hkey );
1084 HeapFree( GetProcessHeap(), 0, cls );
1086 return hkey;
1089 static IDataObject *shellex_get_dataobj( LPSHELLEXECUTEINFOW sei )
1091 LPCITEMIDLIST pidllast = NULL;
1092 IDataObject *dataobj = NULL;
1093 IShellFolder *shf = NULL;
1094 LPITEMIDLIST pidl = NULL;
1095 HRESULT r;
1097 if (sei->fMask & SEE_MASK_CLASSALL)
1098 pidl = sei->lpIDList;
1099 else
1101 WCHAR fullpath[MAX_PATH];
1102 BOOL ret;
1104 fullpath[0] = 0;
1105 ret = GetFullPathNameW( sei->lpFile, MAX_PATH, fullpath, NULL );
1106 if (!ret)
1107 goto end;
1109 pidl = ILCreateFromPathW( fullpath );
1112 r = SHBindToParent( pidl, &IID_IShellFolder, (LPVOID*)&shf, &pidllast );
1113 if ( FAILED( r ) )
1114 goto end;
1116 IShellFolder_GetUIObjectOf( shf, NULL, 1, &pidllast,
1117 &IID_IDataObject, NULL, (LPVOID*) &dataobj );
1119 end:
1120 if ( pidl != sei->lpIDList )
1121 ILFree( pidl );
1122 if ( shf )
1123 IShellFolder_Release( shf );
1124 return dataobj;
1127 static HRESULT shellex_run_context_menu_default( IShellExtInit *obj,
1128 LPSHELLEXECUTEINFOW sei )
1130 IContextMenu *cm = NULL;
1131 CMINVOKECOMMANDINFOEX ici;
1132 MENUITEMINFOW info;
1133 WCHAR string[0x80];
1134 INT i, n, def = -1;
1135 HMENU hmenu = 0;
1136 HRESULT r;
1138 TRACE("%p %p\n", obj, sei );
1140 r = IShellExtInit_QueryInterface( obj, &IID_IContextMenu, (LPVOID*) &cm );
1141 if ( FAILED( r ) )
1142 return r;
1144 hmenu = CreateMenu();
1145 if ( !hmenu )
1146 goto end;
1148 /* the number of the last menu added is returned in r */
1149 r = IContextMenu_QueryContextMenu( cm, hmenu, 0, 0x20, 0x7fff, CMF_DEFAULTONLY );
1150 if ( FAILED( r ) )
1151 goto end;
1153 n = GetMenuItemCount( hmenu );
1154 for ( i = 0; i < n; i++ )
1156 memset( &info, 0, sizeof info );
1157 info.cbSize = sizeof info;
1158 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_STATE | MIIM_DATA | MIIM_ID;
1159 info.dwTypeData = string;
1160 info.cch = sizeof string;
1161 string[0] = 0;
1162 GetMenuItemInfoW( hmenu, i, TRUE, &info );
1164 TRACE("menu %d %s %08x %08lx %08x %08x\n", i, debugstr_w(string),
1165 info.fState, info.dwItemData, info.fType, info.wID );
1166 if ( ( !sei->lpVerb && (info.fState & MFS_DEFAULT) ) ||
1167 ( sei->lpVerb && !lstrcmpiW( sei->lpVerb, string ) ) )
1169 def = i;
1170 break;
1174 r = E_FAIL;
1175 if ( def == -1 )
1176 goto end;
1178 memset( &ici, 0, sizeof ici );
1179 ici.cbSize = sizeof ici;
1180 ici.fMask = CMIC_MASK_UNICODE | (sei->fMask & (SEE_MASK_NOASYNC|SEE_MASK_ASYNCOK|SEE_MASK_FLAG_NO_UI));
1181 ici.nShow = sei->nShow;
1182 ici.lpVerb = MAKEINTRESOURCEA( def );
1183 ici.hwnd = sei->hwnd;
1184 ici.lpParametersW = sei->lpParameters;
1186 r = IContextMenu_InvokeCommand( cm, (LPCMINVOKECOMMANDINFO) &ici );
1188 TRACE("invoke command returned %08x\n", r );
1190 end:
1191 if ( hmenu )
1192 DestroyMenu( hmenu );
1193 if ( cm )
1194 IContextMenu_Release( cm );
1195 return r;
1198 static HRESULT shellex_load_object_and_run( HKEY hkey, LPCGUID guid, LPSHELLEXECUTEINFOW sei )
1200 IDataObject *dataobj = NULL;
1201 IObjectWithSite *ows = NULL;
1202 IShellExtInit *obj = NULL;
1203 HRESULT r;
1205 TRACE("%p %s %p\n", hkey, debugstr_guid( guid ), sei );
1207 r = CoInitialize( NULL );
1208 if ( FAILED( r ) )
1209 goto end;
1211 r = CoCreateInstance( guid, NULL, CLSCTX_INPROC_SERVER,
1212 &IID_IShellExtInit, (LPVOID*)&obj );
1213 if ( FAILED( r ) )
1215 ERR("failed %08x\n", r );
1216 goto end;
1219 dataobj = shellex_get_dataobj( sei );
1220 if ( !dataobj )
1222 ERR("failed to get data object\n");
1223 goto end;
1226 r = IShellExtInit_Initialize( obj, NULL, dataobj, hkey );
1227 if ( FAILED( r ) )
1228 goto end;
1230 r = IShellExtInit_QueryInterface( obj, &IID_IObjectWithSite, (LPVOID*) &ows );
1231 if ( FAILED( r ) )
1232 goto end;
1234 IObjectWithSite_SetSite( ows, NULL );
1236 r = shellex_run_context_menu_default( obj, sei );
1238 end:
1239 if ( ows )
1240 IObjectWithSite_Release( ows );
1241 if ( dataobj )
1242 IDataObject_Release( dataobj );
1243 if ( obj )
1244 IShellExtInit_Release( obj );
1245 CoUninitialize();
1246 return r;
1250 /*************************************************************************
1251 * ShellExecute_FromContextMenu [Internal]
1253 static LONG ShellExecute_FromContextMenu( LPSHELLEXECUTEINFOW sei )
1255 static const WCHAR szcm[] = { 's','h','e','l','l','e','x','\\',
1256 'C','o','n','t','e','x','t','M','e','n','u','H','a','n','d','l','e','r','s',0 };
1257 HKEY hkey, hkeycm = 0;
1258 WCHAR szguid[39];
1259 HRESULT hr;
1260 GUID guid;
1261 DWORD i;
1262 LONG r;
1264 TRACE("%s\n", debugstr_w(sei->lpFile) );
1266 hkey = ShellExecute_GetClassKey( sei );
1267 if ( !hkey )
1268 return ERROR_FUNCTION_FAILED;
1270 r = RegOpenKeyW( hkey, szcm, &hkeycm );
1271 if ( r == ERROR_SUCCESS )
1273 i = 0;
1274 while ( 1 )
1276 r = RegEnumKeyW( hkeycm, i++, szguid, sizeof(szguid)/sizeof(szguid[0]) );
1277 if ( r != ERROR_SUCCESS )
1278 break;
1280 hr = CLSIDFromString( szguid, &guid );
1281 if (SUCCEEDED(hr))
1283 /* stop at the first one that succeeds in running */
1284 hr = shellex_load_object_and_run( hkey, &guid, sei );
1285 if ( SUCCEEDED( hr ) )
1286 break;
1289 RegCloseKey( hkeycm );
1292 if ( hkey != sei->hkeyClass )
1293 RegCloseKey( hkey );
1294 return r;
1297 static UINT_PTR SHELL_execute_class( LPCWSTR wszApplicationName, LPSHELLEXECUTEINFOW psei, LPSHELLEXECUTEINFOW psei_out, SHELL_ExecuteW32 execfunc )
1299 static const WCHAR wSpace[] = {' ',0};
1300 WCHAR execCmd[1024], wcmd[1024];
1301 /* launch a document by fileclass like 'WordPad.Document.1' */
1302 /* the Commandline contains 'c:\Path\wordpad.exe "%1"' */
1303 /* FIXME: wcmd should not be of a fixed size. Fixed to 1024, MAX_PATH is way too short! */
1304 ULONG cmask=(psei->fMask & SEE_MASK_CLASSALL);
1305 DWORD resultLen;
1306 BOOL done;
1308 HCR_GetExecuteCommandW((cmask == SEE_MASK_CLASSKEY) ? psei->hkeyClass : NULL,
1309 (cmask == SEE_MASK_CLASSNAME) ? psei->lpClass: NULL,
1310 psei->lpVerb,
1311 execCmd, sizeof(execCmd));
1313 /* FIXME: get the extension of lpFile, check if it fits to the lpClass */
1314 TRACE("SEE_MASK_CLASSNAME->%s, doc->%s\n", debugstr_w(execCmd), debugstr_w(wszApplicationName));
1316 wcmd[0] = '\0';
1317 done = SHELL_ArgifyW(wcmd, sizeof(wcmd)/sizeof(WCHAR), execCmd, wszApplicationName, psei->lpIDList, NULL, &resultLen);
1318 if (!done && wszApplicationName[0])
1320 strcatW(wcmd, wSpace);
1321 strcatW(wcmd, wszApplicationName);
1323 if (resultLen > sizeof(wcmd)/sizeof(WCHAR))
1324 ERR("Argify buffer not large enough... truncating\n");
1325 return execfunc(wcmd, NULL, FALSE, psei, psei_out);
1328 static BOOL SHELL_translate_idlist( LPSHELLEXECUTEINFOW sei, LPWSTR wszParameters, DWORD parametersLen, LPWSTR wszApplicationName, DWORD dwApplicationNameLen )
1330 static const WCHAR wExplorer[] = {'e','x','p','l','o','r','e','r','.','e','x','e',0};
1331 WCHAR buffer[MAX_PATH];
1332 BOOL appKnownSingular = FALSE;
1334 /* last chance to translate IDList: now also allow CLSID paths */
1335 if (SUCCEEDED(SHELL_GetPathFromIDListForExecuteW(sei->lpIDList, buffer, sizeof(buffer)))) {
1336 if (buffer[0]==':' && buffer[1]==':') {
1337 /* open shell folder for the specified class GUID */
1338 if (strlenW(buffer) + 1 > parametersLen)
1339 ERR("parameters len exceeds buffer size (%i > %i), truncating\n",
1340 lstrlenW(buffer) + 1, parametersLen);
1341 lstrcpynW(wszParameters, buffer, parametersLen);
1342 if (strlenW(wExplorer) > dwApplicationNameLen)
1343 ERR("application len exceeds buffer size (%i > %i), truncating\n",
1344 lstrlenW(wExplorer) + 1, dwApplicationNameLen);
1345 lstrcpynW(wszApplicationName, wExplorer, dwApplicationNameLen);
1346 appKnownSingular = TRUE;
1348 sei->fMask &= ~SEE_MASK_INVOKEIDLIST;
1349 } else {
1350 WCHAR target[MAX_PATH];
1351 DWORD attribs;
1352 DWORD resultLen;
1353 /* Check if we're executing a directory and if so use the
1354 handler for the Folder class */
1355 strcpyW(target, buffer);
1356 attribs = GetFileAttributesW(buffer);
1357 if (attribs != INVALID_FILE_ATTRIBUTES &&
1358 (attribs & FILE_ATTRIBUTE_DIRECTORY) &&
1359 HCR_GetExecuteCommandW(0, wszFolder,
1360 sei->lpVerb,
1361 buffer, sizeof(buffer))) {
1362 SHELL_ArgifyW(wszApplicationName, dwApplicationNameLen,
1363 buffer, target, sei->lpIDList, NULL, &resultLen);
1364 if (resultLen > dwApplicationNameLen)
1365 ERR("Argify buffer not large enough... truncating\n");
1366 appKnownSingular = FALSE;
1368 sei->fMask &= ~SEE_MASK_INVOKEIDLIST;
1371 return appKnownSingular;
1374 static UINT_PTR SHELL_quote_and_execute( LPCWSTR wcmd, LPCWSTR wszParameters, LPCWSTR lpstrProtocol, LPCWSTR wszApplicationName, LPWSTR env, LPSHELLEXECUTEINFOW psei, LPSHELLEXECUTEINFOW psei_out, SHELL_ExecuteW32 execfunc )
1376 static const WCHAR wQuote[] = {'"',0};
1377 static const WCHAR wSpace[] = {' ',0};
1378 UINT_PTR retval;
1379 DWORD len;
1380 WCHAR *wszQuotedCmd;
1382 /* Length of quotes plus length of command plus NULL terminator */
1383 len = 2 + lstrlenW(wcmd) + 1;
1384 if (wszParameters[0])
1386 /* Length of space plus length of parameters */
1387 len += 1 + lstrlenW(wszParameters);
1389 wszQuotedCmd = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1390 /* Must quote to handle case where cmd contains spaces,
1391 * else security hole if malicious user creates executable file "C:\\Program"
1393 strcpyW(wszQuotedCmd, wQuote);
1394 strcatW(wszQuotedCmd, wcmd);
1395 strcatW(wszQuotedCmd, wQuote);
1396 if (wszParameters[0]) {
1397 strcatW(wszQuotedCmd, wSpace);
1398 strcatW(wszQuotedCmd, wszParameters);
1400 TRACE("%s/%s => %s/%s\n", debugstr_w(wszApplicationName), debugstr_w(psei->lpVerb), debugstr_w(wszQuotedCmd), debugstr_w(lpstrProtocol));
1401 if (*lpstrProtocol)
1402 retval = execute_from_key(lpstrProtocol, wszApplicationName, env, psei->lpParameters, wcmd, execfunc, psei, psei_out);
1403 else
1404 retval = execfunc(wszQuotedCmd, env, FALSE, psei, psei_out);
1405 HeapFree(GetProcessHeap(), 0, wszQuotedCmd);
1406 return retval;
1409 static UINT_PTR SHELL_execute_url( LPCWSTR lpFile, LPCWSTR wFile, LPCWSTR wcmd, LPSHELLEXECUTEINFOW psei, LPSHELLEXECUTEINFOW psei_out, SHELL_ExecuteW32 execfunc )
1411 static const WCHAR wShell[] = {'\\','s','h','e','l','l','\\',0};
1412 static const WCHAR wCommand[] = {'\\','c','o','m','m','a','n','d',0};
1413 UINT_PTR retval;
1414 WCHAR *lpstrProtocol;
1415 LPCWSTR lpstrRes;
1416 INT iSize;
1417 DWORD len;
1419 lpstrRes = strchrW(lpFile, ':');
1420 if (lpstrRes)
1421 iSize = lpstrRes - lpFile;
1422 else
1423 iSize = strlenW(lpFile);
1425 TRACE("Got URL: %s\n", debugstr_w(lpFile));
1426 /* Looking for ...protocol\shell\lpOperation\command */
1427 len = iSize + lstrlenW(wShell) + lstrlenW(wCommand) + 1;
1428 if (psei->lpVerb)
1429 len += lstrlenW(psei->lpVerb);
1430 else
1431 len += lstrlenW(wszOpen);
1432 lpstrProtocol = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1433 memcpy(lpstrProtocol, lpFile, iSize*sizeof(WCHAR));
1434 lpstrProtocol[iSize] = '\0';
1435 strcatW(lpstrProtocol, wShell);
1436 strcatW(lpstrProtocol, psei->lpVerb? psei->lpVerb: wszOpen);
1437 strcatW(lpstrProtocol, wCommand);
1439 /* Remove File Protocol from lpFile */
1440 /* In the case file://path/file */
1441 if (!strncmpiW(lpFile, wFile, iSize))
1443 lpFile += iSize;
1444 while (*lpFile == ':') lpFile++;
1446 retval = execute_from_key(lpstrProtocol, lpFile, NULL, psei->lpParameters,
1447 wcmd, execfunc, psei, psei_out);
1448 HeapFree(GetProcessHeap(), 0, lpstrProtocol);
1449 return retval;
1452 static void do_error_dialog( UINT_PTR retval, HWND hwnd )
1454 WCHAR msg[2048];
1455 int error_code=GetLastError();
1457 if (retval == SE_ERR_NOASSOC)
1458 LoadStringW(shell32_hInstance, IDS_SHLEXEC_NOASSOC, msg, sizeof(msg)/sizeof(WCHAR));
1459 else
1460 FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error_code, 0, msg, sizeof(msg)/sizeof(WCHAR), NULL);
1462 MessageBoxW(hwnd, msg, NULL, MB_ICONERROR);
1465 /*************************************************************************
1466 * SHELL_execute [Internal]
1468 static BOOL SHELL_execute( LPSHELLEXECUTEINFOW sei, SHELL_ExecuteW32 execfunc )
1470 static const WCHAR wSpace[] = {' ',0};
1471 static const WCHAR wWww[] = {'w','w','w',0};
1472 static const WCHAR wFile[] = {'f','i','l','e',0};
1473 static const WCHAR wHttp[] = {'h','t','t','p',':','/','/',0};
1474 static const DWORD unsupportedFlags =
1475 SEE_MASK_INVOKEIDLIST | SEE_MASK_ICON | SEE_MASK_HOTKEY |
1476 SEE_MASK_CONNECTNETDRV | SEE_MASK_FLAG_DDEWAIT |
1477 SEE_MASK_UNICODE | SEE_MASK_ASYNCOK | SEE_MASK_HMONITOR;
1479 WCHAR parametersBuffer[1024], dirBuffer[MAX_PATH], wcmdBuffer[1024];
1480 WCHAR *wszApplicationName, *wszParameters, *wszDir, *wcmd;
1481 DWORD dwApplicationNameLen = MAX_PATH+2;
1482 DWORD parametersLen = sizeof(parametersBuffer) / sizeof(WCHAR);
1483 DWORD dirLen = sizeof(dirBuffer) / sizeof(WCHAR);
1484 DWORD wcmdLen = sizeof(wcmdBuffer) / sizeof(WCHAR);
1485 DWORD len;
1486 SHELLEXECUTEINFOW sei_tmp; /* modifiable copy of SHELLEXECUTEINFO struct */
1487 WCHAR wfileName[MAX_PATH];
1488 WCHAR *env;
1489 WCHAR lpstrProtocol[256];
1490 LPCWSTR lpFile;
1491 UINT_PTR retval = SE_ERR_NOASSOC;
1492 BOOL appKnownSingular = FALSE;
1494 /* make a local copy of the LPSHELLEXECUTEINFO structure and work with this from now on */
1495 sei_tmp = *sei;
1497 TRACE("mask=0x%08x hwnd=%p verb=%s file=%s parm=%s dir=%s show=0x%08x class=%s\n",
1498 sei_tmp.fMask, sei_tmp.hwnd, debugstr_w(sei_tmp.lpVerb),
1499 debugstr_w(sei_tmp.lpFile), debugstr_w(sei_tmp.lpParameters),
1500 debugstr_w(sei_tmp.lpDirectory), sei_tmp.nShow,
1501 ((sei_tmp.fMask & SEE_MASK_CLASSALL) == SEE_MASK_CLASSNAME) ?
1502 debugstr_w(sei_tmp.lpClass) : "not used");
1504 sei->hProcess = NULL;
1506 /* make copies of all path/command strings */
1507 if (!sei_tmp.lpFile)
1509 wszApplicationName = HeapAlloc(GetProcessHeap(), 0, dwApplicationNameLen*sizeof(WCHAR));
1510 *wszApplicationName = '\0';
1512 else if (*sei_tmp.lpFile == '\"')
1514 DWORD l = strlenW(sei_tmp.lpFile+1);
1515 if(l >= dwApplicationNameLen) dwApplicationNameLen = l+1;
1516 wszApplicationName = HeapAlloc(GetProcessHeap(), 0, dwApplicationNameLen*sizeof(WCHAR));
1517 memcpy(wszApplicationName, sei_tmp.lpFile+1, (l+1)*sizeof(WCHAR));
1518 if (wszApplicationName[l-1] == '\"')
1519 wszApplicationName[l-1] = '\0';
1520 appKnownSingular = TRUE;
1521 TRACE("wszApplicationName=%s\n",debugstr_w(wszApplicationName));
1522 } else {
1523 DWORD l = strlenW(sei_tmp.lpFile)+1;
1524 if(l > dwApplicationNameLen) dwApplicationNameLen = l+1;
1525 wszApplicationName = HeapAlloc(GetProcessHeap(), 0, dwApplicationNameLen*sizeof(WCHAR));
1526 memcpy(wszApplicationName, sei_tmp.lpFile, l*sizeof(WCHAR));
1529 wszParameters = parametersBuffer;
1530 if (sei_tmp.lpParameters)
1532 len = lstrlenW(sei_tmp.lpParameters) + 1;
1533 if (len > parametersLen)
1535 wszParameters = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1536 parametersLen = len;
1538 strcpyW(wszParameters, sei_tmp.lpParameters);
1540 else
1541 *wszParameters = '\0';
1543 wszDir = dirBuffer;
1544 if (sei_tmp.lpDirectory)
1546 len = lstrlenW(sei_tmp.lpDirectory) + 1;
1547 if (len > dirLen)
1549 wszDir = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1550 dirLen = len;
1552 strcpyW(wszDir, sei_tmp.lpDirectory);
1554 else
1555 *wszDir = '\0';
1557 /* adjust string pointers to point to the new buffers */
1558 sei_tmp.lpFile = wszApplicationName;
1559 sei_tmp.lpParameters = wszParameters;
1560 sei_tmp.lpDirectory = wszDir;
1562 if (sei_tmp.fMask & unsupportedFlags)
1564 FIXME("flags ignored: 0x%08x\n", sei_tmp.fMask & unsupportedFlags);
1567 /* process the IDList */
1568 if (sei_tmp.fMask & SEE_MASK_IDLIST)
1570 IShellExecuteHookW* pSEH;
1572 HRESULT hr = SHBindToParent(sei_tmp.lpIDList, &IID_IShellExecuteHookW, (LPVOID*)&pSEH, NULL);
1574 if (SUCCEEDED(hr))
1576 hr = IShellExecuteHookW_Execute(pSEH, &sei_tmp);
1578 IShellExecuteHookW_Release(pSEH);
1580 if (hr == S_OK) {
1581 HeapFree(GetProcessHeap(), 0, wszApplicationName);
1582 if (wszParameters != parametersBuffer)
1583 HeapFree(GetProcessHeap(), 0, wszParameters);
1584 if (wszDir != dirBuffer)
1585 HeapFree(GetProcessHeap(), 0, wszDir);
1586 return TRUE;
1590 SHGetPathFromIDListW(sei_tmp.lpIDList, wszApplicationName);
1591 appKnownSingular = TRUE;
1592 TRACE("-- idlist=%p (%s)\n", sei_tmp.lpIDList, debugstr_w(wszApplicationName));
1595 if ( ERROR_SUCCESS == ShellExecute_FromContextMenu( &sei_tmp ) )
1597 sei->hInstApp = (HINSTANCE) 33;
1598 HeapFree(GetProcessHeap(), 0, wszApplicationName);
1599 if (wszParameters != parametersBuffer)
1600 HeapFree(GetProcessHeap(), 0, wszParameters);
1601 if (wszDir != dirBuffer)
1602 HeapFree(GetProcessHeap(), 0, wszDir);
1603 return TRUE;
1606 if (sei_tmp.fMask & SEE_MASK_CLASSALL)
1608 retval = SHELL_execute_class( wszApplicationName, &sei_tmp, sei,
1609 execfunc );
1610 if (retval <= 32 && !(sei_tmp.fMask & SEE_MASK_FLAG_NO_UI))
1611 do_error_dialog(retval, sei_tmp.hwnd);
1612 HeapFree(GetProcessHeap(), 0, wszApplicationName);
1613 if (wszParameters != parametersBuffer)
1614 HeapFree(GetProcessHeap(), 0, wszParameters);
1615 if (wszDir != dirBuffer)
1616 HeapFree(GetProcessHeap(), 0, wszDir);
1617 return retval > 32;
1620 /* Has the IDList not yet been translated? */
1621 if (sei_tmp.fMask & SEE_MASK_IDLIST)
1623 appKnownSingular = SHELL_translate_idlist( &sei_tmp, wszParameters,
1624 parametersLen,
1625 wszApplicationName,
1626 dwApplicationNameLen );
1629 /* expand environment strings */
1630 len = ExpandEnvironmentStringsW(sei_tmp.lpFile, NULL, 0);
1631 if (len>0)
1633 LPWSTR buf;
1634 buf = HeapAlloc(GetProcessHeap(),0,(len+1)*sizeof(WCHAR));
1636 ExpandEnvironmentStringsW(sei_tmp.lpFile, buf, len+1);
1637 HeapFree(GetProcessHeap(), 0, wszApplicationName);
1638 dwApplicationNameLen = len+1;
1639 wszApplicationName = buf;
1640 /* appKnownSingular unmodified */
1642 sei_tmp.lpFile = wszApplicationName;
1645 if (*sei_tmp.lpParameters)
1647 len = ExpandEnvironmentStringsW(sei_tmp.lpParameters, NULL, 0);
1648 if (len > 0)
1650 LPWSTR buf;
1651 len++;
1652 buf = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
1653 ExpandEnvironmentStringsW(sei_tmp.lpParameters, buf, len);
1654 if (wszParameters != parametersBuffer)
1655 HeapFree(GetProcessHeap(), 0, wszParameters);
1656 wszParameters = buf;
1657 parametersLen = len;
1658 sei_tmp.lpParameters = wszParameters;
1662 if (*sei_tmp.lpDirectory)
1664 len = ExpandEnvironmentStringsW(sei_tmp.lpDirectory, NULL, 0);
1665 if (len > 0)
1667 LPWSTR buf;
1668 len++;
1669 buf = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
1670 ExpandEnvironmentStringsW(sei_tmp.lpDirectory, buf, len);
1671 if (wszDir != dirBuffer)
1672 HeapFree(GetProcessHeap(), 0, wszDir);
1673 wszDir = buf;
1674 sei_tmp.lpDirectory = wszDir;
1678 /* Else, try to execute the filename */
1679 TRACE("execute:%s,%s,%s\n", debugstr_w(wszApplicationName), debugstr_w(wszParameters), debugstr_w(wszDir));
1681 /* separate out command line arguments from executable file name */
1682 if (!*sei_tmp.lpParameters && !appKnownSingular) {
1683 /* If the executable path is quoted, handle the rest of the command line as parameters. */
1684 if (sei_tmp.lpFile[0] == '"') {
1685 LPWSTR src = wszApplicationName/*sei_tmp.lpFile*/ + 1;
1686 LPWSTR dst = wfileName;
1687 LPWSTR end;
1689 /* copy the unquoted executable path to 'wfileName' */
1690 while(*src && *src!='"')
1691 *dst++ = *src++;
1693 *dst = '\0';
1695 if (*src == '"') {
1696 end = ++src;
1698 while(isspace(*src))
1699 ++src;
1700 } else
1701 end = src;
1703 /* copy the parameter string to 'wszParameters' */
1704 strcpyW(wszParameters, src);
1706 /* terminate previous command string after the quote character */
1707 *end = '\0';
1709 else
1711 /* If the executable name is not quoted, we have to use this search loop here,
1712 that in CreateProcess() is not sufficient because it does not handle shell links. */
1713 WCHAR buffer[MAX_PATH], xlpFile[MAX_PATH];
1714 LPWSTR space, s;
1716 LPWSTR beg = wszApplicationName/*sei_tmp.lpFile*/;
1717 for(s=beg; (space=strchrW(s, ' ')); s=space+1) {
1718 int idx = space-sei_tmp.lpFile;
1719 memcpy(buffer, sei_tmp.lpFile, idx * sizeof(WCHAR));
1720 buffer[idx] = '\0';
1722 /*FIXME This finds directory paths if the targeted file name contains spaces. */
1723 if (SearchPathW(*sei_tmp.lpDirectory? sei_tmp.lpDirectory: NULL, buffer, wszExe, sizeof(xlpFile)/sizeof(xlpFile[0]), xlpFile, NULL))
1725 /* separate out command from parameter string */
1726 LPCWSTR p = space + 1;
1728 while(isspaceW(*p))
1729 ++p;
1731 strcpyW(wszParameters, p);
1732 *space = '\0';
1734 break;
1738 lstrcpynW(wfileName, sei_tmp.lpFile,sizeof(wfileName)/sizeof(WCHAR));
1740 } else
1741 lstrcpynW(wfileName, sei_tmp.lpFile,sizeof(wfileName)/sizeof(WCHAR));
1743 lpFile = wfileName;
1745 wcmd = wcmdBuffer;
1746 len = lstrlenW(wszApplicationName) + 1;
1747 if (sei_tmp.lpParameters[0])
1748 len += 1 + lstrlenW(wszParameters);
1749 if (len > wcmdLen)
1751 wcmd = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1752 wcmdLen = len;
1754 strcpyW(wcmd, wszApplicationName);
1755 if (sei_tmp.lpParameters[0]) {
1756 strcatW(wcmd, wSpace);
1757 strcatW(wcmd, wszParameters);
1760 retval = execfunc(wcmd, NULL, FALSE, &sei_tmp, sei);
1761 if (retval > 32) {
1762 HeapFree(GetProcessHeap(), 0, wszApplicationName);
1763 if (wszParameters != parametersBuffer)
1764 HeapFree(GetProcessHeap(), 0, wszParameters);
1765 if (wszDir != dirBuffer)
1766 HeapFree(GetProcessHeap(), 0, wszDir);
1767 if (wcmd != wcmdBuffer)
1768 HeapFree(GetProcessHeap(), 0, wcmd);
1769 return TRUE;
1772 /* Else, try to find the executable */
1773 wcmd[0] = '\0';
1774 retval = SHELL_FindExecutable(sei_tmp.lpDirectory, lpFile, sei_tmp.lpVerb, wcmd, wcmdLen, lpstrProtocol, &env, sei_tmp.lpIDList, sei_tmp.lpParameters);
1775 if (retval > 32) /* Found */
1777 retval = SHELL_quote_and_execute( wcmd, wszParameters, lpstrProtocol,
1778 wszApplicationName, env, &sei_tmp,
1779 sei, execfunc );
1780 HeapFree( GetProcessHeap(), 0, env );
1782 else if (PathIsDirectoryW(lpFile))
1784 static const WCHAR wExplorer[] = {'e','x','p','l','o','r','e','r',0};
1785 static const WCHAR wQuote[] = {'"',0};
1786 WCHAR wExec[MAX_PATH];
1787 WCHAR * lpQuotedFile = HeapAlloc( GetProcessHeap(), 0, sizeof(WCHAR) * (strlenW(lpFile) + 3) );
1789 if (lpQuotedFile)
1791 retval = SHELL_FindExecutable( sei_tmp.lpDirectory, wExplorer,
1792 wszOpen, wExec, MAX_PATH,
1793 NULL, &env, NULL, NULL );
1794 if (retval > 32)
1796 strcpyW(lpQuotedFile, wQuote);
1797 strcatW(lpQuotedFile, lpFile);
1798 strcatW(lpQuotedFile, wQuote);
1799 retval = SHELL_quote_and_execute( wExec, lpQuotedFile,
1800 lpstrProtocol,
1801 wszApplicationName, env,
1802 &sei_tmp, sei, execfunc );
1803 HeapFree( GetProcessHeap(), 0, env );
1805 HeapFree( GetProcessHeap(), 0, lpQuotedFile );
1807 else
1808 retval = 0; /* Out of memory */
1810 else if (PathIsURLW(lpFile)) /* File not found, check for URL */
1812 retval = SHELL_execute_url( lpFile, wFile, wcmd, &sei_tmp, sei, execfunc );
1814 /* Check if file specified is in the form www.??????.*** */
1815 else if (!strncmpiW(lpFile, wWww, 3))
1817 /* if so, append lpFile http:// and call ShellExecute */
1818 WCHAR lpstrTmpFile[256];
1819 strcpyW(lpstrTmpFile, wHttp);
1820 strcatW(lpstrTmpFile, lpFile);
1821 retval = (UINT_PTR)ShellExecuteW(sei_tmp.hwnd, sei_tmp.lpVerb, lpstrTmpFile, NULL, NULL, 0);
1824 TRACE("retval %lu\n", retval);
1826 HeapFree(GetProcessHeap(), 0, wszApplicationName);
1827 if (wszParameters != parametersBuffer)
1828 HeapFree(GetProcessHeap(), 0, wszParameters);
1829 if (wszDir != dirBuffer)
1830 HeapFree(GetProcessHeap(), 0, wszDir);
1831 if (wcmd != wcmdBuffer)
1832 HeapFree(GetProcessHeap(), 0, wcmd);
1834 sei->hInstApp = (HINSTANCE)(retval > 32 ? 33 : retval);
1836 if (retval <= 32 && !(sei_tmp.fMask & SEE_MASK_FLAG_NO_UI))
1837 do_error_dialog(retval, sei_tmp.hwnd);
1838 return retval > 32;
1841 /*************************************************************************
1842 * ShellExecuteA [SHELL32.290]
1844 HINSTANCE WINAPI ShellExecuteA(HWND hWnd, LPCSTR lpOperation,LPCSTR lpFile,
1845 LPCSTR lpParameters,LPCSTR lpDirectory, INT iShowCmd)
1847 SHELLEXECUTEINFOA sei;
1849 TRACE("%p,%s,%s,%s,%s,%d\n",
1850 hWnd, debugstr_a(lpOperation), debugstr_a(lpFile),
1851 debugstr_a(lpParameters), debugstr_a(lpDirectory), iShowCmd);
1853 sei.cbSize = sizeof(sei);
1854 sei.fMask = SEE_MASK_FLAG_NO_UI;
1855 sei.hwnd = hWnd;
1856 sei.lpVerb = lpOperation;
1857 sei.lpFile = lpFile;
1858 sei.lpParameters = lpParameters;
1859 sei.lpDirectory = lpDirectory;
1860 sei.nShow = iShowCmd;
1861 sei.lpIDList = 0;
1862 sei.lpClass = 0;
1863 sei.hkeyClass = 0;
1864 sei.dwHotKey = 0;
1865 sei.hProcess = 0;
1867 ShellExecuteExA (&sei);
1868 return sei.hInstApp;
1871 /*************************************************************************
1872 * ShellExecuteExA [SHELL32.292]
1875 BOOL WINAPI DECLSPEC_HOTPATCH ShellExecuteExA (LPSHELLEXECUTEINFOA sei)
1877 SHELLEXECUTEINFOW seiW;
1878 BOOL ret;
1879 WCHAR *wVerb = NULL, *wFile = NULL, *wParameters = NULL, *wDirectory = NULL, *wClass = NULL;
1881 TRACE("%p\n", sei);
1883 memcpy(&seiW, sei, sizeof(SHELLEXECUTEINFOW));
1885 if (sei->lpVerb)
1886 seiW.lpVerb = __SHCloneStrAtoW(&wVerb, sei->lpVerb);
1888 if (sei->lpFile)
1889 seiW.lpFile = __SHCloneStrAtoW(&wFile, sei->lpFile);
1891 if (sei->lpParameters)
1892 seiW.lpParameters = __SHCloneStrAtoW(&wParameters, sei->lpParameters);
1894 if (sei->lpDirectory)
1895 seiW.lpDirectory = __SHCloneStrAtoW(&wDirectory, sei->lpDirectory);
1897 if ((sei->fMask & SEE_MASK_CLASSALL) == SEE_MASK_CLASSNAME && sei->lpClass)
1898 seiW.lpClass = __SHCloneStrAtoW(&wClass, sei->lpClass);
1899 else
1900 seiW.lpClass = NULL;
1902 ret = SHELL_execute( &seiW, SHELL_ExecuteW );
1904 sei->hInstApp = seiW.hInstApp;
1906 if (sei->fMask & SEE_MASK_NOCLOSEPROCESS)
1907 sei->hProcess = seiW.hProcess;
1909 SHFree(wVerb);
1910 SHFree(wFile);
1911 SHFree(wParameters);
1912 SHFree(wDirectory);
1913 SHFree(wClass);
1915 return ret;
1918 /*************************************************************************
1919 * ShellExecuteExW [SHELL32.293]
1922 BOOL WINAPI DECLSPEC_HOTPATCH ShellExecuteExW (LPSHELLEXECUTEINFOW sei)
1924 return SHELL_execute( sei, SHELL_ExecuteW );
1927 /*************************************************************************
1928 * ShellExecuteW [SHELL32.294]
1929 * from shellapi.h
1930 * WINSHELLAPI HINSTANCE APIENTRY ShellExecuteW(HWND hwnd, LPCWSTR lpOperation,
1931 * LPCWSTR lpFile, LPCWSTR lpParameters, LPCWSTR lpDirectory, INT nShowCmd);
1933 HINSTANCE WINAPI ShellExecuteW(HWND hwnd, LPCWSTR lpOperation, LPCWSTR lpFile,
1934 LPCWSTR lpParameters, LPCWSTR lpDirectory, INT nShowCmd)
1936 SHELLEXECUTEINFOW sei;
1938 TRACE("\n");
1939 sei.cbSize = sizeof(sei);
1940 sei.fMask = SEE_MASK_FLAG_NO_UI;
1941 sei.hwnd = hwnd;
1942 sei.lpVerb = lpOperation;
1943 sei.lpFile = lpFile;
1944 sei.lpParameters = lpParameters;
1945 sei.lpDirectory = lpDirectory;
1946 sei.nShow = nShowCmd;
1947 sei.lpIDList = 0;
1948 sei.lpClass = 0;
1949 sei.hkeyClass = 0;
1950 sei.dwHotKey = 0;
1951 sei.hProcess = 0;
1953 SHELL_execute( &sei, SHELL_ExecuteW );
1954 return sei.hInstApp;
1957 /*************************************************************************
1958 * WOWShellExecute [SHELL32.@]
1960 * FIXME: the callback function most likely doesn't work the same way on Windows.
1962 HINSTANCE WINAPI WOWShellExecute(HWND hWnd, LPCSTR lpOperation,LPCSTR lpFile,
1963 LPCSTR lpParameters,LPCSTR lpDirectory, INT iShowCmd, void *callback)
1965 SHELLEXECUTEINFOW seiW;
1966 WCHAR *wVerb = NULL, *wFile = NULL, *wParameters = NULL, *wDirectory = NULL;
1967 HANDLE hProcess = 0;
1969 seiW.lpVerb = lpOperation ? __SHCloneStrAtoW(&wVerb, lpOperation) : NULL;
1970 seiW.lpFile = lpFile ? __SHCloneStrAtoW(&wFile, lpFile) : NULL;
1971 seiW.lpParameters = lpParameters ? __SHCloneStrAtoW(&wParameters, lpParameters) : NULL;
1972 seiW.lpDirectory = lpDirectory ? __SHCloneStrAtoW(&wDirectory, lpDirectory) : NULL;
1974 seiW.cbSize = sizeof(seiW);
1975 seiW.fMask = 0;
1976 seiW.hwnd = hWnd;
1977 seiW.nShow = iShowCmd;
1978 seiW.lpIDList = 0;
1979 seiW.lpClass = 0;
1980 seiW.hkeyClass = 0;
1981 seiW.dwHotKey = 0;
1982 seiW.hProcess = hProcess;
1984 SHELL_execute( &seiW, callback );
1986 SHFree(wVerb);
1987 SHFree(wFile);
1988 SHFree(wParameters);
1989 SHFree(wDirectory);
1990 return seiW.hInstApp;
1993 /*************************************************************************
1994 * OpenAs_RunDLLA [SHELL32.@]
1996 void WINAPI OpenAs_RunDLLA(HWND hwnd, HINSTANCE hinst, LPCSTR cmdline, int cmdshow)
1998 FIXME("%p, %p, %s, %d\n", hwnd, hinst, debugstr_a(cmdline), cmdshow);
2001 /*************************************************************************
2002 * OpenAs_RunDLLW [SHELL32.@]
2004 void WINAPI OpenAs_RunDLLW(HWND hwnd, HINSTANCE hinst, LPCWSTR cmdline, int cmdshow)
2006 FIXME("%p, %p, %s, %d\n", hwnd, hinst, debugstr_w(cmdline), cmdshow);