Prepare dlls/{comctl32,gdi,msvideo,setupapi,shell32,twain,winmm} for
[wine/multimedia.git] / dlls / shell32 / shlexec.c
blob215c48cff42a051ea6900b58313cd20600ab682e
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 "heap.h"
37 #include "shellapi.h"
38 #include "shlobj.h"
39 #include "shlwapi.h"
40 #include "ddeml.h"
42 #include "wine/winbase16.h"
43 #include "shell32_main.h"
44 #include "undocshell.h"
46 #include "wine/debug.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(exec);
50 /* this function is supposed to expand the escape sequences found in the registry
51 * some diving reported that the following were used:
52 * + %1, %2... seem to report to parameter of index N in ShellExecute pmts
53 * %1 file
54 * %2 printer
55 * %3 driver
56 * %4 port
57 * %I adress of a global item ID (explorer switch /idlist)
58 * %L seems to be %1 as long filename followed by the 8+3 variation
59 * %S ???
60 * %* all following parameters (see batfile)
62 static BOOL argify(char* res, int len, const char* fmt, const char* lpFile)
64 char xlpFile[1024];
65 BOOL done = FALSE;
67 while (*fmt)
69 if (*fmt == '%')
71 switch (*++fmt)
73 case '\0':
74 case '%':
75 *res++ = '%';
76 break;
77 case '1':
78 case '*':
79 if (!done || (*fmt == '1'))
81 if (SearchPathA(NULL, lpFile, ".exe", sizeof(xlpFile), xlpFile, NULL))
83 strcpy(res, xlpFile);
84 res += strlen(xlpFile);
86 else
88 strcpy(res, lpFile);
89 res += strlen(lpFile);
92 break;
93 default: FIXME("Unknown escape sequence %%%c\n", *fmt);
95 fmt++;
96 done = TRUE;
98 else
99 *res++ = *fmt++;
101 *res = '\0';
102 return done;
105 /*************************************************************************
106 * SHELL_ExecuteA [Internal]
109 static HINSTANCE SHELL_ExecuteA(char *lpCmd, LPSHELLEXECUTEINFOA sei, BOOL is32)
111 STARTUPINFOA startup;
112 PROCESS_INFORMATION info;
113 HINSTANCE retval = 31;
115 TRACE("Execute %s from directory %s\n", lpCmd, sei->lpDirectory);
116 ZeroMemory(&startup,sizeof(STARTUPINFOA));
117 startup.cb = sizeof(STARTUPINFOA);
118 startup.dwFlags = STARTF_USESHOWWINDOW;
119 startup.wShowWindow = sei->nShow;
120 if (is32)
122 if (CreateProcessA(NULL, lpCmd, NULL, NULL, FALSE, 0,
123 NULL, sei->lpDirectory, &startup, &info))
125 retval = (HINSTANCE)33;
126 if(sei->fMask & SEE_MASK_NOCLOSEPROCESS)
127 sei->hProcess = info.hProcess;
128 else
129 CloseHandle( info.hProcess );
130 CloseHandle( info.hThread );
132 else if ((retval = GetLastError()) >= (HINSTANCE)32)
134 FIXME("Strange error set by CreateProcess: %d\n", retval);
135 retval = (HINSTANCE)ERROR_BAD_FORMAT;
138 else
139 retval = WinExec16(lpCmd, sei->nShow);
141 sei->hInstApp = retval;
142 return retval;
145 /*************************************************************************
146 * SHELL_FindExecutable [Internal]
148 * Utility for code sharing between FindExecutable and ShellExecute
149 * in:
150 * lpFile the name of a file
151 * lpOperation the operation on it (open)
152 * out:
153 * lpResult a buffer, big enough :-(, to store the command to do the
154 * operation on the file
155 * key a buffer, big enough, to get the key name to do actually the
156 * command (it'll be used afterwards for more information
157 * on the operation)
159 static HINSTANCE SHELL_FindExecutable(LPCSTR lpPath, LPCSTR lpFile, LPCSTR lpOperation,
160 LPSTR lpResult, LPSTR key)
162 char *extension = NULL; /* pointer to file extension */
163 char tmpext[5]; /* local copy to mung as we please */
164 char filetype[256]; /* registry name for this filetype */
165 LONG filetypelen = 256; /* length of above */
166 char command[256]; /* command from registry */
167 LONG commandlen = 256; /* This is the most DOS can handle :) */
168 char buffer[256]; /* Used to GetProfileString */
169 HINSTANCE retval = 31; /* default - 'No association was found' */
170 char *tok; /* token pointer */
171 int i; /* random counter */
172 char xlpFile[256] = ""; /* result of SearchPath */
174 TRACE("%s\n", (lpFile != NULL) ? lpFile : "-");
176 lpResult[0] = '\0'; /* Start off with an empty return string */
178 /* trap NULL parameters on entry */
179 if ((lpFile == NULL) || (lpResult == NULL) || (lpOperation == NULL))
181 WARN("(lpFile=%s,lpResult=%s,lpOperation=%s): NULL parameter\n",
182 lpFile, lpOperation, lpResult);
183 return 2; /* File not found. Close enough, I guess. */
186 if (SearchPathA(lpPath, lpFile, ".exe", sizeof(xlpFile), xlpFile, NULL))
188 TRACE("SearchPathA returned non-zero\n");
189 lpFile = xlpFile;
192 /* First thing we need is the file's extension */
193 extension = strrchr(xlpFile, '.'); /* Assume last "." is the one; */
194 /* File->Run in progman uses */
195 /* .\FILE.EXE :( */
196 TRACE("xlpFile=%s,extension=%s\n", xlpFile, extension);
198 if ((extension == NULL) || (extension == &xlpFile[strlen(xlpFile)]))
200 WARN("Returning 31 - No association\n");
201 return 31; /* no association */
204 /* Make local copy & lowercase it for reg & 'programs=' lookup */
205 lstrcpynA(tmpext, extension, 5);
206 CharLowerA(tmpext);
207 TRACE("%s file\n", tmpext);
209 /* Three places to check: */
210 /* 1. win.ini, [windows], programs (NB no leading '.') */
211 /* 2. Registry, HKEY_CLASS_ROOT\<filetype>\shell\open\command */
212 /* 3. win.ini, [extensions], extension (NB no leading '.' */
213 /* All I know of the order is that registry is checked before */
214 /* extensions; however, it'd make sense to check the programs */
215 /* section first, so that's what happens here. */
217 if (key) *key = '\0';
219 /* See if it's a program - if GetProfileString fails, we skip this
220 * section. Actually, if GetProfileString fails, we've probably
221 * got a lot more to worry about than running a program... */
222 if (GetProfileStringA("windows", "programs", "exe pif bat com",
223 buffer, sizeof(buffer)) > 0)
225 for (i = 0;i<strlen(buffer); i++) buffer[i] = tolower(buffer[i]);
227 tok = strtok(buffer, " \t"); /* ? */
228 while (tok!= NULL)
230 if (strcmp(tok, &tmpext[1]) == 0) /* have to skip the leading "." */
232 strcpy(lpResult, xlpFile);
233 /* Need to perhaps check that the file has a path
234 * attached */
235 TRACE("found %s\n", lpResult);
236 return 33;
238 /* Greater than 32 to indicate success FIXME According to the
239 * docs, I should be returning a handle for the
240 * executable. Does this mean I'm supposed to open the
241 * executable file or something? More RTFM, I guess... */
243 tok = strtok(NULL, " \t");
247 /* Check registry */
248 if (RegQueryValueA(HKEY_CLASSES_ROOT, tmpext, filetype,
249 &filetypelen) == ERROR_SUCCESS)
251 filetype[filetypelen] = '\0';
252 TRACE("File type: %s\n", filetype);
254 /* Looking for ...buffer\shell\lpOperation\command */
255 strcat(filetype, "\\shell\\");
256 strcat(filetype, lpOperation);
257 strcat(filetype, "\\command");
259 if (RegQueryValueA(HKEY_CLASSES_ROOT, filetype, command,
260 &commandlen) == ERROR_SUCCESS)
262 if (key) strcpy(key, filetype);
263 #if 0
264 LPSTR tmp;
265 char param[256];
266 LONG paramlen = 256;
268 /* FIXME: it seems all Windows version don't behave the same here.
269 * the doc states that this ddeexec information can be found after
270 * the exec names.
271 * on Win98, it doesn't appear, but I think it does on Win2k
273 /* Get the parameters needed by the application
274 from the associated ddeexec key */
275 tmp = strstr(filetype, "command");
276 tmp[0] = '\0';
277 strcat(filetype, "ddeexec");
279 if (RegQueryValueA(HKEY_CLASSES_ROOT, filetype, param, &paramlen) == ERROR_SUCCESS)
281 strcat(command, " ");
282 strcat(command, param);
283 commandlen += paramlen;
285 #endif
286 command[commandlen] = '\0';
287 argify(lpResult, sizeof(lpResult), command, xlpFile);
288 retval = 33; /* FIXME see above */
291 else /* Check win.ini */
293 /* Toss the leading dot */
294 extension++;
295 if (GetProfileStringA("extensions", extension, "", command,
296 sizeof(command)) > 0)
298 if (strlen(command) != 0)
300 strcpy(lpResult, command);
301 tok = strstr(lpResult, "^"); /* should be ^.extension? */
302 if (tok != NULL)
304 tok[0] = '\0';
305 strcat(lpResult, xlpFile); /* what if no dir in xlpFile? */
306 tok = strstr(command, "^"); /* see above */
307 if ((tok != NULL) && (strlen(tok)>5))
309 strcat(lpResult, &tok[5]);
312 retval = 33; /* FIXME - see above */
317 TRACE("returning %s\n", lpResult);
318 return retval;
321 /******************************************************************
322 * dde_cb
324 * callback for the DDE connection. not really usefull
326 static HDDEDATA CALLBACK dde_cb(UINT uType, UINT uFmt, HCONV hConv,
327 HSZ hsz1, HSZ hsz2,
328 HDDEDATA hData, DWORD dwData1, DWORD dwData2)
330 return (HDDEDATA)0;
333 /******************************************************************
334 * dde_connect
336 * ShellExecute helper. Used to do an operation with a DDE connection
338 * Handles both the direct connection (try #1), and if it fails,
339 * launching an application and trying (#2) to connect to it
342 static unsigned dde_connect(char* key, char* start, char* ddeexec,
343 const char* lpFile,
344 LPSHELLEXECUTEINFOA sei, BOOL is32)
346 char* endkey = key + strlen(key);
347 char app[256], topic[256], ifexec[256], res[256];
348 LONG applen, topiclen, ifexeclen;
349 char* exec;
350 DWORD ddeInst = 0;
351 DWORD tid;
352 HSZ hszApp, hszTopic;
353 HCONV hConv;
354 unsigned ret = 31;
356 strcpy(endkey, "\\application");
357 applen = sizeof(app);
358 if (RegQueryValueA(HKEY_CLASSES_ROOT, key, app, &applen) != ERROR_SUCCESS)
360 FIXME("default app name NIY %s\n", key);
361 return 2;
364 strcpy(endkey, "\\topic");
365 topiclen = sizeof(topic);
366 if (RegQueryValueA(HKEY_CLASSES_ROOT, key, topic, &topiclen) != ERROR_SUCCESS)
368 strcpy(topic, "System");
371 if (DdeInitializeA(&ddeInst, dde_cb, APPCMD_CLIENTONLY, 0L) != DMLERR_NO_ERROR)
373 return 2;
376 hszApp = DdeCreateStringHandleA(ddeInst, app, CP_WINANSI);
377 hszTopic = DdeCreateStringHandleA(ddeInst, topic, CP_WINANSI);
379 hConv = DdeConnect(ddeInst, hszApp, hszTopic, NULL);
380 exec = ddeexec;
381 if (!hConv)
383 TRACE("Launching '%s'\n", start);
384 ret = SHELL_ExecuteA(start, sei, is32);
385 if (ret < 32)
387 TRACE("Couldn't launch\n");
388 goto error;
390 hConv = DdeConnect(ddeInst, hszApp, hszTopic, NULL);
391 if (!hConv)
393 ret = 30; /* whatever */
394 goto error;
396 strcpy(endkey, "\\ifexec");
397 ifexeclen = sizeof(ifexec);
398 if (RegQueryValueA(HKEY_CLASSES_ROOT, key, ifexec, &ifexeclen) == ERROR_SUCCESS)
400 exec = ifexec;
404 argify(res, sizeof(res), exec, lpFile);
405 TRACE("%s %s => %s\n", exec, lpFile, res);
407 ret = (DdeClientTransaction(res, strlen(res) + 1, hConv, 0L, 0,
408 XTYP_EXECUTE, 10000, &tid) != DMLERR_NO_ERROR) ? 31 : 32;
409 DdeDisconnect(hConv);
410 error:
411 DdeUninitialize(ddeInst);
412 return ret;
415 /*************************************************************************
416 * execute_from_key [Internal]
418 static HINSTANCE execute_from_key(LPSTR key, LPCSTR lpFile, LPSHELLEXECUTEINFOA sei, BOOL is32)
420 char cmd[1024] = "";
421 LONG cmdlen = sizeof(cmd);
422 HINSTANCE retval = 31;
424 /* Get the application for the registry */
425 if (RegQueryValueA(HKEY_CLASSES_ROOT, key, cmd, &cmdlen) == ERROR_SUCCESS)
427 LPSTR tmp;
428 char param[256] = "";
429 LONG paramlen = 256;
431 /* Get the parameters needed by the application
432 from the associated ddeexec key */
433 tmp = strstr(key, "command");
434 assert(tmp);
435 strcpy(tmp, "ddeexec");
437 if (RegQueryValueA(HKEY_CLASSES_ROOT, key, param, &paramlen) == ERROR_SUCCESS)
439 TRACE("Got ddeexec %s => %s\n", key, param);
440 retval = dde_connect(key, cmd, param, lpFile, sei, is32);
442 else
444 /* Is there a replace() function anywhere? */
445 cmd[cmdlen] = '\0';
446 argify(param, sizeof(param), cmd, lpFile);
447 retval = SHELL_ExecuteA(param, sei, is32);
450 else TRACE("ooch\n");
452 return retval;
455 /*************************************************************************
456 * FindExecutableA [SHELL32.@]
458 HINSTANCE WINAPI FindExecutableA(LPCSTR lpFile, LPCSTR lpDirectory, LPSTR lpResult)
460 HINSTANCE retval = 31; /* default - 'No association was found' */
461 char old_dir[1024];
463 TRACE("File %s, Dir %s\n",
464 (lpFile != NULL ? lpFile : "-"), (lpDirectory != NULL ? lpDirectory : "-"));
466 lpResult[0] = '\0'; /* Start off with an empty return string */
468 /* trap NULL parameters on entry */
469 if ((lpFile == NULL) || (lpResult == NULL))
471 /* FIXME - should throw a warning, perhaps! */
472 return 2; /* File not found. Close enough, I guess. */
475 if (lpDirectory)
477 GetCurrentDirectoryA(sizeof(old_dir), old_dir);
478 SetCurrentDirectoryA(lpDirectory);
481 retval = SHELL_FindExecutable(lpDirectory, lpFile, "open", lpResult, NULL);
483 TRACE("returning %s\n", lpResult);
484 if (lpDirectory)
485 SetCurrentDirectoryA(old_dir);
486 return retval;
489 /*************************************************************************
490 * FindExecutableW [SHELL32.@]
492 HINSTANCE WINAPI FindExecutableW(LPCWSTR lpFile, LPCWSTR lpDirectory, LPWSTR lpResult)
494 FIXME("(%p,%p,%p): stub\n", lpFile, lpDirectory, lpResult);
495 return 31; /* default - 'No association was found' */
498 /*************************************************************************
499 * ShellExecuteExA32 [Internal]
501 BOOL WINAPI ShellExecuteExA32 (LPSHELLEXECUTEINFOA sei, BOOL is32)
503 CHAR szApplicationName[MAX_PATH],szCommandline[MAX_PATH],szPidl[20],fileName[MAX_PATH];
504 LPSTR pos;
505 int gap, len;
506 char lpstrProtocol[256];
507 LPCSTR lpFile,lpOperation;
508 HINSTANCE retval = 31;
509 char cmd[1024];
510 BOOL done;
512 TRACE("mask=0x%08lx hwnd=0x%04x verb=%s file=%s parm=%s dir=%s show=0x%08x class=%s\n",
513 sei->fMask, sei->hwnd, debugstr_a(sei->lpVerb),
514 debugstr_a(sei->lpFile), debugstr_a(sei->lpParameters),
515 debugstr_a(sei->lpDirectory), sei->nShow,
516 (sei->fMask & SEE_MASK_CLASSNAME) ? debugstr_a(sei->lpClass) : "not used");
518 sei->hProcess = (HANDLE)NULL;
519 ZeroMemory(szApplicationName,MAX_PATH);
520 if (sei->lpFile)
521 strcpy(szApplicationName, sei->lpFile);
523 ZeroMemory(szCommandline,MAX_PATH);
524 if (sei->lpParameters)
525 strcpy(szCommandline, sei->lpParameters);
527 if (sei->fMask & ((SEE_MASK_CLASSKEY & ~SEE_MASK_CLASSNAME) |
528 SEE_MASK_INVOKEIDLIST | SEE_MASK_ICON | SEE_MASK_HOTKEY |
529 SEE_MASK_CONNECTNETDRV | SEE_MASK_FLAG_DDEWAIT |
530 SEE_MASK_DOENVSUBST | SEE_MASK_FLAG_NO_UI | SEE_MASK_UNICODE |
531 SEE_MASK_NO_CONSOLE | SEE_MASK_ASYNCOK | SEE_MASK_HMONITOR ))
533 FIXME("flags ignored: 0x%08lx\n", sei->fMask);
536 /* process the IDList */
537 if ( (sei->fMask & SEE_MASK_INVOKEIDLIST) == SEE_MASK_INVOKEIDLIST) /*0x0c*/
539 SHGetPathFromIDListA (sei->lpIDList,szApplicationName);
540 TRACE("-- idlist=%p (%s)\n", sei->lpIDList, szApplicationName);
542 else
544 if (sei->fMask & SEE_MASK_IDLIST )
546 pos = strstr(szCommandline, "%I");
547 if (pos)
549 LPVOID pv;
550 HGLOBAL hmem = SHAllocShared ( sei->lpIDList, ILGetSize(sei->lpIDList), 0);
551 pv = SHLockShared(hmem,0);
552 sprintf(szPidl,":%p",pv );
553 SHUnlockShared(pv);
555 gap = strlen(szPidl);
556 len = strlen(pos)-2;
557 memmove(pos+gap,pos+2,len);
558 memcpy(pos,szPidl,gap);
563 if (sei->fMask & SEE_MASK_CLASSNAME)
565 /* launch a document by fileclass like 'WordPad.Document.1' */
566 /* the Commandline contains 'c:\Path\wordpad.exe "%1"' */
567 /* FIXME: szCommandline should not be of a fixed size. Plus MAX_PATH is way too short! */
568 HCR_GetExecuteCommand(sei->lpClass, (sei->lpVerb) ? sei->lpVerb : "open", szCommandline, sizeof(szCommandline));
569 /* FIXME: get the extension of lpFile, check if it fits to the lpClass */
570 TRACE("SEE_MASK_CLASSNAME->'%s', doc->'%s'\n", szCommandline, szApplicationName);
572 cmd[0] = '\0';
573 done = argify(cmd, sizeof(cmd), szCommandline, szApplicationName);
574 if (!done && szApplicationName[0])
576 strcat(cmd, " ");
577 strcat(cmd, szApplicationName);
579 retval = SHELL_ExecuteA(cmd, sei, is32);
580 if (retval > 32)
581 return TRUE;
582 else
583 return FALSE;
586 /* We set the default to open, and that should generally work.
587 But that is not really the way the MS docs say to do it. */
588 if (sei->lpVerb == NULL)
589 lpOperation = "open";
590 else
591 lpOperation = sei->lpVerb;
593 /* Else, try to execute the filename */
594 TRACE("execute:'%s','%s'\n",szApplicationName, szCommandline);
596 strcpy(fileName, szApplicationName);
597 lpFile = fileName;
598 if (szCommandline[0]) {
599 strcat(szApplicationName, " ");
600 strcat(szApplicationName, szCommandline);
603 retval = SHELL_ExecuteA(szApplicationName, sei, is32);
604 if (retval > 32)
605 return TRUE;
607 /* Else, try to find the executable */
608 cmd[0] = '\0';
609 retval = SHELL_FindExecutable(sei->lpDirectory, lpFile, lpOperation, cmd, lpstrProtocol);
610 if (retval > 32) /* Found */
612 if (szCommandline[0]) {
613 strcat(cmd, " ");
614 strcat(cmd, szCommandline);
616 TRACE("%s/%s => %s/%s\n", szApplicationName, lpOperation, cmd, lpstrProtocol);
617 if (*lpstrProtocol)
618 retval = execute_from_key(lpstrProtocol, szApplicationName, sei, is32);
619 else
620 retval = SHELL_ExecuteA(cmd, sei, is32);
622 else if (PathIsURLA((LPSTR)lpFile)) /* File not found, check for URL */
624 LPSTR lpstrRes;
625 INT iSize;
627 lpstrRes = strchr(lpFile, ':');
628 /* PathIsURLA probably should fail on strings without a ':', but it doesn't */
629 if (lpstrRes)
630 iSize = lpstrRes - lpFile;
631 else
632 iSize = strlen(lpFile);
634 TRACE("Got URL: %s\n", lpFile);
635 /* Looking for ...protocol\shell\lpOperation\command */
636 strncpy(lpstrProtocol, lpFile, iSize);
637 lpstrProtocol[iSize] = '\0';
638 strcat(lpstrProtocol, "\\shell\\");
639 strcat(lpstrProtocol, lpOperation);
640 strcat(lpstrProtocol, "\\command");
642 /* Remove File Protocol from lpFile */
643 /* In the case file://path/file */
644 if (!strncasecmp(lpFile, "file", iSize))
646 lpFile += iSize;
647 while (*lpFile == ':') lpFile++;
649 retval = execute_from_key(lpstrProtocol, lpFile, sei, is32);
651 /* Check if file specified is in the form www.??????.*** */
652 else if (!strncasecmp(lpFile, "www", 3))
654 /* if so, append lpFile http:// and call ShellExecute */
655 char lpstrTmpFile[256] = "http://" ;
656 strcat(lpstrTmpFile, lpFile);
657 retval = ShellExecuteA(sei->hwnd, lpOperation, lpstrTmpFile, NULL, NULL, 0);
660 if (retval <= 32)
662 sei->hInstApp = retval;
663 return FALSE;
666 sei->hInstApp = 33;
667 return TRUE;
671 /*************************************************************************
672 * ShellExecute [SHELL.20]
674 HINSTANCE16 WINAPI ShellExecute16( HWND16 hWnd, LPCSTR lpOperation,
675 LPCSTR lpFile, LPCSTR lpParameters,
676 LPCSTR lpDirectory, INT16 iShowCmd )
678 SHELLEXECUTEINFOA sei;
679 HANDLE hProcess = 0;
681 sei.cbSize = sizeof(sei);
682 sei.fMask = 0;
683 sei.hwnd = HWND_32(hWnd);
684 sei.lpVerb = lpOperation;
685 sei.lpFile = lpFile;
686 sei.lpParameters = lpParameters;
687 sei.lpDirectory = lpDirectory;
688 sei.nShow = iShowCmd;
689 sei.lpIDList = 0;
690 sei.lpClass = 0;
691 sei.hkeyClass = 0;
692 sei.dwHotKey = 0;
693 sei.hProcess = hProcess;
695 ShellExecuteExA32 (&sei, FALSE);
696 return (HINSTANCE16)sei.hInstApp;
699 /*************************************************************************
700 * ShellExecuteA [SHELL32.290]
702 HINSTANCE WINAPI ShellExecuteA(HWND hWnd, LPCSTR lpOperation,LPCSTR lpFile,
703 LPCSTR lpParameters,LPCSTR lpDirectory, INT iShowCmd)
705 SHELLEXECUTEINFOA sei;
706 HANDLE hProcess = 0;
708 TRACE("\n");
709 sei.cbSize = sizeof(sei);
710 sei.fMask = 0;
711 sei.hwnd = hWnd;
712 sei.lpVerb = lpOperation;
713 sei.lpFile = lpFile;
714 sei.lpParameters = lpParameters;
715 sei.lpDirectory = lpDirectory;
716 sei.nShow = iShowCmd;
717 sei.lpIDList = 0;
718 sei.lpClass = 0;
719 sei.hkeyClass = 0;
720 sei.dwHotKey = 0;
721 sei.hProcess = hProcess;
723 ShellExecuteExA32 (&sei, TRUE);
724 return sei.hInstApp;
727 /*************************************************************************
728 * ShellExecuteEx [SHELL32.291]
731 BOOL WINAPI ShellExecuteExAW (LPVOID sei)
733 if (SHELL_OsIsUnicode())
734 return ShellExecuteExW (sei);
735 return ShellExecuteExA32 (sei, TRUE);
738 /*************************************************************************
739 * ShellExecuteExA [SHELL32.292]
742 BOOL WINAPI ShellExecuteExA (LPSHELLEXECUTEINFOA sei)
744 return ShellExecuteExA32 (sei, TRUE);
747 /*************************************************************************
748 * ShellExecuteExW [SHELL32.293]
751 BOOL WINAPI ShellExecuteExW (LPSHELLEXECUTEINFOW sei)
753 SHELLEXECUTEINFOA seiA;
754 DWORD ret;
756 TRACE("%p\n", sei);
758 memcpy(&seiA, sei, sizeof(SHELLEXECUTEINFOA));
760 if (sei->lpVerb)
761 seiA.lpVerb = HEAP_strdupWtoA( GetProcessHeap(), 0, sei->lpVerb);
763 if (sei->lpFile)
764 seiA.lpFile = HEAP_strdupWtoA( GetProcessHeap(), 0, sei->lpFile);
766 if (sei->lpParameters)
767 seiA.lpParameters = HEAP_strdupWtoA( GetProcessHeap(), 0, sei->lpParameters);
769 if (sei->lpDirectory)
770 seiA.lpDirectory = HEAP_strdupWtoA( GetProcessHeap(), 0, sei->lpDirectory);
772 if ((sei->fMask & SEE_MASK_CLASSNAME) && sei->lpClass)
773 seiA.lpClass = HEAP_strdupWtoA( GetProcessHeap(), 0, sei->lpClass);
774 else
775 seiA.lpClass = NULL;
777 ret = ShellExecuteExA(&seiA);
779 if (seiA.lpVerb) HeapFree( GetProcessHeap(), 0, (LPSTR) seiA.lpVerb );
780 if (seiA.lpFile) HeapFree( GetProcessHeap(), 0, (LPSTR) seiA.lpFile );
781 if (seiA.lpParameters) HeapFree( GetProcessHeap(), 0, (LPSTR) seiA.lpParameters );
782 if (seiA.lpDirectory) HeapFree( GetProcessHeap(), 0, (LPSTR) seiA.lpDirectory );
783 if (seiA.lpClass) HeapFree( GetProcessHeap(), 0, (LPSTR) seiA.lpClass );
785 return ret;
788 /*************************************************************************
789 * ShellExecuteW [SHELL32.294]
790 * from shellapi.h
791 * WINSHELLAPI HINSTANCE APIENTRY ShellExecuteW(HWND hwnd, LPCWSTR lpOperation,
792 * LPCWSTR lpFile, LPCWSTR lpParameters, LPCWSTR lpDirectory, INT nShowCmd);
794 HINSTANCE WINAPI ShellExecuteW(HWND hwnd, LPCWSTR lpOperation, LPCWSTR lpFile,
795 LPCWSTR lpParameters, LPCWSTR lpDirectory, INT nShowCmd)
797 SHELLEXECUTEINFOW sei;
798 HANDLE hProcess = 0;
800 TRACE("\n");
801 sei.cbSize = sizeof(sei);
802 sei.fMask = 0;
803 sei.hwnd = hwnd;
804 sei.lpVerb = lpOperation;
805 sei.lpFile = lpFile;
806 sei.lpParameters = lpParameters;
807 sei.lpDirectory = lpDirectory;
808 sei.nShow = nShowCmd;
809 sei.lpIDList = 0;
810 sei.lpClass = 0;
811 sei.hkeyClass = 0;
812 sei.dwHotKey = 0;
813 sei.hProcess = hProcess;
815 ShellExecuteExW (&sei);
816 return sei.hInstApp;