kernel32: FindExSearchLimitToDirectories has no effect on FindFirstFileEx.
[wine] / dlls / 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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 #define COBJMACROS
36
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"
44
45 #include "wine/winbase16.h"
46 #include "shell32_main.h"
47 #include "pidl.h"
48
49 #include "wine/debug.h"
50
51 WINE_DEFAULT_DEBUG_CHANNEL(exec);
52
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};
59
60 #define SEE_MASK_CLASSALL (SEE_MASK_CLASSNAME | SEE_MASK_CLASSKEY)
61
62
63 /***********************************************************************
64  *      SHELL_ArgifyW [Internal]
65  *
66  * this function is supposed to expand the escape sequences found in the registry
67  * some diving reported that the following were used:
68  * + %1, %2...  seem to report to parameter of index N in ShellExecute pmts
69  *      %1 file
70  *      %2 printer
71  *      %3 driver
72  *      %4 port
73  * %I address of a global item ID (explorer switch /idlist)
74  * %L seems to be %1 as long filename followed by the 8+3 variation
75  * %S ???
76  * %* all following parameters (see batfile)
77  *
78  */
79 static BOOL SHELL_ArgifyW(WCHAR* out, int len, const WCHAR* fmt, const WCHAR* lpFile, LPITEMIDLIST pidl, LPCWSTR args, DWORD* out_len)
80 {
81     WCHAR   xlpFile[1024];
82     BOOL    done = FALSE;
83     BOOL    found_p1 = FALSE;
84     PWSTR   res = out;
85     PCWSTR  cmd;
86     DWORD   used = 0;
87
88     TRACE("%p, %d, %s, %s, %p, %p\n", out, len, debugstr_w(fmt),
89           debugstr_w(lpFile), pidl, args);
90
91     while (*fmt)
92     {
93         if (*fmt == '%')
94         {
95             switch (*++fmt)
96             {
97             case '\0':
98             case '%':
99                 used++;
100                 if (used < len)
101                     *res++ = '%';
102                 break;
103
104             case '2':
105             case '3':
106             case '4':
107             case '5':
108             case '6':
109             case '7':
110             case '8':
111             case '9':
112             case '0':
113             case '*':
114                 if (args)
115                 {
116                     if (*fmt == '*')
117                     {
118                         used++;
119                         if (used < len)
120                             *res++ = '"';
121                         while(*args)
122                         {
123                             used++;
124                             if (used < len)
125                                 *res++ = *args++;
126                             else
127                                 args++;
128                         }
129                         used++;
130                         if (used < len)
131                             *res++ = '"';
132                     }
133                     else
134                     {
135                         while(*args && !isspace(*args))
136                         {
137                             used++;
138                             if (used < len)
139                                 *res++ = *args++;
140                             else
141                                 args++;
142                         }
143
144                         while(isspace(*args))
145                             ++args;
146                     }
147                     break;
148                 }
149                 /* else fall through */
150             case '1':
151                 if (!done || (*fmt == '1'))
152                 {
153                     /*FIXME Is the call to SearchPathW() really needed? We already have separated out the parameter string in args. */
154                     if (SearchPathW(NULL, lpFile, wszExe, sizeof(xlpFile)/sizeof(WCHAR), xlpFile, NULL))
155                         cmd = xlpFile;
156                     else
157                         cmd = lpFile;
158
159                     used += strlenW(cmd);
160                     if (used < len)
161                     {
162                         strcpyW(res, cmd);
163                         res += strlenW(cmd);
164                     }
165                 }
166                 found_p1 = TRUE;
167                 break;
168
169             /*
170              * IE uses this a lot for activating things such as windows media
171              * player. This is not verified to be fully correct but it appears
172              * to work just fine.
173              */
174             case 'l':
175             case 'L':
176                 if (lpFile) {
177                     used += strlenW(lpFile);
178                     if (used < len)
179                     {
180                         strcpyW(res, lpFile);
181                         res += strlenW(lpFile);
182                     }
183                 }
184                 found_p1 = TRUE;
185                 break;
186
187             case 'i':
188             case 'I':
189                 if (pidl) {
190                     INT chars = 0;
191                     /* %p should not exceed 8, maybe 16 when looking foward to 64bit.
192                      * allowing a buffer of 100 should more than exceed all needs */
193                     WCHAR buf[100];
194                     LPVOID  pv;
195                     HGLOBAL hmem = SHAllocShared(pidl, ILGetSize(pidl), 0);
196                     pv = SHLockShared(hmem, 0);
197                     chars = sprintfW(buf, wszILPtr, pv);
198                     if (chars >= sizeof(buf)/sizeof(WCHAR))
199                         ERR("pidl format buffer too small!\n");
200                     used += chars;
201                     if (used < len)
202                     {
203                         strcpyW(res,buf);
204                         res += chars;
205                     }
206                     SHUnlockShared(pv);
207                 }
208                 found_p1 = TRUE;
209                 break;
210
211             default:
212                 /*
213                  * Check if this is an env-variable here...
214                  */
215
216                 /* Make sure that we have at least one more %.*/
217                 if (strchrW(fmt, '%'))
218                 {
219                     WCHAR   tmpBuffer[1024];
220                     PWSTR   tmpB = tmpBuffer;
221                     WCHAR   tmpEnvBuff[MAX_PATH];
222                     DWORD   envRet;
223
224                     while (*fmt != '%')
225                         *tmpB++ = *fmt++;
226                     *tmpB++ = 0;
227
228                     TRACE("Checking %s to be an env-var\n", debugstr_w(tmpBuffer));
229
230                     envRet = GetEnvironmentVariableW(tmpBuffer, tmpEnvBuff, MAX_PATH);
231                     if (envRet == 0 || envRet > MAX_PATH)
232                     {
233                         used += strlenW(tmpBuffer);
234                         if (used < len)
235                         {
236                             strcpyW( res, tmpBuffer );
237                             res += strlenW(tmpBuffer);
238                         }
239                     }
240                     else
241                     {
242                         used += strlenW(tmpEnvBuff);
243                         if (used < len)
244                         {
245                             strcpyW( res, tmpEnvBuff );
246                             res += strlenW(tmpEnvBuff);
247                         }
248                     }
249                 }
250                 done = TRUE;
251                 break;
252             }
253             /* Don't skip past terminator (catch a single '%' at the end) */
254             if (*fmt != '\0')
255             {
256                 fmt++;
257             }
258         }
259         else
260         {
261             used ++;
262             if (used < len) 
263                 *res++ = *fmt++;
264             else
265                 fmt++;
266         }
267     }
268
269     *res = '\0';
270     TRACE("used %i of %i space\n",used,len);
271     if (out_len)
272         *out_len = used;
273
274     return found_p1;
275 }
276
277 static HRESULT SHELL_GetPathFromIDListForExecuteW(LPCITEMIDLIST pidl, LPWSTR pszPath, UINT uOutSize)
278 {
279     STRRET strret;
280     IShellFolder* desktop;
281
282     HRESULT hr = SHGetDesktopFolder(&desktop);
283
284     if (SUCCEEDED(hr)) {
285         hr = IShellFolder_GetDisplayNameOf(desktop, pidl, SHGDN_FORPARSING, &strret);
286
287         if (SUCCEEDED(hr))
288             StrRetToStrNW(pszPath, uOutSize, &strret, pidl);
289
290         IShellFolder_Release(desktop);
291     }
292
293     return hr;
294 }
295
296 /*************************************************************************
297  *      SHELL_ExecuteW [Internal]
298  *
299  */
300 static UINT_PTR SHELL_ExecuteW(const WCHAR *lpCmd, WCHAR *env, BOOL shWait,
301                             LPSHELLEXECUTEINFOW psei, LPSHELLEXECUTEINFOW psei_out)
302 {
303     STARTUPINFOW  startup;
304     PROCESS_INFORMATION info;
305     UINT_PTR retval = SE_ERR_NOASSOC;
306     UINT gcdret = 0;
307     WCHAR curdir[MAX_PATH];
308     DWORD dwCreationFlags;
309     const WCHAR *lpDirectory = NULL;
310
311     TRACE("Execute %s from directory %s\n", debugstr_w(lpCmd), debugstr_w(psei->lpDirectory));
312
313     /* make sure we don't fail the CreateProcess if the calling app passes in
314      * a bad working directory */
315     if (psei->lpDirectory && psei->lpDirectory[0])
316     {
317         DWORD attr = GetFileAttributesW(psei->lpDirectory);
318         if (attr != INVALID_FILE_ATTRIBUTES && attr & FILE_ATTRIBUTE_DIRECTORY)
319             lpDirectory = psei->lpDirectory;
320     }
321
322     /* ShellExecute specifies the command from psei->lpDirectory
323      * if present. Not from the current dir as CreateProcess does */
324     if( lpDirectory )
325         if( ( gcdret = GetCurrentDirectoryW( MAX_PATH, curdir)))
326             if( !SetCurrentDirectoryW( lpDirectory))
327                 ERR("cannot set directory %s\n", debugstr_w(lpDirectory));
328     ZeroMemory(&startup,sizeof(STARTUPINFOW));
329     startup.cb = sizeof(STARTUPINFOW);
330     startup.dwFlags = STARTF_USESHOWWINDOW;
331     startup.wShowWindow = psei->nShow;
332     dwCreationFlags = CREATE_UNICODE_ENVIRONMENT;
333     if (psei->fMask & SEE_MASK_NO_CONSOLE)
334         dwCreationFlags |= CREATE_NEW_CONSOLE;
335     if (CreateProcessW(NULL, (LPWSTR)lpCmd, NULL, NULL, FALSE, dwCreationFlags, env,
336                        lpDirectory, &startup, &info))
337     {
338         /* Give 30 seconds to the app to come up, if desired. Probably only needed
339            when starting app immediately before making a DDE connection. */
340         if (shWait)
341             if (WaitForInputIdle( info.hProcess, 30000 ) == WAIT_FAILED)
342                 WARN("WaitForInputIdle failed: Error %d\n", GetLastError() );
343         retval = 33;
344         if (psei->fMask & SEE_MASK_NOCLOSEPROCESS)
345             psei_out->hProcess = info.hProcess;
346         else
347             CloseHandle( info.hProcess );
348         CloseHandle( info.hThread );
349     }
350     else if ((retval = GetLastError()) >= 32)
351     {
352         TRACE("CreateProcess returned error %ld\n", retval);
353         retval = ERROR_BAD_FORMAT;
354     }
355
356     TRACE("returning %lu\n", retval);
357
358     psei_out->hInstApp = (HINSTANCE)retval;
359     if( gcdret )
360         if( !SetCurrentDirectoryW( curdir))
361             ERR("cannot return to directory %s\n", debugstr_w(curdir));
362
363     return retval;
364 }
365
366
367 /***********************************************************************
368  *           SHELL_BuildEnvW    [Internal]
369  *
370  * Build the environment for the new process, adding the specified
371  * path to the PATH variable. Returned pointer must be freed by caller.
372  */
373 static void *SHELL_BuildEnvW( const WCHAR *path )
374 {
375     static const WCHAR wPath[] = {'P','A','T','H','=',0};
376     WCHAR *strings, *new_env;
377     WCHAR *p, *p2;
378     int total = strlenW(path) + 1;
379     BOOL got_path = FALSE;
380
381     if (!(strings = GetEnvironmentStringsW())) return NULL;
382     p = strings;
383     while (*p)
384     {
385         int len = strlenW(p) + 1;
386         if (!strncmpiW( p, wPath, 5 )) got_path = TRUE;
387         total += len;
388         p += len;
389     }
390     if (!got_path) total += 5;  /* we need to create PATH */
391     total++;  /* terminating null */
392
393     if (!(new_env = HeapAlloc( GetProcessHeap(), 0, total * sizeof(WCHAR) )))
394     {
395         FreeEnvironmentStringsW( strings );
396         return NULL;
397     }
398     p = strings;
399     p2 = new_env;
400     while (*p)
401     {
402         int len = strlenW(p) + 1;
403         memcpy( p2, p, len * sizeof(WCHAR) );
404         if (!strncmpiW( p, wPath, 5 ))
405         {
406             p2[len - 1] = ';';
407             strcpyW( p2 + len, path );
408             p2 += strlenW(path) + 1;
409         }
410         p += len;
411         p2 += len;
412     }
413     if (!got_path)
414     {
415         strcpyW( p2, wPath );
416         strcatW( p2, path );
417         p2 += strlenW(p2) + 1;
418     }
419     *p2 = 0;
420     FreeEnvironmentStringsW( strings );
421     return new_env;
422 }
423
424
425 /***********************************************************************
426  *           SHELL_TryAppPathW  [Internal]
427  *
428  * Helper function for SHELL_FindExecutable
429  * @param lpResult - pointer to a buffer of size MAX_PATH
430  * On entry: szName is a filename (probably without path separators).
431  * On exit: if szName found in "App Path", place full path in lpResult, and return true
432  */
433 static BOOL SHELL_TryAppPathW( LPCWSTR szName, LPWSTR lpResult, WCHAR **env)
434 {
435     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',
436         '\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','A','p','p',' ','P','a','t','h','s','\\',0};
437     static const WCHAR wPath[] = {'P','a','t','h',0};
438     HKEY hkApp = 0;
439     WCHAR buffer[1024];
440     LONG len;
441     LONG res;
442     BOOL found = FALSE;
443
444     if (env) *env = NULL;
445     strcpyW(buffer, wszKeyAppPaths);
446     strcatW(buffer, szName);
447     res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, buffer, 0, KEY_READ, &hkApp);
448     if (res) goto end;
449
450     len = MAX_PATH*sizeof(WCHAR);
451     res = RegQueryValueW(hkApp, NULL, lpResult, &len);
452     if (res) goto end;
453     found = TRUE;
454
455     if (env)
456     {
457         DWORD count = sizeof(buffer);
458         if (!RegQueryValueExW(hkApp, wPath, NULL, NULL, (LPBYTE)buffer, &count) && buffer[0])
459             *env = SHELL_BuildEnvW( buffer );
460     }
461
462 end:
463     if (hkApp) RegCloseKey(hkApp);
464     return found;
465 }
466
467 static UINT SHELL_FindExecutableByOperation(LPCWSTR lpOperation, LPWSTR key, LPWSTR filetype, LPWSTR command, LONG commandlen)
468 {
469     static const WCHAR wCommand[] = {'\\','c','o','m','m','a','n','d',0};
470     HKEY hkeyClass;
471     WCHAR verb[MAX_PATH];
472
473     if (RegOpenKeyExW(HKEY_CLASSES_ROOT, filetype, 0, 0x02000000, &hkeyClass))
474         return SE_ERR_NOASSOC;
475     if (!HCR_GetDefaultVerbW(hkeyClass, lpOperation, verb, sizeof(verb)))
476         return SE_ERR_NOASSOC;
477     RegCloseKey(hkeyClass);
478
479     /* Looking for ...buffer\shell\<verb>\command */
480     strcatW(filetype, wszShell);
481     strcatW(filetype, verb);
482     strcatW(filetype, wCommand);
483
484     if (RegQueryValueW(HKEY_CLASSES_ROOT, filetype, command,
485                        &commandlen) == ERROR_SUCCESS)
486     {
487         commandlen /= sizeof(WCHAR);
488         if (key) strcpyW(key, filetype);
489 #if 0
490         LPWSTR tmp;
491         WCHAR param[256];
492         LONG paramlen = sizeof(param);
493         static const WCHAR wSpace[] = {' ',0};
494
495         /* FIXME: it seems all Windows version don't behave the same here.
496          * the doc states that this ddeexec information can be found after
497          * the exec names.
498          * on Win98, it doesn't appear, but I think it does on Win2k
499          */
500         /* Get the parameters needed by the application
501            from the associated ddeexec key */
502         tmp = strstrW(filetype, wCommand);
503         tmp[0] = '\0';
504         strcatW(filetype, wDdeexec);
505         if (RegQueryValueW(HKEY_CLASSES_ROOT, filetype, param,
506                                      &paramlen) == ERROR_SUCCESS)
507         {
508             paramlen /= sizeof(WCHAR);
509             strcatW(command, wSpace);
510             strcatW(command, param);
511             commandlen += paramlen;
512         }
513 #endif
514
515         command[commandlen] = '\0';
516
517         return 33; /* FIXME see SHELL_FindExecutable() */
518     }
519
520     return SE_ERR_NOASSOC;
521 }
522
523 /*************************************************************************
524  *      SHELL_FindExecutable [Internal]
525  *
526  * Utility for code sharing between FindExecutable and ShellExecute
527  * in:
528  *      lpFile the name of a file
529  *      lpOperation the operation on it (open)
530  * out:
531  *      lpResult a buffer, big enough :-(, to store the command to do the
532  *              operation on the file
533  *      key a buffer, big enough, to get the key name to do actually the
534  *              command (it'll be used afterwards for more information
535  *              on the operation)
536  */
537 UINT SHELL_FindExecutable(LPCWSTR lpPath, LPCWSTR lpFile, LPCWSTR lpOperation,
538                                  LPWSTR lpResult, int resultLen, LPWSTR key, WCHAR **env, LPITEMIDLIST pidl, LPCWSTR args)
539 {
540     static const WCHAR wWindows[] = {'w','i','n','d','o','w','s',0};
541     static const WCHAR wPrograms[] = {'p','r','o','g','r','a','m','s',0};
542     static const WCHAR wExtensions[] = {'e','x','e',' ','p','i','f',' ','b','a','t',' ','c','m','d',' ','c','o','m',0};
543     WCHAR *extension = NULL; /* pointer to file extension */
544     WCHAR filetype[256];     /* registry name for this filetype */
545     LONG  filetypelen = sizeof(filetype); /* length of above */
546     WCHAR command[1024];     /* command from registry */
547     WCHAR wBuffer[256];      /* Used to GetProfileString */
548     UINT  retval = SE_ERR_NOASSOC;
549     WCHAR *tok;              /* token pointer */
550     WCHAR xlpFile[256];      /* result of SearchPath */
551     DWORD attribs;           /* file attributes */
552
553     TRACE("%s\n", debugstr_w(lpFile));
554
555     if (!lpResult)
556         return ERROR_INVALID_PARAMETER;
557
558     xlpFile[0] = '\0';
559     lpResult[0] = '\0'; /* Start off with an empty return string */
560     if (key) *key = '\0';
561
562     /* trap NULL parameters on entry */
563     if (!lpFile)
564     {
565         WARN("(lpFile=%s,lpResult=%s): NULL parameter\n",
566              debugstr_w(lpFile), debugstr_w(lpResult));
567         return ERROR_FILE_NOT_FOUND; /* File not found. Close enough, I guess. */
568     }
569
570     if (SHELL_TryAppPathW( lpFile, lpResult, env ))
571     {
572         TRACE("found %s via App Paths\n", debugstr_w(lpResult));
573         return 33;
574     }
575
576     if (SearchPathW(lpPath, lpFile, wszExe, sizeof(xlpFile)/sizeof(WCHAR), xlpFile, NULL))
577     {
578         TRACE("SearchPathW returned non-zero\n");
579         lpFile = xlpFile;
580         /* Hey, isn't this value ignored?  Why make this call?  Shouldn't we return here?  --dank*/
581     }
582
583     attribs = GetFileAttributesW(lpFile);
584     if (attribs!=INVALID_FILE_ATTRIBUTES && (attribs&FILE_ATTRIBUTE_DIRECTORY))
585     {
586        strcpyW(filetype, wszFolder);
587        filetypelen = 6;    /* strlen("Folder") */
588     }
589     else
590     {
591         /* First thing we need is the file's extension */
592         extension = strrchrW(xlpFile, '.'); /* Assume last "." is the one; */
593         /* File->Run in progman uses */
594         /* .\FILE.EXE :( */
595         TRACE("xlpFile=%s,extension=%s\n", debugstr_w(xlpFile), debugstr_w(extension));
596
597         if (extension == NULL || extension[1]==0)
598         {
599             WARN("Returning SE_ERR_NOASSOC\n");
600             return SE_ERR_NOASSOC;
601         }
602
603         /* Three places to check: */
604         /* 1. win.ini, [windows], programs (NB no leading '.') */
605         /* 2. Registry, HKEY_CLASS_ROOT\<filetype>\shell\open\command */
606         /* 3. win.ini, [extensions], extension (NB no leading '.' */
607         /* All I know of the order is that registry is checked before */
608         /* extensions; however, it'd make sense to check the programs */
609         /* section first, so that's what happens here. */
610
611         /* See if it's a program - if GetProfileString fails, we skip this
612          * section. Actually, if GetProfileString fails, we've probably
613          * got a lot more to worry about than running a program... */
614         if (GetProfileStringW(wWindows, wPrograms, wExtensions, wBuffer, sizeof(wBuffer)/sizeof(WCHAR)) > 0)
615         {
616             CharLowerW(wBuffer);
617             tok = wBuffer;
618             while (*tok)
619             {
620                 WCHAR *p = tok;
621                 while (*p && *p != ' ' && *p != '\t') p++;
622                 if (*p)
623                 {
624                     *p++ = 0;
625                     while (*p == ' ' || *p == '\t') p++;
626                 }
627
628                 if (strcmpiW(tok, &extension[1]) == 0) /* have to skip the leading "." */
629                 {
630                     strcpyW(lpResult, xlpFile);
631                     /* Need to perhaps check that the file has a path
632                      * attached */
633                     TRACE("found %s\n", debugstr_w(lpResult));
634                     return 33;
635
636                     /* Greater than 32 to indicate success FIXME According to the
637                      * docs, I should be returning a handle for the
638                      * executable. Does this mean I'm supposed to open the
639                      * executable file or something? More RTFM, I guess... */
640                 }
641                 tok = p;
642             }
643         }
644
645         /* Check registry */
646         if (RegQueryValueW(HKEY_CLASSES_ROOT, extension, filetype,
647                            &filetypelen) == ERROR_SUCCESS)
648         {
649             filetypelen /= sizeof(WCHAR);
650             if (filetypelen == sizeof(filetype)/sizeof(WCHAR))
651                 filetypelen--;
652             filetype[filetypelen] = '\0';
653             TRACE("File type: %s\n", debugstr_w(filetype));
654         }
655         else
656         {
657             *filetype = '\0';
658             filetypelen = 0;
659         }
660     }
661
662     if (*filetype)
663     {
664         /* pass the operation string to SHELL_FindExecutableByOperation() */
665         filetype[filetypelen] = '\0';
666         retval = SHELL_FindExecutableByOperation(lpOperation, key, filetype, command, sizeof(command));
667
668         if (retval > 32)
669         {
670             DWORD finishedLen;
671             SHELL_ArgifyW(lpResult, resultLen, command, xlpFile, pidl, args, &finishedLen);
672             if (finishedLen > resultLen)
673                 ERR("Argify buffer not large enough.. truncated\n");
674
675             /* Remove double quotation marks and command line arguments */
676             if (*lpResult == '"')
677             {
678                 WCHAR *p = lpResult;
679                 while (*(p + 1) != '"')
680                 {
681                     *p = *(p + 1);
682                     p++;
683                 }
684                 *p = '\0';
685             }
686             else
687             {
688                 /* Truncate on first space, like Windows:
689                  * http://support.microsoft.com/?scid=kb%3Ben-us%3B140724
690                  */
691                 WCHAR *p = lpResult;
692                 while (*p != ' ' && *p != '\0')
693                     p++;
694                 *p='\0';
695             }
696         }
697     }
698     else /* Check win.ini */
699     {
700         static const WCHAR wExtensions[] = {'e','x','t','e','n','s','i','o','n','s',0};
701
702         /* Toss the leading dot */
703         extension++;
704         if (GetProfileStringW(wExtensions, extension, wszEmpty, command, sizeof(command)/sizeof(WCHAR)) > 0)
705         {
706             if (strlenW(command) != 0)
707             {
708                 strcpyW(lpResult, command);
709                 tok = strchrW(lpResult, '^'); /* should be ^.extension? */
710                 if (tok != NULL)
711                 {
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))
716                     {
717                         strcatW(lpResult, &tok[5]);
718                     }
719                 }
720                 retval = 33; /* FIXME - see above */
721             }
722         }
723     }
724
725     TRACE("returning %s\n", debugstr_w(lpResult));
726     return retval;
727 }
728
729 /******************************************************************
730  *              dde_cb
731  *
732  * callback for the DDE connection. not really useful
733  */
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)
737 {
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;
741 }
742
743 /******************************************************************
744  *              dde_connect
745  *
746  * ShellExecute helper. Used to do an operation with a DDE connection
747  *
748  * Handles both the direct connection (try #1), and if it fails,
749  * launching an application and trying (#2) to connect to it
750  *
751  */
752 static unsigned dde_connect(WCHAR* key, const WCHAR* start, WCHAR* ddeexec,
753                             const WCHAR* lpFile, WCHAR *env,
754                             LPCWSTR szCommandline, LPITEMIDLIST pidl, SHELL_ExecuteW32 execfunc,
755                             LPSHELLEXECUTEINFOW psei, LPSHELLEXECUTEINFOW psei_out)
756 {
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 *     endkey = key + strlenW(key);
760     WCHAR       app[256], topic[256], ifexec[256], res[256];
761     LONG        applen, topiclen, ifexeclen;
762     WCHAR *     exec;
763     DWORD       ddeInst = 0;
764     DWORD       tid;
765     DWORD       resultLen;
766     HSZ         hszApp, hszTopic;
767     HCONV       hConv;
768     HDDEDATA    hDdeData;
769     unsigned    ret = SE_ERR_NOASSOC;
770     BOOL unicode = !(GetVersion() & 0x80000000);
771
772     strcpyW(endkey, wApplication);
773     applen = sizeof(app);
774     if (RegQueryValueW(HKEY_CLASSES_ROOT, key, app, &applen) != ERROR_SUCCESS)
775     {
776         WCHAR command[1024], fullpath[MAX_PATH];
777         static const WCHAR wSo[] = { '.','s','o',0 };
778         int sizeSo = sizeof(wSo)/sizeof(WCHAR);
779         LPWSTR ptr = NULL;
780         DWORD ret = 0;
781
782         /* Get application command from start string and find filename of application */
783         if (*start == '"')
784         {
785             strcpyW(command, start+1);
786             if ((ptr = strchrW(command, '"')))
787                 *ptr = 0;
788             ret = SearchPathW(NULL, command, wszExe, sizeof(fullpath)/sizeof(WCHAR), fullpath, &ptr);
789         }
790         else
791         {
792             LPWSTR p,space;
793             for (p=(LPWSTR)start; (space=strchrW(p, ' ')); p=space+1)
794             {
795                 int idx = space-start;
796                 memcpy(command, start, idx*sizeof(WCHAR));
797                 command[idx] = '\0';
798                 if ((ret = SearchPathW(NULL, command, wszExe, sizeof(fullpath)/sizeof(WCHAR), fullpath, &ptr)))
799                     break;
800             }
801             if (!ret)
802                 ret = SearchPathW(NULL, start, wszExe, sizeof(fullpath)/sizeof(WCHAR), fullpath, &ptr);
803         }
804
805         if (!ret)
806         {
807             ERR("Unable to find application path for command %s\n", debugstr_w(start));
808             return ERROR_ACCESS_DENIED;
809         }
810         strcpyW(app, ptr);
811
812         /* Remove extensions (including .so) */
813         ptr = app + strlenW(app) - (sizeSo-1);
814         if (strlenW(app) >= sizeSo &&
815             !strcmpW(ptr, wSo))
816             *ptr = 0;
817
818         ptr = strrchrW(app, '.');
819         assert(ptr);
820         *ptr = 0;
821     }
822
823     strcpyW(endkey, wTopic);
824     topiclen = sizeof(topic);
825     if (RegQueryValueW(HKEY_CLASSES_ROOT, key, topic, &topiclen) != ERROR_SUCCESS)
826     {
827         static const WCHAR wSystem[] = {'S','y','s','t','e','m',0};
828         strcpyW(topic, wSystem);
829     }
830
831     if (unicode)
832     {
833         if (DdeInitializeW(&ddeInst, dde_cb, APPCMD_CLIENTONLY, 0L) != DMLERR_NO_ERROR)
834             return 2;
835     }
836     else
837     {
838         if (DdeInitializeA(&ddeInst, dde_cb, APPCMD_CLIENTONLY, 0L) != DMLERR_NO_ERROR)
839             return 2;
840     }
841
842     hszApp = DdeCreateStringHandleW(ddeInst, app, CP_WINUNICODE);
843     hszTopic = DdeCreateStringHandleW(ddeInst, topic, CP_WINUNICODE);
844
845     hConv = DdeConnect(ddeInst, hszApp, hszTopic, NULL);
846     exec = ddeexec;
847     if (!hConv)
848     {
849         static const WCHAR wIfexec[] = {'\\','i','f','e','x','e','c',0};
850         TRACE("Launching %s\n", debugstr_w(start));
851         ret = execfunc(start, env, TRUE, psei, psei_out);
852         if (ret <= 32)
853         {
854             TRACE("Couldn't launch\n");
855             goto error;
856         }
857         hConv = DdeConnect(ddeInst, hszApp, hszTopic, NULL);
858         if (!hConv)
859         {
860             TRACE("Couldn't connect. ret=%d\n", ret);
861             DdeUninitialize(ddeInst);
862             SetLastError(ERROR_DDE_FAIL);
863             return 30; /* whatever */
864         }
865         strcpyW(endkey, wIfexec);
866         ifexeclen = sizeof(ifexec);
867         if (RegQueryValueW(HKEY_CLASSES_ROOT, key, ifexec, &ifexeclen) == ERROR_SUCCESS)
868         {
869             exec = ifexec;
870         }
871     }
872
873     SHELL_ArgifyW(res, sizeof(res)/sizeof(WCHAR), exec, lpFile, pidl, szCommandline, &resultLen);
874     if (resultLen > sizeof(res)/sizeof(WCHAR))
875         ERR("Argify buffer not large enough, truncated\n");
876     TRACE("%s %s => %s\n", debugstr_w(exec), debugstr_w(lpFile), debugstr_w(res));
877
878     /* It's documented in the KB 330337 that IE has a bug and returns
879      * error DMLERR_NOTPROCESSED on XTYP_EXECUTE request.
880      */
881     if (unicode)
882         hDdeData = DdeClientTransaction((LPBYTE)res, (strlenW(res) + 1) * sizeof(WCHAR), hConv, 0L, 0,
883                                          XTYP_EXECUTE, 30000, &tid);
884     else
885     {
886         DWORD lenA = WideCharToMultiByte(CP_ACP, 0, res, -1, NULL, 0, NULL, NULL);
887         char *resA = HeapAlloc(GetProcessHeap(), 0, lenA);
888         WideCharToMultiByte(CP_ACP, 0, res, -1, resA, lenA, NULL, NULL);
889         hDdeData = DdeClientTransaction( (LPBYTE)resA, lenA, hConv, 0L, 0,
890                                          XTYP_EXECUTE, 10000, &tid );
891         HeapFree(GetProcessHeap(), 0, resA);
892     }
893     if (hDdeData)
894         DdeFreeDataHandle(hDdeData);
895     else
896         WARN("DdeClientTransaction failed with error %04x\n", DdeGetLastError(ddeInst));
897     ret = 33;
898
899     DdeDisconnect(hConv);
900
901  error:
902     DdeUninitialize(ddeInst);
903
904     return ret;
905 }
906
907 /*************************************************************************
908  *      execute_from_key [Internal]
909  */
910 static UINT_PTR execute_from_key(LPWSTR key, LPCWSTR lpFile, WCHAR *env, LPCWSTR szCommandline,
911                              LPCWSTR executable_name,
912                              SHELL_ExecuteW32 execfunc,
913                              LPSHELLEXECUTEINFOW psei, LPSHELLEXECUTEINFOW psei_out)
914 {
915     static const WCHAR wCommand[] = {'c','o','m','m','a','n','d',0};
916     static const WCHAR wDdeexec[] = {'d','d','e','e','x','e','c',0};
917     WCHAR cmd[256], param[1024], ddeexec[256];
918     LONG cmdlen = sizeof(cmd), ddeexeclen = sizeof(ddeexec);
919     UINT_PTR retval = SE_ERR_NOASSOC;
920     DWORD resultLen;
921     LPWSTR tmp;
922
923     TRACE("%s %s %s %s %s\n", debugstr_w(key), debugstr_w(lpFile), debugstr_w(env),
924            debugstr_w(szCommandline), debugstr_w(executable_name));
925
926     cmd[0] = '\0';
927     param[0] = '\0';
928
929     /* Get the application from the registry */
930     if (RegQueryValueW(HKEY_CLASSES_ROOT, key, cmd, &cmdlen) == ERROR_SUCCESS)
931     {
932         TRACE("got cmd: %s\n", debugstr_w(cmd));
933
934         /* Is there a replace() function anywhere? */
935         cmdlen /= sizeof(WCHAR);
936         cmd[cmdlen] = '\0';
937         SHELL_ArgifyW(param, sizeof(param)/sizeof(WCHAR), cmd, lpFile, psei->lpIDList, szCommandline, &resultLen);
938         if (resultLen > sizeof(param)/sizeof(WCHAR))
939             ERR("Argify buffer not large enough, truncating\n");
940     }
941
942     /* Get the parameters needed by the application
943        from the associated ddeexec key */
944     tmp = strstrW(key, wCommand);
945     assert(tmp);
946     strcpyW(tmp, wDdeexec);
947
948     if (RegQueryValueW(HKEY_CLASSES_ROOT, key, ddeexec, &ddeexeclen) == ERROR_SUCCESS)
949     {
950         TRACE("Got ddeexec %s => %s\n", debugstr_w(key), debugstr_w(ddeexec));
951         if (!param[0]) strcpyW(param, executable_name);
952         retval = dde_connect(key, param, ddeexec, lpFile, env, szCommandline, psei->lpIDList, execfunc, psei, psei_out);
953     }
954     else if (param[0])
955     {
956         TRACE("executing: %s\n", debugstr_w(param));
957         retval = execfunc(param, env, FALSE, psei, psei_out);
958     }
959     else
960         WARN("Nothing appropriate found for %s\n", debugstr_w(key));
961
962     return retval;
963 }
964
965 /*************************************************************************
966  * FindExecutableA                      [SHELL32.@]
967  */
968 HINSTANCE WINAPI FindExecutableA(LPCSTR lpFile, LPCSTR lpDirectory, LPSTR lpResult)
969 {
970     HINSTANCE retval;
971     WCHAR *wFile = NULL, *wDirectory = NULL;
972     WCHAR wResult[MAX_PATH];
973
974     if (lpFile) __SHCloneStrAtoW(&wFile, lpFile);
975     if (lpDirectory) __SHCloneStrAtoW(&wDirectory, lpDirectory);
976
977     retval = FindExecutableW(wFile, wDirectory, wResult);
978     WideCharToMultiByte(CP_ACP, 0, wResult, -1, lpResult, MAX_PATH, NULL, NULL);
979     SHFree( wFile );
980     SHFree( wDirectory );
981
982     TRACE("returning %s\n", lpResult);
983     return retval;
984 }
985
986 /*************************************************************************
987  * FindExecutableW                      [SHELL32.@]
988  *
989  * This function returns the executable associated with the specified file
990  * for the default verb.
991  *
992  * PARAMS
993  *  lpFile   [I] The file to find the association for. This must refer to
994  *               an existing file otherwise FindExecutable fails and returns
995  *               SE_ERR_FNF.
996  *  lpResult [O] Points to a buffer into which the executable path is
997  *               copied. This parameter must not be NULL otherwise
998  *               FindExecutable() segfaults. The buffer must be of size at
999  *               least MAX_PATH characters.
1000  *
1001  * RETURNS
1002  *  A value greater than 32 on success, less than or equal to 32 otherwise.
1003  *  See the SE_ERR_* constants.
1004  *
1005  * NOTES
1006  *  On Windows XP and 2003, FindExecutable() seems to first convert the
1007  *  filename into 8.3 format, thus taking into account only the first three
1008  *  characters of the extension, and expects to find an association for those.
1009  *  However other Windows versions behave sanely.
1010  */
1011 HINSTANCE WINAPI FindExecutableW(LPCWSTR lpFile, LPCWSTR lpDirectory, LPWSTR lpResult)
1012 {
1013     UINT_PTR retval = SE_ERR_NOASSOC;
1014     WCHAR old_dir[1024];
1015
1016     TRACE("File %s, Dir %s\n", debugstr_w(lpFile), debugstr_w(lpDirectory));
1017
1018     lpResult[0] = '\0'; /* Start off with an empty return string */
1019     if (lpFile == NULL)
1020         return (HINSTANCE)SE_ERR_FNF;
1021
1022     if (lpDirectory)
1023     {
1024         GetCurrentDirectoryW(sizeof(old_dir)/sizeof(WCHAR), old_dir);
1025         SetCurrentDirectoryW(lpDirectory);
1026     }
1027
1028     retval = SHELL_FindExecutable(lpDirectory, lpFile, wszOpen, lpResult, MAX_PATH, NULL, NULL, NULL, NULL);
1029
1030     TRACE("returning %s\n", debugstr_w(lpResult));
1031     if (lpDirectory)
1032         SetCurrentDirectoryW(old_dir);
1033     return (HINSTANCE)retval;
1034 }
1035
1036 /* FIXME: is this already implemented somewhere else? */
1037 static HKEY ShellExecute_GetClassKey( LPSHELLEXECUTEINFOW sei )
1038 {
1039     LPCWSTR ext = NULL, lpClass = NULL;
1040     LPWSTR cls = NULL;
1041     DWORD type = 0, sz = 0;
1042     HKEY hkey = 0;
1043     LONG r;
1044
1045     if (sei->fMask & SEE_MASK_CLASSALL)
1046         return sei->hkeyClass;
1047  
1048     if (sei->fMask & SEE_MASK_CLASSNAME)
1049         lpClass = sei->lpClass;
1050     else
1051     {
1052         ext = PathFindExtensionW( sei->lpFile );
1053         TRACE("ext = %s\n", debugstr_w( ext ) );
1054         if (!ext)
1055             return hkey;
1056
1057         r = RegOpenKeyW( HKEY_CLASSES_ROOT, ext, &hkey );
1058         if (r != ERROR_SUCCESS )
1059             return hkey;
1060
1061         r = RegQueryValueExW( hkey, NULL, 0, &type, NULL, &sz );
1062         if ( r == ERROR_SUCCESS && type == REG_SZ )
1063         {
1064             sz += sizeof (WCHAR);
1065             cls = HeapAlloc( GetProcessHeap(), 0, sz );
1066             cls[0] = 0;
1067             RegQueryValueExW( hkey, NULL, 0, &type, (LPBYTE) cls, &sz );
1068         }
1069
1070         RegCloseKey( hkey );
1071         lpClass = cls;
1072     }
1073
1074     TRACE("class = %s\n", debugstr_w(lpClass) );
1075
1076     hkey = 0;
1077     if ( lpClass )
1078         RegOpenKeyW( HKEY_CLASSES_ROOT, lpClass, &hkey );
1079
1080     HeapFree( GetProcessHeap(), 0, cls );
1081
1082     return hkey;
1083 }
1084
1085 static IDataObject *shellex_get_dataobj( LPSHELLEXECUTEINFOW sei )
1086 {
1087     LPCITEMIDLIST pidllast = NULL;
1088     IDataObject *dataobj = NULL;
1089     IShellFolder *shf = NULL;
1090     LPITEMIDLIST pidl = NULL;
1091     HRESULT r;
1092
1093     if (sei->fMask & SEE_MASK_CLASSALL)
1094         pidl = sei->lpIDList;
1095     else
1096     {
1097         WCHAR fullpath[MAX_PATH];
1098
1099         fullpath[0] = 0;
1100         r = GetFullPathNameW( sei->lpFile, MAX_PATH, fullpath, NULL );
1101         if (!r)
1102             goto end;
1103
1104         pidl = ILCreateFromPathW( fullpath );
1105     }
1106
1107     r = SHBindToParent( pidl, &IID_IShellFolder, (LPVOID*)&shf, &pidllast );
1108     if ( FAILED( r ) )
1109         goto end;
1110
1111     IShellFolder_GetUIObjectOf( shf, NULL, 1, &pidllast,
1112                                 &IID_IDataObject, NULL, (LPVOID*) &dataobj );
1113
1114 end:
1115     if ( pidl != sei->lpIDList )
1116         ILFree( pidl );
1117     if ( shf )
1118         IShellFolder_Release( shf );
1119     return dataobj;
1120 }
1121
1122 static HRESULT shellex_run_context_menu_default( IShellExtInit *obj,
1123                                                  LPSHELLEXECUTEINFOW sei )
1124 {
1125     IContextMenu *cm = NULL;
1126     CMINVOKECOMMANDINFOEX ici;
1127     MENUITEMINFOW info;
1128     WCHAR string[0x80];
1129     INT i, n, def = -1;
1130     HMENU hmenu = 0;
1131     HRESULT r;
1132
1133     TRACE("%p %p\n", obj, sei );
1134
1135     r = IShellExtInit_QueryInterface( obj, &IID_IContextMenu, (LPVOID*) &cm );
1136     if ( FAILED( r ) )
1137         return r;
1138
1139     hmenu = CreateMenu();
1140     if ( !hmenu )
1141         goto end;
1142
1143     /* the number of the last menu added is returned in r */
1144     r = IContextMenu_QueryContextMenu( cm, hmenu, 0, 0x20, 0x7fff, CMF_DEFAULTONLY );
1145     if ( FAILED( r ) )
1146         goto end;
1147
1148     n = GetMenuItemCount( hmenu );
1149     for ( i = 0; i < n; i++ )
1150     {
1151         memset( &info, 0, sizeof info );
1152         info.cbSize = sizeof info;
1153         info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_STATE | MIIM_DATA | MIIM_ID;
1154         info.dwTypeData = string;
1155         info.cch = sizeof string;
1156         string[0] = 0;
1157         GetMenuItemInfoW( hmenu, i, TRUE, &info );
1158
1159         TRACE("menu %d %s %08x %08lx %08x %08x\n", i, debugstr_w(string),
1160             info.fState, info.dwItemData, info.fType, info.wID );
1161         if ( ( !sei->lpVerb && (info.fState & MFS_DEFAULT) ) ||
1162              ( sei->lpVerb && !lstrcmpiW( sei->lpVerb, string ) ) )
1163         {
1164             def = i;
1165             break;
1166         }
1167     }
1168
1169     r = E_FAIL;
1170     if ( def == -1 )
1171         goto end;
1172
1173     memset( &ici, 0, sizeof ici );
1174     ici.cbSize = sizeof ici;
1175     ici.fMask = CMIC_MASK_UNICODE;
1176     ici.nShow = sei->nShow;
1177     ici.lpVerb = MAKEINTRESOURCEA( def );
1178     ici.hwnd = sei->hwnd;
1179     ici.lpParametersW = sei->lpParameters;
1180     
1181     r = IContextMenu_InvokeCommand( cm, (LPCMINVOKECOMMANDINFO) &ici );
1182
1183     TRACE("invoke command returned %08x\n", r );
1184
1185 end:
1186     if ( hmenu )
1187         DestroyMenu( hmenu );
1188     if ( cm )
1189         IContextMenu_Release( cm );
1190     return r;
1191 }
1192
1193 static HRESULT shellex_load_object_and_run( HKEY hkey, LPCGUID guid, LPSHELLEXECUTEINFOW sei )
1194 {
1195     IDataObject *dataobj = NULL;
1196     IObjectWithSite *ows = NULL;
1197     IShellExtInit *obj = NULL;
1198     HRESULT r;
1199
1200     TRACE("%p %s %p\n", hkey, debugstr_guid( guid ), sei );
1201
1202     r = CoInitialize( NULL );
1203     if ( FAILED( r ) )
1204         goto end;
1205
1206     r = CoCreateInstance( guid, NULL, CLSCTX_INPROC_SERVER,
1207                            &IID_IShellExtInit, (LPVOID*)&obj );
1208     if ( FAILED( r ) )
1209     {
1210         ERR("failed %08x\n", r );
1211         goto end;
1212     }
1213
1214     dataobj = shellex_get_dataobj( sei );
1215     if ( !dataobj )
1216     {
1217         ERR("failed to get data object\n");
1218         goto end;
1219     }
1220
1221     r = IShellExtInit_Initialize( obj, NULL, dataobj, hkey );
1222     if ( FAILED( r ) )
1223         goto end;
1224
1225     r = IShellExtInit_QueryInterface( obj, &IID_IObjectWithSite, (LPVOID*) &ows );
1226     if ( FAILED( r ) )
1227         goto end;
1228
1229     IObjectWithSite_SetSite( ows, NULL );
1230
1231     r = shellex_run_context_menu_default( obj, sei );
1232
1233 end:
1234     if ( ows )
1235         IObjectWithSite_Release( ows );
1236     if ( dataobj )
1237         IDataObject_Release( dataobj );
1238     if ( obj )
1239         IShellExtInit_Release( obj );
1240     CoUninitialize();
1241     return r;
1242 }
1243
1244
1245 /*************************************************************************
1246  *      ShellExecute_FromContextMenu [Internal]
1247  */
1248 static LONG ShellExecute_FromContextMenu( LPSHELLEXECUTEINFOW sei )
1249 {
1250     static const WCHAR szcm[] = { 's','h','e','l','l','e','x','\\',
1251         'C','o','n','t','e','x','t','M','e','n','u','H','a','n','d','l','e','r','s',0 };
1252     HKEY hkey, hkeycm = 0;
1253     WCHAR szguid[39];
1254     HRESULT hr;
1255     GUID guid;
1256     DWORD i;
1257     LONG r;
1258
1259     TRACE("%s\n", debugstr_w(sei->lpFile) );
1260
1261     hkey = ShellExecute_GetClassKey( sei );
1262     if ( !hkey )
1263         return ERROR_FUNCTION_FAILED;
1264
1265     r = RegOpenKeyW( hkey, szcm, &hkeycm );
1266     if ( r == ERROR_SUCCESS )
1267     {
1268         i = 0;
1269         while ( 1 )
1270         {
1271             r = RegEnumKeyW( hkeycm, i++, szguid, 39 );
1272             if ( r != ERROR_SUCCESS )
1273                 break;
1274
1275             hr = CLSIDFromString( szguid, &guid );
1276             if (SUCCEEDED(hr))
1277             {
1278                 /* stop at the first one that succeeds in running */
1279                 hr = shellex_load_object_and_run( hkey, &guid, sei );
1280                 if ( SUCCEEDED( hr ) )
1281                     break;
1282             }
1283         }
1284         RegCloseKey( hkeycm );
1285     }
1286
1287     if ( hkey != sei->hkeyClass )
1288         RegCloseKey( hkey );
1289     return r;
1290 }
1291
1292 /*************************************************************************
1293  *      SHELL_execute [Internal]
1294  */
1295 BOOL SHELL_execute( LPSHELLEXECUTEINFOW sei, SHELL_ExecuteW32 execfunc )
1296 {
1297     static const WCHAR wQuote[] = {'"',0};
1298     static const WCHAR wSpace[] = {' ',0};
1299     static const WCHAR wWww[] = {'w','w','w',0};
1300     static const WCHAR wFile[] = {'f','i','l','e',0};
1301     static const WCHAR wHttp[] = {'h','t','t','p',':','/','/',0};
1302     static const WCHAR wExplorer[] = {'e','x','p','l','o','r','e','r','.','e','x','e',0};
1303     static const DWORD unsupportedFlags =
1304         SEE_MASK_INVOKEIDLIST  | SEE_MASK_ICON         | SEE_MASK_HOTKEY |
1305         SEE_MASK_CONNECTNETDRV | SEE_MASK_FLAG_DDEWAIT | SEE_MASK_FLAG_NO_UI |
1306         SEE_MASK_UNICODE       | SEE_MASK_ASYNCOK      | SEE_MASK_HMONITOR;
1307
1308     WCHAR *wszApplicationName, wszParameters[1024], wszDir[MAX_PATH];
1309     DWORD dwApplicationNameLen = MAX_PATH+2;
1310     DWORD len;
1311     SHELLEXECUTEINFOW sei_tmp;  /* modifiable copy of SHELLEXECUTEINFO struct */
1312     WCHAR wfileName[MAX_PATH];
1313     WCHAR *env;
1314     WCHAR lpstrProtocol[256];
1315     LPCWSTR lpFile;
1316     UINT_PTR retval = SE_ERR_NOASSOC;
1317     WCHAR wcmd[1024];
1318     WCHAR buffer[MAX_PATH];
1319     BOOL done;
1320     BOOL appKnownSingular = FALSE;
1321
1322     /* make a local copy of the LPSHELLEXECUTEINFO structure and work with this from now on */
1323     memcpy(&sei_tmp, sei, sizeof(sei_tmp));
1324
1325     TRACE("mask=0x%08x hwnd=%p verb=%s file=%s parm=%s dir=%s show=0x%08x class=%s\n",
1326             sei_tmp.fMask, sei_tmp.hwnd, debugstr_w(sei_tmp.lpVerb),
1327             debugstr_w(sei_tmp.lpFile), debugstr_w(sei_tmp.lpParameters),
1328             debugstr_w(sei_tmp.lpDirectory), sei_tmp.nShow,
1329             ((sei_tmp.fMask & SEE_MASK_CLASSALL) == SEE_MASK_CLASSNAME) ?
1330                 debugstr_w(sei_tmp.lpClass) : "not used");
1331
1332     sei->hProcess = NULL;
1333
1334     /* make copies of all path/command strings */
1335     if (!sei_tmp.lpFile)
1336     {
1337         wszApplicationName = HeapAlloc(GetProcessHeap(), 0, dwApplicationNameLen*sizeof(WCHAR));
1338         *wszApplicationName = '\0';
1339     }
1340     else if (*sei_tmp.lpFile == '\"')
1341     {
1342         DWORD l = strlenW(sei_tmp.lpFile+1);
1343         if(l >= dwApplicationNameLen) dwApplicationNameLen = l+1;
1344         wszApplicationName = HeapAlloc(GetProcessHeap(), 0, dwApplicationNameLen*sizeof(WCHAR));
1345         memcpy(wszApplicationName, sei_tmp.lpFile+1, (l+1)*sizeof(WCHAR));
1346         if (wszApplicationName[l-1] == '\"')
1347             wszApplicationName[l-1] = '\0';
1348         appKnownSingular = TRUE;
1349         TRACE("wszApplicationName=%s\n",debugstr_w(wszApplicationName));
1350     } else {
1351         DWORD l = strlenW(sei_tmp.lpFile)+1;
1352         if(l > dwApplicationNameLen) dwApplicationNameLen = l+1;
1353         wszApplicationName = HeapAlloc(GetProcessHeap(), 0, dwApplicationNameLen*sizeof(WCHAR));
1354         memcpy(wszApplicationName, sei_tmp.lpFile, l*sizeof(WCHAR));
1355     }
1356
1357     if (sei_tmp.lpParameters)
1358         strcpyW(wszParameters, sei_tmp.lpParameters);
1359     else
1360         *wszParameters = '\0';
1361
1362     if (sei_tmp.lpDirectory)
1363         strcpyW(wszDir, sei_tmp.lpDirectory);
1364     else
1365         *wszDir = '\0';
1366
1367     /* adjust string pointers to point to the new buffers */
1368     sei_tmp.lpFile = wszApplicationName;
1369     sei_tmp.lpParameters = wszParameters;
1370     sei_tmp.lpDirectory = wszDir;
1371
1372     if (sei_tmp.fMask & unsupportedFlags)
1373     {
1374         FIXME("flags ignored: 0x%08x\n", sei_tmp.fMask & unsupportedFlags);
1375     }
1376
1377     /* process the IDList */
1378     if (sei_tmp.fMask & SEE_MASK_IDLIST)
1379     {
1380         IShellExecuteHookW* pSEH;
1381
1382         HRESULT hr = SHBindToParent(sei_tmp.lpIDList, &IID_IShellExecuteHookW, (LPVOID*)&pSEH, NULL);
1383
1384         if (SUCCEEDED(hr))
1385         {
1386             hr = IShellExecuteHookW_Execute(pSEH, &sei_tmp);
1387
1388             IShellExecuteHookW_Release(pSEH);
1389
1390             if (hr == S_OK) {
1391                 HeapFree(GetProcessHeap(), 0, wszApplicationName);
1392                 return TRUE;
1393             }
1394         }
1395
1396         SHGetPathFromIDListW(sei_tmp.lpIDList, wszApplicationName);
1397         appKnownSingular = TRUE;
1398         TRACE("-- idlist=%p (%s)\n", sei_tmp.lpIDList, debugstr_w(wszApplicationName));
1399     }
1400
1401     if ( ERROR_SUCCESS == ShellExecute_FromContextMenu( &sei_tmp ) )
1402     {
1403         sei->hInstApp = (HINSTANCE) 33;
1404         HeapFree(GetProcessHeap(), 0, wszApplicationName);
1405         return TRUE;
1406     }
1407
1408     if (sei_tmp.fMask & SEE_MASK_CLASSALL)
1409     {
1410         /* launch a document by fileclass like 'WordPad.Document.1' */
1411         /* the Commandline contains 'c:\Path\wordpad.exe "%1"' */
1412         /* FIXME: szCommandline should not be of a fixed size. Fixed to 1024, MAX_PATH is way too short! */
1413         ULONG cmask=(sei_tmp.fMask & SEE_MASK_CLASSALL);
1414         DWORD resultLen;
1415         HCR_GetExecuteCommandW((cmask == SEE_MASK_CLASSKEY) ? sei_tmp.hkeyClass : NULL,
1416                                (cmask == SEE_MASK_CLASSNAME) ? sei_tmp.lpClass: NULL,
1417                                sei_tmp.lpVerb,
1418                                wszParameters, sizeof(wszParameters)/sizeof(WCHAR));
1419
1420         /* FIXME: get the extension of lpFile, check if it fits to the lpClass */
1421         TRACE("SEE_MASK_CLASSNAME->%s, doc->%s\n", debugstr_w(wszParameters), debugstr_w(wszApplicationName));
1422
1423         wcmd[0] = '\0';
1424         done = SHELL_ArgifyW(wcmd, sizeof(wcmd)/sizeof(WCHAR), wszParameters, wszApplicationName, sei_tmp.lpIDList, NULL, &resultLen);
1425         if (!done && wszApplicationName[0])
1426         {
1427             strcatW(wcmd, wSpace);
1428             strcatW(wcmd, wszApplicationName);
1429         }
1430         if (resultLen > sizeof(wcmd)/sizeof(WCHAR))
1431             ERR("Argify buffer not large enough... truncating\n");
1432         retval = execfunc(wcmd, NULL, FALSE, &sei_tmp, sei);
1433
1434         HeapFree(GetProcessHeap(), 0, wszApplicationName);
1435         return retval > 32;
1436     }
1437
1438     /* Has the IDList not yet been translated? */
1439     if (sei_tmp.fMask & SEE_MASK_IDLIST)
1440     {
1441         /* last chance to translate IDList: now also allow CLSID paths */
1442         if (SUCCEEDED(SHELL_GetPathFromIDListForExecuteW(sei_tmp.lpIDList, buffer, sizeof(buffer)))) {
1443             if (buffer[0]==':' && buffer[1]==':') {
1444                 /* open shell folder for the specified class GUID */
1445                 strcpyW(wszParameters, buffer);
1446                 strcpyW(wszApplicationName, wExplorer);
1447                 appKnownSingular = TRUE;
1448
1449                 sei_tmp.fMask &= ~SEE_MASK_INVOKEIDLIST;
1450             } else {
1451                 WCHAR target[MAX_PATH];
1452                 DWORD attribs;
1453                 DWORD resultLen;
1454                 /* Check if we're executing a directory and if so use the
1455                    handler for the Folder class */
1456                 strcpyW(target, buffer);
1457                 attribs = GetFileAttributesW(buffer);
1458                 if (attribs != INVALID_FILE_ATTRIBUTES &&
1459                     (attribs & FILE_ATTRIBUTE_DIRECTORY) &&
1460                     HCR_GetExecuteCommandW(0, wszFolder,
1461                                            sei_tmp.lpVerb,
1462                                            buffer, sizeof(buffer))) {
1463                     SHELL_ArgifyW(wszApplicationName, dwApplicationNameLen,
1464                                   buffer, target, sei_tmp.lpIDList, NULL, &resultLen);
1465                     if (resultLen > dwApplicationNameLen)
1466                         ERR("Argify buffer not large enough... truncating\n");
1467                     appKnownSingular = FALSE;
1468                 }
1469                 sei_tmp.fMask &= ~SEE_MASK_INVOKEIDLIST;
1470             }
1471         }
1472     }
1473
1474     /* expand environment strings */
1475     len = ExpandEnvironmentStringsW(sei_tmp.lpFile, NULL, 0);
1476     if (len>0)
1477     {
1478         LPWSTR buf;
1479         buf = HeapAlloc(GetProcessHeap(),0,(len+1)*sizeof(WCHAR));
1480
1481         ExpandEnvironmentStringsW(sei_tmp.lpFile, buf, len+1);
1482         HeapFree(GetProcessHeap(), 0, wszApplicationName);
1483         dwApplicationNameLen = len+1;
1484         wszApplicationName = buf;
1485         /* appKnownSingular unmodified */
1486
1487         sei_tmp.lpFile = wszApplicationName;
1488     }
1489
1490     if (*sei_tmp.lpParameters)
1491     {
1492         len = ExpandEnvironmentStringsW(sei_tmp.lpParameters, NULL, 0);
1493         if (len > 0)
1494         {
1495             LPWSTR buf;
1496             len++;
1497             buf = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
1498             ExpandEnvironmentStringsW(sei_tmp.lpParameters, buf, len);
1499             if (len > 1024)
1500                 ERR("Parameters exceeds buffer size (%i > 1024)\n",len);
1501             lstrcpynW(wszParameters, buf, min(1024,len));
1502             HeapFree(GetProcessHeap(),0,buf);
1503         }
1504     }
1505
1506     if (*sei_tmp.lpDirectory)
1507     {
1508         len = ExpandEnvironmentStringsW(sei_tmp.lpDirectory, NULL, 0);
1509         if (len > 0)
1510         {
1511             LPWSTR buf;
1512             len++;
1513             buf = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
1514             ExpandEnvironmentStringsW(sei_tmp.lpDirectory, buf, len);
1515             if (len > 1024)
1516                 ERR("Directory exceeds buffer size (%i > 1024)\n",len);
1517             lstrcpynW(wszDir, buf, min(1024,len));
1518             HeapFree(GetProcessHeap(),0,buf);
1519         }
1520     }
1521
1522     /* Else, try to execute the filename */
1523     TRACE("execute:%s,%s,%s\n", debugstr_w(wszApplicationName), debugstr_w(wszParameters), debugstr_w(wszDir));
1524
1525     /* separate out command line arguments from executable file name */
1526     if (!*sei_tmp.lpParameters && !appKnownSingular) {
1527         /* If the executable path is quoted, handle the rest of the command line as parameters. */
1528         if (sei_tmp.lpFile[0] == '"') {
1529             LPWSTR src = wszApplicationName/*sei_tmp.lpFile*/ + 1;
1530             LPWSTR dst = wfileName;
1531             LPWSTR end;
1532
1533             /* copy the unquoted executable path to 'wfileName' */
1534             while(*src && *src!='"')
1535                 *dst++ = *src++;
1536
1537             *dst = '\0';
1538
1539             if (*src == '"') {
1540                 end = ++src;
1541
1542                 while(isspace(*src))
1543                     ++src;
1544             } else
1545                 end = src;
1546
1547             /* copy the parameter string to 'wszParameters' */
1548             strcpyW(wszParameters, src);
1549
1550             /* terminate previous command string after the quote character */
1551             *end = '\0';
1552         }
1553         else
1554         {
1555             /* If the executable name is not quoted, we have to use this search loop here,
1556                that in CreateProcess() is not sufficient because it does not handle shell links. */
1557             WCHAR buffer[MAX_PATH], xlpFile[MAX_PATH];
1558             LPWSTR space, s;
1559
1560             LPWSTR beg = wszApplicationName/*sei_tmp.lpFile*/;
1561             for(s=beg; (space=strchrW(s, ' ')); s=space+1) {
1562                 int idx = space-sei_tmp.lpFile;
1563                 memcpy(buffer, sei_tmp.lpFile, idx * sizeof(WCHAR));
1564                 buffer[idx] = '\0';
1565
1566                 /*FIXME This finds directory paths if the targeted file name contains spaces. */
1567                 if (SearchPathW(*sei_tmp.lpDirectory? sei_tmp.lpDirectory: NULL, buffer, wszExe, sizeof(xlpFile), xlpFile, NULL))
1568                 {
1569                     /* separate out command from parameter string */
1570                     LPCWSTR p = space + 1;
1571
1572                     while(isspaceW(*p))
1573                         ++p;
1574
1575                     strcpyW(wszParameters, p);
1576                     *space = '\0';
1577
1578                     break;
1579                 }
1580             }
1581
1582             strcpyW(wfileName, sei_tmp.lpFile);
1583         }
1584     } else
1585         strcpyW(wfileName, sei_tmp.lpFile);
1586
1587     lpFile = wfileName;
1588
1589     strcpyW(wcmd, wszApplicationName);
1590     if (sei_tmp.lpParameters[0]) {
1591         strcatW(wcmd, wSpace);
1592         strcatW(wcmd, wszParameters);
1593     }
1594
1595     retval = execfunc(wcmd, NULL, FALSE, &sei_tmp, sei);
1596     if (retval > 32) {
1597         HeapFree(GetProcessHeap(), 0, wszApplicationName);
1598         return TRUE;
1599     }
1600
1601     /* Else, try to find the executable */
1602     wcmd[0] = '\0';
1603     retval = SHELL_FindExecutable(sei_tmp.lpDirectory, lpFile, sei_tmp.lpVerb, wcmd, 1024, lpstrProtocol, &env, sei_tmp.lpIDList, sei_tmp.lpParameters);
1604     if (retval > 32)  /* Found */
1605     {
1606         WCHAR wszQuotedCmd[MAX_PATH+2];
1607         /* Must quote to handle case where cmd contains spaces,
1608          * else security hole if malicious user creates executable file "C:\\Program"
1609          */
1610         strcpyW(wszQuotedCmd, wQuote);
1611         strcatW(wszQuotedCmd, wcmd);
1612         strcatW(wszQuotedCmd, wQuote);
1613         if (wszParameters[0]) {
1614             strcatW(wszQuotedCmd, wSpace);
1615             strcatW(wszQuotedCmd, wszParameters);
1616         }
1617         TRACE("%s/%s => %s/%s\n", debugstr_w(wszApplicationName), debugstr_w(sei_tmp.lpVerb), debugstr_w(wszQuotedCmd), debugstr_w(lpstrProtocol));
1618         if (*lpstrProtocol)
1619             retval = execute_from_key(lpstrProtocol, wszApplicationName, env, sei_tmp.lpParameters, wcmd, execfunc, &sei_tmp, sei);
1620         else
1621             retval = execfunc(wszQuotedCmd, env, FALSE, &sei_tmp, sei);
1622         HeapFree( GetProcessHeap(), 0, env );
1623     }
1624     else if (PathIsURLW(lpFile))    /* File not found, check for URL */
1625     {
1626         static const WCHAR wShell[] = {'\\','s','h','e','l','l','\\',0};
1627         static const WCHAR wCommand[] = {'\\','c','o','m','m','a','n','d',0};
1628         LPWSTR lpstrRes;
1629         INT iSize;
1630
1631         lpstrRes = strchrW(lpFile, ':');
1632         if (lpstrRes)
1633             iSize = lpstrRes - lpFile;
1634         else
1635             iSize = strlenW(lpFile);
1636
1637         TRACE("Got URL: %s\n", debugstr_w(lpFile));
1638         /* Looking for ...protocol\shell\lpOperation\command */
1639         memcpy(lpstrProtocol, lpFile, iSize*sizeof(WCHAR));
1640         lpstrProtocol[iSize] = '\0';
1641         strcatW(lpstrProtocol, wShell);
1642         strcatW(lpstrProtocol, sei_tmp.lpVerb? sei_tmp.lpVerb: wszOpen);
1643         strcatW(lpstrProtocol, wCommand);
1644
1645         /* Remove File Protocol from lpFile */
1646         /* In the case file://path/file     */
1647         if (!strncmpiW(lpFile, wFile, iSize))
1648         {
1649             lpFile += iSize;
1650             while (*lpFile == ':') lpFile++;
1651         }
1652         retval = execute_from_key(lpstrProtocol, lpFile, NULL, sei_tmp.lpParameters, wcmd, execfunc, &sei_tmp, sei);
1653     }
1654     /* Check if file specified is in the form www.??????.*** */
1655     else if (!strncmpiW(lpFile, wWww, 3))
1656     {
1657         /* if so, append lpFile http:// and call ShellExecute */
1658         WCHAR lpstrTmpFile[256];
1659         strcpyW(lpstrTmpFile, wHttp);
1660         strcatW(lpstrTmpFile, lpFile);
1661         retval = (UINT_PTR)ShellExecuteW(sei_tmp.hwnd, sei_tmp.lpVerb, lpstrTmpFile, NULL, NULL, 0);
1662     }
1663
1664     TRACE("retval %lu\n", retval);
1665
1666     HeapFree(GetProcessHeap(), 0, wszApplicationName);
1667
1668     sei->hInstApp = (HINSTANCE)(retval > 32 ? 33 : retval);
1669     return retval > 32;
1670 }
1671
1672 /*************************************************************************
1673  * ShellExecuteA                        [SHELL32.290]
1674  */
1675 HINSTANCE WINAPI ShellExecuteA(HWND hWnd, LPCSTR lpOperation,LPCSTR lpFile,
1676                                LPCSTR lpParameters,LPCSTR lpDirectory, INT iShowCmd)
1677 {
1678     SHELLEXECUTEINFOA sei;
1679
1680     TRACE("%p,%s,%s,%s,%s,%d\n",
1681           hWnd, debugstr_a(lpOperation), debugstr_a(lpFile),
1682           debugstr_a(lpParameters), debugstr_a(lpDirectory), iShowCmd);
1683
1684     sei.cbSize = sizeof(sei);
1685     sei.fMask = 0;
1686     sei.hwnd = hWnd;
1687     sei.lpVerb = lpOperation;
1688     sei.lpFile = lpFile;
1689     sei.lpParameters = lpParameters;
1690     sei.lpDirectory = lpDirectory;
1691     sei.nShow = iShowCmd;
1692     sei.lpIDList = 0;
1693     sei.lpClass = 0;
1694     sei.hkeyClass = 0;
1695     sei.dwHotKey = 0;
1696     sei.hProcess = 0;
1697
1698     ShellExecuteExA (&sei);
1699     return sei.hInstApp;
1700 }
1701
1702 /*************************************************************************
1703  * ShellExecuteExA                              [SHELL32.292]
1704  *
1705  */
1706 BOOL WINAPI ShellExecuteExA (LPSHELLEXECUTEINFOA sei)
1707 {
1708     SHELLEXECUTEINFOW seiW;
1709     BOOL ret;
1710     WCHAR *wVerb = NULL, *wFile = NULL, *wParameters = NULL, *wDirectory = NULL, *wClass = NULL;
1711
1712     TRACE("%p\n", sei);
1713
1714     memcpy(&seiW, sei, sizeof(SHELLEXECUTEINFOW));
1715
1716     if (sei->lpVerb)
1717         seiW.lpVerb = __SHCloneStrAtoW(&wVerb, sei->lpVerb);
1718
1719     if (sei->lpFile)
1720         seiW.lpFile = __SHCloneStrAtoW(&wFile, sei->lpFile);
1721
1722     if (sei->lpParameters)
1723         seiW.lpParameters = __SHCloneStrAtoW(&wParameters, sei->lpParameters);
1724
1725     if (sei->lpDirectory)
1726         seiW.lpDirectory = __SHCloneStrAtoW(&wDirectory, sei->lpDirectory);
1727
1728     if ((sei->fMask & SEE_MASK_CLASSALL) == SEE_MASK_CLASSNAME && sei->lpClass)
1729         seiW.lpClass = __SHCloneStrAtoW(&wClass, sei->lpClass);
1730     else
1731         seiW.lpClass = NULL;
1732
1733     ret = SHELL_execute( &seiW, SHELL_ExecuteW );
1734
1735     sei->hInstApp = seiW.hInstApp;
1736
1737     if (sei->fMask & SEE_MASK_NOCLOSEPROCESS)
1738         sei->hProcess = seiW.hProcess;
1739
1740     SHFree(wVerb);
1741     SHFree(wFile);
1742     SHFree(wParameters);
1743     SHFree(wDirectory);
1744     SHFree(wClass);
1745
1746     return ret;
1747 }
1748
1749 /*************************************************************************
1750  * ShellExecuteExW                              [SHELL32.293]
1751  *
1752  */
1753 BOOL WINAPI ShellExecuteExW (LPSHELLEXECUTEINFOW sei)
1754 {
1755     return SHELL_execute( sei, SHELL_ExecuteW );
1756 }
1757
1758 /*************************************************************************
1759  * ShellExecuteW                        [SHELL32.294]
1760  * from shellapi.h
1761  * WINSHELLAPI HINSTANCE APIENTRY ShellExecuteW(HWND hwnd, LPCWSTR lpOperation,
1762  * LPCWSTR lpFile, LPCWSTR lpParameters, LPCWSTR lpDirectory, INT nShowCmd);
1763  */
1764 HINSTANCE WINAPI ShellExecuteW(HWND hwnd, LPCWSTR lpOperation, LPCWSTR lpFile,
1765                                LPCWSTR lpParameters, LPCWSTR lpDirectory, INT nShowCmd)
1766 {
1767     SHELLEXECUTEINFOW sei;
1768
1769     TRACE("\n");
1770     sei.cbSize = sizeof(sei);
1771     sei.fMask = 0;
1772     sei.hwnd = hwnd;
1773     sei.lpVerb = lpOperation;
1774     sei.lpFile = lpFile;
1775     sei.lpParameters = lpParameters;
1776     sei.lpDirectory = lpDirectory;
1777     sei.nShow = nShowCmd;
1778     sei.lpIDList = 0;
1779     sei.lpClass = 0;
1780     sei.hkeyClass = 0;
1781     sei.dwHotKey = 0;
1782     sei.hProcess = 0;
1783
1784     SHELL_execute( &sei, SHELL_ExecuteW );
1785     return sei.hInstApp;
1786 }
1787
1788 /*************************************************************************
1789  * OpenAs_RunDLLA          [SHELL32.@]
1790  */
1791 void WINAPI OpenAs_RunDLLA(HWND hwnd, HINSTANCE hinst, LPCSTR cmdline, int cmdshow)
1792 {
1793     FIXME("%p, %p, %s, %d\n", hwnd, hinst, debugstr_a(cmdline), cmdshow);
1794 }
1795
1796 /*************************************************************************
1797  * OpenAs_RunDLLW          [SHELL32.@]
1798  */
1799 void WINAPI OpenAs_RunDLLW(HWND hwnd, HINSTANCE hinst, LPCWSTR cmdline, int cmdshow)
1800 {
1801     FIXME("%p, %p, %s, %d\n", hwnd, hinst, debugstr_w(cmdline), cmdshow);
1802 }