msxml3: Fix attributes formatting.
[wine/multimedia.git] / dlls / shell32 / shell32_main.c
blob981a24591c126c13185999a15d99c617bb691a08
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 * - an odd number of '\'s followed by '"' correspond to half that number
68 * of '\' followed by a '"' (extension of the above)
69 * '\\\"' -> '\"'
70 * '\\\\\"' -> '\\"'
71 * - an even number of '\'s followed by a '"' correspond to half that number
72 * of '\', plus a regular quote serving as an argument delimiter (which
73 * means it does not appear in the result)
74 * 'a\\"b c"' -> 'a\b c'
75 * 'a\\\\"b c"' -> 'a\\b c'
76 * - '\' that are not followed by a '"' are copied literally
77 * 'a\b' -> 'a\b'
78 * 'a\\b' -> 'a\\b'
80 * Note:
81 * '\t' == 0x0009
82 * ' ' == 0x0020
83 * '"' == 0x0022
84 * '\\' == 0x005c
86 LPWSTR* WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int* numargs)
88 DWORD argc;
89 LPWSTR *argv;
90 LPCWSTR cs;
91 LPWSTR arg,s,d;
92 LPWSTR cmdline;
93 int in_quotes,bcount;
95 if (*lpCmdline==0)
97 /* Return the path to the executable */
98 DWORD len, deslen=MAX_PATH, size;
100 size = sizeof(LPWSTR) + deslen*sizeof(WCHAR) + sizeof(LPWSTR);
101 for (;;)
103 if (!(argv = LocalAlloc(LMEM_FIXED, size))) return NULL;
104 len = GetModuleFileNameW(0, (LPWSTR)(argv+1), deslen);
105 if (!len)
107 LocalFree(argv);
108 return NULL;
110 if (len < deslen) break;
111 deslen*=2;
112 size = sizeof(LPWSTR) + deslen*sizeof(WCHAR) + sizeof(LPWSTR);
113 LocalFree( argv );
115 argv[0]=(LPWSTR)(argv+1);
116 if (numargs)
117 *numargs=1;
119 return argv;
122 /* to get a writable copy */
123 argc=0;
124 bcount=0;
125 in_quotes=0;
126 cs=lpCmdline;
127 while (1)
129 if (*cs==0 || ((*cs==0x0009 || *cs==0x0020) && !in_quotes))
131 /* space */
132 argc++;
133 /* skip the remaining spaces */
134 while (*cs==0x0009 || *cs==0x0020) {
135 cs++;
137 if (*cs==0)
138 break;
139 bcount=0;
140 continue;
142 else if (*cs==0x005c)
144 /* '\', count them */
145 bcount++;
147 else if ((*cs==0x0022) && ((bcount & 1)==0))
149 /* unescaped '"' */
150 in_quotes=!in_quotes;
151 bcount=0;
153 else
155 /* a regular character */
156 bcount=0;
158 cs++;
160 /* Allocate in a single lump, the string array, and the strings that go with it.
161 * This way the caller can make a single GlobalFree call to free both, as per MSDN.
163 argv=LocalAlloc(LMEM_FIXED, argc*sizeof(LPWSTR)+(strlenW(lpCmdline)+1)*sizeof(WCHAR));
164 if (!argv)
165 return NULL;
166 cmdline=(LPWSTR)(argv+argc);
167 strcpyW(cmdline, lpCmdline);
169 argc=0;
170 bcount=0;
171 in_quotes=0;
172 arg=d=s=cmdline;
173 while (*s)
175 if ((*s==0x0009 || *s==0x0020) && !in_quotes)
177 /* Close the argument and copy it */
178 *d=0;
179 argv[argc++]=arg;
181 /* skip the remaining spaces */
182 do {
183 s++;
184 } while (*s==0x0009 || *s==0x0020);
186 /* Start with a new argument */
187 arg=d=s;
188 bcount=0;
190 else if (*s==0x005c)
192 /* '\\' */
193 *d++=*s++;
194 bcount++;
196 else if (*s==0x0022)
198 /* '"' */
199 if ((bcount & 1)==0)
201 /* Preceded by an even number of '\', this is half that
202 * number of '\', plus a quote which we erase.
204 d-=bcount/2;
205 in_quotes=!in_quotes;
206 s++;
208 else
210 /* Preceded by an odd number of '\', this is half that
211 * number of '\' followed by a '"'
213 d=d-bcount/2-1;
214 *d++='"';
215 s++;
217 bcount=0;
219 else
221 /* a regular character */
222 *d++=*s++;
223 bcount=0;
226 if (*arg)
228 *d='\0';
229 argv[argc++]=arg;
231 if (numargs)
232 *numargs=argc;
234 return argv;
237 static DWORD shgfi_get_exe_type(LPCWSTR szFullPath)
239 BOOL status = FALSE;
240 HANDLE hfile;
241 DWORD BinaryType;
242 IMAGE_DOS_HEADER mz_header;
243 IMAGE_NT_HEADERS nt;
244 DWORD len;
245 char magic[4];
247 status = GetBinaryTypeW (szFullPath, &BinaryType);
248 if (!status)
249 return 0;
250 if (BinaryType == SCS_DOS_BINARY || BinaryType == SCS_PIF_BINARY)
251 return 0x4d5a;
253 hfile = CreateFileW( szFullPath, GENERIC_READ, FILE_SHARE_READ,
254 NULL, OPEN_EXISTING, 0, 0 );
255 if ( hfile == INVALID_HANDLE_VALUE )
256 return 0;
259 * The next section is adapted from MODULE_GetBinaryType, as we need
260 * to examine the image header to get OS and version information. We
261 * know from calling GetBinaryTypeA that the image is valid and either
262 * an NE or PE, so much error handling can be omitted.
263 * Seek to the start of the file and read the header information.
266 SetFilePointer( hfile, 0, NULL, SEEK_SET );
267 ReadFile( hfile, &mz_header, sizeof(mz_header), &len, NULL );
269 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
270 ReadFile( hfile, magic, sizeof(magic), &len, NULL );
271 if ( *(DWORD*)magic == IMAGE_NT_SIGNATURE )
273 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
274 ReadFile( hfile, &nt, sizeof(nt), &len, NULL );
275 CloseHandle( hfile );
276 /* DLL files are not executable and should return 0 */
277 if (nt.FileHeader.Characteristics & IMAGE_FILE_DLL)
278 return 0;
279 if (nt.OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI)
281 return IMAGE_NT_SIGNATURE |
282 (nt.OptionalHeader.MajorSubsystemVersion << 24) |
283 (nt.OptionalHeader.MinorSubsystemVersion << 16);
285 return IMAGE_NT_SIGNATURE;
287 else if ( *(WORD*)magic == IMAGE_OS2_SIGNATURE )
289 IMAGE_OS2_HEADER ne;
290 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
291 ReadFile( hfile, &ne, sizeof(ne), &len, NULL );
292 CloseHandle( hfile );
293 if (ne.ne_exetyp == 2)
294 return IMAGE_OS2_SIGNATURE | (ne.ne_expver << 16);
295 return 0;
297 CloseHandle( hfile );
298 return 0;
301 /*************************************************************************
302 * SHELL_IsShortcut [internal]
304 * Decide if an item id list points to a shell shortcut
306 BOOL SHELL_IsShortcut(LPCITEMIDLIST pidlLast)
308 char szTemp[MAX_PATH];
309 HKEY keyCls;
310 BOOL ret = FALSE;
312 if (_ILGetExtension(pidlLast, szTemp, MAX_PATH) &&
313 HCR_MapTypeToValueA(szTemp, szTemp, MAX_PATH, TRUE))
315 if (ERROR_SUCCESS == RegOpenKeyExA(HKEY_CLASSES_ROOT, szTemp, 0, KEY_QUERY_VALUE, &keyCls))
317 if (ERROR_SUCCESS == RegQueryValueExA(keyCls, "IsShortcut", NULL, NULL, NULL, NULL))
318 ret = TRUE;
320 RegCloseKey(keyCls);
324 return ret;
327 #define SHGFI_KNOWN_FLAGS \
328 (SHGFI_SMALLICON | SHGFI_OPENICON | SHGFI_SHELLICONSIZE | SHGFI_PIDL | \
329 SHGFI_USEFILEATTRIBUTES | SHGFI_ADDOVERLAYS | SHGFI_OVERLAYINDEX | \
330 SHGFI_ICON | SHGFI_DISPLAYNAME | SHGFI_TYPENAME | SHGFI_ATTRIBUTES | \
331 SHGFI_ICONLOCATION | SHGFI_EXETYPE | SHGFI_SYSICONINDEX | \
332 SHGFI_LINKOVERLAY | SHGFI_SELECTED | SHGFI_ATTR_SPECIFIED)
334 /*************************************************************************
335 * SHGetFileInfoW [SHELL32.@]
338 DWORD_PTR WINAPI SHGetFileInfoW(LPCWSTR path,DWORD dwFileAttributes,
339 SHFILEINFOW *psfi, UINT sizeofpsfi, UINT flags )
341 WCHAR szLocation[MAX_PATH], szFullPath[MAX_PATH];
342 int iIndex;
343 DWORD_PTR ret = TRUE;
344 DWORD dwAttributes = 0;
345 IShellFolder * psfParent = NULL;
346 IExtractIconW * pei = NULL;
347 LPITEMIDLIST pidlLast = NULL, pidl = NULL;
348 HRESULT hr = S_OK;
349 BOOL IconNotYetLoaded=TRUE;
350 UINT uGilFlags = 0;
352 TRACE("%s fattr=0x%x sfi=%p(attr=0x%08x) size=0x%x flags=0x%x\n",
353 (flags & SHGFI_PIDL)? "pidl" : debugstr_w(path), dwFileAttributes,
354 psfi, psfi->dwAttributes, sizeofpsfi, flags);
356 if (!path)
357 return FALSE;
359 /* windows initializes these values regardless of the flags */
360 if (psfi != NULL)
362 psfi->szDisplayName[0] = '\0';
363 psfi->szTypeName[0] = '\0';
364 psfi->iIcon = 0;
367 if (!(flags & SHGFI_PIDL))
369 /* SHGetFileInfo should work with absolute and relative paths */
370 if (PathIsRelativeW(path))
372 GetCurrentDirectoryW(MAX_PATH, szLocation);
373 PathCombineW(szFullPath, szLocation, path);
375 else
377 lstrcpynW(szFullPath, path, MAX_PATH);
381 if (flags & SHGFI_EXETYPE)
383 if (flags != SHGFI_EXETYPE)
384 return 0;
385 return shgfi_get_exe_type(szFullPath);
389 * psfi is NULL normally to query EXE type. If it is NULL, none of the
390 * below makes sense anyway. Windows allows this and just returns FALSE
392 if (psfi == NULL)
393 return FALSE;
396 * translate the path into a pidl only when SHGFI_USEFILEATTRIBUTES
397 * is not specified.
398 * The pidl functions fail on not existing file names
401 if (flags & SHGFI_PIDL)
403 pidl = ILClone((LPCITEMIDLIST)path);
405 else if (!(flags & SHGFI_USEFILEATTRIBUTES))
407 hr = SHILCreateFromPathW(szFullPath, &pidl, &dwAttributes);
410 if ((flags & SHGFI_PIDL) || !(flags & SHGFI_USEFILEATTRIBUTES))
412 /* get the parent shellfolder */
413 if (pidl)
415 hr = SHBindToParent( pidl, &IID_IShellFolder, (LPVOID*)&psfParent,
416 (LPCITEMIDLIST*)&pidlLast );
417 if (SUCCEEDED(hr))
418 pidlLast = ILClone(pidlLast);
419 ILFree(pidl);
421 else
423 ERR("pidl is null!\n");
424 return FALSE;
428 /* get the attributes of the child */
429 if (SUCCEEDED(hr) && (flags & SHGFI_ATTRIBUTES))
431 if (!(flags & SHGFI_ATTR_SPECIFIED))
433 psfi->dwAttributes = 0xffffffff;
435 if (psfParent)
436 IShellFolder_GetAttributesOf( psfParent, 1, (LPCITEMIDLIST*)&pidlLast,
437 &(psfi->dwAttributes) );
440 /* get the displayname */
441 if (SUCCEEDED(hr) && (flags & SHGFI_DISPLAYNAME))
443 if (flags & SHGFI_USEFILEATTRIBUTES && !(flags & SHGFI_PIDL))
445 lstrcpyW (psfi->szDisplayName, PathFindFileNameW(szFullPath));
447 else
449 STRRET str;
450 hr = IShellFolder_GetDisplayNameOf( psfParent, pidlLast,
451 SHGDN_INFOLDER, &str);
452 StrRetToStrNW (psfi->szDisplayName, MAX_PATH, &str, pidlLast);
456 /* get the type name */
457 if (SUCCEEDED(hr) && (flags & SHGFI_TYPENAME))
459 static const WCHAR szFile[] = { 'F','i','l','e',0 };
460 static const WCHAR szDashFile[] = { '-','f','i','l','e',0 };
462 if (!(flags & SHGFI_USEFILEATTRIBUTES) || (flags & SHGFI_PIDL))
464 char ftype[80];
466 _ILGetFileType(pidlLast, ftype, 80);
467 MultiByteToWideChar(CP_ACP, 0, ftype, -1, psfi->szTypeName, 80 );
469 else
471 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
472 strcatW (psfi->szTypeName, szFile);
473 else
475 WCHAR sTemp[64];
477 lstrcpyW(sTemp,PathFindExtensionW(szFullPath));
478 if (!( HCR_MapTypeToValueW(sTemp, sTemp, 64, TRUE) &&
479 HCR_MapTypeToValueW(sTemp, psfi->szTypeName, 80, FALSE )))
481 lstrcpynW (psfi->szTypeName, sTemp, 64);
482 strcatW (psfi->szTypeName, szDashFile);
488 /* ### icons ###*/
489 if (flags & SHGFI_OPENICON)
490 uGilFlags |= GIL_OPENICON;
492 if (flags & SHGFI_LINKOVERLAY)
493 uGilFlags |= GIL_FORSHORTCUT;
494 else if ((flags&SHGFI_ADDOVERLAYS) ||
495 (flags&(SHGFI_ICON|SHGFI_SMALLICON))==SHGFI_ICON)
497 if (SHELL_IsShortcut(pidlLast))
498 uGilFlags |= GIL_FORSHORTCUT;
501 if (flags & SHGFI_OVERLAYINDEX)
502 FIXME("SHGFI_OVERLAYINDEX unhandled\n");
504 if (flags & SHGFI_SELECTED)
505 FIXME("set icon to selected, stub\n");
507 if (flags & SHGFI_SHELLICONSIZE)
508 FIXME("set icon to shell size, stub\n");
510 /* get the iconlocation */
511 if (SUCCEEDED(hr) && (flags & SHGFI_ICONLOCATION ))
513 UINT uDummy,uFlags;
515 if (flags & SHGFI_USEFILEATTRIBUTES && !(flags & SHGFI_PIDL))
517 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
519 lstrcpyW(psfi->szDisplayName, swShell32Name);
520 psfi->iIcon = -IDI_SHELL_FOLDER;
522 else
524 WCHAR* szExt;
525 static const WCHAR p1W[] = {'%','1',0};
526 WCHAR sTemp [MAX_PATH];
528 szExt = PathFindExtensionW(szFullPath);
529 TRACE("szExt=%s\n", debugstr_w(szExt));
530 if ( szExt &&
531 HCR_MapTypeToValueW(szExt, sTemp, MAX_PATH, TRUE) &&
532 HCR_GetDefaultIconW(sTemp, sTemp, MAX_PATH, &psfi->iIcon))
534 if (lstrcmpW(p1W, sTemp))
535 strcpyW(psfi->szDisplayName, sTemp);
536 else
538 /* the icon is in the file */
539 strcpyW(psfi->szDisplayName, szFullPath);
542 else
543 ret = FALSE;
546 else
548 hr = IShellFolder_GetUIObjectOf(psfParent, 0, 1,
549 (LPCITEMIDLIST*)&pidlLast, &IID_IExtractIconW,
550 &uDummy, (LPVOID*)&pei);
551 if (SUCCEEDED(hr))
553 hr = IExtractIconW_GetIconLocation(pei, uGilFlags,
554 szLocation, MAX_PATH, &iIndex, &uFlags);
556 if (uFlags & GIL_NOTFILENAME)
557 ret = FALSE;
558 else
560 lstrcpyW (psfi->szDisplayName, szLocation);
561 psfi->iIcon = iIndex;
563 IExtractIconW_Release(pei);
568 /* get icon index (or load icon)*/
569 if (SUCCEEDED(hr) && (flags & (SHGFI_ICON | SHGFI_SYSICONINDEX)))
571 if (flags & SHGFI_USEFILEATTRIBUTES && !(flags & SHGFI_PIDL))
573 WCHAR sTemp [MAX_PATH];
574 WCHAR * szExt;
575 int icon_idx=0;
577 lstrcpynW(sTemp, szFullPath, MAX_PATH);
579 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
580 psfi->iIcon = SIC_GetIconIndex(swShell32Name, -IDI_SHELL_FOLDER, 0);
581 else
583 static const WCHAR p1W[] = {'%','1',0};
585 psfi->iIcon = 0;
586 szExt = PathFindExtensionW(sTemp);
587 if ( szExt &&
588 HCR_MapTypeToValueW(szExt, sTemp, MAX_PATH, TRUE) &&
589 HCR_GetDefaultIconW(sTemp, sTemp, MAX_PATH, &icon_idx))
591 if (!lstrcmpW(p1W,sTemp)) /* icon is in the file */
592 strcpyW(sTemp, szFullPath);
594 if (flags & SHGFI_SYSICONINDEX)
596 psfi->iIcon = SIC_GetIconIndex(sTemp,icon_idx,0);
597 if (psfi->iIcon == -1)
598 psfi->iIcon = 0;
600 else
602 UINT ret;
603 if (flags & SHGFI_SMALLICON)
604 ret = PrivateExtractIconsW( sTemp,icon_idx,
605 GetSystemMetrics( SM_CXSMICON ),
606 GetSystemMetrics( SM_CYSMICON ),
607 &psfi->hIcon, 0, 1, 0);
608 else
609 ret = PrivateExtractIconsW( sTemp, icon_idx,
610 GetSystemMetrics( SM_CXICON),
611 GetSystemMetrics( SM_CYICON),
612 &psfi->hIcon, 0, 1, 0);
613 if (ret != 0 && ret != (UINT)-1)
615 IconNotYetLoaded=FALSE;
616 psfi->iIcon = icon_idx;
622 else
624 if (!(PidlToSicIndex(psfParent, pidlLast, !(flags & SHGFI_SMALLICON),
625 uGilFlags, &(psfi->iIcon))))
627 ret = FALSE;
630 if (ret && (flags & SHGFI_SYSICONINDEX))
632 if (flags & SHGFI_SMALLICON)
633 ret = (DWORD_PTR) ShellSmallIconList;
634 else
635 ret = (DWORD_PTR) ShellBigIconList;
639 /* icon handle */
640 if (SUCCEEDED(hr) && (flags & SHGFI_ICON) && IconNotYetLoaded)
642 if (flags & SHGFI_SMALLICON)
643 psfi->hIcon = ImageList_GetIcon( ShellSmallIconList, psfi->iIcon, ILD_NORMAL);
644 else
645 psfi->hIcon = ImageList_GetIcon( ShellBigIconList, psfi->iIcon, ILD_NORMAL);
648 if (flags & ~SHGFI_KNOWN_FLAGS)
649 FIXME("unknown flags %08x\n", flags & ~SHGFI_KNOWN_FLAGS);
651 if (psfParent)
652 IShellFolder_Release(psfParent);
654 if (hr != S_OK)
655 ret = FALSE;
657 SHFree(pidlLast);
659 TRACE ("icon=%p index=0x%08x attr=0x%08x name=%s type=%s ret=0x%08lx\n",
660 psfi->hIcon, psfi->iIcon, psfi->dwAttributes,
661 debugstr_w(psfi->szDisplayName), debugstr_w(psfi->szTypeName), ret);
663 return ret;
666 /*************************************************************************
667 * SHGetFileInfoA [SHELL32.@]
669 * Note:
670 * MSVBVM60.__vbaNew2 expects this function to return a value in range
671 * 1 .. 0x7fff when the function succeeds and flags does not contain
672 * SHGFI_EXETYPE or SHGFI_SYSICONINDEX (see bug 7701)
674 DWORD_PTR WINAPI SHGetFileInfoA(LPCSTR path,DWORD dwFileAttributes,
675 SHFILEINFOA *psfi, UINT sizeofpsfi,
676 UINT flags )
678 INT len;
679 LPWSTR temppath = NULL;
680 LPCWSTR pathW;
681 DWORD_PTR ret;
682 SHFILEINFOW temppsfi;
684 if (flags & SHGFI_PIDL)
686 /* path contains a pidl */
687 pathW = (LPCWSTR)path;
689 else
691 len = MultiByteToWideChar(CP_ACP, 0, path, -1, NULL, 0);
692 temppath = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
693 MultiByteToWideChar(CP_ACP, 0, path, -1, temppath, len);
694 pathW = temppath;
697 if (psfi && (flags & SHGFI_ATTR_SPECIFIED))
698 temppsfi.dwAttributes=psfi->dwAttributes;
700 if (psfi == NULL)
701 ret = SHGetFileInfoW(pathW, dwFileAttributes, NULL, sizeof(temppsfi), flags);
702 else
703 ret = SHGetFileInfoW(pathW, dwFileAttributes, &temppsfi, sizeof(temppsfi), flags);
705 if (psfi)
707 if(flags & SHGFI_ICON)
708 psfi->hIcon=temppsfi.hIcon;
709 if(flags & (SHGFI_SYSICONINDEX|SHGFI_ICON|SHGFI_ICONLOCATION))
710 psfi->iIcon=temppsfi.iIcon;
711 if(flags & SHGFI_ATTRIBUTES)
712 psfi->dwAttributes=temppsfi.dwAttributes;
713 if(flags & (SHGFI_DISPLAYNAME|SHGFI_ICONLOCATION))
715 WideCharToMultiByte(CP_ACP, 0, temppsfi.szDisplayName, -1,
716 psfi->szDisplayName, sizeof(psfi->szDisplayName), NULL, NULL);
718 if(flags & SHGFI_TYPENAME)
720 WideCharToMultiByte(CP_ACP, 0, temppsfi.szTypeName, -1,
721 psfi->szTypeName, sizeof(psfi->szTypeName), NULL, NULL);
725 HeapFree(GetProcessHeap(), 0, temppath);
727 return ret;
730 /*************************************************************************
731 * DuplicateIcon [SHELL32.@]
733 HICON WINAPI DuplicateIcon( HINSTANCE hInstance, HICON hIcon)
735 ICONINFO IconInfo;
736 HICON hDupIcon = 0;
738 TRACE("%p %p\n", hInstance, hIcon);
740 if (GetIconInfo(hIcon, &IconInfo))
742 hDupIcon = CreateIconIndirect(&IconInfo);
744 /* clean up hbmMask and hbmColor */
745 DeleteObject(IconInfo.hbmMask);
746 DeleteObject(IconInfo.hbmColor);
749 return hDupIcon;
752 /*************************************************************************
753 * ExtractIconA [SHELL32.@]
755 HICON WINAPI ExtractIconA(HINSTANCE hInstance, LPCSTR lpszFile, UINT nIconIndex)
757 HICON ret;
758 INT len = MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, NULL, 0);
759 LPWSTR lpwstrFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
761 TRACE("%p %s %d\n", hInstance, lpszFile, nIconIndex);
763 MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, lpwstrFile, len);
764 ret = ExtractIconW(hInstance, lpwstrFile, nIconIndex);
765 HeapFree(GetProcessHeap(), 0, lpwstrFile);
767 return ret;
770 /*************************************************************************
771 * ExtractIconW [SHELL32.@]
773 HICON WINAPI ExtractIconW(HINSTANCE hInstance, LPCWSTR lpszFile, UINT nIconIndex)
775 HICON hIcon = NULL;
776 UINT ret;
777 UINT cx = GetSystemMetrics(SM_CXICON), cy = GetSystemMetrics(SM_CYICON);
779 TRACE("%p %s %d\n", hInstance, debugstr_w(lpszFile), nIconIndex);
781 if (nIconIndex == (UINT)-1)
783 ret = PrivateExtractIconsW(lpszFile, 0, cx, cy, NULL, NULL, 0, LR_DEFAULTCOLOR);
784 if (ret != (UINT)-1 && ret)
785 return (HICON)(UINT_PTR)ret;
786 return NULL;
788 else
789 ret = PrivateExtractIconsW(lpszFile, nIconIndex, cx, cy, &hIcon, NULL, 1, LR_DEFAULTCOLOR);
791 if (ret == (UINT)-1)
792 return (HICON)1;
793 else if (ret > 0 && hIcon)
794 return hIcon;
796 return NULL;
799 HRESULT WINAPI SHCreateFileExtractIconW(LPCWSTR file, DWORD attribs, REFIID riid, void **ppv)
801 FIXME("%s, %x, %s, %p\n", debugstr_w(file), attribs, debugstr_guid(riid), ppv);
802 *ppv = NULL;
803 return E_NOTIMPL;
806 /*************************************************************************
807 * Printer_LoadIconsW [SHELL32.205]
809 VOID WINAPI Printer_LoadIconsW(LPCWSTR wsPrinterName, HICON * pLargeIcon, HICON * pSmallIcon)
811 INT iconindex=IDI_SHELL_PRINTER;
813 TRACE("(%s, %p, %p)\n", debugstr_w(wsPrinterName), pLargeIcon, pSmallIcon);
815 /* We should check if wsPrinterName is
816 1. the Default Printer or not
817 2. connected or not
818 3. a Local Printer or a Network-Printer
819 and use different Icons
821 if((wsPrinterName != NULL) && (wsPrinterName[0] != 0))
823 FIXME("(select Icon by PrinterName %s not implemented)\n", debugstr_w(wsPrinterName));
826 if(pLargeIcon != NULL)
827 *pLargeIcon = LoadImageW(shell32_hInstance,
828 (LPCWSTR) MAKEINTRESOURCE(iconindex), IMAGE_ICON,
829 0, 0, LR_DEFAULTCOLOR|LR_DEFAULTSIZE);
831 if(pSmallIcon != NULL)
832 *pSmallIcon = LoadImageW(shell32_hInstance,
833 (LPCWSTR) MAKEINTRESOURCE(iconindex), IMAGE_ICON,
834 16, 16, LR_DEFAULTCOLOR);
837 /*************************************************************************
838 * Printers_RegisterWindowW [SHELL32.213]
839 * used by "printui.dll":
840 * find the Window of the given Type for the specific Printer and
841 * return the already existent hwnd or open a new window
843 BOOL WINAPI Printers_RegisterWindowW(LPCWSTR wsPrinter, DWORD dwType,
844 HANDLE * phClassPidl, HWND * phwnd)
846 FIXME("(%s, %x, %p (%p), %p (%p)) stub!\n", debugstr_w(wsPrinter), dwType,
847 phClassPidl, (phClassPidl != NULL) ? *(phClassPidl) : NULL,
848 phwnd, (phwnd != NULL) ? *(phwnd) : NULL);
850 return FALSE;
853 /*************************************************************************
854 * Printers_UnregisterWindow [SHELL32.214]
856 VOID WINAPI Printers_UnregisterWindow(HANDLE hClassPidl, HWND hwnd)
858 FIXME("(%p, %p) stub!\n", hClassPidl, hwnd);
861 /*************************************************************************
862 * SHGetPropertyStoreFromParsingName [SHELL32.@]
864 HRESULT WINAPI SHGetPropertyStoreFromParsingName(PCWSTR pszPath, IBindCtx *pbc, GETPROPERTYSTOREFLAGS flags, REFIID riid, void **ppv)
866 FIXME("(%s %p %u %p %p) stub!\n", debugstr_w(pszPath), pbc, flags, riid, ppv);
867 return E_NOTIMPL;
870 /*************************************************************************/
872 typedef struct
874 LPCWSTR szApp;
875 LPCWSTR szOtherStuff;
876 HICON hIcon;
877 HFONT hFont;
878 } ABOUT_INFO;
880 #define DROP_FIELD_TOP (-12)
882 static void paint_dropline( HDC hdc, HWND hWnd )
884 HWND hWndCtl = GetDlgItem(hWnd, IDC_ABOUT_WINE_TEXT);
885 RECT rect;
887 if (!hWndCtl) return;
888 GetWindowRect( hWndCtl, &rect );
889 MapWindowPoints( 0, hWnd, (LPPOINT)&rect, 2 );
890 rect.top += DROP_FIELD_TOP;
891 rect.bottom = rect.top + 2;
892 DrawEdge( hdc, &rect, BDR_SUNKENOUTER, BF_RECT );
895 /*************************************************************************
896 * SHHelpShortcuts_RunDLLA [SHELL32.@]
899 DWORD WINAPI SHHelpShortcuts_RunDLLA(DWORD dwArg1, DWORD dwArg2, DWORD dwArg3, DWORD dwArg4)
901 FIXME("(%x, %x, %x, %x) stub!\n", dwArg1, dwArg2, dwArg3, dwArg4);
902 return 0;
905 /*************************************************************************
906 * SHHelpShortcuts_RunDLLA [SHELL32.@]
909 DWORD WINAPI SHHelpShortcuts_RunDLLW(DWORD dwArg1, DWORD dwArg2, DWORD dwArg3, DWORD dwArg4)
911 FIXME("(%x, %x, %x, %x) stub!\n", dwArg1, dwArg2, dwArg3, dwArg4);
912 return 0;
915 /*************************************************************************
916 * SHLoadInProc [SHELL32.@]
917 * Create an instance of specified object class from within
918 * the shell process and release it immediately
920 HRESULT WINAPI SHLoadInProc (REFCLSID rclsid)
922 void *ptr = NULL;
924 TRACE("%s\n", debugstr_guid(rclsid));
926 CoCreateInstance(rclsid, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown,&ptr);
927 if(ptr)
929 IUnknown * pUnk = ptr;
930 IUnknown_Release(pUnk);
931 return NOERROR;
933 return DISP_E_MEMBERNOTFOUND;
936 static void add_authors( HWND list )
938 static const WCHAR eol[] = {'\r','\n',0};
939 static const WCHAR authors[] = {'A','U','T','H','O','R','S',0};
940 WCHAR *strW, *start, *end;
941 HRSRC rsrc = FindResourceW( shell32_hInstance, authors, (LPCWSTR)RT_RCDATA );
942 char *strA = LockResource( LoadResource( shell32_hInstance, rsrc ));
943 DWORD sizeW, sizeA = SizeofResource( shell32_hInstance, rsrc );
945 if (!strA) return;
946 sizeW = MultiByteToWideChar( CP_UTF8, 0, strA, sizeA, NULL, 0 ) + 1;
947 if (!(strW = HeapAlloc( GetProcessHeap(), 0, sizeW * sizeof(WCHAR) ))) return;
948 MultiByteToWideChar( CP_UTF8, 0, strA, sizeA, strW, sizeW );
949 strW[sizeW - 1] = 0;
951 start = strpbrkW( strW, eol ); /* skip the header line */
952 while (start)
954 while (*start && strchrW( eol, *start )) start++;
955 if (!*start) break;
956 end = strpbrkW( start, eol );
957 if (end) *end++ = 0;
958 SendMessageW( list, LB_ADDSTRING, -1, (LPARAM)start );
959 start = end;
961 HeapFree( GetProcessHeap(), 0, strW );
964 /*************************************************************************
965 * AboutDlgProc (internal)
967 static INT_PTR CALLBACK AboutDlgProc( HWND hWnd, UINT msg, WPARAM wParam,
968 LPARAM lParam )
970 HWND hWndCtl;
972 TRACE("\n");
974 switch(msg)
976 case WM_INITDIALOG:
978 ABOUT_INFO *info = (ABOUT_INFO *)lParam;
979 WCHAR template[512], buffer[512], version[64];
980 extern const char *wine_get_build_id(void);
982 if (info)
984 SendDlgItemMessageW(hWnd, stc1, STM_SETICON,(WPARAM)info->hIcon, 0);
985 GetWindowTextW( hWnd, template, sizeof(template)/sizeof(WCHAR) );
986 sprintfW( buffer, template, info->szApp );
987 SetWindowTextW( hWnd, buffer );
988 SetWindowTextW( GetDlgItem(hWnd, IDC_ABOUT_STATIC_TEXT1), info->szApp );
989 SetWindowTextW( GetDlgItem(hWnd, IDC_ABOUT_STATIC_TEXT2), info->szOtherStuff );
990 GetWindowTextW( GetDlgItem(hWnd, IDC_ABOUT_STATIC_TEXT3),
991 template, sizeof(template)/sizeof(WCHAR) );
992 MultiByteToWideChar( CP_UTF8, 0, wine_get_build_id(), -1,
993 version, sizeof(version)/sizeof(WCHAR) );
994 sprintfW( buffer, template, version );
995 SetWindowTextW( GetDlgItem(hWnd, IDC_ABOUT_STATIC_TEXT3), buffer );
996 hWndCtl = GetDlgItem(hWnd, IDC_ABOUT_LISTBOX);
997 SendMessageW( hWndCtl, WM_SETREDRAW, 0, 0 );
998 SendMessageW( hWndCtl, WM_SETFONT, (WPARAM)info->hFont, 0 );
999 add_authors( hWndCtl );
1000 SendMessageW( hWndCtl, WM_SETREDRAW, 1, 0 );
1003 return 1;
1005 case WM_PAINT:
1007 PAINTSTRUCT ps;
1008 HDC hDC = BeginPaint( hWnd, &ps );
1009 paint_dropline( hDC, hWnd );
1010 EndPaint( hWnd, &ps );
1012 break;
1014 case WM_COMMAND:
1015 if (wParam == IDOK || wParam == IDCANCEL)
1017 EndDialog(hWnd, TRUE);
1018 return TRUE;
1020 if (wParam == IDC_ABOUT_LICENSE)
1022 MSGBOXPARAMSW params;
1024 params.cbSize = sizeof(params);
1025 params.hwndOwner = hWnd;
1026 params.hInstance = shell32_hInstance;
1027 params.lpszText = MAKEINTRESOURCEW(IDS_LICENSE);
1028 params.lpszCaption = MAKEINTRESOURCEW(IDS_LICENSE_CAPTION);
1029 params.dwStyle = MB_ICONINFORMATION | MB_OK;
1030 params.lpszIcon = 0;
1031 params.dwContextHelpId = 0;
1032 params.lpfnMsgBoxCallback = NULL;
1033 params.dwLanguageId = LANG_NEUTRAL;
1034 MessageBoxIndirectW( &params );
1036 break;
1037 case WM_CLOSE:
1038 EndDialog(hWnd, TRUE);
1039 break;
1042 return 0;
1046 /*************************************************************************
1047 * ShellAboutA [SHELL32.288]
1049 BOOL WINAPI ShellAboutA( HWND hWnd, LPCSTR szApp, LPCSTR szOtherStuff, HICON hIcon )
1051 BOOL ret;
1052 LPWSTR appW = NULL, otherW = NULL;
1053 int len;
1055 if (szApp)
1057 len = MultiByteToWideChar(CP_ACP, 0, szApp, -1, NULL, 0);
1058 appW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1059 MultiByteToWideChar(CP_ACP, 0, szApp, -1, appW, len);
1061 if (szOtherStuff)
1063 len = MultiByteToWideChar(CP_ACP, 0, szOtherStuff, -1, NULL, 0);
1064 otherW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1065 MultiByteToWideChar(CP_ACP, 0, szOtherStuff, -1, otherW, len);
1068 ret = ShellAboutW(hWnd, appW, otherW, hIcon);
1070 HeapFree(GetProcessHeap(), 0, otherW);
1071 HeapFree(GetProcessHeap(), 0, appW);
1072 return ret;
1076 /*************************************************************************
1077 * ShellAboutW [SHELL32.289]
1079 BOOL WINAPI ShellAboutW( HWND hWnd, LPCWSTR szApp, LPCWSTR szOtherStuff,
1080 HICON hIcon )
1082 ABOUT_INFO info;
1083 LOGFONTW logFont;
1084 BOOL bRet;
1085 static const WCHAR wszSHELL_ABOUT_MSGBOX[] =
1086 {'S','H','E','L','L','_','A','B','O','U','T','_','M','S','G','B','O','X',0};
1088 TRACE("\n");
1090 if (!hIcon) hIcon = LoadImageW( 0, (LPWSTR)IDI_WINLOGO, IMAGE_ICON, 48, 48, LR_SHARED );
1091 info.szApp = szApp;
1092 info.szOtherStuff = szOtherStuff;
1093 info.hIcon = hIcon;
1095 SystemParametersInfoW( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 );
1096 info.hFont = CreateFontIndirectW( &logFont );
1098 bRet = DialogBoxParamW( shell32_hInstance, wszSHELL_ABOUT_MSGBOX, hWnd, AboutDlgProc, (LPARAM)&info );
1099 DeleteObject(info.hFont);
1100 return bRet;
1103 /*************************************************************************
1104 * FreeIconList (SHELL32.@)
1106 void WINAPI FreeIconList( DWORD dw )
1108 FIXME("%x: stub\n",dw);
1111 /*************************************************************************
1112 * SHLoadNonloadedIconOverlayIdentifiers (SHELL32.@)
1114 HRESULT WINAPI SHLoadNonloadedIconOverlayIdentifiers( VOID )
1116 FIXME("stub\n");
1117 return S_OK;
1120 /***********************************************************************
1121 * DllGetVersion [SHELL32.@]
1123 * Retrieves version information of the 'SHELL32.DLL'
1125 * PARAMS
1126 * pdvi [O] pointer to version information structure.
1128 * RETURNS
1129 * Success: S_OK
1130 * Failure: E_INVALIDARG
1132 * NOTES
1133 * Returns version of a shell32.dll from IE4.01 SP1.
1136 HRESULT WINAPI DllGetVersion (DLLVERSIONINFO *pdvi)
1138 /* FIXME: shouldn't these values come from the version resource? */
1139 if (pdvi->cbSize == sizeof(DLLVERSIONINFO) ||
1140 pdvi->cbSize == sizeof(DLLVERSIONINFO2))
1142 pdvi->dwMajorVersion = WINE_FILEVERSION_MAJOR;
1143 pdvi->dwMinorVersion = WINE_FILEVERSION_MINOR;
1144 pdvi->dwBuildNumber = WINE_FILEVERSION_BUILD;
1145 pdvi->dwPlatformID = WINE_FILEVERSION_PLATFORMID;
1146 if (pdvi->cbSize == sizeof(DLLVERSIONINFO2))
1148 DLLVERSIONINFO2 *pdvi2 = (DLLVERSIONINFO2 *)pdvi;
1150 pdvi2->dwFlags = 0;
1151 pdvi2->ullVersion = MAKEDLLVERULL(WINE_FILEVERSION_MAJOR,
1152 WINE_FILEVERSION_MINOR,
1153 WINE_FILEVERSION_BUILD,
1154 WINE_FILEVERSION_PLATFORMID);
1156 TRACE("%u.%u.%u.%u\n",
1157 pdvi->dwMajorVersion, pdvi->dwMinorVersion,
1158 pdvi->dwBuildNumber, pdvi->dwPlatformID);
1159 return S_OK;
1161 else
1163 WARN("wrong DLLVERSIONINFO size from app\n");
1164 return E_INVALIDARG;
1168 /*************************************************************************
1169 * global variables of the shell32.dll
1170 * all are once per process
1173 HINSTANCE shell32_hInstance = 0;
1174 HIMAGELIST ShellSmallIconList = 0;
1175 HIMAGELIST ShellBigIconList = 0;
1178 /*************************************************************************
1179 * SHELL32 DllMain
1181 * NOTES
1182 * calling oleinitialize here breaks sone apps.
1184 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
1186 TRACE("%p 0x%x %p\n", hinstDLL, fdwReason, fImpLoad);
1188 switch (fdwReason)
1190 case DLL_PROCESS_ATTACH:
1191 shell32_hInstance = hinstDLL;
1192 DisableThreadLibraryCalls(shell32_hInstance);
1194 /* get full path to this DLL for IExtractIconW_fnGetIconLocation() */
1195 GetModuleFileNameW(hinstDLL, swShell32Name, MAX_PATH);
1196 swShell32Name[MAX_PATH - 1] = '\0';
1198 InitCommonControlsEx(NULL);
1200 SIC_Initialize();
1201 InitChangeNotifications();
1202 break;
1204 case DLL_PROCESS_DETACH:
1205 shell32_hInstance = 0;
1206 SIC_Destroy();
1207 FreeChangeNotifications();
1208 break;
1210 return TRUE;
1213 /*************************************************************************
1214 * DllInstall [SHELL32.@]
1216 * PARAMETERS
1218 * BOOL bInstall - TRUE for install, FALSE for uninstall
1219 * LPCWSTR pszCmdLine - command line (unused by shell32?)
1222 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
1224 FIXME("%s %s: stub\n", bInstall ? "TRUE":"FALSE", debugstr_w(cmdline));
1225 return S_OK; /* indicate success */
1228 /***********************************************************************
1229 * DllCanUnloadNow (SHELL32.@)
1231 HRESULT WINAPI DllCanUnloadNow(void)
1233 return S_FALSE;
1236 /***********************************************************************
1237 * DllRegisterServer (SHELL32.@)
1239 HRESULT WINAPI DllRegisterServer(void)
1241 HRESULT hr = __wine_register_resources( shell32_hInstance );
1242 if (SUCCEEDED(hr)) hr = SHELL_RegisterShellFolders();
1243 return hr;
1246 /***********************************************************************
1247 * DllUnregisterServer (SHELL32.@)
1249 HRESULT WINAPI DllUnregisterServer(void)
1251 return __wine_unregister_resources( shell32_hInstance );
1254 /***********************************************************************
1255 * ExtractVersionResource16W (SHELL32.@)
1257 BOOL WINAPI ExtractVersionResource16W(LPWSTR s, DWORD d)
1259 FIXME("(%s %x) stub!\n", debugstr_w(s), d);
1260 return FALSE;
1263 /***********************************************************************
1264 * InitNetworkAddressControl (SHELL32.@)
1266 BOOL WINAPI InitNetworkAddressControl(void)
1268 FIXME("stub\n");
1269 return FALSE;
1272 /***********************************************************************
1273 * ShellHookProc (SHELL32.@)
1275 LRESULT CALLBACK ShellHookProc(DWORD a, DWORD b, DWORD c)
1277 FIXME("Stub\n");
1278 return 0;
1281 HRESULT WINAPI SHGetLocalizedName(LPCWSTR path, LPWSTR module, UINT size, INT *res)
1283 FIXME("%s %p %u %p: stub\n", debugstr_w(path), module, size, res);
1284 return E_NOTIMPL;
1287 HRESULT WINAPI SetCurrentProcessExplicitAppUserModelID(PCWSTR appid)
1289 FIXME("%s: stub\n", debugstr_w(appid));
1290 return E_NOTIMPL;