Removed unnecessary HANDLE typecasts.
[wine/hacks.git] / dlls / shell32 / shlexec.c
blob291d9710bd7f03cb3b9b9c7dd929ba86491303bd
1 /*
2 * Shell Library Functions
4 * Copyright 1998 Marcus Meissner
5 * Copyright 2002 Eric Pouech
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "config.h"
24 #include <stdlib.h>
25 #include <string.h>
26 #include <stdio.h>
27 #ifdef HAVE_UNISTD_H
28 # include <unistd.h>
29 #endif
30 #include <ctype.h>
31 #include <assert.h>
33 #include "windef.h"
34 #include "winerror.h"
35 #include "winreg.h"
36 #include "wownt32.h"
37 #include "heap.h"
38 #include "shellapi.h"
39 #include "shlobj.h"
40 #include "shlwapi.h"
41 #include "ddeml.h"
43 #include "wine/winbase16.h"
44 #include "shell32_main.h"
45 #include "undocshell.h"
47 #include "wine/debug.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(exec);
51 /***********************************************************************
52 * this function is supposed to expand the escape sequences found in the registry
53 * some diving reported that the following were used:
54 * + %1, %2... seem to report to parameter of index N in ShellExecute pmts
55 * %1 file
56 * %2 printer
57 * %3 driver
58 * %4 port
59 * %I adress of a global item ID (explorer switch /idlist)
60 * %L seems to be %1 as long filename followed by the 8+3 variation
61 * %S ???
62 * %* all following parameters (see batfile)
64 static BOOL argify(char* res, int len, const char* fmt, const char* lpFile)
66 char xlpFile[1024];
67 BOOL done = FALSE;
69 while (*fmt)
71 if (*fmt == '%')
73 switch (*++fmt)
75 case '\0':
76 case '%':
77 *res++ = '%';
78 break;
79 case '1':
80 case '*':
81 if (!done || (*fmt == '1'))
83 if (SearchPathA(NULL, lpFile, ".exe", sizeof(xlpFile), xlpFile, NULL))
85 strcpy(res, xlpFile);
86 res += strlen(xlpFile);
88 else
90 strcpy(res, lpFile);
91 res += strlen(lpFile);
94 break;
95 default: FIXME("Unknown escape sequence %%%c\n", *fmt);
97 fmt++;
98 done = TRUE;
100 else
101 *res++ = *fmt++;
103 *res = '\0';
104 return done;
107 /*************************************************************************
108 * SHELL_ExecuteA [Internal]
111 static UINT SHELL_ExecuteA(char *lpCmd, LPSHELLEXECUTEINFOA sei, BOOL shWait)
113 STARTUPINFOA startup;
114 PROCESS_INFORMATION info;
115 UINT retval = 31;
117 TRACE("Execute %s from directory %s\n", lpCmd, sei->lpDirectory);
118 ZeroMemory(&startup,sizeof(STARTUPINFOA));
119 startup.cb = sizeof(STARTUPINFOA);
120 startup.dwFlags = STARTF_USESHOWWINDOW;
121 startup.wShowWindow = sei->nShow;
122 if (CreateProcessA(NULL, lpCmd, NULL, NULL, FALSE, 0,
123 NULL, sei->lpDirectory, &startup, &info))
125 /* Give 30 seconds to the app to come up, if desired. Probably only needed
126 when starting app immediately before making a DDE connection. */
127 if (shWait)
128 if (WaitForInputIdle( info.hProcess, 30000 ) == -1)
129 WARN("WaitForInputIdle failed: Error %ld\n", GetLastError() );
130 retval = 33;
131 if(sei->fMask & SEE_MASK_NOCLOSEPROCESS)
132 sei->hProcess = info.hProcess;
133 else
134 CloseHandle( info.hProcess );
135 CloseHandle( info.hThread );
137 else if ((retval = GetLastError()) >= 32)
139 FIXME("Strange error set by CreateProcess: %d\n", retval);
140 retval = ERROR_BAD_FORMAT;
143 sei->hInstApp = (HINSTANCE)retval;
144 return retval;
147 /*************************************************************************
148 * SHELL_FindExecutable [Internal]
150 * Utility for code sharing between FindExecutable and ShellExecute
151 * in:
152 * lpFile the name of a file
153 * lpOperation the operation on it (open)
154 * out:
155 * lpResult a buffer, big enough :-(, to store the command to do the
156 * operation on the file
157 * key a buffer, big enough, to get the key name to do actually the
158 * command (it'll be used afterwards for more information
159 * on the operation)
161 static UINT SHELL_FindExecutable(LPCSTR lpPath, LPCSTR lpFile, LPCSTR lpOperation,
162 LPSTR lpResult, LPSTR key)
164 char *extension = NULL; /* pointer to file extension */
165 char tmpext[5]; /* local copy to mung as we please */
166 char filetype[256]; /* registry name for this filetype */
167 LONG filetypelen = 256; /* length of above */
168 char command[256]; /* command from registry */
169 LONG commandlen = 256; /* This is the most DOS can handle :) */
170 char buffer[256]; /* Used to GetProfileString */
171 UINT retval = 31; /* default - 'No association was found' */
172 char *tok; /* token pointer */
173 int i; /* random counter */
174 char xlpFile[256] = ""; /* result of SearchPath */
176 TRACE("%s\n", (lpFile != NULL) ? lpFile : "-");
178 lpResult[0] = '\0'; /* Start off with an empty return string */
180 /* trap NULL parameters on entry */
181 if ((lpFile == NULL) || (lpResult == NULL) || (lpOperation == NULL))
183 WARN("(lpFile=%s,lpResult=%s,lpOperation=%s): NULL parameter\n",
184 lpFile, lpOperation, lpResult);
185 return 2; /* File not found. Close enough, I guess. */
188 if (SearchPathA(lpPath, lpFile, ".exe", sizeof(xlpFile), xlpFile, NULL))
190 TRACE("SearchPathA returned non-zero\n");
191 lpFile = xlpFile;
194 /* First thing we need is the file's extension */
195 extension = strrchr(xlpFile, '.'); /* Assume last "." is the one; */
196 /* File->Run in progman uses */
197 /* .\FILE.EXE :( */
198 TRACE("xlpFile=%s,extension=%s\n", xlpFile, extension);
200 if ((extension == NULL) || (extension == &xlpFile[strlen(xlpFile)]))
202 WARN("Returning 31 - No association\n");
203 return 31; /* no association */
206 /* Make local copy & lowercase it for reg & 'programs=' lookup */
207 lstrcpynA(tmpext, extension, 5);
208 CharLowerA(tmpext);
209 TRACE("%s file\n", tmpext);
211 /* Three places to check: */
212 /* 1. win.ini, [windows], programs (NB no leading '.') */
213 /* 2. Registry, HKEY_CLASS_ROOT\<filetype>\shell\open\command */
214 /* 3. win.ini, [extensions], extension (NB no leading '.' */
215 /* All I know of the order is that registry is checked before */
216 /* extensions; however, it'd make sense to check the programs */
217 /* section first, so that's what happens here. */
219 if (key) *key = '\0';
221 /* See if it's a program - if GetProfileString fails, we skip this
222 * section. Actually, if GetProfileString fails, we've probably
223 * got a lot more to worry about than running a program... */
224 if (GetProfileStringA("windows", "programs", "exe pif bat com",
225 buffer, sizeof(buffer)) > 0)
227 for (i = 0;i<strlen(buffer); i++) buffer[i] = tolower(buffer[i]);
229 tok = strtok(buffer, " \t"); /* ? */
230 while (tok!= NULL)
232 if (strcmp(tok, &tmpext[1]) == 0) /* have to skip the leading "." */
234 strcpy(lpResult, xlpFile);
235 /* Need to perhaps check that the file has a path
236 * attached */
237 TRACE("found %s\n", lpResult);
238 return 33;
240 /* Greater than 32 to indicate success FIXME According to the
241 * docs, I should be returning a handle for the
242 * executable. Does this mean I'm supposed to open the
243 * executable file or something? More RTFM, I guess... */
245 tok = strtok(NULL, " \t");
249 /* Check registry */
250 if (RegQueryValueA(HKEY_CLASSES_ROOT, tmpext, filetype,
251 &filetypelen) == ERROR_SUCCESS)
253 filetype[filetypelen] = '\0';
254 TRACE("File type: %s\n", filetype);
256 /* Looking for ...buffer\shell\lpOperation\command */
257 strcat(filetype, "\\shell\\");
258 strcat(filetype, lpOperation);
259 strcat(filetype, "\\command");
261 if (RegQueryValueA(HKEY_CLASSES_ROOT, filetype, command,
262 &commandlen) == ERROR_SUCCESS)
264 if (key) strcpy(key, filetype);
265 #if 0
266 LPSTR tmp;
267 char param[256];
268 LONG paramlen = 256;
270 /* FIXME: it seems all Windows version don't behave the same here.
271 * the doc states that this ddeexec information can be found after
272 * the exec names.
273 * on Win98, it doesn't appear, but I think it does on Win2k
275 /* Get the parameters needed by the application
276 from the associated ddeexec key */
277 tmp = strstr(filetype, "command");
278 tmp[0] = '\0';
279 strcat(filetype, "ddeexec");
281 if (RegQueryValueA(HKEY_CLASSES_ROOT, filetype, param, &paramlen) == ERROR_SUCCESS)
283 strcat(command, " ");
284 strcat(command, param);
285 commandlen += paramlen;
287 #endif
288 command[commandlen] = '\0';
289 argify(lpResult, sizeof(lpResult), command, xlpFile);
290 retval = 33; /* FIXME see above */
293 else /* Check win.ini */
295 /* Toss the leading dot */
296 extension++;
297 if (GetProfileStringA("extensions", extension, "", command,
298 sizeof(command)) > 0)
300 if (strlen(command) != 0)
302 strcpy(lpResult, command);
303 tok = strstr(lpResult, "^"); /* should be ^.extension? */
304 if (tok != NULL)
306 tok[0] = '\0';
307 strcat(lpResult, xlpFile); /* what if no dir in xlpFile? */
308 tok = strstr(command, "^"); /* see above */
309 if ((tok != NULL) && (strlen(tok)>5))
311 strcat(lpResult, &tok[5]);
314 retval = 33; /* FIXME - see above */
319 TRACE("returning %s\n", lpResult);
320 return retval;
323 /******************************************************************
324 * dde_cb
326 * callback for the DDE connection. not really usefull
328 static HDDEDATA CALLBACK dde_cb(UINT uType, UINT uFmt, HCONV hConv,
329 HSZ hsz1, HSZ hsz2,
330 HDDEDATA hData, DWORD dwData1, DWORD dwData2)
332 return NULL;
335 /******************************************************************
336 * dde_connect
338 * ShellExecute helper. Used to do an operation with a DDE connection
340 * Handles both the direct connection (try #1), and if it fails,
341 * launching an application and trying (#2) to connect to it
344 static unsigned dde_connect(char* key, char* start, char* ddeexec,
345 const char* lpFile,
346 LPSHELLEXECUTEINFOA sei, SHELL_ExecuteA1632 execfunc)
348 char* endkey = key + strlen(key);
349 char app[256], topic[256], ifexec[256], res[256];
350 LONG applen, topiclen, ifexeclen;
351 char* exec;
352 DWORD ddeInst = 0;
353 DWORD tid;
354 HSZ hszApp, hszTopic;
355 HCONV hConv;
356 unsigned ret = 31;
358 strcpy(endkey, "\\application");
359 applen = sizeof(app);
360 if (RegQueryValueA(HKEY_CLASSES_ROOT, key, app, &applen) != ERROR_SUCCESS)
362 FIXME("default app name NIY %s\n", key);
363 return 2;
366 strcpy(endkey, "\\topic");
367 topiclen = sizeof(topic);
368 if (RegQueryValueA(HKEY_CLASSES_ROOT, key, topic, &topiclen) != ERROR_SUCCESS)
370 strcpy(topic, "System");
373 if (DdeInitializeA(&ddeInst, dde_cb, APPCMD_CLIENTONLY, 0L) != DMLERR_NO_ERROR)
375 return 2;
378 hszApp = DdeCreateStringHandleA(ddeInst, app, CP_WINANSI);
379 hszTopic = DdeCreateStringHandleA(ddeInst, topic, CP_WINANSI);
381 hConv = DdeConnect(ddeInst, hszApp, hszTopic, NULL);
382 exec = ddeexec;
383 if (!hConv)
385 TRACE("Launching '%s'\n", start);
386 ret = execfunc(start, sei, TRUE);
387 if (ret < 32)
389 TRACE("Couldn't launch\n");
390 goto error;
392 hConv = DdeConnect(ddeInst, hszApp, hszTopic, NULL);
393 if (!hConv)
395 TRACE("Couldn't connect. ret=%d\n", ret);
396 ret = 30; /* whatever */
397 goto error;
399 strcpy(endkey, "\\ifexec");
400 ifexeclen = sizeof(ifexec);
401 if (RegQueryValueA(HKEY_CLASSES_ROOT, key, ifexec, &ifexeclen) == ERROR_SUCCESS)
403 exec = ifexec;
407 argify(res, sizeof(res), exec, lpFile);
408 TRACE("%s %s => %s\n", exec, lpFile, res);
410 ret = (DdeClientTransaction(res, strlen(res) + 1, hConv, 0L, 0,
411 XTYP_EXECUTE, 10000, &tid) != DMLERR_NO_ERROR) ? 31 : 33;
412 DdeDisconnect(hConv);
413 error:
414 DdeUninitialize(ddeInst);
415 return ret;
418 /*************************************************************************
419 * execute_from_key [Internal]
421 static UINT execute_from_key(LPSTR key, LPCSTR lpFile, LPSHELLEXECUTEINFOA sei, SHELL_ExecuteA1632 execfunc)
423 char cmd[1024] = "";
424 LONG cmdlen = sizeof(cmd);
425 UINT retval = 31;
427 /* Get the application for the registry */
428 if (RegQueryValueA(HKEY_CLASSES_ROOT, key, cmd, &cmdlen) == ERROR_SUCCESS)
430 LPSTR tmp;
431 char param[256] = "";
432 LONG paramlen = 256;
434 /* Get the parameters needed by the application
435 from the associated ddeexec key */
436 tmp = strstr(key, "command");
437 assert(tmp);
438 strcpy(tmp, "ddeexec");
440 if (RegQueryValueA(HKEY_CLASSES_ROOT, key, param, &paramlen) == ERROR_SUCCESS)
442 TRACE("Got ddeexec %s => %s\n", key, param);
443 retval = dde_connect(key, cmd, param, lpFile, sei, execfunc);
445 else
447 /* Is there a replace() function anywhere? */
448 cmd[cmdlen] = '\0';
449 argify(param, sizeof(param), cmd, lpFile);
450 retval = execfunc(param, sei, FALSE);
453 else TRACE("ooch\n");
455 return retval;
458 /*************************************************************************
459 * FindExecutableA [SHELL32.@]
461 HINSTANCE WINAPI FindExecutableA(LPCSTR lpFile, LPCSTR lpDirectory, LPSTR lpResult)
463 UINT retval = 31; /* default - 'No association was found' */
464 char old_dir[1024];
466 TRACE("File %s, Dir %s\n",
467 (lpFile != NULL ? lpFile : "-"), (lpDirectory != NULL ? lpDirectory : "-"));
469 lpResult[0] = '\0'; /* Start off with an empty return string */
471 /* trap NULL parameters on entry */
472 if ((lpFile == NULL) || (lpResult == NULL))
474 /* FIXME - should throw a warning, perhaps! */
475 return (HINSTANCE)2; /* File not found. Close enough, I guess. */
478 if (lpDirectory)
480 GetCurrentDirectoryA(sizeof(old_dir), old_dir);
481 SetCurrentDirectoryA(lpDirectory);
484 retval = SHELL_FindExecutable(lpDirectory, lpFile, "open", lpResult, NULL);
486 TRACE("returning %s\n", lpResult);
487 if (lpDirectory)
488 SetCurrentDirectoryA(old_dir);
489 return (HINSTANCE)retval;
492 /*************************************************************************
493 * FindExecutableW [SHELL32.@]
495 HINSTANCE WINAPI FindExecutableW(LPCWSTR lpFile, LPCWSTR lpDirectory, LPWSTR lpResult)
497 FIXME("(%p,%p,%p): stub\n", lpFile, lpDirectory, lpResult);
498 return (HINSTANCE)31; /* default - 'No association was found' */
501 /*************************************************************************
502 * ShellExecuteExA32 [Internal]
504 BOOL WINAPI ShellExecuteExA32 (LPSHELLEXECUTEINFOA sei, SHELL_ExecuteA1632 execfunc)
506 CHAR szApplicationName[MAX_PATH],szCommandline[MAX_PATH],szPidl[20],fileName[MAX_PATH];
507 LPSTR pos;
508 int gap, len;
509 char lpstrProtocol[256];
510 LPCSTR lpFile,lpOperation;
511 UINT retval = 31;
512 char cmd[1024];
513 BOOL done;
515 TRACE("mask=0x%08lx hwnd=%p verb=%s file=%s parm=%s dir=%s show=0x%08x class=%s\n",
516 sei->fMask, sei->hwnd, debugstr_a(sei->lpVerb),
517 debugstr_a(sei->lpFile), debugstr_a(sei->lpParameters),
518 debugstr_a(sei->lpDirectory), sei->nShow,
519 (sei->fMask & SEE_MASK_CLASSNAME) ? debugstr_a(sei->lpClass) : "not used");
521 sei->hProcess = (HANDLE)NULL;
522 ZeroMemory(szApplicationName,MAX_PATH);
523 if (sei->lpFile)
524 strcpy(szApplicationName, sei->lpFile);
526 ZeroMemory(szCommandline,MAX_PATH);
527 if (sei->lpParameters)
528 strcpy(szCommandline, sei->lpParameters);
530 if (sei->fMask & ((SEE_MASK_CLASSKEY & ~SEE_MASK_CLASSNAME) |
531 SEE_MASK_INVOKEIDLIST | SEE_MASK_ICON | SEE_MASK_HOTKEY |
532 SEE_MASK_CONNECTNETDRV | SEE_MASK_FLAG_DDEWAIT |
533 SEE_MASK_DOENVSUBST | SEE_MASK_FLAG_NO_UI | SEE_MASK_UNICODE |
534 SEE_MASK_NO_CONSOLE | SEE_MASK_ASYNCOK | SEE_MASK_HMONITOR ))
536 FIXME("flags ignored: 0x%08lx\n", sei->fMask);
539 /* process the IDList */
540 if ( (sei->fMask & SEE_MASK_INVOKEIDLIST) == SEE_MASK_INVOKEIDLIST) /*0x0c*/
542 SHGetPathFromIDListA (sei->lpIDList,szApplicationName);
543 TRACE("-- idlist=%p (%s)\n", sei->lpIDList, szApplicationName);
545 else
547 if (sei->fMask & SEE_MASK_IDLIST )
549 pos = strstr(szCommandline, "%I");
550 if (pos)
552 LPVOID pv;
553 HGLOBAL hmem = SHAllocShared ( sei->lpIDList, ILGetSize(sei->lpIDList), 0);
554 pv = SHLockShared(hmem,0);
555 sprintf(szPidl,":%p",pv );
556 SHUnlockShared(pv);
558 gap = strlen(szPidl);
559 len = strlen(pos)-2;
560 memmove(pos+gap,pos+2,len);
561 memcpy(pos,szPidl,gap);
566 if (sei->fMask & SEE_MASK_CLASSNAME)
568 /* launch a document by fileclass like 'WordPad.Document.1' */
569 /* the Commandline contains 'c:\Path\wordpad.exe "%1"' */
570 /* FIXME: szCommandline should not be of a fixed size. Plus MAX_PATH is way too short! */
571 HCR_GetExecuteCommand(sei->lpClass, (sei->lpVerb) ? sei->lpVerb : "open", szCommandline, sizeof(szCommandline));
572 /* FIXME: get the extension of lpFile, check if it fits to the lpClass */
573 TRACE("SEE_MASK_CLASSNAME->'%s', doc->'%s'\n", szCommandline, szApplicationName);
575 cmd[0] = '\0';
576 done = argify(cmd, sizeof(cmd), szCommandline, szApplicationName);
577 if (!done && szApplicationName[0])
579 strcat(cmd, " ");
580 strcat(cmd, szApplicationName);
582 retval = execfunc(cmd, sei, FALSE);
583 if (retval > 32)
584 return TRUE;
585 else
586 return FALSE;
589 /* We set the default to open, and that should generally work.
590 But that is not really the way the MS docs say to do it. */
591 if (sei->lpVerb == NULL)
592 lpOperation = "open";
593 else
594 lpOperation = sei->lpVerb;
596 /* Else, try to execute the filename */
597 TRACE("execute:'%s','%s'\n",szApplicationName, szCommandline);
599 strcpy(fileName, szApplicationName);
600 lpFile = fileName;
601 if (szCommandline[0]) {
602 strcat(szApplicationName, " ");
603 strcat(szApplicationName, szCommandline);
606 retval = execfunc(szApplicationName, sei, FALSE);
607 if (retval > 32)
608 return TRUE;
610 /* Else, try to find the executable */
611 cmd[0] = '\0';
612 retval = SHELL_FindExecutable(sei->lpDirectory, lpFile, lpOperation, cmd, lpstrProtocol);
613 if (retval > 32) /* Found */
615 if (szCommandline[0]) {
616 strcat(cmd, " ");
617 strcat(cmd, szCommandline);
619 TRACE("%s/%s => %s/%s\n", szApplicationName, lpOperation, cmd, lpstrProtocol);
620 if (*lpstrProtocol)
621 retval = execute_from_key(lpstrProtocol, szApplicationName, sei, execfunc);
622 else
623 retval = execfunc(cmd, sei, FALSE);
625 else if (PathIsURLA((LPSTR)lpFile)) /* File not found, check for URL */
627 LPSTR lpstrRes;
628 INT iSize;
630 lpstrRes = strchr(lpFile, ':');
631 if (lpstrRes)
632 iSize = lpstrRes - lpFile;
633 else
634 iSize = strlen(lpFile);
636 TRACE("Got URL: %s\n", lpFile);
637 /* Looking for ...protocol\shell\lpOperation\command */
638 strncpy(lpstrProtocol, lpFile, iSize);
639 lpstrProtocol[iSize] = '\0';
640 strcat(lpstrProtocol, "\\shell\\");
641 strcat(lpstrProtocol, lpOperation);
642 strcat(lpstrProtocol, "\\command");
644 /* Remove File Protocol from lpFile */
645 /* In the case file://path/file */
646 if (!strncasecmp(lpFile, "file", iSize))
648 lpFile += iSize;
649 while (*lpFile == ':') lpFile++;
651 retval = execute_from_key(lpstrProtocol, lpFile, sei, execfunc);
653 /* Check if file specified is in the form www.??????.*** */
654 else if (!strncasecmp(lpFile, "www", 3))
656 /* if so, append lpFile http:// and call ShellExecute */
657 char lpstrTmpFile[256] = "http://" ;
658 strcat(lpstrTmpFile, lpFile);
659 retval = (UINT)ShellExecuteA(sei->hwnd, lpOperation, lpstrTmpFile, NULL, NULL, 0);
662 if (retval <= 32)
664 sei->hInstApp = (HINSTANCE)retval;
665 return FALSE;
668 sei->hInstApp = (HINSTANCE)33;
669 return TRUE;
672 /*************************************************************************
673 * ShellExecuteA [SHELL32.290]
675 HINSTANCE WINAPI ShellExecuteA(HWND hWnd, LPCSTR lpOperation,LPCSTR lpFile,
676 LPCSTR lpParameters,LPCSTR lpDirectory, INT iShowCmd)
678 SHELLEXECUTEINFOA sei;
679 HANDLE hProcess = 0;
681 TRACE("\n");
682 sei.cbSize = sizeof(sei);
683 sei.fMask = 0;
684 sei.hwnd = hWnd;
685 sei.lpVerb = lpOperation;
686 sei.lpFile = lpFile;
687 sei.lpParameters = lpParameters;
688 sei.lpDirectory = lpDirectory;
689 sei.nShow = iShowCmd;
690 sei.lpIDList = 0;
691 sei.lpClass = 0;
692 sei.hkeyClass = 0;
693 sei.dwHotKey = 0;
694 sei.hProcess = hProcess;
696 ShellExecuteExA32 (&sei, SHELL_ExecuteA);
697 return sei.hInstApp;
700 /*************************************************************************
701 * ShellExecuteEx [SHELL32.291]
704 BOOL WINAPI ShellExecuteExAW (LPVOID sei)
706 if (SHELL_OsIsUnicode())
707 return ShellExecuteExW (sei);
708 return ShellExecuteExA32 (sei, SHELL_ExecuteA);
711 /*************************************************************************
712 * ShellExecuteExA [SHELL32.292]
715 BOOL WINAPI ShellExecuteExA (LPSHELLEXECUTEINFOA sei)
717 return ShellExecuteExA32 (sei, SHELL_ExecuteA);
720 /*************************************************************************
721 * ShellExecuteExW [SHELL32.293]
724 BOOL WINAPI ShellExecuteExW (LPSHELLEXECUTEINFOW sei)
726 SHELLEXECUTEINFOA seiA;
727 DWORD ret;
729 TRACE("%p\n", sei);
731 memcpy(&seiA, sei, sizeof(SHELLEXECUTEINFOA));
733 if (sei->lpVerb)
734 seiA.lpVerb = HEAP_strdupWtoA( GetProcessHeap(), 0, sei->lpVerb);
736 if (sei->lpFile)
737 seiA.lpFile = HEAP_strdupWtoA( GetProcessHeap(), 0, sei->lpFile);
739 if (sei->lpParameters)
740 seiA.lpParameters = HEAP_strdupWtoA( GetProcessHeap(), 0, sei->lpParameters);
742 if (sei->lpDirectory)
743 seiA.lpDirectory = HEAP_strdupWtoA( GetProcessHeap(), 0, sei->lpDirectory);
745 if ((sei->fMask & SEE_MASK_CLASSNAME) && sei->lpClass)
746 seiA.lpClass = HEAP_strdupWtoA( GetProcessHeap(), 0, sei->lpClass);
747 else
748 seiA.lpClass = NULL;
750 ret = ShellExecuteExA(&seiA);
752 if (seiA.lpVerb) HeapFree( GetProcessHeap(), 0, (LPSTR) seiA.lpVerb );
753 if (seiA.lpFile) HeapFree( GetProcessHeap(), 0, (LPSTR) seiA.lpFile );
754 if (seiA.lpParameters) HeapFree( GetProcessHeap(), 0, (LPSTR) seiA.lpParameters );
755 if (seiA.lpDirectory) HeapFree( GetProcessHeap(), 0, (LPSTR) seiA.lpDirectory );
756 if (seiA.lpClass) HeapFree( GetProcessHeap(), 0, (LPSTR) seiA.lpClass );
758 return ret;
761 /*************************************************************************
762 * ShellExecuteW [SHELL32.294]
763 * from shellapi.h
764 * WINSHELLAPI HINSTANCE APIENTRY ShellExecuteW(HWND hwnd, LPCWSTR lpOperation,
765 * LPCWSTR lpFile, LPCWSTR lpParameters, LPCWSTR lpDirectory, INT nShowCmd);
767 HINSTANCE WINAPI ShellExecuteW(HWND hwnd, LPCWSTR lpOperation, LPCWSTR lpFile,
768 LPCWSTR lpParameters, LPCWSTR lpDirectory, INT nShowCmd)
770 SHELLEXECUTEINFOW sei;
771 HANDLE hProcess = 0;
773 TRACE("\n");
774 sei.cbSize = sizeof(sei);
775 sei.fMask = 0;
776 sei.hwnd = hwnd;
777 sei.lpVerb = lpOperation;
778 sei.lpFile = lpFile;
779 sei.lpParameters = lpParameters;
780 sei.lpDirectory = lpDirectory;
781 sei.nShow = nShowCmd;
782 sei.lpIDList = 0;
783 sei.lpClass = 0;
784 sei.hkeyClass = 0;
785 sei.dwHotKey = 0;
786 sei.hProcess = hProcess;
788 ShellExecuteExW (&sei);
789 return sei.hInstApp;