shlwapi: Handle URL_WININET_COMPATIBILITY flag in UrlCanonicalize.
[wine/multimedia.git] / dlls / shell32 / shell32_main.c
blob7d78ab5d576cefbdcdddf6c85cd5d145a44803eb
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 "shlwapi.h"
41 #include "propsys.h"
43 #include "undocshell.h"
44 #include "pidl.h"
45 #include "shell32_main.h"
46 #include "version.h"
47 #include "shresdef.h"
49 #include "wine/debug.h"
50 #include "wine/unicode.h"
52 WINE_DEFAULT_DEBUG_CHANNEL(shell);
54 extern const char * const SHELL_Authors[];
56 /*************************************************************************
57 * CommandLineToArgvW [SHELL32.@]
59 * We must interpret the quotes in the command line to rebuild the argv
60 * array correctly:
61 * - arguments are separated by spaces or tabs
62 * - quotes serve as optional argument delimiters
63 * '"a b"' -> 'a b'
64 * - escaped quotes must be converted back to '"'
65 * '\"' -> '"'
66 * - an odd number of '\'s followed by '"' correspond to half that number
67 * of '\' followed by a '"' (extension of the above)
68 * '\\\"' -> '\"'
69 * '\\\\\"' -> '\\"'
70 * - an even number of '\'s followed by a '"' correspond to half that number
71 * of '\', plus a regular quote serving as an argument delimiter (which
72 * means it does not appear in the result)
73 * 'a\\"b c"' -> 'a\b c'
74 * 'a\\\\"b c"' -> 'a\\b c'
75 * - '\' that are not followed by a '"' are copied literally
76 * 'a\b' -> 'a\b'
77 * 'a\\b' -> 'a\\b'
79 * Note:
80 * '\t' == 0x0009
81 * ' ' == 0x0020
82 * '"' == 0x0022
83 * '\\' == 0x005c
85 LPWSTR* WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int* numargs)
87 DWORD argc;
88 LPWSTR *argv;
89 LPCWSTR cs;
90 LPWSTR arg,s,d;
91 LPWSTR cmdline;
92 int in_quotes,bcount;
94 if (*lpCmdline==0)
96 /* Return the path to the executable */
97 DWORD len, deslen=MAX_PATH, size;
99 size = sizeof(LPWSTR) + deslen*sizeof(WCHAR) + sizeof(LPWSTR);
100 for (;;)
102 if (!(argv = LocalAlloc(LMEM_FIXED, size))) return NULL;
103 len = GetModuleFileNameW(0, (LPWSTR)(argv+1), deslen);
104 if (!len)
106 LocalFree(argv);
107 return NULL;
109 if (len < deslen) break;
110 deslen*=2;
111 size = sizeof(LPWSTR) + deslen*sizeof(WCHAR) + sizeof(LPWSTR);
112 LocalFree( argv );
114 argv[0]=(LPWSTR)(argv+1);
115 if (numargs)
116 *numargs=1;
118 return argv;
121 /* to get a writable copy */
122 argc=0;
123 bcount=0;
124 in_quotes=0;
125 cs=lpCmdline;
126 while (1)
128 if (*cs==0 || ((*cs==0x0009 || *cs==0x0020) && !in_quotes))
130 /* space */
131 argc++;
132 /* skip the remaining spaces */
133 while (*cs==0x0009 || *cs==0x0020) {
134 cs++;
136 if (*cs==0)
137 break;
138 bcount=0;
139 continue;
141 else if (*cs==0x005c)
143 /* '\', count them */
144 bcount++;
146 else if ((*cs==0x0022) && ((bcount & 1)==0))
148 /* unescaped '"' */
149 in_quotes=!in_quotes;
150 bcount=0;
152 else
154 /* a regular character */
155 bcount=0;
157 cs++;
159 /* Allocate in a single lump, the string array, and the strings that go with it.
160 * This way the caller can make a single GlobalFree call to free both, as per MSDN.
162 argv=LocalAlloc(LMEM_FIXED, argc*sizeof(LPWSTR)+(strlenW(lpCmdline)+1)*sizeof(WCHAR));
163 if (!argv)
164 return NULL;
165 cmdline=(LPWSTR)(argv+argc);
166 strcpyW(cmdline, lpCmdline);
168 argc=0;
169 bcount=0;
170 in_quotes=0;
171 arg=d=s=cmdline;
172 while (*s)
174 if ((*s==0x0009 || *s==0x0020) && !in_quotes)
176 /* Close the argument and copy it */
177 *d=0;
178 argv[argc++]=arg;
180 /* skip the remaining spaces */
181 do {
182 s++;
183 } while (*s==0x0009 || *s==0x0020);
185 /* Start with a new argument */
186 arg=d=s;
187 bcount=0;
189 else if (*s==0x005c)
191 /* '\\' */
192 *d++=*s++;
193 bcount++;
195 else if (*s==0x0022)
197 /* '"' */
198 if ((bcount & 1)==0)
200 /* Preceded by an even number of '\', this is half that
201 * number of '\', plus a quote which we erase.
203 d-=bcount/2;
204 in_quotes=!in_quotes;
205 s++;
207 else
209 /* Preceded by an odd number of '\', this is half that
210 * number of '\' followed by a '"'
212 d=d-bcount/2-1;
213 *d++='"';
214 s++;
216 bcount=0;
218 else
220 /* a regular character */
221 *d++=*s++;
222 bcount=0;
225 if (*arg)
227 *d='\0';
228 argv[argc++]=arg;
230 if (numargs)
231 *numargs=argc;
233 return argv;
236 static DWORD shgfi_get_exe_type(LPCWSTR szFullPath)
238 BOOL status = FALSE;
239 HANDLE hfile;
240 DWORD BinaryType;
241 IMAGE_DOS_HEADER mz_header;
242 IMAGE_NT_HEADERS nt;
243 DWORD len;
244 char magic[4];
246 status = GetBinaryTypeW (szFullPath, &BinaryType);
247 if (!status)
248 return 0;
249 if (BinaryType == SCS_DOS_BINARY || BinaryType == SCS_PIF_BINARY)
250 return 0x4d5a;
252 hfile = CreateFileW( szFullPath, GENERIC_READ, FILE_SHARE_READ,
253 NULL, OPEN_EXISTING, 0, 0 );
254 if ( hfile == INVALID_HANDLE_VALUE )
255 return 0;
258 * The next section is adapted from MODULE_GetBinaryType, as we need
259 * to examine the image header to get OS and version information. We
260 * know from calling GetBinaryTypeA that the image is valid and either
261 * an NE or PE, so much error handling can be omitted.
262 * Seek to the start of the file and read the header information.
265 SetFilePointer( hfile, 0, NULL, SEEK_SET );
266 ReadFile( hfile, &mz_header, sizeof(mz_header), &len, NULL );
268 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
269 ReadFile( hfile, magic, sizeof(magic), &len, NULL );
270 if ( *(DWORD*)magic == IMAGE_NT_SIGNATURE )
272 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
273 ReadFile( hfile, &nt, sizeof(nt), &len, NULL );
274 CloseHandle( hfile );
275 /* DLL files are not executable and should return 0 */
276 if (nt.FileHeader.Characteristics & IMAGE_FILE_DLL)
277 return 0;
278 if (nt.OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI)
280 return IMAGE_NT_SIGNATURE |
281 (nt.OptionalHeader.MajorSubsystemVersion << 24) |
282 (nt.OptionalHeader.MinorSubsystemVersion << 16);
284 return IMAGE_NT_SIGNATURE;
286 else if ( *(WORD*)magic == IMAGE_OS2_SIGNATURE )
288 IMAGE_OS2_HEADER ne;
289 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
290 ReadFile( hfile, &ne, sizeof(ne), &len, NULL );
291 CloseHandle( hfile );
292 if (ne.ne_exetyp == 2)
293 return IMAGE_OS2_SIGNATURE | (ne.ne_expver << 16);
294 return 0;
296 CloseHandle( hfile );
297 return 0;
300 /*************************************************************************
301 * SHELL_IsShortcut [internal]
303 * Decide if an item id list points to a shell shortcut
305 BOOL SHELL_IsShortcut(LPCITEMIDLIST pidlLast)
307 char szTemp[MAX_PATH];
308 HKEY keyCls;
309 BOOL ret = FALSE;
311 if (_ILGetExtension(pidlLast, szTemp, MAX_PATH) &&
312 HCR_MapTypeToValueA(szTemp, szTemp, MAX_PATH, TRUE))
314 if (ERROR_SUCCESS == RegOpenKeyExA(HKEY_CLASSES_ROOT, szTemp, 0, KEY_QUERY_VALUE, &keyCls))
316 if (ERROR_SUCCESS == RegQueryValueExA(keyCls, "IsShortcut", NULL, NULL, NULL, NULL))
317 ret = TRUE;
319 RegCloseKey(keyCls);
323 return ret;
326 #define SHGFI_KNOWN_FLAGS \
327 (SHGFI_SMALLICON | SHGFI_OPENICON | SHGFI_SHELLICONSIZE | SHGFI_PIDL | \
328 SHGFI_USEFILEATTRIBUTES | SHGFI_ADDOVERLAYS | SHGFI_OVERLAYINDEX | \
329 SHGFI_ICON | SHGFI_DISPLAYNAME | SHGFI_TYPENAME | SHGFI_ATTRIBUTES | \
330 SHGFI_ICONLOCATION | SHGFI_EXETYPE | SHGFI_SYSICONINDEX | \
331 SHGFI_LINKOVERLAY | SHGFI_SELECTED | SHGFI_ATTR_SPECIFIED)
333 /*************************************************************************
334 * SHGetFileInfoW [SHELL32.@]
337 DWORD_PTR WINAPI SHGetFileInfoW(LPCWSTR path,DWORD dwFileAttributes,
338 SHFILEINFOW *psfi, UINT sizeofpsfi, UINT flags )
340 WCHAR szLocation[MAX_PATH], szFullPath[MAX_PATH];
341 int iIndex;
342 DWORD_PTR ret = TRUE;
343 DWORD dwAttributes = 0;
344 IShellFolder * psfParent = NULL;
345 IExtractIconW * pei = NULL;
346 LPITEMIDLIST pidlLast = NULL, pidl = NULL;
347 HRESULT hr = S_OK;
348 BOOL IconNotYetLoaded=TRUE;
349 UINT uGilFlags = 0;
351 TRACE("%s fattr=0x%x sfi=%p(attr=0x%08x) size=0x%x flags=0x%x\n",
352 (flags & SHGFI_PIDL)? "pidl" : debugstr_w(path), dwFileAttributes,
353 psfi, psfi->dwAttributes, sizeofpsfi, flags);
355 if (!path)
356 return FALSE;
358 /* windows initializes these values regardless of the flags */
359 if (psfi != NULL)
361 psfi->szDisplayName[0] = '\0';
362 psfi->szTypeName[0] = '\0';
363 psfi->iIcon = 0;
366 if (!(flags & SHGFI_PIDL))
368 /* SHGetFileInfo should work with absolute and relative paths */
369 if (PathIsRelativeW(path))
371 GetCurrentDirectoryW(MAX_PATH, szLocation);
372 PathCombineW(szFullPath, szLocation, path);
374 else
376 lstrcpynW(szFullPath, path, MAX_PATH);
380 if (flags & SHGFI_EXETYPE)
382 if (flags != SHGFI_EXETYPE)
383 return 0;
384 return shgfi_get_exe_type(szFullPath);
388 * psfi is NULL normally to query EXE type. If it is NULL, none of the
389 * below makes sense anyway. Windows allows this and just returns FALSE
391 if (psfi == NULL)
392 return FALSE;
395 * translate the path into a pidl only when SHGFI_USEFILEATTRIBUTES
396 * is not specified.
397 * The pidl functions fail on not existing file names
400 if (flags & SHGFI_PIDL)
402 pidl = ILClone((LPCITEMIDLIST)path);
404 else if (!(flags & SHGFI_USEFILEATTRIBUTES))
406 hr = SHILCreateFromPathW(szFullPath, &pidl, &dwAttributes);
409 if ((flags & SHGFI_PIDL) || !(flags & SHGFI_USEFILEATTRIBUTES))
411 /* get the parent shellfolder */
412 if (pidl)
414 hr = SHBindToParent( pidl, &IID_IShellFolder, (LPVOID*)&psfParent,
415 (LPCITEMIDLIST*)&pidlLast );
416 if (SUCCEEDED(hr))
417 pidlLast = ILClone(pidlLast);
418 ILFree(pidl);
420 else
422 ERR("pidl is null!\n");
423 return FALSE;
427 /* get the attributes of the child */
428 if (SUCCEEDED(hr) && (flags & SHGFI_ATTRIBUTES))
430 if (!(flags & SHGFI_ATTR_SPECIFIED))
432 psfi->dwAttributes = 0xffffffff;
434 if (psfParent)
435 IShellFolder_GetAttributesOf( psfParent, 1, (LPCITEMIDLIST*)&pidlLast,
436 &(psfi->dwAttributes) );
439 /* get the displayname */
440 if (SUCCEEDED(hr) && (flags & SHGFI_DISPLAYNAME))
442 if (flags & SHGFI_USEFILEATTRIBUTES && !(flags & SHGFI_PIDL))
444 lstrcpyW (psfi->szDisplayName, PathFindFileNameW(szFullPath));
446 else
448 STRRET str;
449 hr = IShellFolder_GetDisplayNameOf( psfParent, pidlLast,
450 SHGDN_INFOLDER, &str);
451 StrRetToStrNW (psfi->szDisplayName, MAX_PATH, &str, pidlLast);
455 /* get the type name */
456 if (SUCCEEDED(hr) && (flags & SHGFI_TYPENAME))
458 static const WCHAR szFile[] = { 'F','i','l','e',0 };
459 static const WCHAR szDashFile[] = { '-','f','i','l','e',0 };
461 if (!(flags & SHGFI_USEFILEATTRIBUTES) || (flags & SHGFI_PIDL))
463 char ftype[80];
465 _ILGetFileType(pidlLast, ftype, 80);
466 MultiByteToWideChar(CP_ACP, 0, ftype, -1, psfi->szTypeName, 80 );
468 else
470 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
471 strcatW (psfi->szTypeName, szFile);
472 else
474 WCHAR sTemp[64];
476 lstrcpyW(sTemp,PathFindExtensionW(szFullPath));
477 if (!( HCR_MapTypeToValueW(sTemp, sTemp, 64, TRUE) &&
478 HCR_MapTypeToValueW(sTemp, psfi->szTypeName, 80, FALSE )))
480 lstrcpynW (psfi->szTypeName, sTemp, 64);
481 strcatW (psfi->szTypeName, szDashFile);
487 /* ### icons ###*/
488 if (flags & SHGFI_OPENICON)
489 uGilFlags |= GIL_OPENICON;
491 if (flags & SHGFI_LINKOVERLAY)
492 uGilFlags |= GIL_FORSHORTCUT;
493 else if ((flags&SHGFI_ADDOVERLAYS) ||
494 (flags&(SHGFI_ICON|SHGFI_SMALLICON))==SHGFI_ICON)
496 if (SHELL_IsShortcut(pidlLast))
497 uGilFlags |= GIL_FORSHORTCUT;
500 if (flags & SHGFI_OVERLAYINDEX)
501 FIXME("SHGFI_OVERLAYINDEX unhandled\n");
503 if (flags & SHGFI_SELECTED)
504 FIXME("set icon to selected, stub\n");
506 if (flags & SHGFI_SHELLICONSIZE)
507 FIXME("set icon to shell size, stub\n");
509 /* get the iconlocation */
510 if (SUCCEEDED(hr) && (flags & SHGFI_ICONLOCATION ))
512 UINT uDummy,uFlags;
514 if (flags & SHGFI_USEFILEATTRIBUTES && !(flags & SHGFI_PIDL))
516 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
518 lstrcpyW(psfi->szDisplayName, swShell32Name);
519 psfi->iIcon = -IDI_SHELL_FOLDER;
521 else
523 WCHAR* szExt;
524 static const WCHAR p1W[] = {'%','1',0};
525 WCHAR sTemp [MAX_PATH];
527 szExt = PathFindExtensionW(szFullPath);
528 TRACE("szExt=%s\n", debugstr_w(szExt));
529 if ( szExt &&
530 HCR_MapTypeToValueW(szExt, sTemp, MAX_PATH, TRUE) &&
531 HCR_GetDefaultIconW(sTemp, sTemp, MAX_PATH, &psfi->iIcon))
533 if (lstrcmpW(p1W, sTemp))
534 strcpyW(psfi->szDisplayName, sTemp);
535 else
537 /* the icon is in the file */
538 strcpyW(psfi->szDisplayName, szFullPath);
541 else
542 ret = FALSE;
545 else
547 hr = IShellFolder_GetUIObjectOf(psfParent, 0, 1,
548 (LPCITEMIDLIST*)&pidlLast, &IID_IExtractIconW,
549 &uDummy, (LPVOID*)&pei);
550 if (SUCCEEDED(hr))
552 hr = IExtractIconW_GetIconLocation(pei, uGilFlags,
553 szLocation, MAX_PATH, &iIndex, &uFlags);
555 if (uFlags & GIL_NOTFILENAME)
556 ret = FALSE;
557 else
559 lstrcpyW (psfi->szDisplayName, szLocation);
560 psfi->iIcon = iIndex;
562 IExtractIconW_Release(pei);
567 /* get icon index (or load icon)*/
568 if (SUCCEEDED(hr) && (flags & (SHGFI_ICON | SHGFI_SYSICONINDEX)))
570 if (flags & SHGFI_USEFILEATTRIBUTES && !(flags & SHGFI_PIDL))
572 WCHAR sTemp [MAX_PATH];
573 WCHAR * szExt;
574 int icon_idx=0;
576 lstrcpynW(sTemp, szFullPath, MAX_PATH);
578 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
579 psfi->iIcon = SIC_GetIconIndex(swShell32Name, -IDI_SHELL_FOLDER, 0);
580 else
582 static const WCHAR p1W[] = {'%','1',0};
584 psfi->iIcon = 0;
585 szExt = PathFindExtensionW(sTemp);
586 if ( szExt &&
587 HCR_MapTypeToValueW(szExt, sTemp, MAX_PATH, TRUE) &&
588 HCR_GetDefaultIconW(sTemp, sTemp, MAX_PATH, &icon_idx))
590 if (!lstrcmpW(p1W,sTemp)) /* icon is in the file */
591 strcpyW(sTemp, szFullPath);
593 if (flags & SHGFI_SYSICONINDEX)
595 psfi->iIcon = SIC_GetIconIndex(sTemp,icon_idx,0);
596 if (psfi->iIcon == -1)
597 psfi->iIcon = 0;
599 else
601 UINT ret;
602 if (flags & SHGFI_SMALLICON)
603 ret = PrivateExtractIconsW( sTemp,icon_idx,
604 GetSystemMetrics( SM_CXSMICON ),
605 GetSystemMetrics( SM_CYSMICON ),
606 &psfi->hIcon, 0, 1, 0);
607 else
608 ret = PrivateExtractIconsW( sTemp, icon_idx,
609 GetSystemMetrics( SM_CXICON),
610 GetSystemMetrics( SM_CYICON),
611 &psfi->hIcon, 0, 1, 0);
612 if (ret != 0 && ret != (UINT)-1)
614 IconNotYetLoaded=FALSE;
615 psfi->iIcon = icon_idx;
621 else
623 if (!(PidlToSicIndex(psfParent, pidlLast, !(flags & SHGFI_SMALLICON),
624 uGilFlags, &(psfi->iIcon))))
626 ret = FALSE;
629 if (ret && (flags & SHGFI_SYSICONINDEX))
631 if (flags & SHGFI_SMALLICON)
632 ret = (DWORD_PTR) ShellSmallIconList;
633 else
634 ret = (DWORD_PTR) ShellBigIconList;
638 /* icon handle */
639 if (SUCCEEDED(hr) && (flags & SHGFI_ICON) && IconNotYetLoaded)
641 if (flags & SHGFI_SMALLICON)
642 psfi->hIcon = ImageList_GetIcon( ShellSmallIconList, psfi->iIcon, ILD_NORMAL);
643 else
644 psfi->hIcon = ImageList_GetIcon( ShellBigIconList, psfi->iIcon, ILD_NORMAL);
647 if (flags & ~SHGFI_KNOWN_FLAGS)
648 FIXME("unknown flags %08x\n", flags & ~SHGFI_KNOWN_FLAGS);
650 if (psfParent)
651 IShellFolder_Release(psfParent);
653 if (hr != S_OK)
654 ret = FALSE;
656 SHFree(pidlLast);
658 TRACE ("icon=%p index=0x%08x attr=0x%08x name=%s type=%s ret=0x%08lx\n",
659 psfi->hIcon, psfi->iIcon, psfi->dwAttributes,
660 debugstr_w(psfi->szDisplayName), debugstr_w(psfi->szTypeName), ret);
662 return ret;
665 /*************************************************************************
666 * SHGetFileInfoA [SHELL32.@]
668 * Note:
669 * MSVBVM60.__vbaNew2 expects this function to return a value in range
670 * 1 .. 0x7fff when the function succeeds and flags does not contain
671 * SHGFI_EXETYPE or SHGFI_SYSICONINDEX (see bug 7701)
673 DWORD_PTR WINAPI SHGetFileInfoA(LPCSTR path,DWORD dwFileAttributes,
674 SHFILEINFOA *psfi, UINT sizeofpsfi,
675 UINT flags )
677 INT len;
678 LPWSTR temppath = NULL;
679 LPCWSTR pathW;
680 DWORD ret;
681 SHFILEINFOW temppsfi;
683 if (flags & SHGFI_PIDL)
685 /* path contains a pidl */
686 pathW = (LPCWSTR)path;
688 else
690 len = MultiByteToWideChar(CP_ACP, 0, path, -1, NULL, 0);
691 temppath = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
692 MultiByteToWideChar(CP_ACP, 0, path, -1, temppath, len);
693 pathW = temppath;
696 if (psfi && (flags & SHGFI_ATTR_SPECIFIED))
697 temppsfi.dwAttributes=psfi->dwAttributes;
699 if (psfi == NULL)
700 ret = SHGetFileInfoW(pathW, dwFileAttributes, NULL, sizeof(temppsfi), flags);
701 else
702 ret = SHGetFileInfoW(pathW, dwFileAttributes, &temppsfi, sizeof(temppsfi), flags);
704 if (psfi)
706 if(flags & SHGFI_ICON)
707 psfi->hIcon=temppsfi.hIcon;
708 if(flags & (SHGFI_SYSICONINDEX|SHGFI_ICON|SHGFI_ICONLOCATION))
709 psfi->iIcon=temppsfi.iIcon;
710 if(flags & SHGFI_ATTRIBUTES)
711 psfi->dwAttributes=temppsfi.dwAttributes;
712 if(flags & (SHGFI_DISPLAYNAME|SHGFI_ICONLOCATION))
714 WideCharToMultiByte(CP_ACP, 0, temppsfi.szDisplayName, -1,
715 psfi->szDisplayName, sizeof(psfi->szDisplayName), NULL, NULL);
717 if(flags & SHGFI_TYPENAME)
719 WideCharToMultiByte(CP_ACP, 0, temppsfi.szTypeName, -1,
720 psfi->szTypeName, sizeof(psfi->szTypeName), NULL, NULL);
724 HeapFree(GetProcessHeap(), 0, temppath);
726 return ret;
729 /*************************************************************************
730 * DuplicateIcon [SHELL32.@]
732 HICON WINAPI DuplicateIcon( HINSTANCE hInstance, HICON hIcon)
734 ICONINFO IconInfo;
735 HICON hDupIcon = 0;
737 TRACE("%p %p\n", hInstance, hIcon);
739 if (GetIconInfo(hIcon, &IconInfo))
741 hDupIcon = CreateIconIndirect(&IconInfo);
743 /* clean up hbmMask and hbmColor */
744 DeleteObject(IconInfo.hbmMask);
745 DeleteObject(IconInfo.hbmColor);
748 return hDupIcon;
751 /*************************************************************************
752 * ExtractIconA [SHELL32.@]
754 HICON WINAPI ExtractIconA(HINSTANCE hInstance, LPCSTR lpszFile, UINT nIconIndex)
756 HICON ret;
757 INT len = MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, NULL, 0);
758 LPWSTR lpwstrFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
760 TRACE("%p %s %d\n", hInstance, lpszFile, nIconIndex);
762 MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, lpwstrFile, len);
763 ret = ExtractIconW(hInstance, lpwstrFile, nIconIndex);
764 HeapFree(GetProcessHeap(), 0, lpwstrFile);
766 return ret;
769 /*************************************************************************
770 * ExtractIconW [SHELL32.@]
772 HICON WINAPI ExtractIconW(HINSTANCE hInstance, LPCWSTR lpszFile, UINT nIconIndex)
774 HICON hIcon = NULL;
775 UINT ret;
776 UINT cx = GetSystemMetrics(SM_CXICON), cy = GetSystemMetrics(SM_CYICON);
778 TRACE("%p %s %d\n", hInstance, debugstr_w(lpszFile), nIconIndex);
780 if (nIconIndex == (UINT)-1)
782 ret = PrivateExtractIconsW(lpszFile, 0, cx, cy, NULL, NULL, 0, LR_DEFAULTCOLOR);
783 if (ret != (UINT)-1 && ret)
784 return (HICON)(UINT_PTR)ret;
785 return NULL;
787 else
788 ret = PrivateExtractIconsW(lpszFile, nIconIndex, cx, cy, &hIcon, NULL, 1, LR_DEFAULTCOLOR);
790 if (ret == (UINT)-1)
791 return (HICON)1;
792 else if (ret > 0 && hIcon)
793 return hIcon;
795 return NULL;
798 HRESULT WINAPI SHCreateFileExtractIconW(LPCWSTR file, DWORD attribs, REFIID riid, void **ppv)
800 FIXME("%s, %x, %s, %p\n", debugstr_w(file), attribs, debugstr_guid(riid), ppv);
801 *ppv = NULL;
802 return E_NOTIMPL;
805 /*************************************************************************
806 * Printer_LoadIconsW [SHELL32.205]
808 VOID WINAPI Printer_LoadIconsW(LPCWSTR wsPrinterName, HICON * pLargeIcon, HICON * pSmallIcon)
810 INT iconindex=IDI_SHELL_PRINTER;
812 TRACE("(%s, %p, %p)\n", debugstr_w(wsPrinterName), pLargeIcon, pSmallIcon);
814 /* We should check if wsPrinterName is
815 1. the Default Printer or not
816 2. connected or not
817 3. a Local Printer or a Network-Printer
818 and use different Icons
820 if((wsPrinterName != NULL) && (wsPrinterName[0] != 0))
822 FIXME("(select Icon by PrinterName %s not implemented)\n", debugstr_w(wsPrinterName));
825 if(pLargeIcon != NULL)
826 *pLargeIcon = LoadImageW(shell32_hInstance,
827 (LPCWSTR) MAKEINTRESOURCE(iconindex), IMAGE_ICON,
828 0, 0, LR_DEFAULTCOLOR|LR_DEFAULTSIZE);
830 if(pSmallIcon != NULL)
831 *pSmallIcon = LoadImageW(shell32_hInstance,
832 (LPCWSTR) MAKEINTRESOURCE(iconindex), IMAGE_ICON,
833 16, 16, LR_DEFAULTCOLOR);
836 /*************************************************************************
837 * Printers_RegisterWindowW [SHELL32.213]
838 * used by "printui.dll":
839 * find the Window of the given Type for the specific Printer and
840 * return the already existent hwnd or open a new window
842 BOOL WINAPI Printers_RegisterWindowW(LPCWSTR wsPrinter, DWORD dwType,
843 HANDLE * phClassPidl, HWND * phwnd)
845 FIXME("(%s, %x, %p (%p), %p (%p)) stub!\n", debugstr_w(wsPrinter), dwType,
846 phClassPidl, (phClassPidl != NULL) ? *(phClassPidl) : NULL,
847 phwnd, (phwnd != NULL) ? *(phwnd) : NULL);
849 return FALSE;
852 /*************************************************************************
853 * Printers_UnregisterWindow [SHELL32.214]
855 VOID WINAPI Printers_UnregisterWindow(HANDLE hClassPidl, HWND hwnd)
857 FIXME("(%p, %p) stub!\n", hClassPidl, hwnd);
860 /*************************************************************************
861 * SHGetPropertyStoreFromParsingName [SHELL32.@]
863 HRESULT WINAPI SHGetPropertyStoreFromParsingName(PCWSTR pszPath, IBindCtx *pbc, GETPROPERTYSTOREFLAGS flags, REFIID riid, void **ppv)
865 FIXME("(%s %p %u %p %p) stub!\n", debugstr_w(pszPath), pbc, flags, riid, ppv);
866 return E_NOTIMPL;
869 /*************************************************************************/
871 typedef struct
873 LPCWSTR szApp;
874 LPCWSTR szOtherStuff;
875 HICON hIcon;
876 HFONT hFont;
877 } ABOUT_INFO;
879 #define DROP_FIELD_TOP (-12)
881 static void paint_dropline( HDC hdc, HWND hWnd )
883 HWND hWndCtl = GetDlgItem(hWnd, IDC_ABOUT_WINE_TEXT);
884 RECT rect;
886 if (!hWndCtl) return;
887 GetWindowRect( hWndCtl, &rect );
888 MapWindowPoints( 0, hWnd, (LPPOINT)&rect, 2 );
889 rect.top += DROP_FIELD_TOP;
890 rect.bottom = rect.top + 2;
891 DrawEdge( hdc, &rect, BDR_SUNKENOUTER, BF_RECT );
894 /*************************************************************************
895 * SHHelpShortcuts_RunDLLA [SHELL32.@]
898 DWORD WINAPI SHHelpShortcuts_RunDLLA(DWORD dwArg1, DWORD dwArg2, DWORD dwArg3, DWORD dwArg4)
900 FIXME("(%x, %x, %x, %x) stub!\n", dwArg1, dwArg2, dwArg3, dwArg4);
901 return 0;
904 /*************************************************************************
905 * SHHelpShortcuts_RunDLLA [SHELL32.@]
908 DWORD WINAPI SHHelpShortcuts_RunDLLW(DWORD dwArg1, DWORD dwArg2, DWORD dwArg3, DWORD dwArg4)
910 FIXME("(%x, %x, %x, %x) stub!\n", dwArg1, dwArg2, dwArg3, dwArg4);
911 return 0;
914 /*************************************************************************
915 * SHLoadInProc [SHELL32.@]
916 * Create an instance of specified object class from within
917 * the shell process and release it immediately
919 HRESULT WINAPI SHLoadInProc (REFCLSID rclsid)
921 void *ptr = NULL;
923 TRACE("%s\n", debugstr_guid(rclsid));
925 CoCreateInstance(rclsid, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown,&ptr);
926 if(ptr)
928 IUnknown * pUnk = ptr;
929 IUnknown_Release(pUnk);
930 return NOERROR;
932 return DISP_E_MEMBERNOTFOUND;
935 /*************************************************************************
936 * AboutDlgProc (internal)
938 static INT_PTR CALLBACK AboutDlgProc( HWND hWnd, UINT msg, WPARAM wParam,
939 LPARAM lParam )
941 HWND hWndCtl;
943 TRACE("\n");
945 switch(msg)
947 case WM_INITDIALOG:
949 ABOUT_INFO *info = (ABOUT_INFO *)lParam;
950 WCHAR template[512], buffer[512], version[64];
951 extern const char *wine_get_build_id(void);
953 if (info)
955 const char* const *pstr = SHELL_Authors;
956 SendDlgItemMessageW(hWnd, stc1, STM_SETICON,(WPARAM)info->hIcon, 0);
957 GetWindowTextW( hWnd, template, sizeof(template)/sizeof(WCHAR) );
958 sprintfW( buffer, template, info->szApp );
959 SetWindowTextW( hWnd, buffer );
960 SetWindowTextW( GetDlgItem(hWnd, IDC_ABOUT_STATIC_TEXT1), info->szApp );
961 SetWindowTextW( GetDlgItem(hWnd, IDC_ABOUT_STATIC_TEXT2), info->szOtherStuff );
962 GetWindowTextW( GetDlgItem(hWnd, IDC_ABOUT_STATIC_TEXT3),
963 template, sizeof(template)/sizeof(WCHAR) );
964 MultiByteToWideChar( CP_UTF8, 0, wine_get_build_id(), -1,
965 version, sizeof(version)/sizeof(WCHAR) );
966 sprintfW( buffer, template, version );
967 SetWindowTextW( GetDlgItem(hWnd, IDC_ABOUT_STATIC_TEXT3), buffer );
968 hWndCtl = GetDlgItem(hWnd, IDC_ABOUT_LISTBOX);
969 SendMessageW( hWndCtl, WM_SETREDRAW, 0, 0 );
970 SendMessageW( hWndCtl, WM_SETFONT, (WPARAM)info->hFont, 0 );
971 while (*pstr)
973 /* authors list is in utf-8 format */
974 MultiByteToWideChar( CP_UTF8, 0, *pstr, -1, buffer, sizeof(buffer)/sizeof(WCHAR) );
975 SendMessageW( hWndCtl, LB_ADDSTRING, -1, (LPARAM)buffer );
976 pstr++;
978 SendMessageW( hWndCtl, WM_SETREDRAW, 1, 0 );
981 return 1;
983 case WM_PAINT:
985 PAINTSTRUCT ps;
986 HDC hDC = BeginPaint( hWnd, &ps );
987 paint_dropline( hDC, hWnd );
988 EndPaint( hWnd, &ps );
990 break;
992 case WM_COMMAND:
993 if (wParam == IDOK || wParam == IDCANCEL)
995 EndDialog(hWnd, TRUE);
996 return TRUE;
998 if (wParam == IDC_ABOUT_LICENSE)
1000 MSGBOXPARAMSW params;
1002 params.cbSize = sizeof(params);
1003 params.hwndOwner = hWnd;
1004 params.hInstance = shell32_hInstance;
1005 params.lpszText = MAKEINTRESOURCEW(IDS_LICENSE);
1006 params.lpszCaption = MAKEINTRESOURCEW(IDS_LICENSE_CAPTION);
1007 params.dwStyle = MB_ICONINFORMATION | MB_OK;
1008 params.lpszIcon = 0;
1009 params.dwContextHelpId = 0;
1010 params.lpfnMsgBoxCallback = NULL;
1011 params.dwLanguageId = LANG_NEUTRAL;
1012 MessageBoxIndirectW( &params );
1014 break;
1015 case WM_CLOSE:
1016 EndDialog(hWnd, TRUE);
1017 break;
1020 return 0;
1024 /*************************************************************************
1025 * ShellAboutA [SHELL32.288]
1027 BOOL WINAPI ShellAboutA( HWND hWnd, LPCSTR szApp, LPCSTR szOtherStuff, HICON hIcon )
1029 BOOL ret;
1030 LPWSTR appW = NULL, otherW = NULL;
1031 int len;
1033 if (szApp)
1035 len = MultiByteToWideChar(CP_ACP, 0, szApp, -1, NULL, 0);
1036 appW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1037 MultiByteToWideChar(CP_ACP, 0, szApp, -1, appW, len);
1039 if (szOtherStuff)
1041 len = MultiByteToWideChar(CP_ACP, 0, szOtherStuff, -1, NULL, 0);
1042 otherW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1043 MultiByteToWideChar(CP_ACP, 0, szOtherStuff, -1, otherW, len);
1046 ret = ShellAboutW(hWnd, appW, otherW, hIcon);
1048 HeapFree(GetProcessHeap(), 0, otherW);
1049 HeapFree(GetProcessHeap(), 0, appW);
1050 return ret;
1054 /*************************************************************************
1055 * ShellAboutW [SHELL32.289]
1057 BOOL WINAPI ShellAboutW( HWND hWnd, LPCWSTR szApp, LPCWSTR szOtherStuff,
1058 HICON hIcon )
1060 ABOUT_INFO info;
1061 LOGFONTW logFont;
1062 BOOL bRet;
1063 static const WCHAR wszSHELL_ABOUT_MSGBOX[] =
1064 {'S','H','E','L','L','_','A','B','O','U','T','_','M','S','G','B','O','X',0};
1066 TRACE("\n");
1068 if (!hIcon) hIcon = LoadImageW( 0, (LPWSTR)IDI_WINLOGO, IMAGE_ICON, 48, 48, LR_SHARED );
1069 info.szApp = szApp;
1070 info.szOtherStuff = szOtherStuff;
1071 info.hIcon = hIcon;
1073 SystemParametersInfoW( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 );
1074 info.hFont = CreateFontIndirectW( &logFont );
1076 bRet = DialogBoxParamW( shell32_hInstance, wszSHELL_ABOUT_MSGBOX, hWnd, AboutDlgProc, (LPARAM)&info );
1077 DeleteObject(info.hFont);
1078 return bRet;
1081 /*************************************************************************
1082 * FreeIconList (SHELL32.@)
1084 void WINAPI FreeIconList( DWORD dw )
1086 FIXME("%x: stub\n",dw);
1089 /*************************************************************************
1090 * SHLoadNonloadedIconOverlayIdentifiers (SHELL32.@)
1092 HRESULT WINAPI SHLoadNonloadedIconOverlayIdentifiers( VOID )
1094 FIXME("stub\n");
1095 return S_OK;
1098 /***********************************************************************
1099 * DllGetVersion [SHELL32.@]
1101 * Retrieves version information of the 'SHELL32.DLL'
1103 * PARAMS
1104 * pdvi [O] pointer to version information structure.
1106 * RETURNS
1107 * Success: S_OK
1108 * Failure: E_INVALIDARG
1110 * NOTES
1111 * Returns version of a shell32.dll from IE4.01 SP1.
1114 HRESULT WINAPI DllGetVersion (DLLVERSIONINFO *pdvi)
1116 /* FIXME: shouldn't these values come from the version resource? */
1117 if (pdvi->cbSize == sizeof(DLLVERSIONINFO) ||
1118 pdvi->cbSize == sizeof(DLLVERSIONINFO2))
1120 pdvi->dwMajorVersion = WINE_FILEVERSION_MAJOR;
1121 pdvi->dwMinorVersion = WINE_FILEVERSION_MINOR;
1122 pdvi->dwBuildNumber = WINE_FILEVERSION_BUILD;
1123 pdvi->dwPlatformID = WINE_FILEVERSION_PLATFORMID;
1124 if (pdvi->cbSize == sizeof(DLLVERSIONINFO2))
1126 DLLVERSIONINFO2 *pdvi2 = (DLLVERSIONINFO2 *)pdvi;
1128 pdvi2->dwFlags = 0;
1129 pdvi2->ullVersion = MAKEDLLVERULL(WINE_FILEVERSION_MAJOR,
1130 WINE_FILEVERSION_MINOR,
1131 WINE_FILEVERSION_BUILD,
1132 WINE_FILEVERSION_PLATFORMID);
1134 TRACE("%u.%u.%u.%u\n",
1135 pdvi->dwMajorVersion, pdvi->dwMinorVersion,
1136 pdvi->dwBuildNumber, pdvi->dwPlatformID);
1137 return S_OK;
1139 else
1141 WARN("wrong DLLVERSIONINFO size from app\n");
1142 return E_INVALIDARG;
1146 /*************************************************************************
1147 * global variables of the shell32.dll
1148 * all are once per process
1151 HINSTANCE shell32_hInstance = 0;
1152 HIMAGELIST ShellSmallIconList = 0;
1153 HIMAGELIST ShellBigIconList = 0;
1156 /*************************************************************************
1157 * SHELL32 DllMain
1159 * NOTES
1160 * calling oleinitialize here breaks sone apps.
1162 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
1164 TRACE("%p 0x%x %p\n", hinstDLL, fdwReason, fImpLoad);
1166 switch (fdwReason)
1168 case DLL_PROCESS_ATTACH:
1169 shell32_hInstance = hinstDLL;
1170 DisableThreadLibraryCalls(shell32_hInstance);
1172 /* get full path to this DLL for IExtractIconW_fnGetIconLocation() */
1173 GetModuleFileNameW(hinstDLL, swShell32Name, MAX_PATH);
1174 swShell32Name[MAX_PATH - 1] = '\0';
1176 InitCommonControlsEx(NULL);
1178 SIC_Initialize();
1179 InitChangeNotifications();
1180 break;
1182 case DLL_PROCESS_DETACH:
1183 shell32_hInstance = 0;
1184 SIC_Destroy();
1185 FreeChangeNotifications();
1186 break;
1188 return TRUE;
1191 /*************************************************************************
1192 * DllInstall [SHELL32.@]
1194 * PARAMETERS
1196 * BOOL bInstall - TRUE for install, FALSE for uninstall
1197 * LPCWSTR pszCmdLine - command line (unused by shell32?)
1200 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
1202 FIXME("%s %s: stub\n", bInstall ? "TRUE":"FALSE", debugstr_w(cmdline));
1203 return S_OK; /* indicate success */
1206 /***********************************************************************
1207 * DllCanUnloadNow (SHELL32.@)
1209 HRESULT WINAPI DllCanUnloadNow(void)
1211 return S_FALSE;
1214 /***********************************************************************
1215 * ExtractVersionResource16W (SHELL32.@)
1217 BOOL WINAPI ExtractVersionResource16W(LPWSTR s, DWORD d)
1219 FIXME("(%s %x) stub!\n", debugstr_w(s), d);
1220 return FALSE;
1223 /***********************************************************************
1224 * InitNetworkAddressControl (SHELL32.@)
1226 BOOL WINAPI InitNetworkAddressControl(void)
1228 FIXME("stub\n");
1229 return FALSE;
1232 /***********************************************************************
1233 * ShellHookProc (SHELL32.@)
1235 LRESULT CALLBACK ShellHookProc(DWORD a, DWORD b, DWORD c)
1237 FIXME("Stub\n");
1238 return 0;
1241 HRESULT WINAPI SHGetLocalizedName(LPCWSTR path, LPWSTR module, UINT size, INT *res)
1243 FIXME("%s %p %u %p: stub\n", debugstr_w(path), module, size, res);
1244 return E_NOTIMPL;