advapi32/tests: Add trailing slashes tests for RegOpen/CreateKey.
[wine.git] / dlls / shell32 / shell32_main.c
blobcabf5e4cde90a27be91c0b81402f1683bd3ada39
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)*2 + deslen*sizeof(WCHAR);
105 for (;;)
107 if (!(argv = LocalAlloc(LMEM_FIXED, size))) return NULL;
108 len = GetModuleFileNameW(0, (LPWSTR)(argv+2), deslen);
109 if (!len)
111 LocalFree(argv);
112 return NULL;
114 if (len < deslen) break;
115 deslen*=2;
116 size = sizeof(LPWSTR)*2 + deslen*sizeof(WCHAR);
117 LocalFree( argv );
119 argv[0]=(LPWSTR)(argv+2);
120 argv[1]=NULL;
121 *numargs=1;
123 return argv;
126 /* --- First count the arguments */
127 argc=1;
128 s=lpCmdline;
129 /* The first argument, the executable path, follows special rules */
130 if (*s=='"')
132 /* The executable path ends at the next quote, no matter what */
133 s++;
134 while (*s)
135 if (*s++=='"')
136 break;
138 else
140 /* The executable path ends at the next space, no matter what */
141 while (*s && *s!=' ' && *s!='\t')
142 s++;
144 /* skip to the first argument, if any */
145 while (*s==' ' || *s=='\t')
146 s++;
147 if (*s)
148 argc++;
150 /* Analyze the remaining arguments */
151 qcount=bcount=0;
152 while (*s)
154 if ((*s==' ' || *s=='\t') && qcount==0)
156 /* skip to the next argument and count it if any */
157 while (*s==' ' || *s=='\t')
158 s++;
159 if (*s)
160 argc++;
161 bcount=0;
163 else if (*s=='\\')
165 /* '\', count them */
166 bcount++;
167 s++;
169 else if (*s=='"')
171 /* '"' */
172 if ((bcount & 1)==0)
173 qcount++; /* unescaped '"' */
174 s++;
175 bcount=0;
176 /* consecutive quotes, see comment in copying code below */
177 while (*s=='"')
179 qcount++;
180 s++;
182 qcount=qcount % 3;
183 if (qcount==2)
184 qcount=0;
186 else
188 /* a regular character */
189 bcount=0;
190 s++;
194 /* Allocate in a single lump, the string array, and the strings that go
195 * with it. This way the caller can make a single LocalFree() call to free
196 * both, as per MSDN.
198 argv=LocalAlloc(LMEM_FIXED, (argc+1)*sizeof(LPWSTR)+(strlenW(lpCmdline)+1)*sizeof(WCHAR));
199 if (!argv)
200 return NULL;
201 cmdline=(LPWSTR)(argv+argc+1);
202 strcpyW(cmdline, lpCmdline);
204 /* --- Then split and copy the arguments */
205 argv[0]=d=cmdline;
206 argc=1;
207 /* The first argument, the executable path, follows special rules */
208 if (*d=='"')
210 /* The executable path ends at the next quote, no matter what */
211 s=d+1;
212 while (*s)
214 if (*s=='"')
216 s++;
217 break;
219 *d++=*s++;
222 else
224 /* The executable path ends at the next space, no matter what */
225 while (*d && *d!=' ' && *d!='\t')
226 d++;
227 s=d;
228 if (*s)
229 s++;
231 /* close the executable path */
232 *d++=0;
233 /* skip to the first argument and initialize it if any */
234 while (*s==' ' || *s=='\t')
235 s++;
236 if (!*s)
238 /* There are no parameters so we are all done */
239 argv[argc]=NULL;
240 *numargs=argc;
241 return argv;
244 /* Split and copy the remaining arguments */
245 argv[argc++]=d;
246 qcount=bcount=0;
247 while (*s)
249 if ((*s==' ' || *s=='\t') && qcount==0)
251 /* close the argument */
252 *d++=0;
253 bcount=0;
255 /* skip to the next one and initialize it if any */
256 do {
257 s++;
258 } while (*s==' ' || *s=='\t');
259 if (*s)
260 argv[argc++]=d;
262 else if (*s=='\\')
264 *d++=*s++;
265 bcount++;
267 else if (*s=='"')
269 if ((bcount & 1)==0)
271 /* Preceded by an even number of '\', this is half that
272 * number of '\', plus a quote which we erase.
274 d-=bcount/2;
275 qcount++;
277 else
279 /* Preceded by an odd number of '\', this is half that
280 * number of '\' followed by a '"'
282 d=d-bcount/2-1;
283 *d++='"';
285 s++;
286 bcount=0;
287 /* Now count the number of consecutive quotes. Note that qcount
288 * already takes into account the opening quote if any, as well as
289 * the quote that lead us here.
291 while (*s=='"')
293 if (++qcount==3)
295 *d++='"';
296 qcount=0;
298 s++;
300 if (qcount==2)
301 qcount=0;
303 else
305 /* a regular character */
306 *d++=*s++;
307 bcount=0;
310 *d='\0';
311 argv[argc]=NULL;
312 *numargs=argc;
314 return argv;
317 static DWORD shgfi_get_exe_type(LPCWSTR szFullPath)
319 BOOL status = FALSE;
320 HANDLE hfile;
321 DWORD BinaryType;
322 IMAGE_DOS_HEADER mz_header;
323 IMAGE_NT_HEADERS nt;
324 DWORD len;
325 char magic[4];
327 status = GetBinaryTypeW (szFullPath, &BinaryType);
328 if (!status)
329 return 0;
330 if (BinaryType == SCS_DOS_BINARY || BinaryType == SCS_PIF_BINARY)
331 return 0x4d5a;
333 hfile = CreateFileW( szFullPath, GENERIC_READ, FILE_SHARE_READ,
334 NULL, OPEN_EXISTING, 0, 0 );
335 if ( hfile == INVALID_HANDLE_VALUE )
336 return 0;
339 * The next section is adapted from MODULE_GetBinaryType, as we need
340 * to examine the image header to get OS and version information. We
341 * know from calling GetBinaryTypeA that the image is valid and either
342 * an NE or PE, so much error handling can be omitted.
343 * Seek to the start of the file and read the header information.
346 SetFilePointer( hfile, 0, NULL, SEEK_SET );
347 ReadFile( hfile, &mz_header, sizeof(mz_header), &len, NULL );
349 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
350 ReadFile( hfile, magic, sizeof(magic), &len, NULL );
351 if ( *(DWORD*)magic == IMAGE_NT_SIGNATURE )
353 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
354 ReadFile( hfile, &nt, sizeof(nt), &len, NULL );
355 CloseHandle( hfile );
356 /* DLL files are not executable and should return 0 */
357 if (nt.FileHeader.Characteristics & IMAGE_FILE_DLL)
358 return 0;
359 if (nt.OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI)
361 return IMAGE_NT_SIGNATURE |
362 (nt.OptionalHeader.MajorSubsystemVersion << 24) |
363 (nt.OptionalHeader.MinorSubsystemVersion << 16);
365 return IMAGE_NT_SIGNATURE;
367 else if ( *(WORD*)magic == IMAGE_OS2_SIGNATURE )
369 IMAGE_OS2_HEADER ne;
370 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
371 ReadFile( hfile, &ne, sizeof(ne), &len, NULL );
372 CloseHandle( hfile );
373 if (ne.ne_exetyp == 2)
374 return IMAGE_OS2_SIGNATURE | (ne.ne_expver << 16);
375 return 0;
377 CloseHandle( hfile );
378 return 0;
381 /*************************************************************************
382 * SHELL_IsShortcut [internal]
384 * Decide if an item id list points to a shell shortcut
386 BOOL SHELL_IsShortcut(LPCITEMIDLIST pidlLast)
388 char szTemp[MAX_PATH];
389 HKEY keyCls;
390 BOOL ret = FALSE;
392 if (_ILGetExtension(pidlLast, szTemp, MAX_PATH) &&
393 HCR_MapTypeToValueA(szTemp, szTemp, MAX_PATH, TRUE))
395 if (ERROR_SUCCESS == RegOpenKeyExA(HKEY_CLASSES_ROOT, szTemp, 0, KEY_QUERY_VALUE, &keyCls))
397 if (ERROR_SUCCESS == RegQueryValueExA(keyCls, "IsShortcut", NULL, NULL, NULL, NULL))
398 ret = TRUE;
400 RegCloseKey(keyCls);
404 return ret;
407 #define SHGFI_KNOWN_FLAGS \
408 (SHGFI_SMALLICON | SHGFI_OPENICON | SHGFI_SHELLICONSIZE | SHGFI_PIDL | \
409 SHGFI_USEFILEATTRIBUTES | SHGFI_ADDOVERLAYS | SHGFI_OVERLAYINDEX | \
410 SHGFI_ICON | SHGFI_DISPLAYNAME | SHGFI_TYPENAME | SHGFI_ATTRIBUTES | \
411 SHGFI_ICONLOCATION | SHGFI_EXETYPE | SHGFI_SYSICONINDEX | \
412 SHGFI_LINKOVERLAY | SHGFI_SELECTED | SHGFI_ATTR_SPECIFIED)
414 /*************************************************************************
415 * SHGetFileInfoW [SHELL32.@]
418 DWORD_PTR WINAPI SHGetFileInfoW(LPCWSTR path,DWORD dwFileAttributes,
419 SHFILEINFOW *psfi, UINT sizeofpsfi, UINT flags )
421 WCHAR szLocation[MAX_PATH], szFullPath[MAX_PATH];
422 int iIndex;
423 DWORD_PTR ret = TRUE;
424 DWORD dwAttributes = 0;
425 IShellFolder * psfParent = NULL;
426 IExtractIconW * pei = NULL;
427 LPITEMIDLIST pidlLast = NULL, pidl = NULL;
428 HRESULT hr = S_OK;
429 BOOL IconNotYetLoaded=TRUE;
430 UINT uGilFlags = 0;
431 HIMAGELIST big_icons, small_icons;
433 TRACE("%s fattr=0x%x sfi=%p(attr=0x%08x) size=0x%x flags=0x%x\n",
434 (flags & SHGFI_PIDL)? "pidl" : debugstr_w(path), dwFileAttributes,
435 psfi, psfi->dwAttributes, sizeofpsfi, flags);
437 if (!path)
438 return FALSE;
440 /* windows initializes these values regardless of the flags */
441 if (psfi != NULL)
443 psfi->szDisplayName[0] = '\0';
444 psfi->szTypeName[0] = '\0';
445 psfi->iIcon = 0;
448 if (!(flags & SHGFI_PIDL))
450 /* SHGetFileInfo should work with absolute and relative paths */
451 if (PathIsRelativeW(path))
453 GetCurrentDirectoryW(MAX_PATH, szLocation);
454 PathCombineW(szFullPath, szLocation, path);
456 else
458 lstrcpynW(szFullPath, path, MAX_PATH);
462 if (flags & SHGFI_EXETYPE)
464 if (flags != SHGFI_EXETYPE)
465 return 0;
466 return shgfi_get_exe_type(szFullPath);
470 * psfi is NULL normally to query EXE type. If it is NULL, none of the
471 * below makes sense anyway. Windows allows this and just returns FALSE
473 if (psfi == NULL)
474 return FALSE;
477 * translate the path into a pidl only when SHGFI_USEFILEATTRIBUTES
478 * is not specified.
479 * The pidl functions fail on not existing file names
482 if (flags & SHGFI_PIDL)
484 pidl = ILClone((LPCITEMIDLIST)path);
486 else if (!(flags & SHGFI_USEFILEATTRIBUTES))
488 hr = SHILCreateFromPathW(szFullPath, &pidl, &dwAttributes);
491 if ((flags & SHGFI_PIDL) || !(flags & SHGFI_USEFILEATTRIBUTES))
493 /* get the parent shellfolder */
494 if (pidl)
496 hr = SHBindToParent( pidl, &IID_IShellFolder, (LPVOID*)&psfParent,
497 (LPCITEMIDLIST*)&pidlLast );
498 if (SUCCEEDED(hr))
499 pidlLast = ILClone(pidlLast);
500 ILFree(pidl);
502 else
504 ERR("pidl is null!\n");
505 return FALSE;
509 /* get the attributes of the child */
510 if (SUCCEEDED(hr) && (flags & SHGFI_ATTRIBUTES))
512 if (!(flags & SHGFI_ATTR_SPECIFIED))
514 psfi->dwAttributes = 0xffffffff;
516 if (psfParent)
517 IShellFolder_GetAttributesOf( psfParent, 1, (LPCITEMIDLIST*)&pidlLast,
518 &(psfi->dwAttributes) );
521 /* get the displayname */
522 if (SUCCEEDED(hr) && (flags & SHGFI_DISPLAYNAME))
524 if (flags & SHGFI_USEFILEATTRIBUTES && !(flags & SHGFI_PIDL))
526 lstrcpyW (psfi->szDisplayName, PathFindFileNameW(szFullPath));
528 else
530 STRRET str;
531 hr = IShellFolder_GetDisplayNameOf( psfParent, pidlLast,
532 SHGDN_INFOLDER, &str);
533 StrRetToStrNW (psfi->szDisplayName, MAX_PATH, &str, pidlLast);
537 /* get the type name */
538 if (SUCCEEDED(hr) && (flags & SHGFI_TYPENAME))
540 static const WCHAR szFile[] = { 'F','i','l','e',0 };
541 static const WCHAR szDashFile[] = { '-','f','i','l','e',0 };
543 if (!(flags & SHGFI_USEFILEATTRIBUTES) || (flags & SHGFI_PIDL))
545 char ftype[80];
547 _ILGetFileType(pidlLast, ftype, 80);
548 MultiByteToWideChar(CP_ACP, 0, ftype, -1, psfi->szTypeName, 80 );
550 else
552 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
553 strcatW (psfi->szTypeName, szFile);
554 else
556 WCHAR sTemp[64];
558 lstrcpyW(sTemp,PathFindExtensionW(szFullPath));
559 if (!( HCR_MapTypeToValueW(sTemp, sTemp, 64, TRUE) &&
560 HCR_MapTypeToValueW(sTemp, psfi->szTypeName, 80, FALSE )))
562 lstrcpynW (psfi->szTypeName, sTemp, 64);
563 strcatW (psfi->szTypeName, szDashFile);
569 /* ### icons ###*/
571 Shell_GetImageLists( &big_icons, &small_icons );
573 if (flags & SHGFI_OPENICON)
574 uGilFlags |= GIL_OPENICON;
576 if (flags & SHGFI_LINKOVERLAY)
577 uGilFlags |= GIL_FORSHORTCUT;
578 else if ((flags&SHGFI_ADDOVERLAYS) ||
579 (flags&(SHGFI_ICON|SHGFI_SMALLICON))==SHGFI_ICON)
581 if (SHELL_IsShortcut(pidlLast))
582 uGilFlags |= GIL_FORSHORTCUT;
585 if (flags & SHGFI_OVERLAYINDEX)
586 FIXME("SHGFI_OVERLAYINDEX unhandled\n");
588 if (flags & SHGFI_SELECTED)
589 FIXME("set icon to selected, stub\n");
591 if (flags & SHGFI_SHELLICONSIZE)
592 FIXME("set icon to shell size, stub\n");
594 /* get the iconlocation */
595 if (SUCCEEDED(hr) && (flags & SHGFI_ICONLOCATION ))
597 UINT uDummy,uFlags;
599 if (flags & SHGFI_USEFILEATTRIBUTES && !(flags & SHGFI_PIDL))
601 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
603 lstrcpyW(psfi->szDisplayName, swShell32Name);
604 psfi->iIcon = -IDI_SHELL_FOLDER;
606 else
608 WCHAR* szExt;
609 static const WCHAR p1W[] = {'%','1',0};
610 WCHAR sTemp [MAX_PATH];
612 szExt = PathFindExtensionW(szFullPath);
613 TRACE("szExt=%s\n", debugstr_w(szExt));
614 if ( szExt &&
615 HCR_MapTypeToValueW(szExt, sTemp, MAX_PATH, TRUE) &&
616 HCR_GetDefaultIconW(sTemp, sTemp, MAX_PATH, &psfi->iIcon))
618 if (lstrcmpW(p1W, sTemp))
619 strcpyW(psfi->szDisplayName, sTemp);
620 else
622 /* the icon is in the file */
623 strcpyW(psfi->szDisplayName, szFullPath);
626 else
627 ret = FALSE;
630 else
632 hr = IShellFolder_GetUIObjectOf(psfParent, 0, 1,
633 (LPCITEMIDLIST*)&pidlLast, &IID_IExtractIconW,
634 &uDummy, (LPVOID*)&pei);
635 if (SUCCEEDED(hr))
637 hr = IExtractIconW_GetIconLocation(pei, uGilFlags,
638 szLocation, MAX_PATH, &iIndex, &uFlags);
640 if (uFlags & GIL_NOTFILENAME)
641 ret = FALSE;
642 else
644 lstrcpyW (psfi->szDisplayName, szLocation);
645 psfi->iIcon = iIndex;
647 IExtractIconW_Release(pei);
652 /* get icon index (or load icon)*/
653 if (SUCCEEDED(hr) && (flags & (SHGFI_ICON | SHGFI_SYSICONINDEX)))
655 if (flags & SHGFI_USEFILEATTRIBUTES && !(flags & SHGFI_PIDL))
657 WCHAR sTemp [MAX_PATH];
658 WCHAR * szExt;
659 int icon_idx=0;
661 lstrcpynW(sTemp, szFullPath, MAX_PATH);
663 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
664 psfi->iIcon = SIC_GetIconIndex(swShell32Name, -IDI_SHELL_FOLDER, 0);
665 else
667 static const WCHAR p1W[] = {'%','1',0};
669 psfi->iIcon = 0;
670 szExt = PathFindExtensionW(sTemp);
671 if ( szExt &&
672 HCR_MapTypeToValueW(szExt, sTemp, MAX_PATH, TRUE) &&
673 HCR_GetDefaultIconW(sTemp, sTemp, MAX_PATH, &icon_idx))
675 if (!lstrcmpW(p1W,sTemp)) /* icon is in the file */
676 strcpyW(sTemp, szFullPath);
678 if (flags & SHGFI_SYSICONINDEX)
680 psfi->iIcon = SIC_GetIconIndex(sTemp,icon_idx,0);
681 if (psfi->iIcon == -1)
682 psfi->iIcon = 0;
684 else
686 UINT ret;
687 if (flags & SHGFI_SMALLICON)
688 ret = PrivateExtractIconsW( sTemp,icon_idx,
689 GetSystemMetrics( SM_CXSMICON ),
690 GetSystemMetrics( SM_CYSMICON ),
691 &psfi->hIcon, 0, 1, 0);
692 else
693 ret = PrivateExtractIconsW( sTemp, icon_idx,
694 GetSystemMetrics( SM_CXICON),
695 GetSystemMetrics( SM_CYICON),
696 &psfi->hIcon, 0, 1, 0);
697 if (ret != 0 && ret != (UINT)-1)
699 IconNotYetLoaded=FALSE;
700 psfi->iIcon = icon_idx;
706 else
708 if (!(PidlToSicIndex(psfParent, pidlLast, !(flags & SHGFI_SMALLICON),
709 uGilFlags, &(psfi->iIcon))))
711 ret = FALSE;
714 if (ret && (flags & SHGFI_SYSICONINDEX))
716 if (flags & SHGFI_SMALLICON)
717 ret = (DWORD_PTR)small_icons;
718 else
719 ret = (DWORD_PTR)big_icons;
723 /* icon handle */
724 if (SUCCEEDED(hr) && (flags & SHGFI_ICON) && IconNotYetLoaded)
726 if (flags & SHGFI_SMALLICON)
727 psfi->hIcon = ImageList_GetIcon( small_icons, psfi->iIcon, ILD_NORMAL);
728 else
729 psfi->hIcon = ImageList_GetIcon( big_icons, psfi->iIcon, ILD_NORMAL);
732 if (flags & ~SHGFI_KNOWN_FLAGS)
733 FIXME("unknown flags %08x\n", flags & ~SHGFI_KNOWN_FLAGS);
735 if (psfParent)
736 IShellFolder_Release(psfParent);
738 if (hr != S_OK)
739 ret = FALSE;
741 SHFree(pidlLast);
743 TRACE ("icon=%p index=0x%08x attr=0x%08x name=%s type=%s ret=0x%08lx\n",
744 psfi->hIcon, psfi->iIcon, psfi->dwAttributes,
745 debugstr_w(psfi->szDisplayName), debugstr_w(psfi->szTypeName), ret);
747 return ret;
750 /*************************************************************************
751 * SHGetFileInfoA [SHELL32.@]
753 * Note:
754 * MSVBVM60.__vbaNew2 expects this function to return a value in range
755 * 1 .. 0x7fff when the function succeeds and flags does not contain
756 * SHGFI_EXETYPE or SHGFI_SYSICONINDEX (see bug 7701)
758 DWORD_PTR WINAPI SHGetFileInfoA(LPCSTR path,DWORD dwFileAttributes,
759 SHFILEINFOA *psfi, UINT sizeofpsfi,
760 UINT flags )
762 INT len;
763 LPWSTR temppath = NULL;
764 LPCWSTR pathW;
765 DWORD_PTR ret;
766 SHFILEINFOW temppsfi;
768 if (flags & SHGFI_PIDL)
770 /* path contains a pidl */
771 pathW = (LPCWSTR)path;
773 else
775 len = MultiByteToWideChar(CP_ACP, 0, path, -1, NULL, 0);
776 temppath = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
777 MultiByteToWideChar(CP_ACP, 0, path, -1, temppath, len);
778 pathW = temppath;
781 if (psfi && (flags & SHGFI_ATTR_SPECIFIED))
782 temppsfi.dwAttributes=psfi->dwAttributes;
784 if (psfi == NULL)
785 ret = SHGetFileInfoW(pathW, dwFileAttributes, NULL, sizeof(temppsfi), flags);
786 else
787 ret = SHGetFileInfoW(pathW, dwFileAttributes, &temppsfi, sizeof(temppsfi), flags);
789 if (psfi)
791 if(flags & SHGFI_ICON)
792 psfi->hIcon=temppsfi.hIcon;
793 if(flags & (SHGFI_SYSICONINDEX|SHGFI_ICON|SHGFI_ICONLOCATION))
794 psfi->iIcon=temppsfi.iIcon;
795 if(flags & SHGFI_ATTRIBUTES)
796 psfi->dwAttributes=temppsfi.dwAttributes;
797 if(flags & (SHGFI_DISPLAYNAME|SHGFI_ICONLOCATION))
799 WideCharToMultiByte(CP_ACP, 0, temppsfi.szDisplayName, -1,
800 psfi->szDisplayName, sizeof(psfi->szDisplayName), NULL, NULL);
802 if(flags & SHGFI_TYPENAME)
804 WideCharToMultiByte(CP_ACP, 0, temppsfi.szTypeName, -1,
805 psfi->szTypeName, sizeof(psfi->szTypeName), NULL, NULL);
809 HeapFree(GetProcessHeap(), 0, temppath);
811 return ret;
814 /*************************************************************************
815 * DuplicateIcon [SHELL32.@]
817 HICON WINAPI DuplicateIcon( HINSTANCE hInstance, HICON hIcon)
819 ICONINFO IconInfo;
820 HICON hDupIcon = 0;
822 TRACE("%p %p\n", hInstance, hIcon);
824 if (GetIconInfo(hIcon, &IconInfo))
826 hDupIcon = CreateIconIndirect(&IconInfo);
828 /* clean up hbmMask and hbmColor */
829 DeleteObject(IconInfo.hbmMask);
830 DeleteObject(IconInfo.hbmColor);
833 return hDupIcon;
836 /*************************************************************************
837 * ExtractIconA [SHELL32.@]
839 HICON WINAPI ExtractIconA(HINSTANCE hInstance, LPCSTR lpszFile, UINT nIconIndex)
841 HICON ret;
842 INT len = MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, NULL, 0);
843 LPWSTR lpwstrFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
845 TRACE("%p %s %d\n", hInstance, lpszFile, nIconIndex);
847 MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, lpwstrFile, len);
848 ret = ExtractIconW(hInstance, lpwstrFile, nIconIndex);
849 HeapFree(GetProcessHeap(), 0, lpwstrFile);
851 return ret;
854 /*************************************************************************
855 * ExtractIconW [SHELL32.@]
857 HICON WINAPI ExtractIconW(HINSTANCE hInstance, LPCWSTR lpszFile, UINT nIconIndex)
859 HICON hIcon = NULL;
860 UINT ret;
861 UINT cx = GetSystemMetrics(SM_CXICON), cy = GetSystemMetrics(SM_CYICON);
863 TRACE("%p %s %d\n", hInstance, debugstr_w(lpszFile), nIconIndex);
865 if (nIconIndex == (UINT)-1)
867 ret = PrivateExtractIconsW(lpszFile, 0, cx, cy, NULL, NULL, 0, LR_DEFAULTCOLOR);
868 if (ret != (UINT)-1 && ret)
869 return (HICON)(UINT_PTR)ret;
870 return NULL;
872 else
873 ret = PrivateExtractIconsW(lpszFile, nIconIndex, cx, cy, &hIcon, NULL, 1, LR_DEFAULTCOLOR);
875 if (ret == (UINT)-1)
876 return (HICON)1;
877 else if (ret > 0 && hIcon)
878 return hIcon;
880 return NULL;
883 HRESULT WINAPI SHCreateFileExtractIconW(LPCWSTR file, DWORD attribs, REFIID riid, void **ppv)
885 FIXME("%s, %x, %s, %p\n", debugstr_w(file), attribs, debugstr_guid(riid), ppv);
886 *ppv = NULL;
887 return E_NOTIMPL;
890 /*************************************************************************
891 * Printer_LoadIconsW [SHELL32.205]
893 VOID WINAPI Printer_LoadIconsW(LPCWSTR wsPrinterName, HICON * pLargeIcon, HICON * pSmallIcon)
895 INT iconindex=IDI_SHELL_PRINTER;
897 TRACE("(%s, %p, %p)\n", debugstr_w(wsPrinterName), pLargeIcon, pSmallIcon);
899 /* We should check if wsPrinterName is
900 1. the Default Printer or not
901 2. connected or not
902 3. a Local Printer or a Network-Printer
903 and use different Icons
905 if((wsPrinterName != NULL) && (wsPrinterName[0] != 0))
907 FIXME("(select Icon by PrinterName %s not implemented)\n", debugstr_w(wsPrinterName));
910 if(pLargeIcon != NULL)
911 *pLargeIcon = LoadImageW(shell32_hInstance,
912 (LPCWSTR) MAKEINTRESOURCE(iconindex), IMAGE_ICON,
913 0, 0, LR_DEFAULTCOLOR|LR_DEFAULTSIZE);
915 if(pSmallIcon != NULL)
916 *pSmallIcon = LoadImageW(shell32_hInstance,
917 (LPCWSTR) MAKEINTRESOURCE(iconindex), IMAGE_ICON,
918 16, 16, LR_DEFAULTCOLOR);
921 /*************************************************************************
922 * Printers_RegisterWindowW [SHELL32.213]
923 * used by "printui.dll":
924 * find the Window of the given Type for the specific Printer and
925 * return the already existent hwnd or open a new window
927 BOOL WINAPI Printers_RegisterWindowW(LPCWSTR wsPrinter, DWORD dwType,
928 HANDLE * phClassPidl, HWND * phwnd)
930 FIXME("(%s, %x, %p (%p), %p (%p)) stub!\n", debugstr_w(wsPrinter), dwType,
931 phClassPidl, (phClassPidl != NULL) ? *(phClassPidl) : NULL,
932 phwnd, (phwnd != NULL) ? *(phwnd) : NULL);
934 return FALSE;
937 /*************************************************************************
938 * Printers_UnregisterWindow [SHELL32.214]
940 VOID WINAPI Printers_UnregisterWindow(HANDLE hClassPidl, HWND hwnd)
942 FIXME("(%p, %p) stub!\n", hClassPidl, hwnd);
945 /*************************************************************************
946 * SHGetPropertyStoreFromParsingName [SHELL32.@]
948 HRESULT WINAPI SHGetPropertyStoreFromParsingName(PCWSTR pszPath, IBindCtx *pbc, GETPROPERTYSTOREFLAGS flags, REFIID riid, void **ppv)
950 FIXME("(%s %p %u %p %p) stub!\n", debugstr_w(pszPath), pbc, flags, riid, ppv);
951 return E_NOTIMPL;
954 /*************************************************************************/
956 typedef struct
958 LPCWSTR szApp;
959 LPCWSTR szOtherStuff;
960 HICON hIcon;
961 HFONT hFont;
962 } ABOUT_INFO;
964 #define DROP_FIELD_TOP (-12)
966 static void paint_dropline( HDC hdc, HWND hWnd )
968 HWND hWndCtl = GetDlgItem(hWnd, IDC_ABOUT_WINE_TEXT);
969 RECT rect;
971 if (!hWndCtl) return;
972 GetWindowRect( hWndCtl, &rect );
973 MapWindowPoints( 0, hWnd, (LPPOINT)&rect, 2 );
974 rect.top += DROP_FIELD_TOP;
975 rect.bottom = rect.top + 2;
976 DrawEdge( hdc, &rect, BDR_SUNKENOUTER, BF_RECT );
979 /*************************************************************************
980 * SHHelpShortcuts_RunDLLA [SHELL32.@]
983 DWORD WINAPI SHHelpShortcuts_RunDLLA(DWORD dwArg1, DWORD dwArg2, DWORD dwArg3, DWORD dwArg4)
985 FIXME("(%x, %x, %x, %x) stub!\n", dwArg1, dwArg2, dwArg3, dwArg4);
986 return 0;
989 /*************************************************************************
990 * SHHelpShortcuts_RunDLLA [SHELL32.@]
993 DWORD WINAPI SHHelpShortcuts_RunDLLW(DWORD dwArg1, DWORD dwArg2, DWORD dwArg3, DWORD dwArg4)
995 FIXME("(%x, %x, %x, %x) stub!\n", dwArg1, dwArg2, dwArg3, dwArg4);
996 return 0;
999 /*************************************************************************
1000 * SHLoadInProc [SHELL32.@]
1001 * Create an instance of specified object class from within
1002 * the shell process and release it immediately
1004 HRESULT WINAPI SHLoadInProc (REFCLSID rclsid)
1006 void *ptr = NULL;
1008 TRACE("%s\n", debugstr_guid(rclsid));
1010 CoCreateInstance(rclsid, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown,&ptr);
1011 if(ptr)
1013 IUnknown * pUnk = ptr;
1014 IUnknown_Release(pUnk);
1015 return S_OK;
1017 return DISP_E_MEMBERNOTFOUND;
1020 static void add_authors( HWND list )
1022 static const WCHAR eol[] = {'\r','\n',0};
1023 static const WCHAR authors[] = {'A','U','T','H','O','R','S',0};
1024 WCHAR *strW, *start, *end;
1025 HRSRC rsrc = FindResourceW( shell32_hInstance, authors, (LPCWSTR)RT_RCDATA );
1026 char *strA = LockResource( LoadResource( shell32_hInstance, rsrc ));
1027 DWORD sizeW, sizeA = SizeofResource( shell32_hInstance, rsrc );
1029 if (!strA) return;
1030 sizeW = MultiByteToWideChar( CP_UTF8, 0, strA, sizeA, NULL, 0 ) + 1;
1031 if (!(strW = HeapAlloc( GetProcessHeap(), 0, sizeW * sizeof(WCHAR) ))) return;
1032 MultiByteToWideChar( CP_UTF8, 0, strA, sizeA, strW, sizeW );
1033 strW[sizeW - 1] = 0;
1035 start = strpbrkW( strW, eol ); /* skip the header line */
1036 while (start)
1038 while (*start && strchrW( eol, *start )) start++;
1039 if (!*start) break;
1040 end = strpbrkW( start, eol );
1041 if (end) *end++ = 0;
1042 SendMessageW( list, LB_ADDSTRING, -1, (LPARAM)start );
1043 start = end;
1045 HeapFree( GetProcessHeap(), 0, strW );
1048 /*************************************************************************
1049 * AboutDlgProc (internal)
1051 static INT_PTR CALLBACK AboutDlgProc( HWND hWnd, UINT msg, WPARAM wParam,
1052 LPARAM lParam )
1054 HWND hWndCtl;
1056 TRACE("\n");
1058 switch(msg)
1060 case WM_INITDIALOG:
1062 ABOUT_INFO *info = (ABOUT_INFO *)lParam;
1063 WCHAR template[512], buffer[512], version[64];
1064 extern const char *wine_get_build_id(void);
1066 if (info)
1068 SendDlgItemMessageW(hWnd, stc1, STM_SETICON,(WPARAM)info->hIcon, 0);
1069 GetWindowTextW( hWnd, template, sizeof(template)/sizeof(WCHAR) );
1070 sprintfW( buffer, template, info->szApp );
1071 SetWindowTextW( hWnd, buffer );
1072 SetWindowTextW( GetDlgItem(hWnd, IDC_ABOUT_STATIC_TEXT1), info->szApp );
1073 SetWindowTextW( GetDlgItem(hWnd, IDC_ABOUT_STATIC_TEXT2), info->szOtherStuff );
1074 GetWindowTextW( GetDlgItem(hWnd, IDC_ABOUT_STATIC_TEXT3),
1075 template, sizeof(template)/sizeof(WCHAR) );
1076 MultiByteToWideChar( CP_UTF8, 0, wine_get_build_id(), -1,
1077 version, sizeof(version)/sizeof(WCHAR) );
1078 sprintfW( buffer, template, version );
1079 SetWindowTextW( GetDlgItem(hWnd, IDC_ABOUT_STATIC_TEXT3), buffer );
1080 hWndCtl = GetDlgItem(hWnd, IDC_ABOUT_LISTBOX);
1081 SendMessageW( hWndCtl, WM_SETREDRAW, 0, 0 );
1082 SendMessageW( hWndCtl, WM_SETFONT, (WPARAM)info->hFont, 0 );
1083 add_authors( hWndCtl );
1084 SendMessageW( hWndCtl, WM_SETREDRAW, 1, 0 );
1087 return 1;
1089 case WM_PAINT:
1091 PAINTSTRUCT ps;
1092 HDC hDC = BeginPaint( hWnd, &ps );
1093 paint_dropline( hDC, hWnd );
1094 EndPaint( hWnd, &ps );
1096 break;
1098 case WM_COMMAND:
1099 if (wParam == IDOK || wParam == IDCANCEL)
1101 EndDialog(hWnd, TRUE);
1102 return TRUE;
1104 if (wParam == IDC_ABOUT_LICENSE)
1106 MSGBOXPARAMSW params;
1108 params.cbSize = sizeof(params);
1109 params.hwndOwner = hWnd;
1110 params.hInstance = shell32_hInstance;
1111 params.lpszText = MAKEINTRESOURCEW(IDS_LICENSE);
1112 params.lpszCaption = MAKEINTRESOURCEW(IDS_LICENSE_CAPTION);
1113 params.dwStyle = MB_ICONINFORMATION | MB_OK;
1114 params.lpszIcon = 0;
1115 params.dwContextHelpId = 0;
1116 params.lpfnMsgBoxCallback = NULL;
1117 params.dwLanguageId = LANG_NEUTRAL;
1118 MessageBoxIndirectW( &params );
1120 break;
1121 case WM_CLOSE:
1122 EndDialog(hWnd, TRUE);
1123 break;
1126 return 0;
1130 /*************************************************************************
1131 * ShellAboutA [SHELL32.288]
1133 BOOL WINAPI ShellAboutA( HWND hWnd, LPCSTR szApp, LPCSTR szOtherStuff, HICON hIcon )
1135 BOOL ret;
1136 LPWSTR appW = NULL, otherW = NULL;
1137 int len;
1139 if (szApp)
1141 len = MultiByteToWideChar(CP_ACP, 0, szApp, -1, NULL, 0);
1142 appW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1143 MultiByteToWideChar(CP_ACP, 0, szApp, -1, appW, len);
1145 if (szOtherStuff)
1147 len = MultiByteToWideChar(CP_ACP, 0, szOtherStuff, -1, NULL, 0);
1148 otherW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1149 MultiByteToWideChar(CP_ACP, 0, szOtherStuff, -1, otherW, len);
1152 ret = ShellAboutW(hWnd, appW, otherW, hIcon);
1154 HeapFree(GetProcessHeap(), 0, otherW);
1155 HeapFree(GetProcessHeap(), 0, appW);
1156 return ret;
1160 /*************************************************************************
1161 * ShellAboutW [SHELL32.289]
1163 BOOL WINAPI ShellAboutW( HWND hWnd, LPCWSTR szApp, LPCWSTR szOtherStuff,
1164 HICON hIcon )
1166 ABOUT_INFO info;
1167 LOGFONTW logFont;
1168 BOOL bRet;
1169 static const WCHAR wszSHELL_ABOUT_MSGBOX[] =
1170 {'S','H','E','L','L','_','A','B','O','U','T','_','M','S','G','B','O','X',0};
1172 TRACE("\n");
1174 if (!hIcon) hIcon = LoadImageW( 0, (LPWSTR)IDI_WINLOGO, IMAGE_ICON, 48, 48, LR_SHARED );
1175 info.szApp = szApp;
1176 info.szOtherStuff = szOtherStuff;
1177 info.hIcon = hIcon;
1179 SystemParametersInfoW( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 );
1180 info.hFont = CreateFontIndirectW( &logFont );
1182 bRet = DialogBoxParamW( shell32_hInstance, wszSHELL_ABOUT_MSGBOX, hWnd, AboutDlgProc, (LPARAM)&info );
1183 DeleteObject(info.hFont);
1184 return bRet;
1187 /*************************************************************************
1188 * FreeIconList (SHELL32.@)
1190 void WINAPI FreeIconList( DWORD dw )
1192 FIXME("%x: stub\n",dw);
1195 /*************************************************************************
1196 * SHLoadNonloadedIconOverlayIdentifiers (SHELL32.@)
1198 HRESULT WINAPI SHLoadNonloadedIconOverlayIdentifiers( VOID )
1200 FIXME("stub\n");
1201 return S_OK;
1204 /***********************************************************************
1205 * DllGetVersion [SHELL32.@]
1207 * Retrieves version information of the 'SHELL32.DLL'
1209 * PARAMS
1210 * pdvi [O] pointer to version information structure.
1212 * RETURNS
1213 * Success: S_OK
1214 * Failure: E_INVALIDARG
1216 * NOTES
1217 * Returns version of a shell32.dll from IE4.01 SP1.
1220 HRESULT WINAPI DllGetVersion (DLLVERSIONINFO *pdvi)
1222 /* FIXME: shouldn't these values come from the version resource? */
1223 if (pdvi->cbSize == sizeof(DLLVERSIONINFO) ||
1224 pdvi->cbSize == sizeof(DLLVERSIONINFO2))
1226 pdvi->dwMajorVersion = WINE_FILEVERSION_MAJOR;
1227 pdvi->dwMinorVersion = WINE_FILEVERSION_MINOR;
1228 pdvi->dwBuildNumber = WINE_FILEVERSION_BUILD;
1229 pdvi->dwPlatformID = WINE_FILEVERSION_PLATFORMID;
1230 if (pdvi->cbSize == sizeof(DLLVERSIONINFO2))
1232 DLLVERSIONINFO2 *pdvi2 = (DLLVERSIONINFO2 *)pdvi;
1234 pdvi2->dwFlags = 0;
1235 pdvi2->ullVersion = MAKEDLLVERULL(WINE_FILEVERSION_MAJOR,
1236 WINE_FILEVERSION_MINOR,
1237 WINE_FILEVERSION_BUILD,
1238 WINE_FILEVERSION_PLATFORMID);
1240 TRACE("%u.%u.%u.%u\n",
1241 pdvi->dwMajorVersion, pdvi->dwMinorVersion,
1242 pdvi->dwBuildNumber, pdvi->dwPlatformID);
1243 return S_OK;
1245 else
1247 WARN("wrong DLLVERSIONINFO size from app\n");
1248 return E_INVALIDARG;
1252 /*************************************************************************
1253 * global variables of the shell32.dll
1254 * all are once per process
1257 HINSTANCE shell32_hInstance = 0;
1260 /*************************************************************************
1261 * SHELL32 DllMain
1263 * NOTES
1264 * calling oleinitialize here breaks some apps.
1266 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
1268 TRACE("%p 0x%x %p\n", hinstDLL, fdwReason, fImpLoad);
1270 switch (fdwReason)
1272 case DLL_PROCESS_ATTACH:
1273 shell32_hInstance = hinstDLL;
1274 DisableThreadLibraryCalls(shell32_hInstance);
1276 /* get full path to this DLL for IExtractIconW_fnGetIconLocation() */
1277 GetModuleFileNameW(hinstDLL, swShell32Name, MAX_PATH);
1278 swShell32Name[MAX_PATH - 1] = '\0';
1280 InitChangeNotifications();
1281 break;
1283 case DLL_PROCESS_DETACH:
1284 if (fImpLoad) break;
1285 SIC_Destroy();
1286 FreeChangeNotifications();
1287 release_desktop_folder();
1288 release_typelib();
1289 break;
1291 return TRUE;
1294 /*************************************************************************
1295 * DllInstall [SHELL32.@]
1297 * PARAMETERS
1299 * BOOL bInstall - TRUE for install, FALSE for uninstall
1300 * LPCWSTR pszCmdLine - command line (unused by shell32?)
1303 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
1305 FIXME("%s %s: stub\n", bInstall ? "TRUE":"FALSE", debugstr_w(cmdline));
1306 return S_OK; /* indicate success */
1309 /***********************************************************************
1310 * DllCanUnloadNow (SHELL32.@)
1312 HRESULT WINAPI DllCanUnloadNow(void)
1314 return S_FALSE;
1317 /***********************************************************************
1318 * DllRegisterServer (SHELL32.@)
1320 HRESULT WINAPI DllRegisterServer(void)
1322 HRESULT hr = __wine_register_resources( shell32_hInstance );
1323 if (SUCCEEDED(hr)) hr = SHELL_RegisterShellFolders();
1324 return hr;
1327 /***********************************************************************
1328 * DllUnregisterServer (SHELL32.@)
1330 HRESULT WINAPI DllUnregisterServer(void)
1332 return __wine_unregister_resources( shell32_hInstance );
1335 /***********************************************************************
1336 * ExtractVersionResource16W (SHELL32.@)
1338 BOOL WINAPI ExtractVersionResource16W(LPWSTR s, DWORD d)
1340 FIXME("(%s %x) stub!\n", debugstr_w(s), d);
1341 return FALSE;
1344 /***********************************************************************
1345 * InitNetworkAddressControl (SHELL32.@)
1347 BOOL WINAPI InitNetworkAddressControl(void)
1349 FIXME("stub\n");
1350 return FALSE;
1353 /***********************************************************************
1354 * ShellHookProc (SHELL32.@)
1356 LRESULT CALLBACK ShellHookProc(DWORD a, DWORD b, DWORD c)
1358 FIXME("Stub\n");
1359 return 0;
1362 /***********************************************************************
1363 * SHGetLocalizedName (SHELL32.@)
1365 HRESULT WINAPI SHGetLocalizedName(LPCWSTR path, LPWSTR module, UINT size, INT *res)
1367 FIXME("%s %p %u %p: stub\n", debugstr_w(path), module, size, res);
1368 return E_NOTIMPL;
1371 /***********************************************************************
1372 * SetCurrentProcessExplicitAppUserModelID (SHELL32.@)
1374 HRESULT WINAPI SetCurrentProcessExplicitAppUserModelID(PCWSTR appid)
1376 FIXME("%s: stub\n", debugstr_w(appid));
1377 return E_NOTIMPL;
1380 /***********************************************************************
1381 * SHSetUnreadMailCountW (SHELL32.@)
1383 HRESULT WINAPI SHSetUnreadMailCountW(LPCWSTR mailaddress, DWORD count, LPCWSTR executecommand)
1385 FIXME("%s %x %s: stub\n", debugstr_w(mailaddress), count, debugstr_w(executecommand));
1386 return E_NOTIMPL;
1389 /***********************************************************************
1390 * SHEnumerateUnreadMailAccountsW (SHELL32.@)
1392 HRESULT WINAPI SHEnumerateUnreadMailAccountsW(HKEY user, DWORD idx, LPWSTR mailaddress, INT mailaddresslen)
1394 FIXME("%p %d %p %d: stub\n", user, idx, mailaddress, mailaddresslen);
1395 return E_NOTIMPL;