ddraw: Avoid LPDIRECT3DEXECUTEBUFFER.
[wine/testsucceed.git] / dlls / shell32 / shell32_main.c
blob7648dbb46e2bf8d225bbe601454e8e7a4f02c486
1 /*
2 * Shell basics
4 * Copyright 1998 Marcus Meissner
5 * Copyright 1998 Juergen Schmied (jsch) * <juergen.schmied@metronet.de>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
24 #include <stdlib.h>
25 #include <string.h>
26 #include <stdarg.h>
27 #include <stdio.h>
29 #define COBJMACROS
31 #include "windef.h"
32 #include "winbase.h"
33 #include "winerror.h"
34 #include "winreg.h"
35 #include "dlgs.h"
36 #include "shellapi.h"
37 #include "winuser.h"
38 #include "wingdi.h"
39 #include "shlobj.h"
40 #include "rpcproxy.h"
41 #include "shlwapi.h"
42 #include "propsys.h"
44 #include "undocshell.h"
45 #include "pidl.h"
46 #include "shell32_main.h"
47 #include "version.h"
48 #include "shresdef.h"
49 #include "initguid.h"
50 #include "shfldr.h"
52 #include "wine/debug.h"
53 #include "wine/unicode.h"
55 WINE_DEFAULT_DEBUG_CHANNEL(shell);
57 /*************************************************************************
58 * CommandLineToArgvW [SHELL32.@]
60 * We must interpret the quotes in the command line to rebuild the argv
61 * array correctly:
62 * - arguments are separated by spaces or tabs
63 * - quotes serve as optional argument delimiters
64 * '"a b"' -> 'a b'
65 * - escaped quotes must be converted back to '"'
66 * '\"' -> '"'
67 * - consecutive backslashes preceding a quote see their number halved with
68 * the remainder escaping the quote:
69 * 2n backslashes + quote -> n backslashes + quote as an argument delimiter
70 * 2n+1 backslashes + quote -> n backslashes + literal quote
71 * - backslashes that are not followed by a quote are copied literally:
72 * 'a\b' -> 'a\b'
73 * 'a\\b' -> 'a\\b'
74 * - in quoted strings, consecutive quotes see their number divided by three
75 * with the remainder modulo 3 deciding whether to close the string or not.
76 * Note that the opening quote must be counted in the consecutive quotes,
77 * that's the (1+) below:
78 * (1+) 3n quotes -> n quotes
79 * (1+) 3n+1 quotes -> n quotes plus closes the quoted string
80 * (1+) 3n+2 quotes -> n+1 quotes plus closes the quoted string
81 * - in unquoted strings, the first quote opens the quoted string and the
82 * remaining consecutive quotes follow the above rule.
84 LPWSTR* WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int* numargs)
86 DWORD argc;
87 LPWSTR *argv;
88 LPCWSTR s;
89 LPWSTR d;
90 LPWSTR cmdline;
91 int qcount,bcount;
93 if(!numargs)
95 SetLastError(ERROR_INVALID_PARAMETER);
96 return NULL;
99 if (*lpCmdline==0)
101 /* Return the path to the executable */
102 DWORD len, deslen=MAX_PATH, size;
104 size = sizeof(LPWSTR) + deslen*sizeof(WCHAR) + sizeof(LPWSTR);
105 for (;;)
107 if (!(argv = LocalAlloc(LMEM_FIXED, size))) return NULL;
108 len = GetModuleFileNameW(0, (LPWSTR)(argv+1), deslen);
109 if (!len)
111 LocalFree(argv);
112 return NULL;
114 if (len < deslen) break;
115 deslen*=2;
116 size = sizeof(LPWSTR) + deslen*sizeof(WCHAR) + sizeof(LPWSTR);
117 LocalFree( argv );
119 argv[0]=(LPWSTR)(argv+1);
120 *numargs=1;
122 return argv;
125 /* --- First count the arguments */
126 argc=1;
127 s=lpCmdline;
128 /* The first argument, the executable path, follows special rules */
129 if (*s=='"')
131 /* The executable path ends at the next quote, no matter what */
132 s++;
133 while (*s)
134 if (*s++=='"')
135 break;
137 else
139 /* The executable path ends at the next space, no matter what */
140 while (*s && *s!=' ' && *s!='\t')
141 s++;
143 /* skip to the first argument, if any */
144 while (*s==' ' || *s=='\t')
145 s++;
146 if (*s)
147 argc++;
149 /* Analyze the remaining arguments */
150 qcount=bcount=0;
151 while (*s)
153 if ((*s==' ' || *s=='\t') && qcount==0)
155 /* skip to the next argument and count it if any */
156 while (*s==' ' || *s=='\t')
157 s++;
158 if (*s)
159 argc++;
160 bcount=0;
162 else if (*s=='\\')
164 /* '\', count them */
165 bcount++;
166 s++;
168 else if (*s=='"')
170 /* '"' */
171 if ((bcount & 1)==0)
172 qcount++; /* unescaped '"' */
173 s++;
174 bcount=0;
175 /* consecutive quotes, see comment in copying code below */
176 while (*s=='"')
178 qcount++;
179 s++;
181 qcount=qcount % 3;
182 if (qcount==2)
183 qcount=0;
185 else
187 /* a regular character */
188 bcount=0;
189 s++;
193 /* Allocate in a single lump, the string array, and the strings that go
194 * with it. This way the caller can make a single LocalFree() call to free
195 * both, as per MSDN.
197 argv=LocalAlloc(LMEM_FIXED, argc*sizeof(LPWSTR)+(strlenW(lpCmdline)+1)*sizeof(WCHAR));
198 if (!argv)
199 return NULL;
200 cmdline=(LPWSTR)(argv+argc);
201 strcpyW(cmdline, lpCmdline);
203 /* --- Then split and copy the arguments */
204 argv[0]=d=cmdline;
205 argc=1;
206 /* The first argument, the executable path, follows special rules */
207 if (*d=='"')
209 /* The executable path ends at the next quote, no matter what */
210 s=d+1;
211 while (*s)
213 if (*s=='"')
215 s++;
216 break;
218 *d++=*s++;
221 else
223 /* The executable path ends at the next space, no matter what */
224 while (*d && *d!=' ' && *d!='\t')
225 d++;
226 s=d;
227 if (*s)
228 s++;
230 /* close the argument */
231 *d++=0;
232 /* skip to the first argument and initialize it if any */
233 while (*s==' ' || *s=='\t')
234 s++;
235 if (*s)
236 argv[argc++]=d;
238 /* Split and copy the remaining arguments */
239 qcount=bcount=0;
240 while (*s)
242 if ((*s==' ' || *s=='\t') && qcount==0)
244 /* close the argument */
245 *d++=0;
246 bcount=0;
248 /* skip to the next one and initialize it if any */
249 do {
250 s++;
251 } while (*s==' ' || *s=='\t');
252 if (*s)
253 argv[argc++]=d;
255 else if (*s=='\\')
257 *d++=*s++;
258 bcount++;
260 else if (*s=='"')
262 if ((bcount & 1)==0)
264 /* Preceded by an even number of '\', this is half that
265 * number of '\', plus a quote which we erase.
267 d-=bcount/2;
268 qcount++;
270 else
272 /* Preceded by an odd number of '\', this is half that
273 * number of '\' followed by a '"'
275 d=d-bcount/2-1;
276 *d++='"';
278 s++;
279 bcount=0;
280 /* Now count the number of consecutive quotes. Note that qcount
281 * already takes into account the opening quote if any, as well as
282 * the quote that lead us here.
284 while (*s=='"')
286 if (++qcount==3)
288 *d++='"';
289 qcount=0;
291 s++;
293 if (qcount==2)
294 qcount=0;
296 else
298 /* a regular character */
299 *d++=*s++;
300 bcount=0;
303 *d='\0';
304 *numargs=argc;
306 return argv;
309 static DWORD shgfi_get_exe_type(LPCWSTR szFullPath)
311 BOOL status = FALSE;
312 HANDLE hfile;
313 DWORD BinaryType;
314 IMAGE_DOS_HEADER mz_header;
315 IMAGE_NT_HEADERS nt;
316 DWORD len;
317 char magic[4];
319 status = GetBinaryTypeW (szFullPath, &BinaryType);
320 if (!status)
321 return 0;
322 if (BinaryType == SCS_DOS_BINARY || BinaryType == SCS_PIF_BINARY)
323 return 0x4d5a;
325 hfile = CreateFileW( szFullPath, GENERIC_READ, FILE_SHARE_READ,
326 NULL, OPEN_EXISTING, 0, 0 );
327 if ( hfile == INVALID_HANDLE_VALUE )
328 return 0;
331 * The next section is adapted from MODULE_GetBinaryType, as we need
332 * to examine the image header to get OS and version information. We
333 * know from calling GetBinaryTypeA that the image is valid and either
334 * an NE or PE, so much error handling can be omitted.
335 * Seek to the start of the file and read the header information.
338 SetFilePointer( hfile, 0, NULL, SEEK_SET );
339 ReadFile( hfile, &mz_header, sizeof(mz_header), &len, NULL );
341 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
342 ReadFile( hfile, magic, sizeof(magic), &len, NULL );
343 if ( *(DWORD*)magic == IMAGE_NT_SIGNATURE )
345 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
346 ReadFile( hfile, &nt, sizeof(nt), &len, NULL );
347 CloseHandle( hfile );
348 /* DLL files are not executable and should return 0 */
349 if (nt.FileHeader.Characteristics & IMAGE_FILE_DLL)
350 return 0;
351 if (nt.OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI)
353 return IMAGE_NT_SIGNATURE |
354 (nt.OptionalHeader.MajorSubsystemVersion << 24) |
355 (nt.OptionalHeader.MinorSubsystemVersion << 16);
357 return IMAGE_NT_SIGNATURE;
359 else if ( *(WORD*)magic == IMAGE_OS2_SIGNATURE )
361 IMAGE_OS2_HEADER ne;
362 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
363 ReadFile( hfile, &ne, sizeof(ne), &len, NULL );
364 CloseHandle( hfile );
365 if (ne.ne_exetyp == 2)
366 return IMAGE_OS2_SIGNATURE | (ne.ne_expver << 16);
367 return 0;
369 CloseHandle( hfile );
370 return 0;
373 /*************************************************************************
374 * SHELL_IsShortcut [internal]
376 * Decide if an item id list points to a shell shortcut
378 BOOL SHELL_IsShortcut(LPCITEMIDLIST pidlLast)
380 char szTemp[MAX_PATH];
381 HKEY keyCls;
382 BOOL ret = FALSE;
384 if (_ILGetExtension(pidlLast, szTemp, MAX_PATH) &&
385 HCR_MapTypeToValueA(szTemp, szTemp, MAX_PATH, TRUE))
387 if (ERROR_SUCCESS == RegOpenKeyExA(HKEY_CLASSES_ROOT, szTemp, 0, KEY_QUERY_VALUE, &keyCls))
389 if (ERROR_SUCCESS == RegQueryValueExA(keyCls, "IsShortcut", NULL, NULL, NULL, NULL))
390 ret = TRUE;
392 RegCloseKey(keyCls);
396 return ret;
399 #define SHGFI_KNOWN_FLAGS \
400 (SHGFI_SMALLICON | SHGFI_OPENICON | SHGFI_SHELLICONSIZE | SHGFI_PIDL | \
401 SHGFI_USEFILEATTRIBUTES | SHGFI_ADDOVERLAYS | SHGFI_OVERLAYINDEX | \
402 SHGFI_ICON | SHGFI_DISPLAYNAME | SHGFI_TYPENAME | SHGFI_ATTRIBUTES | \
403 SHGFI_ICONLOCATION | SHGFI_EXETYPE | SHGFI_SYSICONINDEX | \
404 SHGFI_LINKOVERLAY | SHGFI_SELECTED | SHGFI_ATTR_SPECIFIED)
406 /*************************************************************************
407 * SHGetFileInfoW [SHELL32.@]
410 DWORD_PTR WINAPI SHGetFileInfoW(LPCWSTR path,DWORD dwFileAttributes,
411 SHFILEINFOW *psfi, UINT sizeofpsfi, UINT flags )
413 WCHAR szLocation[MAX_PATH], szFullPath[MAX_PATH];
414 int iIndex;
415 DWORD_PTR ret = TRUE;
416 DWORD dwAttributes = 0;
417 IShellFolder * psfParent = NULL;
418 IExtractIconW * pei = NULL;
419 LPITEMIDLIST pidlLast = NULL, pidl = NULL;
420 HRESULT hr = S_OK;
421 BOOL IconNotYetLoaded=TRUE;
422 UINT uGilFlags = 0;
424 TRACE("%s fattr=0x%x sfi=%p(attr=0x%08x) size=0x%x flags=0x%x\n",
425 (flags & SHGFI_PIDL)? "pidl" : debugstr_w(path), dwFileAttributes,
426 psfi, psfi->dwAttributes, sizeofpsfi, flags);
428 if (!path)
429 return FALSE;
431 /* windows initializes these values regardless of the flags */
432 if (psfi != NULL)
434 psfi->szDisplayName[0] = '\0';
435 psfi->szTypeName[0] = '\0';
436 psfi->iIcon = 0;
439 if (!(flags & SHGFI_PIDL))
441 /* SHGetFileInfo should work with absolute and relative paths */
442 if (PathIsRelativeW(path))
444 GetCurrentDirectoryW(MAX_PATH, szLocation);
445 PathCombineW(szFullPath, szLocation, path);
447 else
449 lstrcpynW(szFullPath, path, MAX_PATH);
453 if (flags & SHGFI_EXETYPE)
455 if (flags != SHGFI_EXETYPE)
456 return 0;
457 return shgfi_get_exe_type(szFullPath);
461 * psfi is NULL normally to query EXE type. If it is NULL, none of the
462 * below makes sense anyway. Windows allows this and just returns FALSE
464 if (psfi == NULL)
465 return FALSE;
468 * translate the path into a pidl only when SHGFI_USEFILEATTRIBUTES
469 * is not specified.
470 * The pidl functions fail on not existing file names
473 if (flags & SHGFI_PIDL)
475 pidl = ILClone((LPCITEMIDLIST)path);
477 else if (!(flags & SHGFI_USEFILEATTRIBUTES))
479 hr = SHILCreateFromPathW(szFullPath, &pidl, &dwAttributes);
482 if ((flags & SHGFI_PIDL) || !(flags & SHGFI_USEFILEATTRIBUTES))
484 /* get the parent shellfolder */
485 if (pidl)
487 hr = SHBindToParent( pidl, &IID_IShellFolder, (LPVOID*)&psfParent,
488 (LPCITEMIDLIST*)&pidlLast );
489 if (SUCCEEDED(hr))
490 pidlLast = ILClone(pidlLast);
491 ILFree(pidl);
493 else
495 ERR("pidl is null!\n");
496 return FALSE;
500 /* get the attributes of the child */
501 if (SUCCEEDED(hr) && (flags & SHGFI_ATTRIBUTES))
503 if (!(flags & SHGFI_ATTR_SPECIFIED))
505 psfi->dwAttributes = 0xffffffff;
507 if (psfParent)
508 IShellFolder_GetAttributesOf( psfParent, 1, (LPCITEMIDLIST*)&pidlLast,
509 &(psfi->dwAttributes) );
512 /* get the displayname */
513 if (SUCCEEDED(hr) && (flags & SHGFI_DISPLAYNAME))
515 if (flags & SHGFI_USEFILEATTRIBUTES && !(flags & SHGFI_PIDL))
517 lstrcpyW (psfi->szDisplayName, PathFindFileNameW(szFullPath));
519 else
521 STRRET str;
522 hr = IShellFolder_GetDisplayNameOf( psfParent, pidlLast,
523 SHGDN_INFOLDER, &str);
524 StrRetToStrNW (psfi->szDisplayName, MAX_PATH, &str, pidlLast);
528 /* get the type name */
529 if (SUCCEEDED(hr) && (flags & SHGFI_TYPENAME))
531 static const WCHAR szFile[] = { 'F','i','l','e',0 };
532 static const WCHAR szDashFile[] = { '-','f','i','l','e',0 };
534 if (!(flags & SHGFI_USEFILEATTRIBUTES) || (flags & SHGFI_PIDL))
536 char ftype[80];
538 _ILGetFileType(pidlLast, ftype, 80);
539 MultiByteToWideChar(CP_ACP, 0, ftype, -1, psfi->szTypeName, 80 );
541 else
543 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
544 strcatW (psfi->szTypeName, szFile);
545 else
547 WCHAR sTemp[64];
549 lstrcpyW(sTemp,PathFindExtensionW(szFullPath));
550 if (!( HCR_MapTypeToValueW(sTemp, sTemp, 64, TRUE) &&
551 HCR_MapTypeToValueW(sTemp, psfi->szTypeName, 80, FALSE )))
553 lstrcpynW (psfi->szTypeName, sTemp, 64);
554 strcatW (psfi->szTypeName, szDashFile);
560 /* ### icons ###*/
561 if (flags & SHGFI_OPENICON)
562 uGilFlags |= GIL_OPENICON;
564 if (flags & SHGFI_LINKOVERLAY)
565 uGilFlags |= GIL_FORSHORTCUT;
566 else if ((flags&SHGFI_ADDOVERLAYS) ||
567 (flags&(SHGFI_ICON|SHGFI_SMALLICON))==SHGFI_ICON)
569 if (SHELL_IsShortcut(pidlLast))
570 uGilFlags |= GIL_FORSHORTCUT;
573 if (flags & SHGFI_OVERLAYINDEX)
574 FIXME("SHGFI_OVERLAYINDEX unhandled\n");
576 if (flags & SHGFI_SELECTED)
577 FIXME("set icon to selected, stub\n");
579 if (flags & SHGFI_SHELLICONSIZE)
580 FIXME("set icon to shell size, stub\n");
582 /* get the iconlocation */
583 if (SUCCEEDED(hr) && (flags & SHGFI_ICONLOCATION ))
585 UINT uDummy,uFlags;
587 if (flags & SHGFI_USEFILEATTRIBUTES && !(flags & SHGFI_PIDL))
589 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
591 lstrcpyW(psfi->szDisplayName, swShell32Name);
592 psfi->iIcon = -IDI_SHELL_FOLDER;
594 else
596 WCHAR* szExt;
597 static const WCHAR p1W[] = {'%','1',0};
598 WCHAR sTemp [MAX_PATH];
600 szExt = PathFindExtensionW(szFullPath);
601 TRACE("szExt=%s\n", debugstr_w(szExt));
602 if ( szExt &&
603 HCR_MapTypeToValueW(szExt, sTemp, MAX_PATH, TRUE) &&
604 HCR_GetDefaultIconW(sTemp, sTemp, MAX_PATH, &psfi->iIcon))
606 if (lstrcmpW(p1W, sTemp))
607 strcpyW(psfi->szDisplayName, sTemp);
608 else
610 /* the icon is in the file */
611 strcpyW(psfi->szDisplayName, szFullPath);
614 else
615 ret = FALSE;
618 else
620 hr = IShellFolder_GetUIObjectOf(psfParent, 0, 1,
621 (LPCITEMIDLIST*)&pidlLast, &IID_IExtractIconW,
622 &uDummy, (LPVOID*)&pei);
623 if (SUCCEEDED(hr))
625 hr = IExtractIconW_GetIconLocation(pei, uGilFlags,
626 szLocation, MAX_PATH, &iIndex, &uFlags);
628 if (uFlags & GIL_NOTFILENAME)
629 ret = FALSE;
630 else
632 lstrcpyW (psfi->szDisplayName, szLocation);
633 psfi->iIcon = iIndex;
635 IExtractIconW_Release(pei);
640 /* get icon index (or load icon)*/
641 if (SUCCEEDED(hr) && (flags & (SHGFI_ICON | SHGFI_SYSICONINDEX)))
643 if (flags & SHGFI_USEFILEATTRIBUTES && !(flags & SHGFI_PIDL))
645 WCHAR sTemp [MAX_PATH];
646 WCHAR * szExt;
647 int icon_idx=0;
649 lstrcpynW(sTemp, szFullPath, MAX_PATH);
651 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
652 psfi->iIcon = SIC_GetIconIndex(swShell32Name, -IDI_SHELL_FOLDER, 0);
653 else
655 static const WCHAR p1W[] = {'%','1',0};
657 psfi->iIcon = 0;
658 szExt = PathFindExtensionW(sTemp);
659 if ( szExt &&
660 HCR_MapTypeToValueW(szExt, sTemp, MAX_PATH, TRUE) &&
661 HCR_GetDefaultIconW(sTemp, sTemp, MAX_PATH, &icon_idx))
663 if (!lstrcmpW(p1W,sTemp)) /* icon is in the file */
664 strcpyW(sTemp, szFullPath);
666 if (flags & SHGFI_SYSICONINDEX)
668 psfi->iIcon = SIC_GetIconIndex(sTemp,icon_idx,0);
669 if (psfi->iIcon == -1)
670 psfi->iIcon = 0;
672 else
674 UINT ret;
675 if (flags & SHGFI_SMALLICON)
676 ret = PrivateExtractIconsW( sTemp,icon_idx,
677 GetSystemMetrics( SM_CXSMICON ),
678 GetSystemMetrics( SM_CYSMICON ),
679 &psfi->hIcon, 0, 1, 0);
680 else
681 ret = PrivateExtractIconsW( sTemp, icon_idx,
682 GetSystemMetrics( SM_CXICON),
683 GetSystemMetrics( SM_CYICON),
684 &psfi->hIcon, 0, 1, 0);
685 if (ret != 0 && ret != (UINT)-1)
687 IconNotYetLoaded=FALSE;
688 psfi->iIcon = icon_idx;
694 else
696 if (!(PidlToSicIndex(psfParent, pidlLast, !(flags & SHGFI_SMALLICON),
697 uGilFlags, &(psfi->iIcon))))
699 ret = FALSE;
702 if (ret && (flags & SHGFI_SYSICONINDEX))
704 if (flags & SHGFI_SMALLICON)
705 ret = (DWORD_PTR) ShellSmallIconList;
706 else
707 ret = (DWORD_PTR) ShellBigIconList;
711 /* icon handle */
712 if (SUCCEEDED(hr) && (flags & SHGFI_ICON) && IconNotYetLoaded)
714 if (flags & SHGFI_SMALLICON)
715 psfi->hIcon = ImageList_GetIcon( ShellSmallIconList, psfi->iIcon, ILD_NORMAL);
716 else
717 psfi->hIcon = ImageList_GetIcon( ShellBigIconList, psfi->iIcon, ILD_NORMAL);
720 if (flags & ~SHGFI_KNOWN_FLAGS)
721 FIXME("unknown flags %08x\n", flags & ~SHGFI_KNOWN_FLAGS);
723 if (psfParent)
724 IShellFolder_Release(psfParent);
726 if (hr != S_OK)
727 ret = FALSE;
729 SHFree(pidlLast);
731 TRACE ("icon=%p index=0x%08x attr=0x%08x name=%s type=%s ret=0x%08lx\n",
732 psfi->hIcon, psfi->iIcon, psfi->dwAttributes,
733 debugstr_w(psfi->szDisplayName), debugstr_w(psfi->szTypeName), ret);
735 return ret;
738 /*************************************************************************
739 * SHGetFileInfoA [SHELL32.@]
741 * Note:
742 * MSVBVM60.__vbaNew2 expects this function to return a value in range
743 * 1 .. 0x7fff when the function succeeds and flags does not contain
744 * SHGFI_EXETYPE or SHGFI_SYSICONINDEX (see bug 7701)
746 DWORD_PTR WINAPI SHGetFileInfoA(LPCSTR path,DWORD dwFileAttributes,
747 SHFILEINFOA *psfi, UINT sizeofpsfi,
748 UINT flags )
750 INT len;
751 LPWSTR temppath = NULL;
752 LPCWSTR pathW;
753 DWORD_PTR ret;
754 SHFILEINFOW temppsfi;
756 if (flags & SHGFI_PIDL)
758 /* path contains a pidl */
759 pathW = (LPCWSTR)path;
761 else
763 len = MultiByteToWideChar(CP_ACP, 0, path, -1, NULL, 0);
764 temppath = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
765 MultiByteToWideChar(CP_ACP, 0, path, -1, temppath, len);
766 pathW = temppath;
769 if (psfi && (flags & SHGFI_ATTR_SPECIFIED))
770 temppsfi.dwAttributes=psfi->dwAttributes;
772 if (psfi == NULL)
773 ret = SHGetFileInfoW(pathW, dwFileAttributes, NULL, sizeof(temppsfi), flags);
774 else
775 ret = SHGetFileInfoW(pathW, dwFileAttributes, &temppsfi, sizeof(temppsfi), flags);
777 if (psfi)
779 if(flags & SHGFI_ICON)
780 psfi->hIcon=temppsfi.hIcon;
781 if(flags & (SHGFI_SYSICONINDEX|SHGFI_ICON|SHGFI_ICONLOCATION))
782 psfi->iIcon=temppsfi.iIcon;
783 if(flags & SHGFI_ATTRIBUTES)
784 psfi->dwAttributes=temppsfi.dwAttributes;
785 if(flags & (SHGFI_DISPLAYNAME|SHGFI_ICONLOCATION))
787 WideCharToMultiByte(CP_ACP, 0, temppsfi.szDisplayName, -1,
788 psfi->szDisplayName, sizeof(psfi->szDisplayName), NULL, NULL);
790 if(flags & SHGFI_TYPENAME)
792 WideCharToMultiByte(CP_ACP, 0, temppsfi.szTypeName, -1,
793 psfi->szTypeName, sizeof(psfi->szTypeName), NULL, NULL);
797 HeapFree(GetProcessHeap(), 0, temppath);
799 return ret;
802 /*************************************************************************
803 * DuplicateIcon [SHELL32.@]
805 HICON WINAPI DuplicateIcon( HINSTANCE hInstance, HICON hIcon)
807 ICONINFO IconInfo;
808 HICON hDupIcon = 0;
810 TRACE("%p %p\n", hInstance, hIcon);
812 if (GetIconInfo(hIcon, &IconInfo))
814 hDupIcon = CreateIconIndirect(&IconInfo);
816 /* clean up hbmMask and hbmColor */
817 DeleteObject(IconInfo.hbmMask);
818 DeleteObject(IconInfo.hbmColor);
821 return hDupIcon;
824 /*************************************************************************
825 * ExtractIconA [SHELL32.@]
827 HICON WINAPI ExtractIconA(HINSTANCE hInstance, LPCSTR lpszFile, UINT nIconIndex)
829 HICON ret;
830 INT len = MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, NULL, 0);
831 LPWSTR lpwstrFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
833 TRACE("%p %s %d\n", hInstance, lpszFile, nIconIndex);
835 MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, lpwstrFile, len);
836 ret = ExtractIconW(hInstance, lpwstrFile, nIconIndex);
837 HeapFree(GetProcessHeap(), 0, lpwstrFile);
839 return ret;
842 /*************************************************************************
843 * ExtractIconW [SHELL32.@]
845 HICON WINAPI ExtractIconW(HINSTANCE hInstance, LPCWSTR lpszFile, UINT nIconIndex)
847 HICON hIcon = NULL;
848 UINT ret;
849 UINT cx = GetSystemMetrics(SM_CXICON), cy = GetSystemMetrics(SM_CYICON);
851 TRACE("%p %s %d\n", hInstance, debugstr_w(lpszFile), nIconIndex);
853 if (nIconIndex == (UINT)-1)
855 ret = PrivateExtractIconsW(lpszFile, 0, cx, cy, NULL, NULL, 0, LR_DEFAULTCOLOR);
856 if (ret != (UINT)-1 && ret)
857 return (HICON)(UINT_PTR)ret;
858 return NULL;
860 else
861 ret = PrivateExtractIconsW(lpszFile, nIconIndex, cx, cy, &hIcon, NULL, 1, LR_DEFAULTCOLOR);
863 if (ret == (UINT)-1)
864 return (HICON)1;
865 else if (ret > 0 && hIcon)
866 return hIcon;
868 return NULL;
871 HRESULT WINAPI SHCreateFileExtractIconW(LPCWSTR file, DWORD attribs, REFIID riid, void **ppv)
873 FIXME("%s, %x, %s, %p\n", debugstr_w(file), attribs, debugstr_guid(riid), ppv);
874 *ppv = NULL;
875 return E_NOTIMPL;
878 /*************************************************************************
879 * Printer_LoadIconsW [SHELL32.205]
881 VOID WINAPI Printer_LoadIconsW(LPCWSTR wsPrinterName, HICON * pLargeIcon, HICON * pSmallIcon)
883 INT iconindex=IDI_SHELL_PRINTER;
885 TRACE("(%s, %p, %p)\n", debugstr_w(wsPrinterName), pLargeIcon, pSmallIcon);
887 /* We should check if wsPrinterName is
888 1. the Default Printer or not
889 2. connected or not
890 3. a Local Printer or a Network-Printer
891 and use different Icons
893 if((wsPrinterName != NULL) && (wsPrinterName[0] != 0))
895 FIXME("(select Icon by PrinterName %s not implemented)\n", debugstr_w(wsPrinterName));
898 if(pLargeIcon != NULL)
899 *pLargeIcon = LoadImageW(shell32_hInstance,
900 (LPCWSTR) MAKEINTRESOURCE(iconindex), IMAGE_ICON,
901 0, 0, LR_DEFAULTCOLOR|LR_DEFAULTSIZE);
903 if(pSmallIcon != NULL)
904 *pSmallIcon = LoadImageW(shell32_hInstance,
905 (LPCWSTR) MAKEINTRESOURCE(iconindex), IMAGE_ICON,
906 16, 16, LR_DEFAULTCOLOR);
909 /*************************************************************************
910 * Printers_RegisterWindowW [SHELL32.213]
911 * used by "printui.dll":
912 * find the Window of the given Type for the specific Printer and
913 * return the already existent hwnd or open a new window
915 BOOL WINAPI Printers_RegisterWindowW(LPCWSTR wsPrinter, DWORD dwType,
916 HANDLE * phClassPidl, HWND * phwnd)
918 FIXME("(%s, %x, %p (%p), %p (%p)) stub!\n", debugstr_w(wsPrinter), dwType,
919 phClassPidl, (phClassPidl != NULL) ? *(phClassPidl) : NULL,
920 phwnd, (phwnd != NULL) ? *(phwnd) : NULL);
922 return FALSE;
925 /*************************************************************************
926 * Printers_UnregisterWindow [SHELL32.214]
928 VOID WINAPI Printers_UnregisterWindow(HANDLE hClassPidl, HWND hwnd)
930 FIXME("(%p, %p) stub!\n", hClassPidl, hwnd);
933 /*************************************************************************
934 * SHGetPropertyStoreFromParsingName [SHELL32.@]
936 HRESULT WINAPI SHGetPropertyStoreFromParsingName(PCWSTR pszPath, IBindCtx *pbc, GETPROPERTYSTOREFLAGS flags, REFIID riid, void **ppv)
938 FIXME("(%s %p %u %p %p) stub!\n", debugstr_w(pszPath), pbc, flags, riid, ppv);
939 return E_NOTIMPL;
942 /*************************************************************************/
944 typedef struct
946 LPCWSTR szApp;
947 LPCWSTR szOtherStuff;
948 HICON hIcon;
949 HFONT hFont;
950 } ABOUT_INFO;
952 #define DROP_FIELD_TOP (-12)
954 static void paint_dropline( HDC hdc, HWND hWnd )
956 HWND hWndCtl = GetDlgItem(hWnd, IDC_ABOUT_WINE_TEXT);
957 RECT rect;
959 if (!hWndCtl) return;
960 GetWindowRect( hWndCtl, &rect );
961 MapWindowPoints( 0, hWnd, (LPPOINT)&rect, 2 );
962 rect.top += DROP_FIELD_TOP;
963 rect.bottom = rect.top + 2;
964 DrawEdge( hdc, &rect, BDR_SUNKENOUTER, BF_RECT );
967 /*************************************************************************
968 * SHHelpShortcuts_RunDLLA [SHELL32.@]
971 DWORD WINAPI SHHelpShortcuts_RunDLLA(DWORD dwArg1, DWORD dwArg2, DWORD dwArg3, DWORD dwArg4)
973 FIXME("(%x, %x, %x, %x) stub!\n", dwArg1, dwArg2, dwArg3, dwArg4);
974 return 0;
977 /*************************************************************************
978 * SHHelpShortcuts_RunDLLA [SHELL32.@]
981 DWORD WINAPI SHHelpShortcuts_RunDLLW(DWORD dwArg1, DWORD dwArg2, DWORD dwArg3, DWORD dwArg4)
983 FIXME("(%x, %x, %x, %x) stub!\n", dwArg1, dwArg2, dwArg3, dwArg4);
984 return 0;
987 /*************************************************************************
988 * SHLoadInProc [SHELL32.@]
989 * Create an instance of specified object class from within
990 * the shell process and release it immediately
992 HRESULT WINAPI SHLoadInProc (REFCLSID rclsid)
994 void *ptr = NULL;
996 TRACE("%s\n", debugstr_guid(rclsid));
998 CoCreateInstance(rclsid, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown,&ptr);
999 if(ptr)
1001 IUnknown * pUnk = ptr;
1002 IUnknown_Release(pUnk);
1003 return S_OK;
1005 return DISP_E_MEMBERNOTFOUND;
1008 static void add_authors( HWND list )
1010 static const WCHAR eol[] = {'\r','\n',0};
1011 static const WCHAR authors[] = {'A','U','T','H','O','R','S',0};
1012 WCHAR *strW, *start, *end;
1013 HRSRC rsrc = FindResourceW( shell32_hInstance, authors, (LPCWSTR)RT_RCDATA );
1014 char *strA = LockResource( LoadResource( shell32_hInstance, rsrc ));
1015 DWORD sizeW, sizeA = SizeofResource( shell32_hInstance, rsrc );
1017 if (!strA) return;
1018 sizeW = MultiByteToWideChar( CP_UTF8, 0, strA, sizeA, NULL, 0 ) + 1;
1019 if (!(strW = HeapAlloc( GetProcessHeap(), 0, sizeW * sizeof(WCHAR) ))) return;
1020 MultiByteToWideChar( CP_UTF8, 0, strA, sizeA, strW, sizeW );
1021 strW[sizeW - 1] = 0;
1023 start = strpbrkW( strW, eol ); /* skip the header line */
1024 while (start)
1026 while (*start && strchrW( eol, *start )) start++;
1027 if (!*start) break;
1028 end = strpbrkW( start, eol );
1029 if (end) *end++ = 0;
1030 SendMessageW( list, LB_ADDSTRING, -1, (LPARAM)start );
1031 start = end;
1033 HeapFree( GetProcessHeap(), 0, strW );
1036 /*************************************************************************
1037 * AboutDlgProc (internal)
1039 static INT_PTR CALLBACK AboutDlgProc( HWND hWnd, UINT msg, WPARAM wParam,
1040 LPARAM lParam )
1042 HWND hWndCtl;
1044 TRACE("\n");
1046 switch(msg)
1048 case WM_INITDIALOG:
1050 ABOUT_INFO *info = (ABOUT_INFO *)lParam;
1051 WCHAR template[512], buffer[512], version[64];
1052 extern const char *wine_get_build_id(void);
1054 if (info)
1056 SendDlgItemMessageW(hWnd, stc1, STM_SETICON,(WPARAM)info->hIcon, 0);
1057 GetWindowTextW( hWnd, template, sizeof(template)/sizeof(WCHAR) );
1058 sprintfW( buffer, template, info->szApp );
1059 SetWindowTextW( hWnd, buffer );
1060 SetWindowTextW( GetDlgItem(hWnd, IDC_ABOUT_STATIC_TEXT1), info->szApp );
1061 SetWindowTextW( GetDlgItem(hWnd, IDC_ABOUT_STATIC_TEXT2), info->szOtherStuff );
1062 GetWindowTextW( GetDlgItem(hWnd, IDC_ABOUT_STATIC_TEXT3),
1063 template, sizeof(template)/sizeof(WCHAR) );
1064 MultiByteToWideChar( CP_UTF8, 0, wine_get_build_id(), -1,
1065 version, sizeof(version)/sizeof(WCHAR) );
1066 sprintfW( buffer, template, version );
1067 SetWindowTextW( GetDlgItem(hWnd, IDC_ABOUT_STATIC_TEXT3), buffer );
1068 hWndCtl = GetDlgItem(hWnd, IDC_ABOUT_LISTBOX);
1069 SendMessageW( hWndCtl, WM_SETREDRAW, 0, 0 );
1070 SendMessageW( hWndCtl, WM_SETFONT, (WPARAM)info->hFont, 0 );
1071 add_authors( hWndCtl );
1072 SendMessageW( hWndCtl, WM_SETREDRAW, 1, 0 );
1075 return 1;
1077 case WM_PAINT:
1079 PAINTSTRUCT ps;
1080 HDC hDC = BeginPaint( hWnd, &ps );
1081 paint_dropline( hDC, hWnd );
1082 EndPaint( hWnd, &ps );
1084 break;
1086 case WM_COMMAND:
1087 if (wParam == IDOK || wParam == IDCANCEL)
1089 EndDialog(hWnd, TRUE);
1090 return TRUE;
1092 if (wParam == IDC_ABOUT_LICENSE)
1094 MSGBOXPARAMSW params;
1096 params.cbSize = sizeof(params);
1097 params.hwndOwner = hWnd;
1098 params.hInstance = shell32_hInstance;
1099 params.lpszText = MAKEINTRESOURCEW(IDS_LICENSE);
1100 params.lpszCaption = MAKEINTRESOURCEW(IDS_LICENSE_CAPTION);
1101 params.dwStyle = MB_ICONINFORMATION | MB_OK;
1102 params.lpszIcon = 0;
1103 params.dwContextHelpId = 0;
1104 params.lpfnMsgBoxCallback = NULL;
1105 params.dwLanguageId = LANG_NEUTRAL;
1106 MessageBoxIndirectW( &params );
1108 break;
1109 case WM_CLOSE:
1110 EndDialog(hWnd, TRUE);
1111 break;
1114 return 0;
1118 /*************************************************************************
1119 * ShellAboutA [SHELL32.288]
1121 BOOL WINAPI ShellAboutA( HWND hWnd, LPCSTR szApp, LPCSTR szOtherStuff, HICON hIcon )
1123 BOOL ret;
1124 LPWSTR appW = NULL, otherW = NULL;
1125 int len;
1127 if (szApp)
1129 len = MultiByteToWideChar(CP_ACP, 0, szApp, -1, NULL, 0);
1130 appW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1131 MultiByteToWideChar(CP_ACP, 0, szApp, -1, appW, len);
1133 if (szOtherStuff)
1135 len = MultiByteToWideChar(CP_ACP, 0, szOtherStuff, -1, NULL, 0);
1136 otherW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1137 MultiByteToWideChar(CP_ACP, 0, szOtherStuff, -1, otherW, len);
1140 ret = ShellAboutW(hWnd, appW, otherW, hIcon);
1142 HeapFree(GetProcessHeap(), 0, otherW);
1143 HeapFree(GetProcessHeap(), 0, appW);
1144 return ret;
1148 /*************************************************************************
1149 * ShellAboutW [SHELL32.289]
1151 BOOL WINAPI ShellAboutW( HWND hWnd, LPCWSTR szApp, LPCWSTR szOtherStuff,
1152 HICON hIcon )
1154 ABOUT_INFO info;
1155 LOGFONTW logFont;
1156 BOOL bRet;
1157 static const WCHAR wszSHELL_ABOUT_MSGBOX[] =
1158 {'S','H','E','L','L','_','A','B','O','U','T','_','M','S','G','B','O','X',0};
1160 TRACE("\n");
1162 if (!hIcon) hIcon = LoadImageW( 0, (LPWSTR)IDI_WINLOGO, IMAGE_ICON, 48, 48, LR_SHARED );
1163 info.szApp = szApp;
1164 info.szOtherStuff = szOtherStuff;
1165 info.hIcon = hIcon;
1167 SystemParametersInfoW( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 );
1168 info.hFont = CreateFontIndirectW( &logFont );
1170 bRet = DialogBoxParamW( shell32_hInstance, wszSHELL_ABOUT_MSGBOX, hWnd, AboutDlgProc, (LPARAM)&info );
1171 DeleteObject(info.hFont);
1172 return bRet;
1175 /*************************************************************************
1176 * FreeIconList (SHELL32.@)
1178 void WINAPI FreeIconList( DWORD dw )
1180 FIXME("%x: stub\n",dw);
1183 /*************************************************************************
1184 * SHLoadNonloadedIconOverlayIdentifiers (SHELL32.@)
1186 HRESULT WINAPI SHLoadNonloadedIconOverlayIdentifiers( VOID )
1188 FIXME("stub\n");
1189 return S_OK;
1192 /***********************************************************************
1193 * DllGetVersion [SHELL32.@]
1195 * Retrieves version information of the 'SHELL32.DLL'
1197 * PARAMS
1198 * pdvi [O] pointer to version information structure.
1200 * RETURNS
1201 * Success: S_OK
1202 * Failure: E_INVALIDARG
1204 * NOTES
1205 * Returns version of a shell32.dll from IE4.01 SP1.
1208 HRESULT WINAPI DllGetVersion (DLLVERSIONINFO *pdvi)
1210 /* FIXME: shouldn't these values come from the version resource? */
1211 if (pdvi->cbSize == sizeof(DLLVERSIONINFO) ||
1212 pdvi->cbSize == sizeof(DLLVERSIONINFO2))
1214 pdvi->dwMajorVersion = WINE_FILEVERSION_MAJOR;
1215 pdvi->dwMinorVersion = WINE_FILEVERSION_MINOR;
1216 pdvi->dwBuildNumber = WINE_FILEVERSION_BUILD;
1217 pdvi->dwPlatformID = WINE_FILEVERSION_PLATFORMID;
1218 if (pdvi->cbSize == sizeof(DLLVERSIONINFO2))
1220 DLLVERSIONINFO2 *pdvi2 = (DLLVERSIONINFO2 *)pdvi;
1222 pdvi2->dwFlags = 0;
1223 pdvi2->ullVersion = MAKEDLLVERULL(WINE_FILEVERSION_MAJOR,
1224 WINE_FILEVERSION_MINOR,
1225 WINE_FILEVERSION_BUILD,
1226 WINE_FILEVERSION_PLATFORMID);
1228 TRACE("%u.%u.%u.%u\n",
1229 pdvi->dwMajorVersion, pdvi->dwMinorVersion,
1230 pdvi->dwBuildNumber, pdvi->dwPlatformID);
1231 return S_OK;
1233 else
1235 WARN("wrong DLLVERSIONINFO size from app\n");
1236 return E_INVALIDARG;
1240 /*************************************************************************
1241 * global variables of the shell32.dll
1242 * all are once per process
1245 HINSTANCE shell32_hInstance = 0;
1246 HIMAGELIST ShellSmallIconList = 0;
1247 HIMAGELIST ShellBigIconList = 0;
1250 /*************************************************************************
1251 * SHELL32 DllMain
1253 * NOTES
1254 * calling oleinitialize here breaks some apps.
1256 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
1258 TRACE("%p 0x%x %p\n", hinstDLL, fdwReason, fImpLoad);
1260 switch (fdwReason)
1262 case DLL_PROCESS_ATTACH:
1263 shell32_hInstance = hinstDLL;
1264 DisableThreadLibraryCalls(shell32_hInstance);
1266 /* get full path to this DLL for IExtractIconW_fnGetIconLocation() */
1267 GetModuleFileNameW(hinstDLL, swShell32Name, MAX_PATH);
1268 swShell32Name[MAX_PATH - 1] = '\0';
1270 InitCommonControlsEx(NULL);
1272 SIC_Initialize();
1273 InitChangeNotifications();
1274 break;
1276 case DLL_PROCESS_DETACH:
1277 shell32_hInstance = 0;
1278 SIC_Destroy();
1279 FreeChangeNotifications();
1280 break;
1282 return TRUE;
1285 /*************************************************************************
1286 * DllInstall [SHELL32.@]
1288 * PARAMETERS
1290 * BOOL bInstall - TRUE for install, FALSE for uninstall
1291 * LPCWSTR pszCmdLine - command line (unused by shell32?)
1294 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
1296 FIXME("%s %s: stub\n", bInstall ? "TRUE":"FALSE", debugstr_w(cmdline));
1297 return S_OK; /* indicate success */
1300 /***********************************************************************
1301 * DllCanUnloadNow (SHELL32.@)
1303 HRESULT WINAPI DllCanUnloadNow(void)
1305 return S_FALSE;
1308 /***********************************************************************
1309 * DllRegisterServer (SHELL32.@)
1311 HRESULT WINAPI DllRegisterServer(void)
1313 HRESULT hr = __wine_register_resources( shell32_hInstance );
1314 if (SUCCEEDED(hr)) hr = SHELL_RegisterShellFolders();
1315 return hr;
1318 /***********************************************************************
1319 * DllUnregisterServer (SHELL32.@)
1321 HRESULT WINAPI DllUnregisterServer(void)
1323 return __wine_unregister_resources( shell32_hInstance );
1326 /***********************************************************************
1327 * ExtractVersionResource16W (SHELL32.@)
1329 BOOL WINAPI ExtractVersionResource16W(LPWSTR s, DWORD d)
1331 FIXME("(%s %x) stub!\n", debugstr_w(s), d);
1332 return FALSE;
1335 /***********************************************************************
1336 * InitNetworkAddressControl (SHELL32.@)
1338 BOOL WINAPI InitNetworkAddressControl(void)
1340 FIXME("stub\n");
1341 return FALSE;
1344 /***********************************************************************
1345 * ShellHookProc (SHELL32.@)
1347 LRESULT CALLBACK ShellHookProc(DWORD a, DWORD b, DWORD c)
1349 FIXME("Stub\n");
1350 return 0;
1353 /***********************************************************************
1354 * SHGetLocalizedName (SHELL32.@)
1356 HRESULT WINAPI SHGetLocalizedName(LPCWSTR path, LPWSTR module, UINT size, INT *res)
1358 FIXME("%s %p %u %p: stub\n", debugstr_w(path), module, size, res);
1359 return E_NOTIMPL;
1362 /***********************************************************************
1363 * SetCurrentProcessExplicitAppUserModelID (SHELL32.@)
1365 HRESULT WINAPI SetCurrentProcessExplicitAppUserModelID(PCWSTR appid)
1367 FIXME("%s: stub\n", debugstr_w(appid));
1368 return E_NOTIMPL;
1371 /***********************************************************************
1372 * SHSetUnreadMailCountW (SHELL32.@)
1374 HRESULT WINAPI SHSetUnreadMailCountW(LPCWSTR mailaddress, DWORD count, LPCWSTR executecommand)
1376 FIXME("%s %x %s: stub\n", debugstr_w(mailaddress), count, debugstr_w(executecommand));
1377 return E_NOTIMPL;