removed unnecessary commented out lines
[reactos.git] / reactos / lib / shell32 / shlexec.c
1 /*
2 * Shell Library Functions
3 *
4 * Copyright 1998 Marcus Meissner
5 * Copyright 2002 Eric Pouech
6 *
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.
11 *
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.
16 *
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22 #include "config.h"
23 #include "wine/port.h"
24
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>
34
35 #include "windef.h"
36 #include "winbase.h"
37 #include "winerror.h"
38 #include "winreg.h"
39 #include "wownt32.h"
40 #include "heap.h"
41 #include "shellapi.h"
42 #include "wingdi.h"
43 #include "winuser.h"
44 #include "shlobj.h"
45 #include "shlwapi.h"
46 #include "ddeml.h"
47
48 #include "wine/winbase16.h"
49 #include "shell32_main.h"
50 #include "undocshell.h"
51 #include "pidl.h"
52
53 #include "wine/debug.h"
54
55 WINE_DEFAULT_DEBUG_CHANNEL(exec);
56
57 /***********************************************************************
58 * this function is supposed to expand the escape sequences found in the registry
59 * some diving reported that the following were used:
60 * + %1, %2... seem to report to parameter of index N in ShellExecute pmts
61 * %1 file
62 * %2 printer
63 * %3 driver
64 * %4 port
65 * %I address of a global item ID (explorer switch /idlist)
66 * %L seems to be %1 as long filename followed by the 8+3 variation
67 * %S ???
68 * %* all following parameters (see batfile)
69 */
70 static BOOL argifyA(char* out, int len, const char* fmt, const char* lpFile, LPITEMIDLIST pidl, LPCSTR args)
71 {
72 char xlpFile[1024];
73 BOOL done = FALSE;
74 LPVOID pv;
75 char *res = out;
76 const char *cmd;
77
78 while (*fmt)
79 {
80 if (*fmt == '%')
81 {
82 switch (*++fmt)
83 {
84 case '\0':
85 case '%':
86 *res++ = '%';
87 break;
88
89 case '2':
90 case '3':
91 case '4':
92 case '5':
93 case '6':
94 case '7':
95 case '8':
96 case '9':
97 case '0':
98 case '*':
99 if (args)
100 {
101 if (*fmt == '*')
102 {
103 *res++ = '"';
104 while(*args)
105 *res++ = *args++;
106 *res++ = '"';
107 }
108 else
109 {
110 while(*args && !isspace(*args))
111 *res++ = *args++;
112
113 while(isspace(*args))
114 ++args;
115 }
116 }
117 else
118 {
119 case '1':
120 if (!done || (*fmt == '1'))
121 {
122 /*FIXME Is SearchPath() really needed? We already have separated out the parameter string in args. */
123 if (SearchPathA(NULL, lpFile, ".exe", sizeof(xlpFile), xlpFile, NULL))
124 cmd = xlpFile;
125 else
126 cmd = lpFile;
127
128 /* Add double quotation marks unless we already have them (e.g.: "%1" %* for exefile) */
129 if (res != out && *(res - 1) == '"')
130 {
131 strcpy(res, cmd);
132 res += strlen(cmd);
133 }
134 else
135 {
136 strcpy(res, cmd);
137 res += strlen(cmd);
138 }
139 }
140 }
141 break;
142
143 /*
144 * IE uses this alot for activating things such as windows media
145 * player. This is not verified to be fully correct but it appears
146 * to work just fine.
147 */
148 case 'l':
149 case 'L':
150 if (lpFile) {
151 strcpy(res, lpFile);
152 res += strlen(lpFile);
153 }
154 break;
155
156 case 'i':
157 case 'I':
158 if (pidl) {
159 HGLOBAL hmem = SHAllocShared(pidl, ILGetSize(pidl), 0);
160 pv = SHLockShared(hmem, 0);
161 res += sprintf(res, ":%p", pv);
162 SHUnlockShared(pv);
163 }
164 break;
165
166 default: FIXME("Unknown escape sequence %%%c\n", *fmt);
167 }
168
169 fmt++;
170 done = TRUE;
171 }
172 else
173 *res++ = *fmt++;
174 }
175
176 *res = '\0';
177
178 return done;
179 }
180
181 HRESULT SHELL_GetPathFromIDListForExecuteA(LPCITEMIDLIST pidl, LPSTR pszPath, UINT uOutSize)
182 {
183 STRRET strret;
184 IShellFolder* desktop;
185
186 HRESULT hr = SHGetDesktopFolder(&desktop);
187
188 if (SUCCEEDED(hr)) {
189 hr = IShellFolder_GetDisplayNameOf(desktop, pidl, SHGDN_FORPARSING, &strret);
190
191 if (SUCCEEDED(hr))
192 StrRetToStrNA(pszPath, uOutSize, &strret, pidl);
193
194 IShellFolder_Release(desktop);
195 }
196
197 return hr;
198 }
199
200 HRESULT SHELL_GetPathFromIDListForExecuteW(LPCITEMIDLIST pidl, LPWSTR pszPath, UINT uOutSize)
201 {
202 STRRET strret;
203 IShellFolder* desktop;
204
205 HRESULT hr = SHGetDesktopFolder(&desktop);
206
207 if (SUCCEEDED(hr)) {
208 hr = IShellFolder_GetDisplayNameOf(desktop, pidl, SHGDN_FORPARSING, &strret);
209
210 if (SUCCEEDED(hr))
211 StrRetToStrNW(pszPath, uOutSize, &strret, pidl);
212
213 IShellFolder_Release(desktop);
214 }
215
216 return hr;
217 }
218
219 /*************************************************************************
220 * SHELL_ResolveShortCutW [Internal]
221 * read shortcut file at 'wcmd' and fill psei with its content
222 */
223 static HRESULT SHELL_ResolveShortCutW(LPWSTR wcmd, LPWSTR wargs, LPWSTR wdir, HWND hwnd, LPCWSTR lpVerb, int* pshowcmd, LPITEMIDLIST* ppidl)
224 {
225 IShellFolder* psf;
226
227 HRESULT hr = SHGetDesktopFolder(&psf);
228
229 *ppidl = NULL;
230
231 if (SUCCEEDED(hr)) {
232 LPITEMIDLIST pidl;
233 ULONG l;
234
235 hr = IShellFolder_ParseDisplayName(psf, 0, 0, wcmd, &l, &pidl, 0);
236
237 if (SUCCEEDED(hr)) {
238 IShellLinkW* psl;
239
240 hr = IShellFolder_GetUIObjectOf(psf, NULL, 1, (LPCITEMIDLIST*)&pidl, &IID_IShellLinkW, NULL, (LPVOID*)&psl);
241
242 if (SUCCEEDED(hr)) {
243 hr = IShellLinkW_Resolve(psl, hwnd, 0);
244
245 if (SUCCEEDED(hr)) {
246 hr = IShellLinkW_GetPath(psl, wcmd, MAX_PATH, NULL, SLGP_UNCPRIORITY);
247
248 if (SUCCEEDED(hr)) {
249 if (!*wcmd) {
250 /* We could not translate the PIDL in the shell link into a valid file system path - so return the PIDL instead. */
251 hr = IShellLinkW_GetIDList(psl, ppidl);
252
253 if (SUCCEEDED(hr) && *ppidl) {
254 /* We got a PIDL instead of a file system path - try to translate it. */
255 if (SUCCEEDED(SHELL_GetPathFromIDListW(*ppidl, wcmd, MAX_PATH))) {
256 SHFree(*ppidl);
257 *ppidl = NULL;
258 }
259 }
260 }
261
262 if (SUCCEEDED(hr)) {
263 /* get command line arguments, working directory and display mode if available */
264 IShellLinkW_GetWorkingDirectory(psl, wdir, MAX_PATH);
265 IShellLinkW_GetArguments(psl, wargs, MAX_PATH);
266 IShellLinkW_GetShowCmd(psl, pshowcmd);
267 }
268 }
269 }
270
271 IShellLinkW_Release(psl);
272 }
273
274 SHFree(pidl);
275 }
276
277 IShellFolder_Release(psf);
278 }
279
280 return hr;
281 }
282
283 /*************************************************************************
284 * SHELL_ResolveShortCutA [Internal]
285 * read shortcut file at 'psei->lpFile' and fill psei with its content
286 */
287 static HRESULT SHELL_ResolveShortCutA(LPSHELLEXECUTEINFOA psei)
288 {
289 WCHAR wcmd[MAX_PATH], wargs[MAX_PATH], wdir[MAX_PATH], wverb[MAX_PATH];
290
291 HRESULT hr = S_OK;
292
293 if (MultiByteToWideChar(CP_ACP, 0, psei->lpFile, -1, wcmd, MAX_PATH)) {
294 MultiByteToWideChar(CP_ACP, 0, psei->lpDirectory, -1, wdir, MAX_PATH);
295 MultiByteToWideChar(CP_ACP, 0, psei->lpVerb?psei->lpVerb:"", -1, wverb, MAX_PATH);
296
297 hr = SHELL_ResolveShortCutW(wcmd, wargs, wdir, psei->hwnd, wverb, &psei->nShow, (LPITEMIDLIST*)&psei->lpIDList);
298
299 if (psei->lpIDList)
300 psei->fMask |= SEE_MASK_IDLIST;
301
302 if (SUCCEEDED(hr)) {
303 WideCharToMultiByte(CP_ACP, 0, wcmd, -1, (LPSTR)psei->lpFile, MAX_PATH/*sizeof(szApplicationName)*/, NULL, NULL);
304 WideCharToMultiByte(CP_ACP, 0, wdir, -1, (LPSTR)psei->lpDirectory, MAX_PATH/*sizeof(szDir)*/, NULL, NULL);
305 WideCharToMultiByte(CP_ACP, 0, wargs, -1, (LPSTR)psei->lpParameters, MAX_PATH/*sizeof(szParameters)*/, NULL, NULL);
306 } else
307 FIXME("We could not resolve the shell shortcut.\n");
308 }
309
310 return hr;
311 }
312
313 /*************************************************************************
314 * SHELL_ExecuteA [Internal]
315 *
316 */
317 static UINT SHELL_ExecuteA(const char *lpCmd, void *env, BOOL shWait,
318 LPSHELLEXECUTEINFOA psei, LPSHELLEXECUTEINFOA psei_out)
319 {
320 STARTUPINFOA startup;
321 PROCESS_INFORMATION info;
322 UINT retval = 31;
323
324 TRACE("Execute %s from directory %s\n", lpCmd, psei->lpDirectory);
325
326 ZeroMemory(&startup,sizeof(STARTUPINFOA));
327 startup.cb = sizeof(STARTUPINFOA);
328 startup.dwFlags = STARTF_USESHOWWINDOW;
329 startup.wShowWindow = psei->nShow;
330
331 if (CreateProcessA(NULL, (LPSTR)lpCmd, NULL, NULL, FALSE, 0,
332 env, *psei->lpDirectory? psei->lpDirectory: NULL, &startup, &info))
333 {
334 /* Give 30 seconds to the app to come up, if desired. Probably only needed
335 when starting app immediately before making a DDE connection. */
336 if (shWait)
337 if (WaitForInputIdle( info.hProcess, 30000 ) == -1)
338 WARN("WaitForInputIdle failed: Error %ld\n", GetLastError() );
339 retval = 33;
340
341 if (psei->fMask & SEE_MASK_NOCLOSEPROCESS)
342 psei_out->hProcess = info.hProcess;
343 else
344 CloseHandle(info.hProcess);
345
346 CloseHandle(info.hThread);
347 }
348 else if ((retval = GetLastError()) >= 32)
349 {
350 FIXME("Strange error set by CreateProcess: %d\n", retval);
351 retval = ERROR_BAD_FORMAT;
352 }
353
354 psei_out->hInstApp = (HINSTANCE)retval;
355 return retval;
356 }
357
358
359 /***********************************************************************
360 * build_env
361 *
362 * Build the environment for the new process, adding the specified
363 * path to the PATH variable. Returned pointer must be freed by caller.
364 */
365 static void *build_env( const char *path )
366 {
367 char *strings, *new_env;
368 char *p, *p2;
369 int total = strlen(path) + 1;
370 BOOL got_path = FALSE;
371
372 if (!(strings = GetEnvironmentStringsA())) return NULL;
373 p = strings;
374 while (*p)
375 {
376 int len = strlen(p) + 1;
377 if (!strncasecmp( p, "PATH=", 5 )) got_path = TRUE;
378 total += len;
379 p += len;
380 }
381 if (!got_path) total += 5; /* we need to create PATH */
382 total++; /* terminating null */
383
384 if (!(new_env = HeapAlloc( GetProcessHeap(), 0, total )))
385 {
386 FreeEnvironmentStringsA( strings );
387 return NULL;
388 }
389 p = strings;
390 p2 = new_env;
391 while (*p)
392 {
393 int len = strlen(p) + 1;
394 memcpy( p2, p, len );
395 if (!strncasecmp( p, "PATH=", 5 ))
396 {
397 p2[len - 1] = ';';
398 strcpy( p2 + len, path );
399 p2 += strlen(path) + 1;
400 }
401 p += len;
402 p2 += len;
403 }
404 if (!got_path)
405 {
406 strcpy( p2, "PATH=" );
407 strcat( p2, path );
408 p2 += strlen(p2) + 1;
409 }
410 *p2 = 0;
411 FreeEnvironmentStringsA( strings );
412 return new_env;
413 }
414
415
416 /***********************************************************************
417 * SHELL_TryAppPath
418 *
419 * Helper function for SHELL_FindExecutable
420 * @param lpResult - pointer to a buffer of size MAX_PATH
421 * On entry: szName is a filename (probably without path separators).
422 * On exit: if szName found in "App Path", place full path in lpResult, and return true
423 */
424 static BOOL SHELL_TryAppPath(LPCSTR szName, LPSTR lpResult, void** env)
425 {
426 HKEY hkApp = 0;
427 char buffer[256];
428 LONG len;
429 LONG res;
430 BOOL found = FALSE;
431
432 if (env) *env = NULL;
433 sprintf(buffer, "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\%s", szName);
434 res = RegOpenKeyExA(HKEY_LOCAL_MACHINE, buffer, 0, KEY_READ, &hkApp);
435 if (res) goto end;
436
437 len = MAX_PATH;
438 res = RegQueryValueA(hkApp, NULL, lpResult, &len);
439 if (res) goto end;
440 found = TRUE;
441
442 if (env)
443 {
444 DWORD count = sizeof(buffer);
445 if (!RegQueryValueExA(hkApp, "Path", NULL, NULL, buffer, &count) && buffer[0])
446 *env = build_env( buffer );
447 }
448
449 end:
450 if (hkApp) RegCloseKey(hkApp);
451 return found;
452 }
453
454 static UINT _FindExecutableByOperation(LPCSTR lpPath, LPCSTR lpFile, LPCSTR lpOperation, LPSTR key, LPSTR filetype, LPSTR command)
455 {
456 LONG commandlen = 256; /* This is the most DOS can handle :) */
457
458 /* Looking for ...buffer\shell\<verb>\command */
459 strcat(filetype, "\\shell\\");
460 strcat(filetype, lpOperation);
461 strcat(filetype, "\\command");
462
463 if (RegQueryValueA(HKEY_CLASSES_ROOT, filetype, command, &commandlen) == ERROR_SUCCESS)
464 {
465 if (key) strcpy(key, filetype);
466 #if 0
467 LPSTR tmp;
468 char param[256];
469 LONG paramlen = 256;
470
471 /* FIXME: it seems all Windows version don't behave the same here.
472 * the doc states that this ddeexec information can be found after
473 * the exec names.
474 * on Win98, it doesn't appear, but I think it does on Win2k
475 */
476 /* Get the parameters needed by the application
477 from the associated ddeexec key */
478 tmp = strstr(filetype, "command");
479 tmp[0] = '\0';
480 strcat(filetype, "ddeexec");
481
482 if (RegQueryValueA(HKEY_CLASSES_ROOT, filetype, param, &paramlen) == ERROR_SUCCESS)
483 {
484 strcat(command, " ");
485 strcat(command, param);
486 commandlen += paramlen;
487 }
488 #endif
489
490 command[commandlen] = '\0';
491
492 return 33; /* FIXME see SHELL_FindExecutable() */
493 }
494
495 return 31; /* default - 'No association was found' */
496 }
497
498 /*************************************************************************
499 * SHELL_FindExecutable [Internal]
500 *
501 * Utility for code sharing between FindExecutable and ShellExecute
502 * in:
503 * lpFile the name of a file
504 * lpOperation the operation on it (open)
505 * out:
506 * lpResult a buffer, big enough :-(, to store the command to do the
507 * operation on the file
508 * key a buffer, big enough, to get the key name to do actually the
509 * command (it'll be used afterwards for more information
510 * on the operation)
511 */
512 UINT SHELL_FindExecutable(LPCSTR lpPath, LPCSTR lpFile, LPCSTR lpOperation,
513 LPSTR lpResult, LPSTR key, void **env, LPITEMIDLIST pidl, LPCSTR args)
514 {
515 char *extension = NULL; /* pointer to file extension */
516 char tmpext[5]; /* local copy to munge as we please */
517 char filetype[256]; /* registry name for this filetype */
518 LONG filetypelen = 256; /* length of above */
519 char command[256]; /* command from registry */
520 char buffer[256]; /* Used to GetProfileString */
521 UINT retval = 31; /* default - 'No association was found' */
522 char *tok; /* token pointer */
523 char xlpFile[256] = ""; /* result of SearchPath */
524 DWORD attribs; /* file attributes */
525
526 TRACE("%s\n", (lpFile != NULL) ? lpFile : "-");
527
528 lpResult[0] = '\0'; /* Start off with an empty return string */
529 if (key) *key = '\0';
530
531 /* trap NULL parameters on entry */
532 if ((lpFile == NULL) || (lpResult == NULL))
533 {
534 WARN("(lpFile=%s,lpResult=%s): NULL parameter\n", lpFile, lpResult);
535 return 2; /* File not found. Close enough, I guess. */
536 }
537
538 if (SHELL_TryAppPath( lpFile, lpResult, env ))
539 {
540 TRACE("found %s via App Paths\n", lpResult);
541 return 33;
542 }
543
544 if (SearchPathA(lpPath, lpFile, ".exe", sizeof(xlpFile), xlpFile, NULL))
545 {
546 TRACE("SearchPathA returned non-zero\n");
547 lpFile = xlpFile;
548 /* Hey, isn't this value ignored? Why make this call? Shouldn't we return here? --dank*/
549 }
550
551 attribs = GetFileAttributesA(lpFile);
552
553 if (attribs!=INVALID_FILE_ATTRIBUTES && (attribs&FILE_ATTRIBUTE_DIRECTORY))
554 {
555 strcpy(filetype, "Folder");
556 filetypelen = 6; /* strlen("Folder") */
557 }
558 else
559 {
560 /* First thing we need is the file's extension */
561 extension = PathFindExtensionA(xlpFile); /* Assume last "." is the one; */
562 /* File->Run in progman uses */
563 /* .\FILE.EXE :( */
564 TRACE("xlpFile=%s,extension=%s\n", xlpFile, extension);
565
566 if ((extension == NULL) || (extension == &xlpFile[strlen(xlpFile)]))
567 {
568 WARN("Returning 31 - No association\n");
569 return 31; /* no association */
570 }
571
572 /* Make local copy & lowercase it for reg & 'programs=' lookup */
573 lstrcpynA(tmpext, extension, 5);
574 CharLowerA(tmpext);
575 TRACE("%s file\n", tmpext);
576
577 /* Three places to check: */
578 /* 1. win.ini, [windows], programs (NB no leading '.') */
579 /* 2. Registry, HKEY_CLASS_ROOT\<filetype>\shell\open\command */
580 /* 3. win.ini, [extensions], extension (NB no leading '.' */
581 /* All I know of the order is that registry is checked before */
582 /* extensions; however, it'd make sense to check the programs */
583 /* section first, so that's what happens here. */
584
585 /* See if it's a program - if GetProfileString fails, we skip this
586 * section. Actually, if GetProfileString fails, we've probably
587 * got a lot more to worry about than running a program... */
588 if (GetProfileStringA("windows", "programs", "exe pif bat cmd com",
589 buffer, sizeof(buffer)) > 0)
590 {
591 UINT i;
592
593 for (i=0; i<strlen(buffer); i++) buffer[i] = tolower(buffer[i]);
594
595 tok = strtok(buffer, " \t"); /* ? */
596 while (tok!= NULL)
597 {
598 if (strcmp(tok, &tmpext[1]) == 0) /* have to skip the leading "." */
599 {
600 strcpy(lpResult, xlpFile);
601 /* Need to perhaps check that the file has a path
602 * attached */
603 TRACE("found %s\n", lpResult);
604 return 33;
605
606 /* Greater than 32 to indicate success FIXME According to the
607 * docs, I should be returning a handle for the
608 * executable. Does this mean I'm supposed to open the
609 * executable file or something? More RTFM, I guess... */
610 }
611 tok = strtok(NULL, " \t");
612 }
613 }
614
615 /* Check registry */
616 if (RegQueryValueA(HKEY_CLASSES_ROOT, tmpext, filetype, &filetypelen) != ERROR_SUCCESS)
617 *filetype = '\0';
618 }
619
620 if (*filetype)
621 {
622 if (lpOperation)
623 {
624 /* pass the operation string to _FindExecutableByOperation() */
625 filetype[filetypelen] = '\0';
626 retval = _FindExecutableByOperation(lpPath, lpFile, lpOperation, key, filetype, command);
627 }
628 else
629 {
630 char operation[MAX_PATH];
631 HKEY hkey;
632
633 strcat(filetype, "\\shell");
634
635 /* enumerate the operation subkeys in the registry and search for one with an associated command */
636 if (RegOpenKeyA(HKEY_CLASSES_ROOT, filetype, &hkey) == ERROR_SUCCESS)
637 {
638 int idx = 0;
639 for(;; ++idx)
640 {
641 if (RegEnumKeyA(hkey, idx, operation, MAX_PATH) != ERROR_SUCCESS)
642 break;
643
644 filetype[filetypelen] = '\0';
645 retval = _FindExecutableByOperation(lpPath, lpFile, operation, key, filetype, command);
646
647 if (retval > 32)
648 break;
649 }
650
651 RegCloseKey(hkey);
652 }
653 }
654
655 if (retval > 32)
656 {
657 argifyA(lpResult, sizeof(lpResult), command, xlpFile, pidl, args);
658
659 /* Remove double quotation marks and command line arguments */
660 if (*lpResult == '"')
661 {
662 char *p = lpResult;
663 while (*(p + 1) != '"')
664 {
665 *p = *(p + 1);
666 p++;
667 }
668 *p = '\0';
669 }
670 }
671 }
672 else if (extension) /* Check win.ini */
673 {
674 /* Toss the leading dot */
675 extension++;
676 if (GetProfileStringA("extensions", extension, "", command,
677 sizeof(command)) > 0)
678 {
679 if (strlen(command) != 0)
680 {
681 strcpy(lpResult, command);
682 tok = strstr(lpResult, "^"); /* should be ^.extension? */
683
684 if (tok != NULL)
685 {
686 tok[0] = '\0';
687 strcat(lpResult, xlpFile); /* what if no dir in xlpFile? */
688 tok = strstr(command, "^"); /* see above */
689 if ((tok != NULL) && (strlen(tok)>5))
690 strcat(lpResult, &tok[5]);
691 }
692
693 retval = 33; /* FIXME - see above */
694 }
695 }
696 }
697
698 TRACE("returning %s\n", lpResult);
699 return retval;
700 }
701
702 /******************************************************************
703 * dde_cb
704 *
705 * callback for the DDE connection. not really usefull
706 */
707 static HDDEDATA CALLBACK dde_cb(UINT uType, UINT uFmt, HCONV hConv,
708 HSZ hsz1, HSZ hsz2,
709 HDDEDATA hData, DWORD dwData1, DWORD dwData2)
710 {
711 return NULL;
712 }
713
714 /******************************************************************
715 * dde_connect
716 *
717 * ShellExecute helper. Used to do an operation with a DDE connection
718 *
719 * Handles both the direct connection (try #1), and if it fails,
720 * launching an application and trying (#2) to connect to it
721 *
722 */
723 static unsigned dde_connect(char* key, char* start, char* ddeexec,
724 const char* lpFile, void *env,
725 LPCSTR szCommandline, LPITEMIDLIST pidl, SHELL_ExecuteA1632 execfunc,
726 LPSHELLEXECUTEINFOA psei, LPSHELLEXECUTEINFOA psei_out)
727 {
728 char* endkey = key + strlen(key);
729 char app[256], topic[256], ifexec[256];
730 char res[1024];
731 LONG applen, topiclen, ifexeclen;
732 char* exec;
733 DWORD ddeInst = 0;
734 DWORD tid;
735 HSZ hszApp, hszTopic;
736 HCONV hConv;
737 unsigned ret = 31;
738
739 strcpy(endkey, "\\application");
740 applen = sizeof(app);
741 if (RegQueryValueA(HKEY_CLASSES_ROOT, key, app, &applen) != ERROR_SUCCESS)
742 {
743 FIXME("default app name NIY %s\n", key);
744 return 2;
745 }
746
747 strcpy(endkey, "\\topic");
748 topiclen = sizeof(topic);
749 if (RegQueryValueA(HKEY_CLASSES_ROOT, key, topic, &topiclen) != ERROR_SUCCESS)
750 {
751 strcpy(topic, "System");
752 }
753
754 if (DdeInitializeA(&ddeInst, dde_cb, APPCMD_CLIENTONLY, 0L) != DMLERR_NO_ERROR)
755 {
756 return 2;
757 }
758
759 hszApp = DdeCreateStringHandleA(ddeInst, app, CP_WINANSI);
760 hszTopic = DdeCreateStringHandleA(ddeInst, topic, CP_WINANSI);
761
762 hConv = DdeConnect(ddeInst, hszApp, hszTopic, NULL);
763 exec = ddeexec;
764 if (!hConv)
765 {
766 TRACE("Launching '%s'\n", start);
767 ret = execfunc(start, env, TRUE, psei, psei_out);
768 if (ret < 32)
769 {
770 TRACE("Couldn't launch\n");
771 goto error;
772 }
773 hConv = DdeConnect(ddeInst, hszApp, hszTopic, NULL);
774 if (!hConv)
775 {
776 TRACE("Couldn't connect. ret=%d\n", ret);
777 ret = 30; /* whatever */
778 goto error;
779 }
780 strcpy(endkey, "\\ifexec");
781 ifexeclen = sizeof(ifexec);
782 if (RegQueryValueA(HKEY_CLASSES_ROOT, key, ifexec, &ifexeclen) == ERROR_SUCCESS)
783 {
784 exec = ifexec;
785 }
786 }
787
788 argifyA(res, sizeof(res), exec, lpFile, pidl, szCommandline);
789 TRACE("%s %s => %s\n", exec, lpFile, res);
790
791 ret = (DdeClientTransaction((LPBYTE)res, strlen(res)+1, hConv, 0L, 0,
792 XTYP_EXECUTE, 10000, &tid) != DMLERR_NO_ERROR) ? 31 : 33;
793 DdeDisconnect(hConv);
794 error:
795 DdeUninitialize(ddeInst);
796 return ret;
797 }
798
799 /*************************************************************************
800 * execute_from_key [Internal]
801 */
802 static UINT execute_from_key(LPSTR key, LPCSTR lpFile, void *env, LPCSTR szCommandline,
803 SHELL_ExecuteA1632 execfunc,
804 LPSHELLEXECUTEINFOA psei, LPSHELLEXECUTEINFOA psei_out)
805 {
806 char cmd[1024] = "";
807 LONG cmdlen = sizeof(cmd);
808 UINT retval = 31;
809
810 /* Get the application for the registry */
811 if (RegQueryValueA(HKEY_CLASSES_ROOT, key, cmd, &cmdlen) == ERROR_SUCCESS)
812 {
813 LPSTR tmp;
814 char param[256] = "";
815 LONG paramlen = 256;
816
817 /* Get the parameters needed by the application
818 from the associated ddeexec key */
819 tmp = strstr(key, "command");
820 assert(tmp);
821 strcpy(tmp, "ddeexec");
822
823 if (RegQueryValueA(HKEY_CLASSES_ROOT, key, param, &paramlen) == ERROR_SUCCESS)
824 {
825 TRACE("Got ddeexec %s => %s\n", key, param);
826 retval = dde_connect(key, cmd, param, lpFile, env, szCommandline, psei->lpIDList, execfunc, psei, psei_out);
827 }
828 else
829 {
830 /* Is there a replace() function anywhere? */
831 cmd[cmdlen] = '\0';
832 argifyA(param, sizeof(param), cmd, lpFile, psei->lpIDList, szCommandline);
833
834 retval = execfunc(param, env, FALSE, psei, psei_out);
835 }
836 }
837 else TRACE("ooch\n");
838
839 return retval;
840 }
841
842 /*************************************************************************
843 * FindExecutableA [SHELL32.@]
844 */
845 HINSTANCE WINAPI FindExecutableA(LPCSTR lpFile, LPCSTR lpDirectory, LPSTR lpResult)
846 {
847 UINT retval = 31; /* default - 'No association was found' */
848 char old_dir[1024];
849
850 TRACE("File %s, Dir %s\n",
851 (lpFile != NULL ? lpFile : "-"), (lpDirectory != NULL ? lpDirectory : "-"));
852
853 lpResult[0] = '\0'; /* Start off with an empty return string */
854
855 /* trap NULL parameters on entry */
856 if ((lpFile == NULL) || (lpResult == NULL))
857 {
858 /* FIXME - should throw a warning, perhaps! */
859 return (HINSTANCE)2; /* File not found. Close enough, I guess. */
860 }
861
862 if (lpDirectory)
863 {
864 GetCurrentDirectoryA(sizeof(old_dir), old_dir);
865 SetCurrentDirectoryA(lpDirectory);
866 }
867
868 retval = SHELL_FindExecutable(lpDirectory, lpFile, "open", lpResult, NULL, NULL, NULL, NULL);
869
870 TRACE("returning %s\n", lpResult);
871 if (lpDirectory)
872 SetCurrentDirectoryA(old_dir);
873 return (HINSTANCE)retval;
874 }
875
876 /*************************************************************************
877 * FindExecutableW [SHELL32.@]
878 */
879 HINSTANCE WINAPI FindExecutableW(LPCWSTR lpFile, LPCWSTR lpDirectory, LPWSTR lpResult)
880 {
881 FIXME("(%p,%p,%p): stub\n", lpFile, lpDirectory, lpResult);
882 return (HINSTANCE)31; /* default - 'No association was found' */
883 }
884
885 /*************************************************************************
886 * ShellExecuteExA32 [Internal]
887 *
888 * FIXME: use PathProcessCommandA() to processes the command line string
889 * use PathResolveA() to search for the fully qualified executable path
890 */
891 BOOL WINAPI ShellExecuteExA32(LPSHELLEXECUTEINFOA psei, SHELL_ExecuteA1632 execfunc)
892 {
893 CHAR szApplicationName[MAX_PATH+2], szParameters[MAX_PATH], fileName[MAX_PATH], szDir[MAX_PATH];
894 SHELLEXECUTEINFOA sei_tmp; /* modifyable copy of SHELLEXECUTEINFO struct */
895 void *env;
896 char szProtocol[256];
897 LPCSTR lpFile;
898 UINT retval = 31;
899 char buffer[1024];
900 const char* ext;
901
902 memcpy(&sei_tmp, psei, sizeof(sei_tmp));
903
904 TRACE("mask=0x%08lx hwnd=%p verb=%s file=%s parm=%s dir=%s show=0x%08x class=%s\n",
905 sei_tmp.fMask, sei_tmp.hwnd, debugstr_a(sei_tmp.lpVerb),
906 debugstr_a(sei_tmp.lpFile), debugstr_a(sei_tmp.lpParameters),
907 debugstr_a(sei_tmp.lpDirectory), sei_tmp.nShow,
908 (sei_tmp.fMask & SEE_MASK_CLASSNAME) ? debugstr_a(sei_tmp.lpClass) : "not used");
909
910 psei->hProcess = NULL;
911
912 if (sei_tmp.lpFile)
913 strcpy(szApplicationName, sei_tmp.lpFile);
914 else
915 *szApplicationName = '\0';
916
917 if (sei_tmp.lpParameters)
918 strcpy(szParameters, sei_tmp.lpParameters);
919 else
920 *szParameters = '\0';
921
922 if (sei_tmp.lpDirectory)
923 strcpy(szDir, sei_tmp.lpDirectory);
924 else
925 *szDir = '\0';
926
927 sei_tmp.lpFile = szApplicationName;
928 sei_tmp.lpParameters = szParameters;
929 sei_tmp.lpDirectory = szDir;
930
931 if (sei_tmp.fMask & (SEE_MASK_ICON | SEE_MASK_HOTKEY |
932 SEE_MASK_CONNECTNETDRV | SEE_MASK_FLAG_DDEWAIT |
933 SEE_MASK_DOENVSUBST | SEE_MASK_FLAG_NO_UI | SEE_MASK_UNICODE |
934 SEE_MASK_NO_CONSOLE | SEE_MASK_ASYNCOK | SEE_MASK_HMONITOR ))
935 {
936 FIXME("flags ignored: 0x%08lx\n", sei_tmp.fMask);
937 }
938
939 /* process the IDList */
940 if (sei_tmp.fMask & SEE_MASK_INVOKEIDLIST) /* 0x0c: includes SEE_MASK_IDLIST */
941 {
942 IShellExecuteHookA* pSEH;
943
944 HRESULT hr = SHBindToParent(sei_tmp.lpIDList, &IID_IShellExecuteHookA, (LPVOID*)&pSEH, NULL);
945
946 if (SUCCEEDED(hr))
947 {
948 hr = IShellExecuteHookA_Execute(pSEH, psei);
949
950 IShellExecuteHookA_Release(pSEH);
951
952 if (hr == S_OK)
953 return TRUE;
954 }
955
956 /* try to translate PIDL directly into the corresponding file system path */
957 if (SUCCEEDED(SHELL_GetPathFromIDListA(sei_tmp.lpIDList, szApplicationName/*sei_tmp.lpFile*/, sizeof(szApplicationName))))
958 {
959 sei_tmp.lpIDList = NULL;
960 sei_tmp.fMask &= ~SEE_MASK_INVOKEIDLIST;
961 }
962
963 TRACE("-- idlist=%p (%s)\n", sei_tmp.lpIDList, sei_tmp.lpFile);
964 }
965
966 if (sei_tmp.fMask & (SEE_MASK_CLASSNAME | SEE_MASK_CLASSKEY))
967 {
968 /* launch a document by fileclass like 'WordPad.Document.1' */
969 /* the Commandline contains 'c:\Path\wordpad.exe "%1"' */
970 /* FIXME: szParameters should not be of a fixed size. Plus MAX_PATH is way too short! */
971 if (sei_tmp.fMask & SEE_MASK_CLASSKEY)
972 HCR_GetExecuteCommandExA(sei_tmp.hkeyClass,
973 sei_tmp.fMask&SEE_MASK_CLASSNAME? sei_tmp.lpClass: NULL,
974 sei_tmp.lpVerb?sei_tmp.lpVerb:"open",
975 szParameters/*sei_tmp.lpParameters*/, sizeof(szParameters));
976 else if (sei_tmp.fMask & SEE_MASK_CLASSNAME)
977 HCR_GetExecuteCommandA(sei_tmp.lpClass, sei_tmp.lpVerb?sei_tmp.lpVerb:"open",
978 szParameters/*sei_tmp.lpParameters*/, sizeof(szParameters));
979
980 /* FIXME: get the extension of lpFile, check if it fits to the lpClass */
981 TRACE("SEE_MASK_CLASSNAME->'%s', doc->'%s'\n", sei_tmp.lpParameters, sei_tmp.lpFile);
982
983 buffer[0] = '\0';
984
985 if (!argifyA(buffer, sizeof(buffer), sei_tmp.lpParameters, sei_tmp.lpFile, sei_tmp.lpIDList, NULL) && sei_tmp.lpFile[0])
986 {
987 strcat(buffer, " ");
988 strcat(buffer, sei_tmp.lpFile);
989 }
990
991 retval = execfunc(buffer, NULL, FALSE, &sei_tmp, psei);
992 if (retval > 32)
993 return TRUE;
994 else
995 return FALSE;
996 }
997
998 /* Else, try to execute the filename */
999 TRACE("execute:'%s','%s'\n", sei_tmp.lpFile, sei_tmp.lpParameters);
1000
1001
1002 /* resolve shell shortcuts */
1003 ext = PathFindExtensionA(sei_tmp.lpFile);
1004
1005 if (ext && !strcasecmp(ext, ".lnk")) /* or check for: shell_attribs & SFGAO_LINK */
1006 {
1007 if (SUCCEEDED(SHELL_ResolveShortCutA(&sei_tmp)))
1008 {
1009 /* repeat IDList processing if needed */
1010 if (sei_tmp.fMask & SEE_MASK_IDLIST)
1011 {
1012 IShellExecuteHookA* pSEH;
1013
1014 HRESULT hr = SHBindToParent(sei_tmp.lpIDList, &IID_IShellExecuteHookA, (LPVOID*)&pSEH, NULL);
1015
1016 if (SUCCEEDED(hr))
1017 {
1018 hr = IShellExecuteHookA_Execute(pSEH, psei);
1019
1020 IShellExecuteHookA_Release(pSEH);
1021
1022 if (hr == S_OK)
1023 return TRUE;
1024 }
1025
1026 TRACE("-- idlist=%p (%s)\n", sei_tmp.lpIDList, sei_tmp.lpFile);
1027 }
1028 }
1029 }
1030
1031
1032 /* Has the IDList not yet been translated? */
1033 if (sei_tmp.fMask & SEE_MASK_IDLIST)
1034 {
1035 /* last chance to translate IDList: now also allow CLSID paths */
1036 if (SUCCEEDED(SHELL_GetPathFromIDListForExecuteA(sei_tmp.lpIDList, buffer, sizeof(buffer)))) {
1037 if (buffer[0]==':' && buffer[1]==':') {
1038 /* open shell folder for the specified class GUID */
1039 strcpy(szParameters, buffer);
1040 strcpy(szApplicationName, "explorer.exe");
1041
1042 sei_tmp.fMask &= ~SEE_MASK_INVOKEIDLIST;
1043 } else if (HCR_GetExecuteCommandA("Folder", sei_tmp.lpVerb?sei_tmp.lpVerb:"open", buffer, sizeof(buffer))) {
1044 argifyA(szApplicationName, sizeof(szApplicationName), buffer, NULL, sei_tmp.lpIDList, NULL);
1045
1046 sei_tmp.fMask &= ~SEE_MASK_INVOKEIDLIST;
1047 }
1048 }
1049 }
1050
1051
1052 /* expand environment strings */
1053
1054 if (ExpandEnvironmentStringsA(sei_tmp.lpFile, buffer, MAX_PATH))
1055 lstrcpyA(szApplicationName/*sei_tmp.lpFile*/, buffer);
1056
1057 if (*sei_tmp.lpParameters)
1058 if (ExpandEnvironmentStringsA(sei_tmp.lpParameters, buffer, MAX_PATH))
1059 lstrcpyA(szParameters/*sei_tmp.lpParameters*/, buffer);
1060
1061 if (*sei_tmp.lpDirectory)
1062 if (ExpandEnvironmentStringsA(sei_tmp.lpDirectory, buffer, MAX_PATH))
1063 lstrcpyA(szDir/*sei_tmp.lpDirectory*/, buffer);
1064
1065
1066 /* separate out command line arguments from executable file name */
1067 if (!*sei_tmp.lpParameters) {
1068 /* If the executable path is quoted, handle the rest of the command line as parameters. */
1069 if (sei_tmp.lpFile[0] == '"') {
1070 LPSTR src = szApplicationName/*sei_tmp.lpFile*/ + 1;
1071 LPSTR dst = fileName;
1072 LPSTR end;
1073
1074 /* copy the unquoted executabe path to 'fileName' */
1075 while(*src && *src!='"')
1076 *dst++ = *src++;
1077
1078 *dst = '\0';
1079
1080 if (*src == '"') {
1081 end = ++src;
1082
1083 while(isspace(*src))
1084 ++src;
1085 } else
1086 end = src;
1087
1088 /* copy the parameter string to 'szParameters' */
1089 strcpy(szParameters, src);
1090
1091 /* terminate previous command string after the quote character */
1092 *end = '\0';
1093 }
1094 else
1095 {
1096 /* If the executable name is not quoted, we have to use this search loop here,
1097 that in CreateProcess() is not sufficient because it does not handle shell links. */
1098 char buffer[MAX_PATH], xlpFile[MAX_PATH];
1099 LPSTR space, s;
1100
1101 LPSTR beg = szApplicationName/*sei_tmp.lpFile*/;
1102 for(s=beg; (space=strchr(s, ' ')); s=space+1) {
1103 int idx = space-sei_tmp.lpFile;
1104 strncpy(buffer, sei_tmp.lpFile, idx);
1105 buffer[idx] = '\0';
1106
1107 if (SearchPathA(*sei_tmp.lpDirectory? sei_tmp.lpDirectory: NULL, buffer, ".exe", sizeof(xlpFile), xlpFile, NULL))
1108 {
1109 /* separate out command from parameter string */
1110 LPCSTR p = space + 1;
1111
1112 while(isspace(*p))
1113 ++p;
1114
1115 strcpy(szParameters, p);
1116 *space = '\0';
1117
1118 break;
1119 }
1120 }
1121
1122 strcpy(fileName, sei_tmp.lpFile);
1123 }
1124 } else
1125 strcpy(fileName, sei_tmp.lpFile);
1126
1127 lpFile = fileName;
1128
1129 if (sei_tmp.lpParameters[0]) {
1130 strcat(szApplicationName/*sei_tmp.lpFile*/, " ");
1131 strcat(szApplicationName/*sei_tmp.lpFile*/, sei_tmp.lpParameters);
1132 }
1133
1134 retval = execfunc(sei_tmp.lpFile, NULL, FALSE, &sei_tmp, psei);
1135 if (retval > 32)
1136 {
1137 /* Now, that we have successfully launched a process, we can free the PIDL.
1138 It may have been used before for %I command line options. */
1139 if (sei_tmp.lpIDList!=psei->lpIDList && sei_tmp.lpIDList)
1140 SHFree(sei_tmp.lpIDList);
1141
1142 TRACE("execfunc: retval=%d psei->hInstApp=%p\n", retval, psei->hInstApp);
1143 return TRUE;
1144 }
1145
1146 /* Else, try to find the executable */
1147 buffer[0] = '\0';
1148 retval = SHELL_FindExecutable(*sei_tmp.lpDirectory? sei_tmp.lpDirectory: NULL, lpFile, sei_tmp.lpVerb, buffer, szProtocol, &env, sei_tmp.lpIDList, sei_tmp.lpParameters);
1149
1150 if (retval > 32) /* Found */
1151 {
1152 CHAR szQuotedCmd[MAX_PATH+2];
1153 /* Must quote to handle case where 'buffer' contains spaces,
1154 * else security hole if malicious user creates executable file "C:\\Program"
1155 *
1156 * FIXME: If we don't have set explicitly command line arguments, we must first
1157 * split executable path from optional command line arguments. Otherwise we would quote
1158 * the complete string with executable path _and_ arguments, which is not what we want.
1159 */
1160 if (sei_tmp.lpParameters[0])
1161 sprintf(szQuotedCmd, "\"%s\" %s", buffer, sei_tmp.lpParameters);
1162 else
1163 sprintf(szQuotedCmd, "\"%s\"", buffer);
1164
1165 TRACE("%s/%s => %s/%s\n", sei_tmp.lpFile, sei_tmp.lpVerb?sei_tmp.lpVerb:"NULL", szQuotedCmd, szProtocol);
1166
1167 if (*szProtocol)
1168 retval = execute_from_key(szProtocol, lpFile, env, sei_tmp.lpParameters, execfunc, &sei_tmp, psei);
1169 else
1170 retval = execfunc(szQuotedCmd, env, FALSE, &sei_tmp, psei);
1171
1172 if (env) HeapFree( GetProcessHeap(), 0, env );
1173 }
1174 else if (PathIsURLA((LPSTR)lpFile)) /* File not found, check for URL */
1175 {
1176 LPSTR lpstrRes;
1177 INT iSize;
1178
1179 lpstrRes = strchr(lpFile, ':');
1180 if (lpstrRes)
1181 iSize = lpstrRes - lpFile;
1182 else
1183 iSize = strlen(lpFile);
1184
1185 TRACE("Got URL: %s\n", lpFile);
1186 /* Looking for ...protocol\shell\<verb>\command */
1187 strncpy(szProtocol, lpFile, iSize);
1188 szProtocol[iSize] = '\0';
1189 strcat(szProtocol, "\\shell\\");
1190 strcat(szProtocol, sei_tmp.lpVerb? sei_tmp.lpVerb: "open"); /*FIXME: enumerate registry subkeys - compare with the loop into SHELL_FindExecutable() */
1191 strcat(szProtocol, "\\command");
1192
1193 /* Remove File Protocol from lpFile */
1194 /* In the case file://path/file */
1195 if (!strncasecmp(lpFile, "file", iSize))
1196 {
1197 lpFile += iSize;
1198 while (*lpFile == ':') lpFile++;
1199 }
1200
1201 retval = execute_from_key(szProtocol, lpFile, NULL, sei_tmp.lpParameters, execfunc, &sei_tmp, psei);
1202 }
1203 /* Check if file specified is in the form www.??????.*** */
1204 else if (!strncasecmp(lpFile, "www", 3))
1205 {
1206 /* if so, append lpFile http:// and call ShellExecute */
1207 char lpstrTmpFile[256] = "http://" ;
1208 strcat(lpstrTmpFile, lpFile);
1209 retval = (UINT)ShellExecuteA(sei_tmp.hwnd, sei_tmp.lpVerb, lpstrTmpFile, NULL, NULL, 0);
1210 }
1211
1212 /* Now we can free the PIDL. It may have been used before for %I command line options. */
1213 if (sei_tmp.lpIDList!=psei->lpIDList && sei_tmp.lpIDList)
1214 SHFree(sei_tmp.lpIDList);
1215
1216 TRACE("ShellExecuteExA32 retval=%d\n", retval);
1217
1218 if (retval <= 32)
1219 {
1220 psei->hInstApp = (HINSTANCE)retval;
1221 return FALSE;
1222 }
1223
1224 psei->hInstApp = (HINSTANCE)33;
1225 return TRUE;
1226 }
1227
1228 /*************************************************************************
1229 * ShellExecuteA [SHELL32.290]
1230 */
1231 HINSTANCE WINAPI ShellExecuteA(HWND hWnd, LPCSTR lpOperation, LPCSTR lpFile,
1232 LPCSTR lpParameters, LPCSTR lpDirectory, INT iShowCmd)
1233 {
1234 SHELLEXECUTEINFOA sei;
1235 HANDLE hProcess = 0;
1236
1237 TRACE("\n");
1238 sei.cbSize = sizeof(sei);
1239 sei.fMask = 0;
1240 sei.hwnd = hWnd;
1241 sei.lpVerb = lpOperation;
1242 sei.lpFile = lpFile;
1243 sei.lpParameters = lpParameters;
1244 sei.lpDirectory = lpDirectory;
1245 sei.nShow = iShowCmd;
1246 sei.lpIDList = 0;
1247 sei.lpClass = 0;
1248 sei.hkeyClass = 0;
1249 sei.dwHotKey = 0;
1250 sei.hProcess = hProcess;
1251
1252 ShellExecuteExA32(&sei, SHELL_ExecuteA);
1253 return sei.hInstApp;
1254 }
1255
1256 /*************************************************************************
1257 * ShellExecuteEx [SHELL32.291]
1258 *
1259 */
1260 BOOL WINAPI ShellExecuteExAW (LPVOID sei)
1261 {
1262 if (SHELL_OsIsUnicode())
1263 return ShellExecuteExW(sei);
1264 return ShellExecuteExA32(sei, SHELL_ExecuteA);
1265 }
1266
1267 /*************************************************************************
1268 * ShellExecuteExA [SHELL32.292]
1269 *
1270 */
1271 BOOL WINAPI ShellExecuteExA (LPSHELLEXECUTEINFOA sei)
1272 {
1273 BOOL ret = ShellExecuteExA32(sei, SHELL_ExecuteA);
1274
1275 TRACE("ShellExecuteExA(): ret=%d\n", ret);
1276
1277 return ret;
1278 }
1279
1280 /*************************************************************************
1281 * ShellExecuteExW [SHELL32.293]
1282 *
1283 */
1284 BOOL WINAPI ShellExecuteExW (LPSHELLEXECUTEINFOW sei)
1285 {
1286 SHELLEXECUTEINFOA seiA;
1287 BOOL ret;
1288
1289 TRACE("%p\n", sei);
1290
1291 memcpy(&seiA, sei, sizeof(SHELLEXECUTEINFOA));
1292
1293 if (sei->lpVerb)
1294 seiA.lpVerb = HEAP_strdupWtoA( GetProcessHeap(), 0, sei->lpVerb);
1295
1296 if (sei->lpFile)
1297 seiA.lpFile = HEAP_strdupWtoA( GetProcessHeap(), 0, sei->lpFile);
1298
1299 if (sei->lpParameters)
1300 seiA.lpParameters = HEAP_strdupWtoA( GetProcessHeap(), 0, sei->lpParameters);
1301
1302 if (sei->lpDirectory)
1303 seiA.lpDirectory = HEAP_strdupWtoA( GetProcessHeap(), 0, sei->lpDirectory);
1304
1305 if ((sei->fMask & SEE_MASK_CLASSNAME) && sei->lpClass)
1306 seiA.lpClass = HEAP_strdupWtoA( GetProcessHeap(), 0, sei->lpClass);
1307 else
1308 seiA.lpClass = NULL;
1309
1310 ret = ShellExecuteExA(&seiA);
1311
1312 if (seiA.lpVerb) HeapFree( GetProcessHeap(), 0, (LPSTR) seiA.lpVerb );
1313 if (seiA.lpFile) HeapFree( GetProcessHeap(), 0, (LPSTR) seiA.lpFile );
1314 if (seiA.lpParameters) HeapFree( GetProcessHeap(), 0, (LPSTR) seiA.lpParameters );
1315 if (seiA.lpDirectory) HeapFree( GetProcessHeap(), 0, (LPSTR) seiA.lpDirectory );
1316 if (seiA.lpClass) HeapFree( GetProcessHeap(), 0, (LPSTR) seiA.lpClass );
1317
1318 sei->hInstApp = seiA.hInstApp;
1319
1320 TRACE("ShellExecuteExW(): ret=%d\n", ret);
1321
1322 return ret;
1323 }
1324
1325 /*************************************************************************
1326 * ShellExecuteW [SHELL32.294]
1327 * from shellapi.h
1328 * WINSHELLAPI HINSTANCE APIENTRY ShellExecuteW(HWND hwnd, LPCWSTR lpOperation,
1329 * LPCWSTR lpFile, LPCWSTR lpParameters, LPCWSTR lpDirectory, INT nShowCmd);
1330 */
1331 HINSTANCE WINAPI ShellExecuteW(HWND hwnd, LPCWSTR lpOperation, LPCWSTR lpFile,
1332 LPCWSTR lpParameters, LPCWSTR lpDirectory, INT nShowCmd)
1333 {
1334 SHELLEXECUTEINFOW sei;
1335 HANDLE hProcess = 0;
1336 int ret;
1337
1338 TRACE("\n");
1339 sei.cbSize = sizeof(sei);
1340 sei.fMask = 0;
1341 sei.hwnd = hwnd;
1342 sei.lpVerb = lpOperation;
1343 sei.lpFile = lpFile;
1344 sei.lpParameters = lpParameters;
1345 sei.lpDirectory = lpDirectory;
1346 sei.nShow = nShowCmd;
1347 sei.lpIDList = 0;
1348 sei.lpClass = 0;
1349 sei.hkeyClass = 0;
1350 sei.dwHotKey = 0;
1351 sei.hProcess = hProcess;
1352
1353 ret = ShellExecuteExW(&sei);
1354
1355 TRACE("ShellExecuteW(): ret=%d module=%p", ret, sei.hInstApp);
1356 return sei.hInstApp;
1357 }