mshtml: Use get_elem_attr_value helper in npplugin.c.
[wine.git] / dlls / shell32 / shell32_main.c
blob091c6e1fc47fa8139a3e269aee3da17062e5b075
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 executable path */
231 *d++=0;
232 /* skip to the first argument and initialize it if any */
233 while (*s==' ' || *s=='\t')
234 s++;
235 if (!*s)
237 /* There are no parameters so we are all done */
238 *numargs=argc;
239 return argv;
242 /* Split and copy the remaining arguments */
243 argv[argc++]=d;
244 qcount=bcount=0;
245 while (*s)
247 if ((*s==' ' || *s=='\t') && qcount==0)
249 /* close the argument */
250 *d++=0;
251 bcount=0;
253 /* skip to the next one and initialize it if any */
254 do {
255 s++;
256 } while (*s==' ' || *s=='\t');
257 if (*s)
258 argv[argc++]=d;
260 else if (*s=='\\')
262 *d++=*s++;
263 bcount++;
265 else if (*s=='"')
267 if ((bcount & 1)==0)
269 /* Preceded by an even number of '\', this is half that
270 * number of '\', plus a quote which we erase.
272 d-=bcount/2;
273 qcount++;
275 else
277 /* Preceded by an odd number of '\', this is half that
278 * number of '\' followed by a '"'
280 d=d-bcount/2-1;
281 *d++='"';
283 s++;
284 bcount=0;
285 /* Now count the number of consecutive quotes. Note that qcount
286 * already takes into account the opening quote if any, as well as
287 * the quote that lead us here.
289 while (*s=='"')
291 if (++qcount==3)
293 *d++='"';
294 qcount=0;
296 s++;
298 if (qcount==2)
299 qcount=0;
301 else
303 /* a regular character */
304 *d++=*s++;
305 bcount=0;
308 *d='\0';
309 *numargs=argc;
311 return argv;
314 static DWORD shgfi_get_exe_type(LPCWSTR szFullPath)
316 BOOL status = FALSE;
317 HANDLE hfile;
318 DWORD BinaryType;
319 IMAGE_DOS_HEADER mz_header;
320 IMAGE_NT_HEADERS nt;
321 DWORD len;
322 char magic[4];
324 status = GetBinaryTypeW (szFullPath, &BinaryType);
325 if (!status)
326 return 0;
327 if (BinaryType == SCS_DOS_BINARY || BinaryType == SCS_PIF_BINARY)
328 return 0x4d5a;
330 hfile = CreateFileW( szFullPath, GENERIC_READ, FILE_SHARE_READ,
331 NULL, OPEN_EXISTING, 0, 0 );
332 if ( hfile == INVALID_HANDLE_VALUE )
333 return 0;
336 * The next section is adapted from MODULE_GetBinaryType, as we need
337 * to examine the image header to get OS and version information. We
338 * know from calling GetBinaryTypeA that the image is valid and either
339 * an NE or PE, so much error handling can be omitted.
340 * Seek to the start of the file and read the header information.
343 SetFilePointer( hfile, 0, NULL, SEEK_SET );
344 ReadFile( hfile, &mz_header, sizeof(mz_header), &len, NULL );
346 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
347 ReadFile( hfile, magic, sizeof(magic), &len, NULL );
348 if ( *(DWORD*)magic == IMAGE_NT_SIGNATURE )
350 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
351 ReadFile( hfile, &nt, sizeof(nt), &len, NULL );
352 CloseHandle( hfile );
353 /* DLL files are not executable and should return 0 */
354 if (nt.FileHeader.Characteristics & IMAGE_FILE_DLL)
355 return 0;
356 if (nt.OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI)
358 return IMAGE_NT_SIGNATURE |
359 (nt.OptionalHeader.MajorSubsystemVersion << 24) |
360 (nt.OptionalHeader.MinorSubsystemVersion << 16);
362 return IMAGE_NT_SIGNATURE;
364 else if ( *(WORD*)magic == IMAGE_OS2_SIGNATURE )
366 IMAGE_OS2_HEADER ne;
367 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
368 ReadFile( hfile, &ne, sizeof(ne), &len, NULL );
369 CloseHandle( hfile );
370 if (ne.ne_exetyp == 2)
371 return IMAGE_OS2_SIGNATURE | (ne.ne_expver << 16);
372 return 0;
374 CloseHandle( hfile );
375 return 0;
378 /*************************************************************************
379 * SHELL_IsShortcut [internal]
381 * Decide if an item id list points to a shell shortcut
383 BOOL SHELL_IsShortcut(LPCITEMIDLIST pidlLast)
385 char szTemp[MAX_PATH];
386 HKEY keyCls;
387 BOOL ret = FALSE;
389 if (_ILGetExtension(pidlLast, szTemp, MAX_PATH) &&
390 HCR_MapTypeToValueA(szTemp, szTemp, MAX_PATH, TRUE))
392 if (ERROR_SUCCESS == RegOpenKeyExA(HKEY_CLASSES_ROOT, szTemp, 0, KEY_QUERY_VALUE, &keyCls))
394 if (ERROR_SUCCESS == RegQueryValueExA(keyCls, "IsShortcut", NULL, NULL, NULL, NULL))
395 ret = TRUE;
397 RegCloseKey(keyCls);
401 return ret;
404 #define SHGFI_KNOWN_FLAGS \
405 (SHGFI_SMALLICON | SHGFI_OPENICON | SHGFI_SHELLICONSIZE | SHGFI_PIDL | \
406 SHGFI_USEFILEATTRIBUTES | SHGFI_ADDOVERLAYS | SHGFI_OVERLAYINDEX | \
407 SHGFI_ICON | SHGFI_DISPLAYNAME | SHGFI_TYPENAME | SHGFI_ATTRIBUTES | \
408 SHGFI_ICONLOCATION | SHGFI_EXETYPE | SHGFI_SYSICONINDEX | \
409 SHGFI_LINKOVERLAY | SHGFI_SELECTED | SHGFI_ATTR_SPECIFIED)
411 /*************************************************************************
412 * SHGetFileInfoW [SHELL32.@]
415 DWORD_PTR WINAPI SHGetFileInfoW(LPCWSTR path,DWORD dwFileAttributes,
416 SHFILEINFOW *psfi, UINT sizeofpsfi, UINT flags )
418 WCHAR szLocation[MAX_PATH], szFullPath[MAX_PATH];
419 int iIndex;
420 DWORD_PTR ret = TRUE;
421 DWORD dwAttributes = 0;
422 IShellFolder * psfParent = NULL;
423 IExtractIconW * pei = NULL;
424 LPITEMIDLIST pidlLast = NULL, pidl = NULL;
425 HRESULT hr = S_OK;
426 BOOL IconNotYetLoaded=TRUE;
427 UINT uGilFlags = 0;
428 HIMAGELIST big_icons, small_icons;
430 TRACE("%s fattr=0x%x sfi=%p(attr=0x%08x) size=0x%x flags=0x%x\n",
431 (flags & SHGFI_PIDL)? "pidl" : debugstr_w(path), dwFileAttributes,
432 psfi, psfi->dwAttributes, sizeofpsfi, flags);
434 if (!path)
435 return FALSE;
437 /* windows initializes these values regardless of the flags */
438 if (psfi != NULL)
440 psfi->szDisplayName[0] = '\0';
441 psfi->szTypeName[0] = '\0';
442 psfi->iIcon = 0;
445 if (!(flags & SHGFI_PIDL))
447 /* SHGetFileInfo should work with absolute and relative paths */
448 if (PathIsRelativeW(path))
450 GetCurrentDirectoryW(MAX_PATH, szLocation);
451 PathCombineW(szFullPath, szLocation, path);
453 else
455 lstrcpynW(szFullPath, path, MAX_PATH);
459 if (flags & SHGFI_EXETYPE)
461 if (flags != SHGFI_EXETYPE)
462 return 0;
463 return shgfi_get_exe_type(szFullPath);
467 * psfi is NULL normally to query EXE type. If it is NULL, none of the
468 * below makes sense anyway. Windows allows this and just returns FALSE
470 if (psfi == NULL)
471 return FALSE;
474 * translate the path into a pidl only when SHGFI_USEFILEATTRIBUTES
475 * is not specified.
476 * The pidl functions fail on not existing file names
479 if (flags & SHGFI_PIDL)
481 pidl = ILClone((LPCITEMIDLIST)path);
483 else if (!(flags & SHGFI_USEFILEATTRIBUTES))
485 hr = SHILCreateFromPathW(szFullPath, &pidl, &dwAttributes);
488 if ((flags & SHGFI_PIDL) || !(flags & SHGFI_USEFILEATTRIBUTES))
490 /* get the parent shellfolder */
491 if (pidl)
493 hr = SHBindToParent( pidl, &IID_IShellFolder, (LPVOID*)&psfParent,
494 (LPCITEMIDLIST*)&pidlLast );
495 if (SUCCEEDED(hr))
496 pidlLast = ILClone(pidlLast);
497 ILFree(pidl);
499 else
501 ERR("pidl is null!\n");
502 return FALSE;
506 /* get the attributes of the child */
507 if (SUCCEEDED(hr) && (flags & SHGFI_ATTRIBUTES))
509 if (!(flags & SHGFI_ATTR_SPECIFIED))
511 psfi->dwAttributes = 0xffffffff;
513 if (psfParent)
514 IShellFolder_GetAttributesOf( psfParent, 1, (LPCITEMIDLIST*)&pidlLast,
515 &(psfi->dwAttributes) );
518 /* get the displayname */
519 if (SUCCEEDED(hr) && (flags & SHGFI_DISPLAYNAME))
521 if (flags & SHGFI_USEFILEATTRIBUTES && !(flags & SHGFI_PIDL))
523 lstrcpyW (psfi->szDisplayName, PathFindFileNameW(szFullPath));
525 else
527 STRRET str;
528 hr = IShellFolder_GetDisplayNameOf( psfParent, pidlLast,
529 SHGDN_INFOLDER, &str);
530 StrRetToStrNW (psfi->szDisplayName, MAX_PATH, &str, pidlLast);
534 /* get the type name */
535 if (SUCCEEDED(hr) && (flags & SHGFI_TYPENAME))
537 static const WCHAR szFile[] = { 'F','i','l','e',0 };
538 static const WCHAR szDashFile[] = { '-','f','i','l','e',0 };
540 if (!(flags & SHGFI_USEFILEATTRIBUTES) || (flags & SHGFI_PIDL))
542 char ftype[80];
544 _ILGetFileType(pidlLast, ftype, 80);
545 MultiByteToWideChar(CP_ACP, 0, ftype, -1, psfi->szTypeName, 80 );
547 else
549 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
550 strcatW (psfi->szTypeName, szFile);
551 else
553 WCHAR sTemp[64];
555 lstrcpyW(sTemp,PathFindExtensionW(szFullPath));
556 if (!( HCR_MapTypeToValueW(sTemp, sTemp, 64, TRUE) &&
557 HCR_MapTypeToValueW(sTemp, psfi->szTypeName, 80, FALSE )))
559 lstrcpynW (psfi->szTypeName, sTemp, 64);
560 strcatW (psfi->szTypeName, szDashFile);
566 /* ### icons ###*/
568 Shell_GetImageLists( &big_icons, &small_icons );
570 if (flags & SHGFI_OPENICON)
571 uGilFlags |= GIL_OPENICON;
573 if (flags & SHGFI_LINKOVERLAY)
574 uGilFlags |= GIL_FORSHORTCUT;
575 else if ((flags&SHGFI_ADDOVERLAYS) ||
576 (flags&(SHGFI_ICON|SHGFI_SMALLICON))==SHGFI_ICON)
578 if (SHELL_IsShortcut(pidlLast))
579 uGilFlags |= GIL_FORSHORTCUT;
582 if (flags & SHGFI_OVERLAYINDEX)
583 FIXME("SHGFI_OVERLAYINDEX unhandled\n");
585 if (flags & SHGFI_SELECTED)
586 FIXME("set icon to selected, stub\n");
588 if (flags & SHGFI_SHELLICONSIZE)
589 FIXME("set icon to shell size, stub\n");
591 /* get the iconlocation */
592 if (SUCCEEDED(hr) && (flags & SHGFI_ICONLOCATION ))
594 UINT uDummy,uFlags;
596 if (flags & SHGFI_USEFILEATTRIBUTES && !(flags & SHGFI_PIDL))
598 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
600 lstrcpyW(psfi->szDisplayName, swShell32Name);
601 psfi->iIcon = -IDI_SHELL_FOLDER;
603 else
605 WCHAR* szExt;
606 static const WCHAR p1W[] = {'%','1',0};
607 WCHAR sTemp [MAX_PATH];
609 szExt = PathFindExtensionW(szFullPath);
610 TRACE("szExt=%s\n", debugstr_w(szExt));
611 if ( szExt &&
612 HCR_MapTypeToValueW(szExt, sTemp, MAX_PATH, TRUE) &&
613 HCR_GetDefaultIconW(sTemp, sTemp, MAX_PATH, &psfi->iIcon))
615 if (lstrcmpW(p1W, sTemp))
616 strcpyW(psfi->szDisplayName, sTemp);
617 else
619 /* the icon is in the file */
620 strcpyW(psfi->szDisplayName, szFullPath);
623 else
624 ret = FALSE;
627 else
629 hr = IShellFolder_GetUIObjectOf(psfParent, 0, 1,
630 (LPCITEMIDLIST*)&pidlLast, &IID_IExtractIconW,
631 &uDummy, (LPVOID*)&pei);
632 if (SUCCEEDED(hr))
634 hr = IExtractIconW_GetIconLocation(pei, uGilFlags,
635 szLocation, MAX_PATH, &iIndex, &uFlags);
637 if (uFlags & GIL_NOTFILENAME)
638 ret = FALSE;
639 else
641 lstrcpyW (psfi->szDisplayName, szLocation);
642 psfi->iIcon = iIndex;
644 IExtractIconW_Release(pei);
649 /* get icon index (or load icon)*/
650 if (SUCCEEDED(hr) && (flags & (SHGFI_ICON | SHGFI_SYSICONINDEX)))
652 if (flags & SHGFI_USEFILEATTRIBUTES && !(flags & SHGFI_PIDL))
654 WCHAR sTemp [MAX_PATH];
655 WCHAR * szExt;
656 int icon_idx=0;
658 lstrcpynW(sTemp, szFullPath, MAX_PATH);
660 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
661 psfi->iIcon = SIC_GetIconIndex(swShell32Name, -IDI_SHELL_FOLDER, 0);
662 else
664 static const WCHAR p1W[] = {'%','1',0};
666 psfi->iIcon = 0;
667 szExt = PathFindExtensionW(sTemp);
668 if ( szExt &&
669 HCR_MapTypeToValueW(szExt, sTemp, MAX_PATH, TRUE) &&
670 HCR_GetDefaultIconW(sTemp, sTemp, MAX_PATH, &icon_idx))
672 if (!lstrcmpW(p1W,sTemp)) /* icon is in the file */
673 strcpyW(sTemp, szFullPath);
675 if (flags & SHGFI_SYSICONINDEX)
677 psfi->iIcon = SIC_GetIconIndex(sTemp,icon_idx,0);
678 if (psfi->iIcon == -1)
679 psfi->iIcon = 0;
681 else
683 UINT ret;
684 if (flags & SHGFI_SMALLICON)
685 ret = PrivateExtractIconsW( sTemp,icon_idx,
686 GetSystemMetrics( SM_CXSMICON ),
687 GetSystemMetrics( SM_CYSMICON ),
688 &psfi->hIcon, 0, 1, 0);
689 else
690 ret = PrivateExtractIconsW( sTemp, icon_idx,
691 GetSystemMetrics( SM_CXICON),
692 GetSystemMetrics( SM_CYICON),
693 &psfi->hIcon, 0, 1, 0);
694 if (ret != 0 && ret != (UINT)-1)
696 IconNotYetLoaded=FALSE;
697 psfi->iIcon = icon_idx;
703 else
705 if (!(PidlToSicIndex(psfParent, pidlLast, !(flags & SHGFI_SMALLICON),
706 uGilFlags, &(psfi->iIcon))))
708 ret = FALSE;
711 if (ret && (flags & SHGFI_SYSICONINDEX))
713 if (flags & SHGFI_SMALLICON)
714 ret = (DWORD_PTR)small_icons;
715 else
716 ret = (DWORD_PTR)big_icons;
720 /* icon handle */
721 if (SUCCEEDED(hr) && (flags & SHGFI_ICON) && IconNotYetLoaded)
723 if (flags & SHGFI_SMALLICON)
724 psfi->hIcon = ImageList_GetIcon( small_icons, psfi->iIcon, ILD_NORMAL);
725 else
726 psfi->hIcon = ImageList_GetIcon( big_icons, psfi->iIcon, ILD_NORMAL);
729 if (flags & ~SHGFI_KNOWN_FLAGS)
730 FIXME("unknown flags %08x\n", flags & ~SHGFI_KNOWN_FLAGS);
732 if (psfParent)
733 IShellFolder_Release(psfParent);
735 if (hr != S_OK)
736 ret = FALSE;
738 SHFree(pidlLast);
740 TRACE ("icon=%p index=0x%08x attr=0x%08x name=%s type=%s ret=0x%08lx\n",
741 psfi->hIcon, psfi->iIcon, psfi->dwAttributes,
742 debugstr_w(psfi->szDisplayName), debugstr_w(psfi->szTypeName), ret);
744 return ret;
747 /*************************************************************************
748 * SHGetFileInfoA [SHELL32.@]
750 * Note:
751 * MSVBVM60.__vbaNew2 expects this function to return a value in range
752 * 1 .. 0x7fff when the function succeeds and flags does not contain
753 * SHGFI_EXETYPE or SHGFI_SYSICONINDEX (see bug 7701)
755 DWORD_PTR WINAPI SHGetFileInfoA(LPCSTR path,DWORD dwFileAttributes,
756 SHFILEINFOA *psfi, UINT sizeofpsfi,
757 UINT flags )
759 INT len;
760 LPWSTR temppath = NULL;
761 LPCWSTR pathW;
762 DWORD_PTR ret;
763 SHFILEINFOW temppsfi;
765 if (flags & SHGFI_PIDL)
767 /* path contains a pidl */
768 pathW = (LPCWSTR)path;
770 else
772 len = MultiByteToWideChar(CP_ACP, 0, path, -1, NULL, 0);
773 temppath = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
774 MultiByteToWideChar(CP_ACP, 0, path, -1, temppath, len);
775 pathW = temppath;
778 if (psfi && (flags & SHGFI_ATTR_SPECIFIED))
779 temppsfi.dwAttributes=psfi->dwAttributes;
781 if (psfi == NULL)
782 ret = SHGetFileInfoW(pathW, dwFileAttributes, NULL, sizeof(temppsfi), flags);
783 else
784 ret = SHGetFileInfoW(pathW, dwFileAttributes, &temppsfi, sizeof(temppsfi), flags);
786 if (psfi)
788 if(flags & SHGFI_ICON)
789 psfi->hIcon=temppsfi.hIcon;
790 if(flags & (SHGFI_SYSICONINDEX|SHGFI_ICON|SHGFI_ICONLOCATION))
791 psfi->iIcon=temppsfi.iIcon;
792 if(flags & SHGFI_ATTRIBUTES)
793 psfi->dwAttributes=temppsfi.dwAttributes;
794 if(flags & (SHGFI_DISPLAYNAME|SHGFI_ICONLOCATION))
796 WideCharToMultiByte(CP_ACP, 0, temppsfi.szDisplayName, -1,
797 psfi->szDisplayName, sizeof(psfi->szDisplayName), NULL, NULL);
799 if(flags & SHGFI_TYPENAME)
801 WideCharToMultiByte(CP_ACP, 0, temppsfi.szTypeName, -1,
802 psfi->szTypeName, sizeof(psfi->szTypeName), NULL, NULL);
806 HeapFree(GetProcessHeap(), 0, temppath);
808 return ret;
811 /*************************************************************************
812 * DuplicateIcon [SHELL32.@]
814 HICON WINAPI DuplicateIcon( HINSTANCE hInstance, HICON hIcon)
816 ICONINFO IconInfo;
817 HICON hDupIcon = 0;
819 TRACE("%p %p\n", hInstance, hIcon);
821 if (GetIconInfo(hIcon, &IconInfo))
823 hDupIcon = CreateIconIndirect(&IconInfo);
825 /* clean up hbmMask and hbmColor */
826 DeleteObject(IconInfo.hbmMask);
827 DeleteObject(IconInfo.hbmColor);
830 return hDupIcon;
833 /*************************************************************************
834 * ExtractIconA [SHELL32.@]
836 HICON WINAPI ExtractIconA(HINSTANCE hInstance, LPCSTR lpszFile, UINT nIconIndex)
838 HICON ret;
839 INT len = MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, NULL, 0);
840 LPWSTR lpwstrFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
842 TRACE("%p %s %d\n", hInstance, lpszFile, nIconIndex);
844 MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, lpwstrFile, len);
845 ret = ExtractIconW(hInstance, lpwstrFile, nIconIndex);
846 HeapFree(GetProcessHeap(), 0, lpwstrFile);
848 return ret;
851 /*************************************************************************
852 * ExtractIconW [SHELL32.@]
854 HICON WINAPI ExtractIconW(HINSTANCE hInstance, LPCWSTR lpszFile, UINT nIconIndex)
856 HICON hIcon = NULL;
857 UINT ret;
858 UINT cx = GetSystemMetrics(SM_CXICON), cy = GetSystemMetrics(SM_CYICON);
860 TRACE("%p %s %d\n", hInstance, debugstr_w(lpszFile), nIconIndex);
862 if (nIconIndex == (UINT)-1)
864 ret = PrivateExtractIconsW(lpszFile, 0, cx, cy, NULL, NULL, 0, LR_DEFAULTCOLOR);
865 if (ret != (UINT)-1 && ret)
866 return (HICON)(UINT_PTR)ret;
867 return NULL;
869 else
870 ret = PrivateExtractIconsW(lpszFile, nIconIndex, cx, cy, &hIcon, NULL, 1, LR_DEFAULTCOLOR);
872 if (ret == (UINT)-1)
873 return (HICON)1;
874 else if (ret > 0 && hIcon)
875 return hIcon;
877 return NULL;
880 HRESULT WINAPI SHCreateFileExtractIconW(LPCWSTR file, DWORD attribs, REFIID riid, void **ppv)
882 FIXME("%s, %x, %s, %p\n", debugstr_w(file), attribs, debugstr_guid(riid), ppv);
883 *ppv = NULL;
884 return E_NOTIMPL;
887 /*************************************************************************
888 * Printer_LoadIconsW [SHELL32.205]
890 VOID WINAPI Printer_LoadIconsW(LPCWSTR wsPrinterName, HICON * pLargeIcon, HICON * pSmallIcon)
892 INT iconindex=IDI_SHELL_PRINTER;
894 TRACE("(%s, %p, %p)\n", debugstr_w(wsPrinterName), pLargeIcon, pSmallIcon);
896 /* We should check if wsPrinterName is
897 1. the Default Printer or not
898 2. connected or not
899 3. a Local Printer or a Network-Printer
900 and use different Icons
902 if((wsPrinterName != NULL) && (wsPrinterName[0] != 0))
904 FIXME("(select Icon by PrinterName %s not implemented)\n", debugstr_w(wsPrinterName));
907 if(pLargeIcon != NULL)
908 *pLargeIcon = LoadImageW(shell32_hInstance,
909 (LPCWSTR) MAKEINTRESOURCE(iconindex), IMAGE_ICON,
910 0, 0, LR_DEFAULTCOLOR|LR_DEFAULTSIZE);
912 if(pSmallIcon != NULL)
913 *pSmallIcon = LoadImageW(shell32_hInstance,
914 (LPCWSTR) MAKEINTRESOURCE(iconindex), IMAGE_ICON,
915 16, 16, LR_DEFAULTCOLOR);
918 /*************************************************************************
919 * Printers_RegisterWindowW [SHELL32.213]
920 * used by "printui.dll":
921 * find the Window of the given Type for the specific Printer and
922 * return the already existent hwnd or open a new window
924 BOOL WINAPI Printers_RegisterWindowW(LPCWSTR wsPrinter, DWORD dwType,
925 HANDLE * phClassPidl, HWND * phwnd)
927 FIXME("(%s, %x, %p (%p), %p (%p)) stub!\n", debugstr_w(wsPrinter), dwType,
928 phClassPidl, (phClassPidl != NULL) ? *(phClassPidl) : NULL,
929 phwnd, (phwnd != NULL) ? *(phwnd) : NULL);
931 return FALSE;
934 /*************************************************************************
935 * Printers_UnregisterWindow [SHELL32.214]
937 VOID WINAPI Printers_UnregisterWindow(HANDLE hClassPidl, HWND hwnd)
939 FIXME("(%p, %p) stub!\n", hClassPidl, hwnd);
942 /*************************************************************************
943 * SHGetPropertyStoreFromParsingName [SHELL32.@]
945 HRESULT WINAPI SHGetPropertyStoreFromParsingName(PCWSTR pszPath, IBindCtx *pbc, GETPROPERTYSTOREFLAGS flags, REFIID riid, void **ppv)
947 FIXME("(%s %p %u %p %p) stub!\n", debugstr_w(pszPath), pbc, flags, riid, ppv);
948 return E_NOTIMPL;
951 /*************************************************************************/
953 typedef struct
955 LPCWSTR szApp;
956 LPCWSTR szOtherStuff;
957 HICON hIcon;
958 HFONT hFont;
959 } ABOUT_INFO;
961 #define DROP_FIELD_TOP (-12)
963 static void paint_dropline( HDC hdc, HWND hWnd )
965 HWND hWndCtl = GetDlgItem(hWnd, IDC_ABOUT_WINE_TEXT);
966 RECT rect;
968 if (!hWndCtl) return;
969 GetWindowRect( hWndCtl, &rect );
970 MapWindowPoints( 0, hWnd, (LPPOINT)&rect, 2 );
971 rect.top += DROP_FIELD_TOP;
972 rect.bottom = rect.top + 2;
973 DrawEdge( hdc, &rect, BDR_SUNKENOUTER, BF_RECT );
976 /*************************************************************************
977 * SHHelpShortcuts_RunDLLA [SHELL32.@]
980 DWORD WINAPI SHHelpShortcuts_RunDLLA(DWORD dwArg1, DWORD dwArg2, DWORD dwArg3, DWORD dwArg4)
982 FIXME("(%x, %x, %x, %x) stub!\n", dwArg1, dwArg2, dwArg3, dwArg4);
983 return 0;
986 /*************************************************************************
987 * SHHelpShortcuts_RunDLLA [SHELL32.@]
990 DWORD WINAPI SHHelpShortcuts_RunDLLW(DWORD dwArg1, DWORD dwArg2, DWORD dwArg3, DWORD dwArg4)
992 FIXME("(%x, %x, %x, %x) stub!\n", dwArg1, dwArg2, dwArg3, dwArg4);
993 return 0;
996 /*************************************************************************
997 * SHLoadInProc [SHELL32.@]
998 * Create an instance of specified object class from within
999 * the shell process and release it immediately
1001 HRESULT WINAPI SHLoadInProc (REFCLSID rclsid)
1003 void *ptr = NULL;
1005 TRACE("%s\n", debugstr_guid(rclsid));
1007 CoCreateInstance(rclsid, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown,&ptr);
1008 if(ptr)
1010 IUnknown * pUnk = ptr;
1011 IUnknown_Release(pUnk);
1012 return S_OK;
1014 return DISP_E_MEMBERNOTFOUND;
1017 static void add_authors( HWND list )
1019 static const WCHAR eol[] = {'\r','\n',0};
1020 static const WCHAR authors[] = {'A','U','T','H','O','R','S',0};
1021 WCHAR *strW, *start, *end;
1022 HRSRC rsrc = FindResourceW( shell32_hInstance, authors, (LPCWSTR)RT_RCDATA );
1023 char *strA = LockResource( LoadResource( shell32_hInstance, rsrc ));
1024 DWORD sizeW, sizeA = SizeofResource( shell32_hInstance, rsrc );
1026 if (!strA) return;
1027 sizeW = MultiByteToWideChar( CP_UTF8, 0, strA, sizeA, NULL, 0 ) + 1;
1028 if (!(strW = HeapAlloc( GetProcessHeap(), 0, sizeW * sizeof(WCHAR) ))) return;
1029 MultiByteToWideChar( CP_UTF8, 0, strA, sizeA, strW, sizeW );
1030 strW[sizeW - 1] = 0;
1032 start = strpbrkW( strW, eol ); /* skip the header line */
1033 while (start)
1035 while (*start && strchrW( eol, *start )) start++;
1036 if (!*start) break;
1037 end = strpbrkW( start, eol );
1038 if (end) *end++ = 0;
1039 SendMessageW( list, LB_ADDSTRING, -1, (LPARAM)start );
1040 start = end;
1042 HeapFree( GetProcessHeap(), 0, strW );
1045 /*************************************************************************
1046 * AboutDlgProc (internal)
1048 static INT_PTR CALLBACK AboutDlgProc( HWND hWnd, UINT msg, WPARAM wParam,
1049 LPARAM lParam )
1051 HWND hWndCtl;
1053 TRACE("\n");
1055 switch(msg)
1057 case WM_INITDIALOG:
1059 ABOUT_INFO *info = (ABOUT_INFO *)lParam;
1060 WCHAR template[512], buffer[512], version[64];
1061 extern const char *wine_get_build_id(void);
1063 if (info)
1065 SendDlgItemMessageW(hWnd, stc1, STM_SETICON,(WPARAM)info->hIcon, 0);
1066 GetWindowTextW( hWnd, template, sizeof(template)/sizeof(WCHAR) );
1067 sprintfW( buffer, template, info->szApp );
1068 SetWindowTextW( hWnd, buffer );
1069 SetWindowTextW( GetDlgItem(hWnd, IDC_ABOUT_STATIC_TEXT1), info->szApp );
1070 SetWindowTextW( GetDlgItem(hWnd, IDC_ABOUT_STATIC_TEXT2), info->szOtherStuff );
1071 GetWindowTextW( GetDlgItem(hWnd, IDC_ABOUT_STATIC_TEXT3),
1072 template, sizeof(template)/sizeof(WCHAR) );
1073 MultiByteToWideChar( CP_UTF8, 0, wine_get_build_id(), -1,
1074 version, sizeof(version)/sizeof(WCHAR) );
1075 sprintfW( buffer, template, version );
1076 SetWindowTextW( GetDlgItem(hWnd, IDC_ABOUT_STATIC_TEXT3), buffer );
1077 hWndCtl = GetDlgItem(hWnd, IDC_ABOUT_LISTBOX);
1078 SendMessageW( hWndCtl, WM_SETREDRAW, 0, 0 );
1079 SendMessageW( hWndCtl, WM_SETFONT, (WPARAM)info->hFont, 0 );
1080 add_authors( hWndCtl );
1081 SendMessageW( hWndCtl, WM_SETREDRAW, 1, 0 );
1084 return 1;
1086 case WM_PAINT:
1088 PAINTSTRUCT ps;
1089 HDC hDC = BeginPaint( hWnd, &ps );
1090 paint_dropline( hDC, hWnd );
1091 EndPaint( hWnd, &ps );
1093 break;
1095 case WM_COMMAND:
1096 if (wParam == IDOK || wParam == IDCANCEL)
1098 EndDialog(hWnd, TRUE);
1099 return TRUE;
1101 if (wParam == IDC_ABOUT_LICENSE)
1103 MSGBOXPARAMSW params;
1105 params.cbSize = sizeof(params);
1106 params.hwndOwner = hWnd;
1107 params.hInstance = shell32_hInstance;
1108 params.lpszText = MAKEINTRESOURCEW(IDS_LICENSE);
1109 params.lpszCaption = MAKEINTRESOURCEW(IDS_LICENSE_CAPTION);
1110 params.dwStyle = MB_ICONINFORMATION | MB_OK;
1111 params.lpszIcon = 0;
1112 params.dwContextHelpId = 0;
1113 params.lpfnMsgBoxCallback = NULL;
1114 params.dwLanguageId = LANG_NEUTRAL;
1115 MessageBoxIndirectW( &params );
1117 break;
1118 case WM_CLOSE:
1119 EndDialog(hWnd, TRUE);
1120 break;
1123 return 0;
1127 /*************************************************************************
1128 * ShellAboutA [SHELL32.288]
1130 BOOL WINAPI ShellAboutA( HWND hWnd, LPCSTR szApp, LPCSTR szOtherStuff, HICON hIcon )
1132 BOOL ret;
1133 LPWSTR appW = NULL, otherW = NULL;
1134 int len;
1136 if (szApp)
1138 len = MultiByteToWideChar(CP_ACP, 0, szApp, -1, NULL, 0);
1139 appW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1140 MultiByteToWideChar(CP_ACP, 0, szApp, -1, appW, len);
1142 if (szOtherStuff)
1144 len = MultiByteToWideChar(CP_ACP, 0, szOtherStuff, -1, NULL, 0);
1145 otherW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1146 MultiByteToWideChar(CP_ACP, 0, szOtherStuff, -1, otherW, len);
1149 ret = ShellAboutW(hWnd, appW, otherW, hIcon);
1151 HeapFree(GetProcessHeap(), 0, otherW);
1152 HeapFree(GetProcessHeap(), 0, appW);
1153 return ret;
1157 /*************************************************************************
1158 * ShellAboutW [SHELL32.289]
1160 BOOL WINAPI ShellAboutW( HWND hWnd, LPCWSTR szApp, LPCWSTR szOtherStuff,
1161 HICON hIcon )
1163 ABOUT_INFO info;
1164 LOGFONTW logFont;
1165 BOOL bRet;
1166 static const WCHAR wszSHELL_ABOUT_MSGBOX[] =
1167 {'S','H','E','L','L','_','A','B','O','U','T','_','M','S','G','B','O','X',0};
1169 TRACE("\n");
1171 if (!hIcon) hIcon = LoadImageW( 0, (LPWSTR)IDI_WINLOGO, IMAGE_ICON, 48, 48, LR_SHARED );
1172 info.szApp = szApp;
1173 info.szOtherStuff = szOtherStuff;
1174 info.hIcon = hIcon;
1176 SystemParametersInfoW( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 );
1177 info.hFont = CreateFontIndirectW( &logFont );
1179 bRet = DialogBoxParamW( shell32_hInstance, wszSHELL_ABOUT_MSGBOX, hWnd, AboutDlgProc, (LPARAM)&info );
1180 DeleteObject(info.hFont);
1181 return bRet;
1184 /*************************************************************************
1185 * FreeIconList (SHELL32.@)
1187 void WINAPI FreeIconList( DWORD dw )
1189 FIXME("%x: stub\n",dw);
1192 /*************************************************************************
1193 * SHLoadNonloadedIconOverlayIdentifiers (SHELL32.@)
1195 HRESULT WINAPI SHLoadNonloadedIconOverlayIdentifiers( VOID )
1197 FIXME("stub\n");
1198 return S_OK;
1201 /***********************************************************************
1202 * DllGetVersion [SHELL32.@]
1204 * Retrieves version information of the 'SHELL32.DLL'
1206 * PARAMS
1207 * pdvi [O] pointer to version information structure.
1209 * RETURNS
1210 * Success: S_OK
1211 * Failure: E_INVALIDARG
1213 * NOTES
1214 * Returns version of a shell32.dll from IE4.01 SP1.
1217 HRESULT WINAPI DllGetVersion (DLLVERSIONINFO *pdvi)
1219 /* FIXME: shouldn't these values come from the version resource? */
1220 if (pdvi->cbSize == sizeof(DLLVERSIONINFO) ||
1221 pdvi->cbSize == sizeof(DLLVERSIONINFO2))
1223 pdvi->dwMajorVersion = WINE_FILEVERSION_MAJOR;
1224 pdvi->dwMinorVersion = WINE_FILEVERSION_MINOR;
1225 pdvi->dwBuildNumber = WINE_FILEVERSION_BUILD;
1226 pdvi->dwPlatformID = WINE_FILEVERSION_PLATFORMID;
1227 if (pdvi->cbSize == sizeof(DLLVERSIONINFO2))
1229 DLLVERSIONINFO2 *pdvi2 = (DLLVERSIONINFO2 *)pdvi;
1231 pdvi2->dwFlags = 0;
1232 pdvi2->ullVersion = MAKEDLLVERULL(WINE_FILEVERSION_MAJOR,
1233 WINE_FILEVERSION_MINOR,
1234 WINE_FILEVERSION_BUILD,
1235 WINE_FILEVERSION_PLATFORMID);
1237 TRACE("%u.%u.%u.%u\n",
1238 pdvi->dwMajorVersion, pdvi->dwMinorVersion,
1239 pdvi->dwBuildNumber, pdvi->dwPlatformID);
1240 return S_OK;
1242 else
1244 WARN("wrong DLLVERSIONINFO size from app\n");
1245 return E_INVALIDARG;
1249 /*************************************************************************
1250 * global variables of the shell32.dll
1251 * all are once per process
1254 HINSTANCE shell32_hInstance = 0;
1257 /*************************************************************************
1258 * SHELL32 DllMain
1260 * NOTES
1261 * calling oleinitialize here breaks some apps.
1263 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
1265 TRACE("%p 0x%x %p\n", hinstDLL, fdwReason, fImpLoad);
1267 switch (fdwReason)
1269 case DLL_PROCESS_ATTACH:
1270 shell32_hInstance = hinstDLL;
1271 DisableThreadLibraryCalls(shell32_hInstance);
1273 /* get full path to this DLL for IExtractIconW_fnGetIconLocation() */
1274 GetModuleFileNameW(hinstDLL, swShell32Name, MAX_PATH);
1275 swShell32Name[MAX_PATH - 1] = '\0';
1277 InitChangeNotifications();
1278 break;
1280 case DLL_PROCESS_DETACH:
1281 if (fImpLoad) break;
1282 SIC_Destroy();
1283 FreeChangeNotifications();
1284 release_typelib();
1285 break;
1287 return TRUE;
1290 /*************************************************************************
1291 * DllInstall [SHELL32.@]
1293 * PARAMETERS
1295 * BOOL bInstall - TRUE for install, FALSE for uninstall
1296 * LPCWSTR pszCmdLine - command line (unused by shell32?)
1299 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
1301 FIXME("%s %s: stub\n", bInstall ? "TRUE":"FALSE", debugstr_w(cmdline));
1302 return S_OK; /* indicate success */
1305 /***********************************************************************
1306 * DllCanUnloadNow (SHELL32.@)
1308 HRESULT WINAPI DllCanUnloadNow(void)
1310 return S_FALSE;
1313 /***********************************************************************
1314 * DllRegisterServer (SHELL32.@)
1316 HRESULT WINAPI DllRegisterServer(void)
1318 HRESULT hr = __wine_register_resources( shell32_hInstance );
1319 if (SUCCEEDED(hr)) hr = SHELL_RegisterShellFolders();
1320 return hr;
1323 /***********************************************************************
1324 * DllUnregisterServer (SHELL32.@)
1326 HRESULT WINAPI DllUnregisterServer(void)
1328 return __wine_unregister_resources( shell32_hInstance );
1331 /***********************************************************************
1332 * ExtractVersionResource16W (SHELL32.@)
1334 BOOL WINAPI ExtractVersionResource16W(LPWSTR s, DWORD d)
1336 FIXME("(%s %x) stub!\n", debugstr_w(s), d);
1337 return FALSE;
1340 /***********************************************************************
1341 * InitNetworkAddressControl (SHELL32.@)
1343 BOOL WINAPI InitNetworkAddressControl(void)
1345 FIXME("stub\n");
1346 return FALSE;
1349 /***********************************************************************
1350 * ShellHookProc (SHELL32.@)
1352 LRESULT CALLBACK ShellHookProc(DWORD a, DWORD b, DWORD c)
1354 FIXME("Stub\n");
1355 return 0;
1358 /***********************************************************************
1359 * SHGetLocalizedName (SHELL32.@)
1361 HRESULT WINAPI SHGetLocalizedName(LPCWSTR path, LPWSTR module, UINT size, INT *res)
1363 FIXME("%s %p %u %p: stub\n", debugstr_w(path), module, size, res);
1364 return E_NOTIMPL;
1367 /***********************************************************************
1368 * SetCurrentProcessExplicitAppUserModelID (SHELL32.@)
1370 HRESULT WINAPI SetCurrentProcessExplicitAppUserModelID(PCWSTR appid)
1372 FIXME("%s: stub\n", debugstr_w(appid));
1373 return E_NOTIMPL;
1376 /***********************************************************************
1377 * SHSetUnreadMailCountW (SHELL32.@)
1379 HRESULT WINAPI SHSetUnreadMailCountW(LPCWSTR mailaddress, DWORD count, LPCWSTR executecommand)
1381 FIXME("%s %x %s: stub\n", debugstr_w(mailaddress), count, debugstr_w(executecommand));
1382 return E_NOTIMPL;