shell32: Use S_OK as successful return code name.
[wine/multimedia.git] / dlls / shell32 / shell32_main.c
blob5370b992a593f12d06a0fb320283f9c691411ff7
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(!numargs)
97 SetLastError(ERROR_INVALID_PARAMETER);
98 return NULL;
101 if (*lpCmdline==0)
103 /* Return the path to the executable */
104 DWORD len, deslen=MAX_PATH, size;
106 size = sizeof(LPWSTR) + deslen*sizeof(WCHAR) + sizeof(LPWSTR);
107 for (;;)
109 if (!(argv = LocalAlloc(LMEM_FIXED, size))) return NULL;
110 len = GetModuleFileNameW(0, (LPWSTR)(argv+1), deslen);
111 if (!len)
113 LocalFree(argv);
114 return NULL;
116 if (len < deslen) break;
117 deslen*=2;
118 size = sizeof(LPWSTR) + deslen*sizeof(WCHAR) + sizeof(LPWSTR);
119 LocalFree( argv );
121 argv[0]=(LPWSTR)(argv+1);
122 *numargs=1;
124 return argv;
127 /* to get a writable copy */
128 argc=0;
129 bcount=0;
130 in_quotes=0;
131 cs=lpCmdline;
132 while (1)
134 if (*cs==0 || ((*cs==0x0009 || *cs==0x0020) && !in_quotes))
136 /* space */
137 argc++;
138 /* skip the remaining spaces */
139 while (*cs==0x0009 || *cs==0x0020) {
140 cs++;
142 if (*cs==0)
143 break;
144 bcount=0;
145 continue;
147 else if (*cs==0x005c)
149 /* '\', count them */
150 bcount++;
152 else if ((*cs==0x0022) && ((bcount & 1)==0))
154 /* unescaped '"' */
155 in_quotes=!in_quotes;
156 bcount=0;
158 else
160 /* a regular character */
161 bcount=0;
163 cs++;
165 /* Allocate in a single lump, the string array, and the strings that go with it.
166 * This way the caller can make a single GlobalFree call to free both, as per MSDN.
168 argv=LocalAlloc(LMEM_FIXED, argc*sizeof(LPWSTR)+(strlenW(lpCmdline)+1)*sizeof(WCHAR));
169 if (!argv)
170 return NULL;
171 cmdline=(LPWSTR)(argv+argc);
172 strcpyW(cmdline, lpCmdline);
174 argc=0;
175 bcount=0;
176 in_quotes=0;
177 arg=d=s=cmdline;
178 while (*s)
180 if ((*s==0x0009 || *s==0x0020) && !in_quotes)
182 /* Close the argument and copy it */
183 *d=0;
184 argv[argc++]=arg;
186 /* skip the remaining spaces */
187 do {
188 s++;
189 } while (*s==0x0009 || *s==0x0020);
191 /* Start with a new argument */
192 arg=d=s;
193 bcount=0;
195 else if (*s==0x005c)
197 /* '\\' */
198 *d++=*s++;
199 bcount++;
201 else if (*s==0x0022)
203 /* '"' */
204 if ((bcount & 1)==0)
206 /* Preceded by an even number of '\', this is half that
207 * number of '\', plus a quote which we erase.
209 d-=bcount/2;
210 in_quotes=!in_quotes;
211 s++;
213 else
215 /* Preceded by an odd number of '\', this is half that
216 * number of '\' followed by a '"'
218 d=d-bcount/2-1;
219 *d++='"';
220 s++;
222 bcount=0;
224 else
226 /* a regular character */
227 *d++=*s++;
228 bcount=0;
231 if (*arg)
233 *d='\0';
234 argv[argc++]=arg;
236 *numargs=argc;
238 return argv;
241 static DWORD shgfi_get_exe_type(LPCWSTR szFullPath)
243 BOOL status = FALSE;
244 HANDLE hfile;
245 DWORD BinaryType;
246 IMAGE_DOS_HEADER mz_header;
247 IMAGE_NT_HEADERS nt;
248 DWORD len;
249 char magic[4];
251 status = GetBinaryTypeW (szFullPath, &BinaryType);
252 if (!status)
253 return 0;
254 if (BinaryType == SCS_DOS_BINARY || BinaryType == SCS_PIF_BINARY)
255 return 0x4d5a;
257 hfile = CreateFileW( szFullPath, GENERIC_READ, FILE_SHARE_READ,
258 NULL, OPEN_EXISTING, 0, 0 );
259 if ( hfile == INVALID_HANDLE_VALUE )
260 return 0;
263 * The next section is adapted from MODULE_GetBinaryType, as we need
264 * to examine the image header to get OS and version information. We
265 * know from calling GetBinaryTypeA that the image is valid and either
266 * an NE or PE, so much error handling can be omitted.
267 * Seek to the start of the file and read the header information.
270 SetFilePointer( hfile, 0, NULL, SEEK_SET );
271 ReadFile( hfile, &mz_header, sizeof(mz_header), &len, NULL );
273 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
274 ReadFile( hfile, magic, sizeof(magic), &len, NULL );
275 if ( *(DWORD*)magic == IMAGE_NT_SIGNATURE )
277 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
278 ReadFile( hfile, &nt, sizeof(nt), &len, NULL );
279 CloseHandle( hfile );
280 /* DLL files are not executable and should return 0 */
281 if (nt.FileHeader.Characteristics & IMAGE_FILE_DLL)
282 return 0;
283 if (nt.OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI)
285 return IMAGE_NT_SIGNATURE |
286 (nt.OptionalHeader.MajorSubsystemVersion << 24) |
287 (nt.OptionalHeader.MinorSubsystemVersion << 16);
289 return IMAGE_NT_SIGNATURE;
291 else if ( *(WORD*)magic == IMAGE_OS2_SIGNATURE )
293 IMAGE_OS2_HEADER ne;
294 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
295 ReadFile( hfile, &ne, sizeof(ne), &len, NULL );
296 CloseHandle( hfile );
297 if (ne.ne_exetyp == 2)
298 return IMAGE_OS2_SIGNATURE | (ne.ne_expver << 16);
299 return 0;
301 CloseHandle( hfile );
302 return 0;
305 /*************************************************************************
306 * SHELL_IsShortcut [internal]
308 * Decide if an item id list points to a shell shortcut
310 BOOL SHELL_IsShortcut(LPCITEMIDLIST pidlLast)
312 char szTemp[MAX_PATH];
313 HKEY keyCls;
314 BOOL ret = FALSE;
316 if (_ILGetExtension(pidlLast, szTemp, MAX_PATH) &&
317 HCR_MapTypeToValueA(szTemp, szTemp, MAX_PATH, TRUE))
319 if (ERROR_SUCCESS == RegOpenKeyExA(HKEY_CLASSES_ROOT, szTemp, 0, KEY_QUERY_VALUE, &keyCls))
321 if (ERROR_SUCCESS == RegQueryValueExA(keyCls, "IsShortcut", NULL, NULL, NULL, NULL))
322 ret = TRUE;
324 RegCloseKey(keyCls);
328 return ret;
331 #define SHGFI_KNOWN_FLAGS \
332 (SHGFI_SMALLICON | SHGFI_OPENICON | SHGFI_SHELLICONSIZE | SHGFI_PIDL | \
333 SHGFI_USEFILEATTRIBUTES | SHGFI_ADDOVERLAYS | SHGFI_OVERLAYINDEX | \
334 SHGFI_ICON | SHGFI_DISPLAYNAME | SHGFI_TYPENAME | SHGFI_ATTRIBUTES | \
335 SHGFI_ICONLOCATION | SHGFI_EXETYPE | SHGFI_SYSICONINDEX | \
336 SHGFI_LINKOVERLAY | SHGFI_SELECTED | SHGFI_ATTR_SPECIFIED)
338 /*************************************************************************
339 * SHGetFileInfoW [SHELL32.@]
342 DWORD_PTR WINAPI SHGetFileInfoW(LPCWSTR path,DWORD dwFileAttributes,
343 SHFILEINFOW *psfi, UINT sizeofpsfi, UINT flags )
345 WCHAR szLocation[MAX_PATH], szFullPath[MAX_PATH];
346 int iIndex;
347 DWORD_PTR ret = TRUE;
348 DWORD dwAttributes = 0;
349 IShellFolder * psfParent = NULL;
350 IExtractIconW * pei = NULL;
351 LPITEMIDLIST pidlLast = NULL, pidl = NULL;
352 HRESULT hr = S_OK;
353 BOOL IconNotYetLoaded=TRUE;
354 UINT uGilFlags = 0;
356 TRACE("%s fattr=0x%x sfi=%p(attr=0x%08x) size=0x%x flags=0x%x\n",
357 (flags & SHGFI_PIDL)? "pidl" : debugstr_w(path), dwFileAttributes,
358 psfi, psfi->dwAttributes, sizeofpsfi, flags);
360 if (!path)
361 return FALSE;
363 /* windows initializes these values regardless of the flags */
364 if (psfi != NULL)
366 psfi->szDisplayName[0] = '\0';
367 psfi->szTypeName[0] = '\0';
368 psfi->iIcon = 0;
371 if (!(flags & SHGFI_PIDL))
373 /* SHGetFileInfo should work with absolute and relative paths */
374 if (PathIsRelativeW(path))
376 GetCurrentDirectoryW(MAX_PATH, szLocation);
377 PathCombineW(szFullPath, szLocation, path);
379 else
381 lstrcpynW(szFullPath, path, MAX_PATH);
385 if (flags & SHGFI_EXETYPE)
387 if (flags != SHGFI_EXETYPE)
388 return 0;
389 return shgfi_get_exe_type(szFullPath);
393 * psfi is NULL normally to query EXE type. If it is NULL, none of the
394 * below makes sense anyway. Windows allows this and just returns FALSE
396 if (psfi == NULL)
397 return FALSE;
400 * translate the path into a pidl only when SHGFI_USEFILEATTRIBUTES
401 * is not specified.
402 * The pidl functions fail on not existing file names
405 if (flags & SHGFI_PIDL)
407 pidl = ILClone((LPCITEMIDLIST)path);
409 else if (!(flags & SHGFI_USEFILEATTRIBUTES))
411 hr = SHILCreateFromPathW(szFullPath, &pidl, &dwAttributes);
414 if ((flags & SHGFI_PIDL) || !(flags & SHGFI_USEFILEATTRIBUTES))
416 /* get the parent shellfolder */
417 if (pidl)
419 hr = SHBindToParent( pidl, &IID_IShellFolder, (LPVOID*)&psfParent,
420 (LPCITEMIDLIST*)&pidlLast );
421 if (SUCCEEDED(hr))
422 pidlLast = ILClone(pidlLast);
423 ILFree(pidl);
425 else
427 ERR("pidl is null!\n");
428 return FALSE;
432 /* get the attributes of the child */
433 if (SUCCEEDED(hr) && (flags & SHGFI_ATTRIBUTES))
435 if (!(flags & SHGFI_ATTR_SPECIFIED))
437 psfi->dwAttributes = 0xffffffff;
439 if (psfParent)
440 IShellFolder_GetAttributesOf( psfParent, 1, (LPCITEMIDLIST*)&pidlLast,
441 &(psfi->dwAttributes) );
444 /* get the displayname */
445 if (SUCCEEDED(hr) && (flags & SHGFI_DISPLAYNAME))
447 if (flags & SHGFI_USEFILEATTRIBUTES && !(flags & SHGFI_PIDL))
449 lstrcpyW (psfi->szDisplayName, PathFindFileNameW(szFullPath));
451 else
453 STRRET str;
454 hr = IShellFolder_GetDisplayNameOf( psfParent, pidlLast,
455 SHGDN_INFOLDER, &str);
456 StrRetToStrNW (psfi->szDisplayName, MAX_PATH, &str, pidlLast);
460 /* get the type name */
461 if (SUCCEEDED(hr) && (flags & SHGFI_TYPENAME))
463 static const WCHAR szFile[] = { 'F','i','l','e',0 };
464 static const WCHAR szDashFile[] = { '-','f','i','l','e',0 };
466 if (!(flags & SHGFI_USEFILEATTRIBUTES) || (flags & SHGFI_PIDL))
468 char ftype[80];
470 _ILGetFileType(pidlLast, ftype, 80);
471 MultiByteToWideChar(CP_ACP, 0, ftype, -1, psfi->szTypeName, 80 );
473 else
475 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
476 strcatW (psfi->szTypeName, szFile);
477 else
479 WCHAR sTemp[64];
481 lstrcpyW(sTemp,PathFindExtensionW(szFullPath));
482 if (!( HCR_MapTypeToValueW(sTemp, sTemp, 64, TRUE) &&
483 HCR_MapTypeToValueW(sTemp, psfi->szTypeName, 80, FALSE )))
485 lstrcpynW (psfi->szTypeName, sTemp, 64);
486 strcatW (psfi->szTypeName, szDashFile);
492 /* ### icons ###*/
493 if (flags & SHGFI_OPENICON)
494 uGilFlags |= GIL_OPENICON;
496 if (flags & SHGFI_LINKOVERLAY)
497 uGilFlags |= GIL_FORSHORTCUT;
498 else if ((flags&SHGFI_ADDOVERLAYS) ||
499 (flags&(SHGFI_ICON|SHGFI_SMALLICON))==SHGFI_ICON)
501 if (SHELL_IsShortcut(pidlLast))
502 uGilFlags |= GIL_FORSHORTCUT;
505 if (flags & SHGFI_OVERLAYINDEX)
506 FIXME("SHGFI_OVERLAYINDEX unhandled\n");
508 if (flags & SHGFI_SELECTED)
509 FIXME("set icon to selected, stub\n");
511 if (flags & SHGFI_SHELLICONSIZE)
512 FIXME("set icon to shell size, stub\n");
514 /* get the iconlocation */
515 if (SUCCEEDED(hr) && (flags & SHGFI_ICONLOCATION ))
517 UINT uDummy,uFlags;
519 if (flags & SHGFI_USEFILEATTRIBUTES && !(flags & SHGFI_PIDL))
521 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
523 lstrcpyW(psfi->szDisplayName, swShell32Name);
524 psfi->iIcon = -IDI_SHELL_FOLDER;
526 else
528 WCHAR* szExt;
529 static const WCHAR p1W[] = {'%','1',0};
530 WCHAR sTemp [MAX_PATH];
532 szExt = PathFindExtensionW(szFullPath);
533 TRACE("szExt=%s\n", debugstr_w(szExt));
534 if ( szExt &&
535 HCR_MapTypeToValueW(szExt, sTemp, MAX_PATH, TRUE) &&
536 HCR_GetDefaultIconW(sTemp, sTemp, MAX_PATH, &psfi->iIcon))
538 if (lstrcmpW(p1W, sTemp))
539 strcpyW(psfi->szDisplayName, sTemp);
540 else
542 /* the icon is in the file */
543 strcpyW(psfi->szDisplayName, szFullPath);
546 else
547 ret = FALSE;
550 else
552 hr = IShellFolder_GetUIObjectOf(psfParent, 0, 1,
553 (LPCITEMIDLIST*)&pidlLast, &IID_IExtractIconW,
554 &uDummy, (LPVOID*)&pei);
555 if (SUCCEEDED(hr))
557 hr = IExtractIconW_GetIconLocation(pei, uGilFlags,
558 szLocation, MAX_PATH, &iIndex, &uFlags);
560 if (uFlags & GIL_NOTFILENAME)
561 ret = FALSE;
562 else
564 lstrcpyW (psfi->szDisplayName, szLocation);
565 psfi->iIcon = iIndex;
567 IExtractIconW_Release(pei);
572 /* get icon index (or load icon)*/
573 if (SUCCEEDED(hr) && (flags & (SHGFI_ICON | SHGFI_SYSICONINDEX)))
575 if (flags & SHGFI_USEFILEATTRIBUTES && !(flags & SHGFI_PIDL))
577 WCHAR sTemp [MAX_PATH];
578 WCHAR * szExt;
579 int icon_idx=0;
581 lstrcpynW(sTemp, szFullPath, MAX_PATH);
583 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
584 psfi->iIcon = SIC_GetIconIndex(swShell32Name, -IDI_SHELL_FOLDER, 0);
585 else
587 static const WCHAR p1W[] = {'%','1',0};
589 psfi->iIcon = 0;
590 szExt = PathFindExtensionW(sTemp);
591 if ( szExt &&
592 HCR_MapTypeToValueW(szExt, sTemp, MAX_PATH, TRUE) &&
593 HCR_GetDefaultIconW(sTemp, sTemp, MAX_PATH, &icon_idx))
595 if (!lstrcmpW(p1W,sTemp)) /* icon is in the file */
596 strcpyW(sTemp, szFullPath);
598 if (flags & SHGFI_SYSICONINDEX)
600 psfi->iIcon = SIC_GetIconIndex(sTemp,icon_idx,0);
601 if (psfi->iIcon == -1)
602 psfi->iIcon = 0;
604 else
606 UINT ret;
607 if (flags & SHGFI_SMALLICON)
608 ret = PrivateExtractIconsW( sTemp,icon_idx,
609 GetSystemMetrics( SM_CXSMICON ),
610 GetSystemMetrics( SM_CYSMICON ),
611 &psfi->hIcon, 0, 1, 0);
612 else
613 ret = PrivateExtractIconsW( sTemp, icon_idx,
614 GetSystemMetrics( SM_CXICON),
615 GetSystemMetrics( SM_CYICON),
616 &psfi->hIcon, 0, 1, 0);
617 if (ret != 0 && ret != (UINT)-1)
619 IconNotYetLoaded=FALSE;
620 psfi->iIcon = icon_idx;
626 else
628 if (!(PidlToSicIndex(psfParent, pidlLast, !(flags & SHGFI_SMALLICON),
629 uGilFlags, &(psfi->iIcon))))
631 ret = FALSE;
634 if (ret && (flags & SHGFI_SYSICONINDEX))
636 if (flags & SHGFI_SMALLICON)
637 ret = (DWORD_PTR) ShellSmallIconList;
638 else
639 ret = (DWORD_PTR) ShellBigIconList;
643 /* icon handle */
644 if (SUCCEEDED(hr) && (flags & SHGFI_ICON) && IconNotYetLoaded)
646 if (flags & SHGFI_SMALLICON)
647 psfi->hIcon = ImageList_GetIcon( ShellSmallIconList, psfi->iIcon, ILD_NORMAL);
648 else
649 psfi->hIcon = ImageList_GetIcon( ShellBigIconList, psfi->iIcon, ILD_NORMAL);
652 if (flags & ~SHGFI_KNOWN_FLAGS)
653 FIXME("unknown flags %08x\n", flags & ~SHGFI_KNOWN_FLAGS);
655 if (psfParent)
656 IShellFolder_Release(psfParent);
658 if (hr != S_OK)
659 ret = FALSE;
661 SHFree(pidlLast);
663 TRACE ("icon=%p index=0x%08x attr=0x%08x name=%s type=%s ret=0x%08lx\n",
664 psfi->hIcon, psfi->iIcon, psfi->dwAttributes,
665 debugstr_w(psfi->szDisplayName), debugstr_w(psfi->szTypeName), ret);
667 return ret;
670 /*************************************************************************
671 * SHGetFileInfoA [SHELL32.@]
673 * Note:
674 * MSVBVM60.__vbaNew2 expects this function to return a value in range
675 * 1 .. 0x7fff when the function succeeds and flags does not contain
676 * SHGFI_EXETYPE or SHGFI_SYSICONINDEX (see bug 7701)
678 DWORD_PTR WINAPI SHGetFileInfoA(LPCSTR path,DWORD dwFileAttributes,
679 SHFILEINFOA *psfi, UINT sizeofpsfi,
680 UINT flags )
682 INT len;
683 LPWSTR temppath = NULL;
684 LPCWSTR pathW;
685 DWORD_PTR ret;
686 SHFILEINFOW temppsfi;
688 if (flags & SHGFI_PIDL)
690 /* path contains a pidl */
691 pathW = (LPCWSTR)path;
693 else
695 len = MultiByteToWideChar(CP_ACP, 0, path, -1, NULL, 0);
696 temppath = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
697 MultiByteToWideChar(CP_ACP, 0, path, -1, temppath, len);
698 pathW = temppath;
701 if (psfi && (flags & SHGFI_ATTR_SPECIFIED))
702 temppsfi.dwAttributes=psfi->dwAttributes;
704 if (psfi == NULL)
705 ret = SHGetFileInfoW(pathW, dwFileAttributes, NULL, sizeof(temppsfi), flags);
706 else
707 ret = SHGetFileInfoW(pathW, dwFileAttributes, &temppsfi, sizeof(temppsfi), flags);
709 if (psfi)
711 if(flags & SHGFI_ICON)
712 psfi->hIcon=temppsfi.hIcon;
713 if(flags & (SHGFI_SYSICONINDEX|SHGFI_ICON|SHGFI_ICONLOCATION))
714 psfi->iIcon=temppsfi.iIcon;
715 if(flags & SHGFI_ATTRIBUTES)
716 psfi->dwAttributes=temppsfi.dwAttributes;
717 if(flags & (SHGFI_DISPLAYNAME|SHGFI_ICONLOCATION))
719 WideCharToMultiByte(CP_ACP, 0, temppsfi.szDisplayName, -1,
720 psfi->szDisplayName, sizeof(psfi->szDisplayName), NULL, NULL);
722 if(flags & SHGFI_TYPENAME)
724 WideCharToMultiByte(CP_ACP, 0, temppsfi.szTypeName, -1,
725 psfi->szTypeName, sizeof(psfi->szTypeName), NULL, NULL);
729 HeapFree(GetProcessHeap(), 0, temppath);
731 return ret;
734 /*************************************************************************
735 * DuplicateIcon [SHELL32.@]
737 HICON WINAPI DuplicateIcon( HINSTANCE hInstance, HICON hIcon)
739 ICONINFO IconInfo;
740 HICON hDupIcon = 0;
742 TRACE("%p %p\n", hInstance, hIcon);
744 if (GetIconInfo(hIcon, &IconInfo))
746 hDupIcon = CreateIconIndirect(&IconInfo);
748 /* clean up hbmMask and hbmColor */
749 DeleteObject(IconInfo.hbmMask);
750 DeleteObject(IconInfo.hbmColor);
753 return hDupIcon;
756 /*************************************************************************
757 * ExtractIconA [SHELL32.@]
759 HICON WINAPI ExtractIconA(HINSTANCE hInstance, LPCSTR lpszFile, UINT nIconIndex)
761 HICON ret;
762 INT len = MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, NULL, 0);
763 LPWSTR lpwstrFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
765 TRACE("%p %s %d\n", hInstance, lpszFile, nIconIndex);
767 MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, lpwstrFile, len);
768 ret = ExtractIconW(hInstance, lpwstrFile, nIconIndex);
769 HeapFree(GetProcessHeap(), 0, lpwstrFile);
771 return ret;
774 /*************************************************************************
775 * ExtractIconW [SHELL32.@]
777 HICON WINAPI ExtractIconW(HINSTANCE hInstance, LPCWSTR lpszFile, UINT nIconIndex)
779 HICON hIcon = NULL;
780 UINT ret;
781 UINT cx = GetSystemMetrics(SM_CXICON), cy = GetSystemMetrics(SM_CYICON);
783 TRACE("%p %s %d\n", hInstance, debugstr_w(lpszFile), nIconIndex);
785 if (nIconIndex == (UINT)-1)
787 ret = PrivateExtractIconsW(lpszFile, 0, cx, cy, NULL, NULL, 0, LR_DEFAULTCOLOR);
788 if (ret != (UINT)-1 && ret)
789 return (HICON)(UINT_PTR)ret;
790 return NULL;
792 else
793 ret = PrivateExtractIconsW(lpszFile, nIconIndex, cx, cy, &hIcon, NULL, 1, LR_DEFAULTCOLOR);
795 if (ret == (UINT)-1)
796 return (HICON)1;
797 else if (ret > 0 && hIcon)
798 return hIcon;
800 return NULL;
803 HRESULT WINAPI SHCreateFileExtractIconW(LPCWSTR file, DWORD attribs, REFIID riid, void **ppv)
805 FIXME("%s, %x, %s, %p\n", debugstr_w(file), attribs, debugstr_guid(riid), ppv);
806 *ppv = NULL;
807 return E_NOTIMPL;
810 /*************************************************************************
811 * Printer_LoadIconsW [SHELL32.205]
813 VOID WINAPI Printer_LoadIconsW(LPCWSTR wsPrinterName, HICON * pLargeIcon, HICON * pSmallIcon)
815 INT iconindex=IDI_SHELL_PRINTER;
817 TRACE("(%s, %p, %p)\n", debugstr_w(wsPrinterName), pLargeIcon, pSmallIcon);
819 /* We should check if wsPrinterName is
820 1. the Default Printer or not
821 2. connected or not
822 3. a Local Printer or a Network-Printer
823 and use different Icons
825 if((wsPrinterName != NULL) && (wsPrinterName[0] != 0))
827 FIXME("(select Icon by PrinterName %s not implemented)\n", debugstr_w(wsPrinterName));
830 if(pLargeIcon != NULL)
831 *pLargeIcon = LoadImageW(shell32_hInstance,
832 (LPCWSTR) MAKEINTRESOURCE(iconindex), IMAGE_ICON,
833 0, 0, LR_DEFAULTCOLOR|LR_DEFAULTSIZE);
835 if(pSmallIcon != NULL)
836 *pSmallIcon = LoadImageW(shell32_hInstance,
837 (LPCWSTR) MAKEINTRESOURCE(iconindex), IMAGE_ICON,
838 16, 16, LR_DEFAULTCOLOR);
841 /*************************************************************************
842 * Printers_RegisterWindowW [SHELL32.213]
843 * used by "printui.dll":
844 * find the Window of the given Type for the specific Printer and
845 * return the already existent hwnd or open a new window
847 BOOL WINAPI Printers_RegisterWindowW(LPCWSTR wsPrinter, DWORD dwType,
848 HANDLE * phClassPidl, HWND * phwnd)
850 FIXME("(%s, %x, %p (%p), %p (%p)) stub!\n", debugstr_w(wsPrinter), dwType,
851 phClassPidl, (phClassPidl != NULL) ? *(phClassPidl) : NULL,
852 phwnd, (phwnd != NULL) ? *(phwnd) : NULL);
854 return FALSE;
857 /*************************************************************************
858 * Printers_UnregisterWindow [SHELL32.214]
860 VOID WINAPI Printers_UnregisterWindow(HANDLE hClassPidl, HWND hwnd)
862 FIXME("(%p, %p) stub!\n", hClassPidl, hwnd);
865 /*************************************************************************
866 * SHGetPropertyStoreFromParsingName [SHELL32.@]
868 HRESULT WINAPI SHGetPropertyStoreFromParsingName(PCWSTR pszPath, IBindCtx *pbc, GETPROPERTYSTOREFLAGS flags, REFIID riid, void **ppv)
870 FIXME("(%s %p %u %p %p) stub!\n", debugstr_w(pszPath), pbc, flags, riid, ppv);
871 return E_NOTIMPL;
874 /*************************************************************************/
876 typedef struct
878 LPCWSTR szApp;
879 LPCWSTR szOtherStuff;
880 HICON hIcon;
881 HFONT hFont;
882 } ABOUT_INFO;
884 #define DROP_FIELD_TOP (-12)
886 static void paint_dropline( HDC hdc, HWND hWnd )
888 HWND hWndCtl = GetDlgItem(hWnd, IDC_ABOUT_WINE_TEXT);
889 RECT rect;
891 if (!hWndCtl) return;
892 GetWindowRect( hWndCtl, &rect );
893 MapWindowPoints( 0, hWnd, (LPPOINT)&rect, 2 );
894 rect.top += DROP_FIELD_TOP;
895 rect.bottom = rect.top + 2;
896 DrawEdge( hdc, &rect, BDR_SUNKENOUTER, BF_RECT );
899 /*************************************************************************
900 * SHHelpShortcuts_RunDLLA [SHELL32.@]
903 DWORD WINAPI SHHelpShortcuts_RunDLLA(DWORD dwArg1, DWORD dwArg2, DWORD dwArg3, DWORD dwArg4)
905 FIXME("(%x, %x, %x, %x) stub!\n", dwArg1, dwArg2, dwArg3, dwArg4);
906 return 0;
909 /*************************************************************************
910 * SHHelpShortcuts_RunDLLA [SHELL32.@]
913 DWORD WINAPI SHHelpShortcuts_RunDLLW(DWORD dwArg1, DWORD dwArg2, DWORD dwArg3, DWORD dwArg4)
915 FIXME("(%x, %x, %x, %x) stub!\n", dwArg1, dwArg2, dwArg3, dwArg4);
916 return 0;
919 /*************************************************************************
920 * SHLoadInProc [SHELL32.@]
921 * Create an instance of specified object class from within
922 * the shell process and release it immediately
924 HRESULT WINAPI SHLoadInProc (REFCLSID rclsid)
926 void *ptr = NULL;
928 TRACE("%s\n", debugstr_guid(rclsid));
930 CoCreateInstance(rclsid, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown,&ptr);
931 if(ptr)
933 IUnknown * pUnk = ptr;
934 IUnknown_Release(pUnk);
935 return S_OK;
937 return DISP_E_MEMBERNOTFOUND;
940 static void add_authors( HWND list )
942 static const WCHAR eol[] = {'\r','\n',0};
943 static const WCHAR authors[] = {'A','U','T','H','O','R','S',0};
944 WCHAR *strW, *start, *end;
945 HRSRC rsrc = FindResourceW( shell32_hInstance, authors, (LPCWSTR)RT_RCDATA );
946 char *strA = LockResource( LoadResource( shell32_hInstance, rsrc ));
947 DWORD sizeW, sizeA = SizeofResource( shell32_hInstance, rsrc );
949 if (!strA) return;
950 sizeW = MultiByteToWideChar( CP_UTF8, 0, strA, sizeA, NULL, 0 ) + 1;
951 if (!(strW = HeapAlloc( GetProcessHeap(), 0, sizeW * sizeof(WCHAR) ))) return;
952 MultiByteToWideChar( CP_UTF8, 0, strA, sizeA, strW, sizeW );
953 strW[sizeW - 1] = 0;
955 start = strpbrkW( strW, eol ); /* skip the header line */
956 while (start)
958 while (*start && strchrW( eol, *start )) start++;
959 if (!*start) break;
960 end = strpbrkW( start, eol );
961 if (end) *end++ = 0;
962 SendMessageW( list, LB_ADDSTRING, -1, (LPARAM)start );
963 start = end;
965 HeapFree( GetProcessHeap(), 0, strW );
968 /*************************************************************************
969 * AboutDlgProc (internal)
971 static INT_PTR CALLBACK AboutDlgProc( HWND hWnd, UINT msg, WPARAM wParam,
972 LPARAM lParam )
974 HWND hWndCtl;
976 TRACE("\n");
978 switch(msg)
980 case WM_INITDIALOG:
982 ABOUT_INFO *info = (ABOUT_INFO *)lParam;
983 WCHAR template[512], buffer[512], version[64];
984 extern const char *wine_get_build_id(void);
986 if (info)
988 SendDlgItemMessageW(hWnd, stc1, STM_SETICON,(WPARAM)info->hIcon, 0);
989 GetWindowTextW( hWnd, template, sizeof(template)/sizeof(WCHAR) );
990 sprintfW( buffer, template, info->szApp );
991 SetWindowTextW( hWnd, buffer );
992 SetWindowTextW( GetDlgItem(hWnd, IDC_ABOUT_STATIC_TEXT1), info->szApp );
993 SetWindowTextW( GetDlgItem(hWnd, IDC_ABOUT_STATIC_TEXT2), info->szOtherStuff );
994 GetWindowTextW( GetDlgItem(hWnd, IDC_ABOUT_STATIC_TEXT3),
995 template, sizeof(template)/sizeof(WCHAR) );
996 MultiByteToWideChar( CP_UTF8, 0, wine_get_build_id(), -1,
997 version, sizeof(version)/sizeof(WCHAR) );
998 sprintfW( buffer, template, version );
999 SetWindowTextW( GetDlgItem(hWnd, IDC_ABOUT_STATIC_TEXT3), buffer );
1000 hWndCtl = GetDlgItem(hWnd, IDC_ABOUT_LISTBOX);
1001 SendMessageW( hWndCtl, WM_SETREDRAW, 0, 0 );
1002 SendMessageW( hWndCtl, WM_SETFONT, (WPARAM)info->hFont, 0 );
1003 add_authors( hWndCtl );
1004 SendMessageW( hWndCtl, WM_SETREDRAW, 1, 0 );
1007 return 1;
1009 case WM_PAINT:
1011 PAINTSTRUCT ps;
1012 HDC hDC = BeginPaint( hWnd, &ps );
1013 paint_dropline( hDC, hWnd );
1014 EndPaint( hWnd, &ps );
1016 break;
1018 case WM_COMMAND:
1019 if (wParam == IDOK || wParam == IDCANCEL)
1021 EndDialog(hWnd, TRUE);
1022 return TRUE;
1024 if (wParam == IDC_ABOUT_LICENSE)
1026 MSGBOXPARAMSW params;
1028 params.cbSize = sizeof(params);
1029 params.hwndOwner = hWnd;
1030 params.hInstance = shell32_hInstance;
1031 params.lpszText = MAKEINTRESOURCEW(IDS_LICENSE);
1032 params.lpszCaption = MAKEINTRESOURCEW(IDS_LICENSE_CAPTION);
1033 params.dwStyle = MB_ICONINFORMATION | MB_OK;
1034 params.lpszIcon = 0;
1035 params.dwContextHelpId = 0;
1036 params.lpfnMsgBoxCallback = NULL;
1037 params.dwLanguageId = LANG_NEUTRAL;
1038 MessageBoxIndirectW( &params );
1040 break;
1041 case WM_CLOSE:
1042 EndDialog(hWnd, TRUE);
1043 break;
1046 return 0;
1050 /*************************************************************************
1051 * ShellAboutA [SHELL32.288]
1053 BOOL WINAPI ShellAboutA( HWND hWnd, LPCSTR szApp, LPCSTR szOtherStuff, HICON hIcon )
1055 BOOL ret;
1056 LPWSTR appW = NULL, otherW = NULL;
1057 int len;
1059 if (szApp)
1061 len = MultiByteToWideChar(CP_ACP, 0, szApp, -1, NULL, 0);
1062 appW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1063 MultiByteToWideChar(CP_ACP, 0, szApp, -1, appW, len);
1065 if (szOtherStuff)
1067 len = MultiByteToWideChar(CP_ACP, 0, szOtherStuff, -1, NULL, 0);
1068 otherW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1069 MultiByteToWideChar(CP_ACP, 0, szOtherStuff, -1, otherW, len);
1072 ret = ShellAboutW(hWnd, appW, otherW, hIcon);
1074 HeapFree(GetProcessHeap(), 0, otherW);
1075 HeapFree(GetProcessHeap(), 0, appW);
1076 return ret;
1080 /*************************************************************************
1081 * ShellAboutW [SHELL32.289]
1083 BOOL WINAPI ShellAboutW( HWND hWnd, LPCWSTR szApp, LPCWSTR szOtherStuff,
1084 HICON hIcon )
1086 ABOUT_INFO info;
1087 LOGFONTW logFont;
1088 BOOL bRet;
1089 static const WCHAR wszSHELL_ABOUT_MSGBOX[] =
1090 {'S','H','E','L','L','_','A','B','O','U','T','_','M','S','G','B','O','X',0};
1092 TRACE("\n");
1094 if (!hIcon) hIcon = LoadImageW( 0, (LPWSTR)IDI_WINLOGO, IMAGE_ICON, 48, 48, LR_SHARED );
1095 info.szApp = szApp;
1096 info.szOtherStuff = szOtherStuff;
1097 info.hIcon = hIcon;
1099 SystemParametersInfoW( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 );
1100 info.hFont = CreateFontIndirectW( &logFont );
1102 bRet = DialogBoxParamW( shell32_hInstance, wszSHELL_ABOUT_MSGBOX, hWnd, AboutDlgProc, (LPARAM)&info );
1103 DeleteObject(info.hFont);
1104 return bRet;
1107 /*************************************************************************
1108 * FreeIconList (SHELL32.@)
1110 void WINAPI FreeIconList( DWORD dw )
1112 FIXME("%x: stub\n",dw);
1115 /*************************************************************************
1116 * SHLoadNonloadedIconOverlayIdentifiers (SHELL32.@)
1118 HRESULT WINAPI SHLoadNonloadedIconOverlayIdentifiers( VOID )
1120 FIXME("stub\n");
1121 return S_OK;
1124 /***********************************************************************
1125 * DllGetVersion [SHELL32.@]
1127 * Retrieves version information of the 'SHELL32.DLL'
1129 * PARAMS
1130 * pdvi [O] pointer to version information structure.
1132 * RETURNS
1133 * Success: S_OK
1134 * Failure: E_INVALIDARG
1136 * NOTES
1137 * Returns version of a shell32.dll from IE4.01 SP1.
1140 HRESULT WINAPI DllGetVersion (DLLVERSIONINFO *pdvi)
1142 /* FIXME: shouldn't these values come from the version resource? */
1143 if (pdvi->cbSize == sizeof(DLLVERSIONINFO) ||
1144 pdvi->cbSize == sizeof(DLLVERSIONINFO2))
1146 pdvi->dwMajorVersion = WINE_FILEVERSION_MAJOR;
1147 pdvi->dwMinorVersion = WINE_FILEVERSION_MINOR;
1148 pdvi->dwBuildNumber = WINE_FILEVERSION_BUILD;
1149 pdvi->dwPlatformID = WINE_FILEVERSION_PLATFORMID;
1150 if (pdvi->cbSize == sizeof(DLLVERSIONINFO2))
1152 DLLVERSIONINFO2 *pdvi2 = (DLLVERSIONINFO2 *)pdvi;
1154 pdvi2->dwFlags = 0;
1155 pdvi2->ullVersion = MAKEDLLVERULL(WINE_FILEVERSION_MAJOR,
1156 WINE_FILEVERSION_MINOR,
1157 WINE_FILEVERSION_BUILD,
1158 WINE_FILEVERSION_PLATFORMID);
1160 TRACE("%u.%u.%u.%u\n",
1161 pdvi->dwMajorVersion, pdvi->dwMinorVersion,
1162 pdvi->dwBuildNumber, pdvi->dwPlatformID);
1163 return S_OK;
1165 else
1167 WARN("wrong DLLVERSIONINFO size from app\n");
1168 return E_INVALIDARG;
1172 /*************************************************************************
1173 * global variables of the shell32.dll
1174 * all are once per process
1177 HINSTANCE shell32_hInstance = 0;
1178 HIMAGELIST ShellSmallIconList = 0;
1179 HIMAGELIST ShellBigIconList = 0;
1182 /*************************************************************************
1183 * SHELL32 DllMain
1185 * NOTES
1186 * calling oleinitialize here breaks sone apps.
1188 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
1190 TRACE("%p 0x%x %p\n", hinstDLL, fdwReason, fImpLoad);
1192 switch (fdwReason)
1194 case DLL_PROCESS_ATTACH:
1195 shell32_hInstance = hinstDLL;
1196 DisableThreadLibraryCalls(shell32_hInstance);
1198 /* get full path to this DLL for IExtractIconW_fnGetIconLocation() */
1199 GetModuleFileNameW(hinstDLL, swShell32Name, MAX_PATH);
1200 swShell32Name[MAX_PATH - 1] = '\0';
1202 InitCommonControlsEx(NULL);
1204 SIC_Initialize();
1205 InitChangeNotifications();
1206 break;
1208 case DLL_PROCESS_DETACH:
1209 shell32_hInstance = 0;
1210 SIC_Destroy();
1211 FreeChangeNotifications();
1212 break;
1214 return TRUE;
1217 /*************************************************************************
1218 * DllInstall [SHELL32.@]
1220 * PARAMETERS
1222 * BOOL bInstall - TRUE for install, FALSE for uninstall
1223 * LPCWSTR pszCmdLine - command line (unused by shell32?)
1226 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
1228 FIXME("%s %s: stub\n", bInstall ? "TRUE":"FALSE", debugstr_w(cmdline));
1229 return S_OK; /* indicate success */
1232 /***********************************************************************
1233 * DllCanUnloadNow (SHELL32.@)
1235 HRESULT WINAPI DllCanUnloadNow(void)
1237 return S_FALSE;
1240 /***********************************************************************
1241 * DllRegisterServer (SHELL32.@)
1243 HRESULT WINAPI DllRegisterServer(void)
1245 HRESULT hr = __wine_register_resources( shell32_hInstance );
1246 if (SUCCEEDED(hr)) hr = SHELL_RegisterShellFolders();
1247 return hr;
1250 /***********************************************************************
1251 * DllUnregisterServer (SHELL32.@)
1253 HRESULT WINAPI DllUnregisterServer(void)
1255 return __wine_unregister_resources( shell32_hInstance );
1258 /***********************************************************************
1259 * ExtractVersionResource16W (SHELL32.@)
1261 BOOL WINAPI ExtractVersionResource16W(LPWSTR s, DWORD d)
1263 FIXME("(%s %x) stub!\n", debugstr_w(s), d);
1264 return FALSE;
1267 /***********************************************************************
1268 * InitNetworkAddressControl (SHELL32.@)
1270 BOOL WINAPI InitNetworkAddressControl(void)
1272 FIXME("stub\n");
1273 return FALSE;
1276 /***********************************************************************
1277 * ShellHookProc (SHELL32.@)
1279 LRESULT CALLBACK ShellHookProc(DWORD a, DWORD b, DWORD c)
1281 FIXME("Stub\n");
1282 return 0;
1285 HRESULT WINAPI SHGetLocalizedName(LPCWSTR path, LPWSTR module, UINT size, INT *res)
1287 FIXME("%s %p %u %p: stub\n", debugstr_w(path), module, size, res);
1288 return E_NOTIMPL;
1291 HRESULT WINAPI SetCurrentProcessExplicitAppUserModelID(PCWSTR appid)
1293 FIXME("%s: stub\n", debugstr_w(appid));
1294 return E_NOTIMPL;