Sync with trunk.
[reactos.git] / dll / win32 / shell32 / shell32_main.cpp
1 /*
2 * Shell basics
3 *
4 * Copyright 1998 Marcus Meissner
5 * Copyright 1998 Juergen Schmied (jsch) * <juergen.schmied@metronet.de>
6 *
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.
11 *
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.
16 *
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
20 */
21
22 #include "precomp.h"
23 #include "shell32_version.h"
24 #include <reactos/version.h>
25
26 WINE_DEFAULT_DEBUG_CHANNEL(shell);
27
28 const char * const SHELL_Authors[] = { "Copyright 1993-"COPYRIGHT_YEAR" WINE team", "Copyright 1998-"COPYRIGHT_YEAR" ReactOS Team", 0 };
29
30 #define MORE_DEBUG 1
31 /*************************************************************************
32 * CommandLineToArgvW [SHELL32.@]
33 *
34 * We must interpret the quotes in the command line to rebuild the argv
35 * array correctly:
36 * - arguments are separated by spaces or tabs
37 * - quotes serve as optional argument delimiters
38 * '"a b"' -> 'a b'
39 * - escaped quotes must be converted back to '"'
40 * '\"' -> '"'
41 * - consecutive backslashes preceding a quote see their number halved with
42 * the remainder escaping the quote:
43 * 2n backslashes + quote -> n backslashes + quote as an argument delimiter
44 * 2n+1 backslashes + quote -> n backslashes + literal quote
45 * - backslashes that are not followed by a quote are copied literally:
46 * 'a\b' -> 'a\b'
47 * 'a\\b' -> 'a\\b'
48 * - in quoted strings, consecutive quotes see their number divided by three
49 * with the remainder modulo 3 deciding whether to close the string or not.
50 * Note that the opening quote must be counted in the consecutive quotes,
51 * that's the (1+) below:
52 * (1+) 3n quotes -> n quotes
53 * (1+) 3n+1 quotes -> n quotes plus closes the quoted string
54 * (1+) 3n+2 quotes -> n+1 quotes plus closes the quoted string
55 * - in unquoted strings, the first quote opens the quoted string and the
56 * remaining consecutive quotes follow the above rule.
57 */
58 LPWSTR* WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int* numargs)
59 {
60 DWORD argc;
61 LPWSTR *argv;
62 LPCWSTR s;
63 LPWSTR d;
64 LPWSTR cmdline;
65 int qcount,bcount;
66
67 if(!numargs)
68 {
69 SetLastError(ERROR_INVALID_PARAMETER);
70 return NULL;
71 }
72
73 if (*lpCmdline==0)
74 {
75 /* Return the path to the executable */
76 DWORD len, deslen=MAX_PATH, size;
77
78 size = sizeof(LPWSTR) + deslen*sizeof(WCHAR) + sizeof(LPWSTR);
79 for (;;)
80 {
81 if (!(argv = (LPWSTR *)LocalAlloc(LMEM_FIXED, size))) return NULL;
82 len = GetModuleFileNameW(0, (LPWSTR)(argv+1), deslen);
83 if (!len)
84 {
85 LocalFree(argv);
86 return NULL;
87 }
88 if (len < deslen) break;
89 deslen*=2;
90 size = sizeof(LPWSTR) + deslen*sizeof(WCHAR) + sizeof(LPWSTR);
91 LocalFree( argv );
92 }
93 argv[0]=(LPWSTR)(argv+1);
94 *numargs=1;
95
96 return argv;
97 }
98
99 /* --- First count the arguments */
100 argc=1;
101 s=lpCmdline;
102 /* The first argument, the executable path, follows special rules */
103 if (*s=='"')
104 {
105 /* The executable path ends at the next quote, no matter what */
106 s++;
107 while (*s)
108 if (*s++=='"')
109 break;
110 }
111 else
112 {
113 /* The executable path ends at the next space, no matter what */
114 while (*s && *s!=' ' && *s!='\t')
115 s++;
116 }
117 /* skip to the first argument, if any */
118 while (*s==' ' || *s=='\t')
119 s++;
120 if (*s)
121 argc++;
122
123 /* Analyze the remaining arguments */
124 qcount=bcount=0;
125 while (*s)
126 {
127 if ((*s==' ' || *s=='\t') && qcount==0)
128 {
129 /* skip to the next argument and count it if any */
130 while (*s==' ' || *s=='\t')
131 s++;
132 if (*s)
133 argc++;
134 bcount=0;
135 }
136 else if (*s=='\\')
137 {
138 /* '\', count them */
139 bcount++;
140 s++;
141 }
142 else if (*s=='"')
143 {
144 /* '"' */
145 if ((bcount & 1)==0)
146 qcount++; /* unescaped '"' */
147 s++;
148 bcount=0;
149 /* consecutive quotes, see comment in copying code below */
150 while (*s=='"')
151 {
152 qcount++;
153 s++;
154 }
155 qcount=qcount % 3;
156 if (qcount==2)
157 qcount=0;
158 }
159 else
160 {
161 /* a regular character */
162 bcount=0;
163 s++;
164 }
165 }
166
167 /* Allocate in a single lump, the string array, and the strings that go
168 * with it. This way the caller can make a single LocalFree() call to free
169 * both, as per MSDN.
170 */
171 argv=(LPWSTR *)LocalAlloc(LMEM_FIXED, argc*sizeof(LPWSTR)+(strlenW(lpCmdline)+1)*sizeof(WCHAR));
172 if (!argv)
173 return NULL;
174 cmdline=(LPWSTR)(argv+argc);
175 strcpyW(cmdline, lpCmdline);
176
177 /* --- Then split and copy the arguments */
178 argv[0]=d=cmdline;
179 argc=1;
180 /* The first argument, the executable path, follows special rules */
181 if (*d=='"')
182 {
183 /* The executable path ends at the next quote, no matter what */
184 s=d+1;
185 while (*s)
186 {
187 if (*s=='"')
188 {
189 s++;
190 break;
191 }
192 *d++=*s++;
193 }
194 }
195 else
196 {
197 /* The executable path ends at the next space, no matter what */
198 while (*d && *d!=' ' && *d!='\t')
199 d++;
200 s=d;
201 if (*s)
202 s++;
203 }
204 /* close the executable path */
205 *d++=0;
206 /* skip to the first argument and initialize it if any */
207 while (*s==' ' || *s=='\t')
208 s++;
209 if (!*s)
210 {
211 /* There are no parameters so we are all done */
212 *numargs=argc;
213 return argv;
214 }
215
216 /* Split and copy the remaining arguments */
217 argv[argc++]=d;
218 qcount=bcount=0;
219 while (*s)
220 {
221 if ((*s==' ' || *s=='\t') && qcount==0)
222 {
223 /* close the argument */
224 *d++=0;
225 bcount=0;
226
227 /* skip to the next one and initialize it if any */
228 do {
229 s++;
230 } while (*s==' ' || *s=='\t');
231 if (*s)
232 argv[argc++]=d;
233 }
234 else if (*s=='\\')
235 {
236 *d++=*s++;
237 bcount++;
238 }
239 else if (*s=='"')
240 {
241 if ((bcount & 1)==0)
242 {
243 /* Preceded by an even number of '\', this is half that
244 * number of '\', plus a quote which we erase.
245 */
246 d-=bcount/2;
247 qcount++;
248 }
249 else
250 {
251 /* Preceded by an odd number of '\', this is half that
252 * number of '\' followed by a '"'
253 */
254 d=d-bcount/2-1;
255 *d++='"';
256 }
257 s++;
258 bcount=0;
259 /* Now count the number of consecutive quotes. Note that qcount
260 * already takes into account the opening quote if any, as well as
261 * the quote that lead us here.
262 */
263 while (*s=='"')
264 {
265 if (++qcount==3)
266 {
267 *d++='"';
268 qcount=0;
269 }
270 s++;
271 }
272 if (qcount==2)
273 qcount=0;
274 }
275 else
276 {
277 /* a regular character */
278 *d++=*s++;
279 bcount=0;
280 }
281 }
282 *d='\0';
283 *numargs=argc;
284
285 return argv;
286 }
287
288 static DWORD shgfi_get_exe_type(LPCWSTR szFullPath)
289 {
290 BOOL status = FALSE;
291 HANDLE hfile;
292 DWORD BinaryType;
293 IMAGE_DOS_HEADER mz_header;
294 IMAGE_NT_HEADERS nt;
295 DWORD len;
296 char magic[4];
297
298 status = GetBinaryTypeW (szFullPath, &BinaryType);
299 if (!status)
300 return 0;
301 if (BinaryType == SCS_DOS_BINARY || BinaryType == SCS_PIF_BINARY)
302 return 0x4d5a;
303
304 hfile = CreateFileW( szFullPath, GENERIC_READ, FILE_SHARE_READ,
305 NULL, OPEN_EXISTING, 0, 0 );
306 if ( hfile == INVALID_HANDLE_VALUE )
307 return 0;
308
309 /*
310 * The next section is adapted from MODULE_GetBinaryType, as we need
311 * to examine the image header to get OS and version information. We
312 * know from calling GetBinaryTypeA that the image is valid and either
313 * an NE or PE, so much error handling can be omitted.
314 * Seek to the start of the file and read the header information.
315 */
316
317 SetFilePointer( hfile, 0, NULL, SEEK_SET );
318 ReadFile( hfile, &mz_header, sizeof(mz_header), &len, NULL );
319
320 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
321 ReadFile( hfile, magic, sizeof(magic), &len, NULL );
322
323 if ( *(DWORD*)magic == IMAGE_NT_SIGNATURE )
324 {
325 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
326 ReadFile( hfile, &nt, sizeof(nt), &len, NULL );
327 CloseHandle( hfile );
328
329 /* DLL files are not executable and should return 0 */
330 if (nt.FileHeader.Characteristics & IMAGE_FILE_DLL)
331 return 0;
332
333 if (nt.OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI)
334 {
335 return IMAGE_NT_SIGNATURE |
336 (nt.OptionalHeader.MajorSubsystemVersion << 24) |
337 (nt.OptionalHeader.MinorSubsystemVersion << 16);
338 }
339 return IMAGE_NT_SIGNATURE;
340 }
341 else if ( *(WORD*)magic == IMAGE_OS2_SIGNATURE )
342 {
343 IMAGE_OS2_HEADER ne;
344 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
345 ReadFile( hfile, &ne, sizeof(ne), &len, NULL );
346 CloseHandle( hfile );
347
348 if (ne.ne_exetyp == 2)
349 return IMAGE_OS2_SIGNATURE | (ne.ne_expver << 16);
350 return 0;
351 }
352 CloseHandle( hfile );
353 return 0;
354 }
355
356 /*************************************************************************
357 * SHELL_IsShortcut [internal]
358 *
359 * Decide if an item id list points to a shell shortcut
360 */
361 BOOL SHELL_IsShortcut(LPCITEMIDLIST pidlLast)
362 {
363 char szTemp[MAX_PATH];
364 HKEY keyCls;
365 BOOL ret = FALSE;
366
367 if (_ILGetExtension(pidlLast, szTemp, MAX_PATH) &&
368 HCR_MapTypeToValueA(szTemp, szTemp, MAX_PATH, TRUE))
369 {
370 if (ERROR_SUCCESS == RegOpenKeyExA(HKEY_CLASSES_ROOT, szTemp, 0, KEY_QUERY_VALUE, &keyCls))
371 {
372 if (ERROR_SUCCESS == RegQueryValueExA(keyCls, "IsShortcut", NULL, NULL, NULL, NULL))
373 ret = TRUE;
374
375 RegCloseKey(keyCls);
376 }
377 }
378
379 return ret;
380 }
381
382 #define SHGFI_KNOWN_FLAGS \
383 (SHGFI_SMALLICON | SHGFI_OPENICON | SHGFI_SHELLICONSIZE | SHGFI_PIDL | \
384 SHGFI_USEFILEATTRIBUTES | SHGFI_ADDOVERLAYS | SHGFI_OVERLAYINDEX | \
385 SHGFI_ICON | SHGFI_DISPLAYNAME | SHGFI_TYPENAME | SHGFI_ATTRIBUTES | \
386 SHGFI_ICONLOCATION | SHGFI_EXETYPE | SHGFI_SYSICONINDEX | \
387 SHGFI_LINKOVERLAY | SHGFI_SELECTED | SHGFI_ATTR_SPECIFIED)
388
389 /*************************************************************************
390 * SHGetFileInfoW [SHELL32.@]
391 *
392 */
393 DWORD_PTR WINAPI SHGetFileInfoW(LPCWSTR path,DWORD dwFileAttributes,
394 SHFILEINFOW *psfi, UINT sizeofpsfi, UINT flags )
395 {
396 WCHAR szLocation[MAX_PATH], szFullPath[MAX_PATH];
397 int iIndex;
398 DWORD_PTR ret = TRUE;
399 DWORD dwAttributes = 0;
400 CComPtr<IShellFolder> psfParent;
401 CComPtr<IExtractIconW> pei;
402 LPITEMIDLIST pidlLast = NULL, pidl = NULL;
403 HRESULT hr = S_OK;
404 BOOL IconNotYetLoaded=TRUE;
405 UINT uGilFlags = 0;
406
407 TRACE("%s fattr=0x%x sfi=%p(attr=0x%08x) size=0x%x flags=0x%x\n",
408 (flags & SHGFI_PIDL)? "pidl" : debugstr_w(path), dwFileAttributes,
409 psfi, psfi->dwAttributes, sizeofpsfi, flags);
410
411 if (!path)
412 return FALSE;
413
414 /* windows initializes these values regardless of the flags */
415 if (psfi != NULL)
416 {
417 psfi->szDisplayName[0] = '\0';
418 psfi->szTypeName[0] = '\0';
419 psfi->iIcon = 0;
420 }
421
422 if (!(flags & SHGFI_PIDL))
423 {
424 /* SHGetFileInfo should work with absolute and relative paths */
425 if (PathIsRelativeW(path))
426 {
427 GetCurrentDirectoryW(MAX_PATH, szLocation);
428 PathCombineW(szFullPath, szLocation, path);
429 }
430 else
431 {
432 lstrcpynW(szFullPath, path, MAX_PATH);
433 }
434 }
435
436 if (flags & SHGFI_EXETYPE)
437 {
438 if (flags != SHGFI_EXETYPE)
439 return 0;
440 return shgfi_get_exe_type(szFullPath);
441 }
442
443 /*
444 * psfi is NULL normally to query EXE type. If it is NULL, none of the
445 * below makes sense anyway. Windows allows this and just returns FALSE
446 */
447 if (psfi == NULL)
448 return FALSE;
449
450 /*
451 * translate the path into a pidl only when SHGFI_USEFILEATTRIBUTES
452 * is not specified.
453 * The pidl functions fail on not existing file names
454 */
455
456 if (flags & SHGFI_PIDL)
457 {
458 pidl = ILClone((LPCITEMIDLIST)path);
459 }
460 else if (!(flags & SHGFI_USEFILEATTRIBUTES))
461 {
462 hr = SHILCreateFromPathW(szFullPath, &pidl, &dwAttributes);
463 }
464
465 if ((flags & SHGFI_PIDL) || !(flags & SHGFI_USEFILEATTRIBUTES))
466 {
467 /* get the parent shellfolder */
468 if (pidl)
469 {
470 hr = SHBindToParent( pidl, IID_IShellFolder, (LPVOID*)&psfParent,
471 (LPCITEMIDLIST*)&pidlLast );
472 if (SUCCEEDED(hr))
473 pidlLast = ILClone(pidlLast);
474 ILFree(pidl);
475 }
476 else
477 {
478 ERR("pidl is null!\n");
479 return FALSE;
480 }
481 }
482
483 /* get the attributes of the child */
484 if (SUCCEEDED(hr) && (flags & SHGFI_ATTRIBUTES))
485 {
486 if (!(flags & SHGFI_ATTR_SPECIFIED))
487 {
488 psfi->dwAttributes = 0xffffffff;
489 }
490 if (psfParent != NULL)
491 psfParent->GetAttributesOf(1, (LPCITEMIDLIST*)&pidlLast,
492 &(psfi->dwAttributes) );
493 }
494
495 /* get the displayname */
496 if (SUCCEEDED(hr) && (flags & SHGFI_DISPLAYNAME))
497 {
498 if (flags & SHGFI_USEFILEATTRIBUTES)
499 {
500 wcscpy (psfi->szDisplayName, PathFindFileNameW(szFullPath));
501 }
502 else
503 {
504 STRRET str;
505 hr = psfParent->GetDisplayNameOf(pidlLast,
506 SHGDN_INFOLDER, &str);
507 StrRetToStrNW (psfi->szDisplayName, MAX_PATH, &str, pidlLast);
508 }
509 }
510
511 /* get the type name */
512 if (SUCCEEDED(hr) && (flags & SHGFI_TYPENAME))
513 {
514 static const WCHAR szFile[] = { 'F','i','l','e',0 };
515 static const WCHAR szDashFile[] = { '-','f','i','l','e',0 };
516
517 if (!(flags & SHGFI_USEFILEATTRIBUTES))
518 {
519 char ftype[80];
520
521 _ILGetFileType(pidlLast, ftype, 80);
522 MultiByteToWideChar(CP_ACP, 0, ftype, -1, psfi->szTypeName, 80 );
523 }
524 else
525 {
526 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
527 wcscat (psfi->szTypeName, szFile);
528 else
529 {
530 WCHAR sTemp[64];
531
532 wcscpy(sTemp,PathFindExtensionW(szFullPath));
533 if (!( HCR_MapTypeToValueW(sTemp, sTemp, 64, TRUE) &&
534 HCR_MapTypeToValueW(sTemp, psfi->szTypeName, 80, FALSE )))
535 {
536 lstrcpynW (psfi->szTypeName, sTemp, 64);
537 wcscat (psfi->szTypeName, szDashFile);
538 }
539 }
540 }
541 }
542
543 /* ### icons ###*/
544 if (flags & SHGFI_OPENICON)
545 uGilFlags |= GIL_OPENICON;
546
547 if (flags & SHGFI_LINKOVERLAY)
548 uGilFlags |= GIL_FORSHORTCUT;
549 else if ((flags&SHGFI_ADDOVERLAYS) ||
550 (flags&(SHGFI_ICON|SHGFI_SMALLICON))==SHGFI_ICON)
551 {
552 if (SHELL_IsShortcut(pidlLast))
553 uGilFlags |= GIL_FORSHORTCUT;
554 }
555
556 if (flags & SHGFI_OVERLAYINDEX)
557 FIXME("SHGFI_OVERLAYINDEX unhandled\n");
558
559 if (flags & SHGFI_SELECTED)
560 FIXME("set icon to selected, stub\n");
561
562 if (flags & SHGFI_SHELLICONSIZE)
563 FIXME("set icon to shell size, stub\n");
564
565 /* get the iconlocation */
566 if (SUCCEEDED(hr) && (flags & SHGFI_ICONLOCATION ))
567 {
568 UINT uDummy,uFlags;
569
570 if (flags & SHGFI_USEFILEATTRIBUTES)
571 {
572 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
573 {
574 wcscpy(psfi->szDisplayName, swShell32Name);
575 psfi->iIcon = -IDI_SHELL_FOLDER;
576 }
577 else
578 {
579 WCHAR* szExt;
580 static const WCHAR p1W[] = {'%','1',0};
581 WCHAR sTemp [MAX_PATH];
582
583 szExt = PathFindExtensionW(szFullPath);
584 TRACE("szExt=%s\n", debugstr_w(szExt));
585 if ( szExt &&
586 HCR_MapTypeToValueW(szExt, sTemp, MAX_PATH, TRUE) &&
587 HCR_GetDefaultIconW(sTemp, sTemp, MAX_PATH, &psfi->iIcon))
588 {
589 if (lstrcmpW(p1W, sTemp))
590 wcscpy(psfi->szDisplayName, sTemp);
591 else
592 {
593 /* the icon is in the file */
594 wcscpy(psfi->szDisplayName, szFullPath);
595 }
596 }
597 else
598 ret = FALSE;
599 }
600 }
601 else
602 {
603 hr = psfParent->GetUIObjectOf(0, 1,
604 (LPCITEMIDLIST*)&pidlLast, IID_IExtractIconW,
605 &uDummy, (LPVOID*)&pei);
606 if (SUCCEEDED(hr))
607 {
608 hr = pei->GetIconLocation(uGilFlags,
609 szLocation, MAX_PATH, &iIndex, &uFlags);
610
611 if (uFlags & GIL_NOTFILENAME)
612 ret = FALSE;
613 else
614 {
615 wcscpy (psfi->szDisplayName, szLocation);
616 psfi->iIcon = iIndex;
617 }
618 }
619 }
620 }
621
622 /* get icon index (or load icon)*/
623 if (SUCCEEDED(hr) && (flags & (SHGFI_ICON | SHGFI_SYSICONINDEX)))
624 {
625 if (flags & SHGFI_USEFILEATTRIBUTES && !(flags & SHGFI_PIDL))
626 {
627 WCHAR sTemp [MAX_PATH];
628 WCHAR * szExt;
629 int icon_idx=0;
630
631 lstrcpynW(sTemp, szFullPath, MAX_PATH);
632
633 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
634 psfi->iIcon = SIC_GetIconIndex(swShell32Name, -IDI_SHELL_FOLDER, 0);
635 else
636 {
637 static const WCHAR p1W[] = {'%','1',0};
638
639 psfi->iIcon = 0;
640 szExt = PathFindExtensionW(sTemp);
641 if ( szExt &&
642 HCR_MapTypeToValueW(szExt, sTemp, MAX_PATH, TRUE) &&
643 HCR_GetDefaultIconW(sTemp, sTemp, MAX_PATH, &icon_idx))
644 {
645 if (!lstrcmpW(p1W,sTemp)) /* icon is in the file */
646 wcscpy(sTemp, szFullPath);
647
648 if (flags & SHGFI_SYSICONINDEX)
649 {
650 psfi->iIcon = SIC_GetIconIndex(sTemp,icon_idx,0);
651 if (psfi->iIcon == -1)
652 psfi->iIcon = 0;
653 }
654 else
655 {
656 UINT ret;
657 if (flags & SHGFI_SMALLICON)
658 ret = PrivateExtractIconsW( sTemp,icon_idx,
659 GetSystemMetrics( SM_CXSMICON ),
660 GetSystemMetrics( SM_CYSMICON ),
661 &psfi->hIcon, 0, 1, 0);
662 else
663 ret = PrivateExtractIconsW( sTemp, icon_idx,
664 GetSystemMetrics( SM_CXICON),
665 GetSystemMetrics( SM_CYICON),
666 &psfi->hIcon, 0, 1, 0);
667
668 if (ret != 0 && ret != 0xFFFFFFFF)
669 {
670 IconNotYetLoaded=FALSE;
671 psfi->iIcon = icon_idx;
672 }
673 }
674 }
675 }
676 }
677 else
678 {
679 if (!(PidlToSicIndex(psfParent, pidlLast, !(flags & SHGFI_SMALLICON),
680 uGilFlags, &(psfi->iIcon))))
681 {
682 ret = FALSE;
683 }
684 }
685 if (ret && (flags & SHGFI_SYSICONINDEX))
686 {
687 if (flags & SHGFI_SMALLICON)
688 ret = (DWORD_PTR) ShellSmallIconList;
689 else
690 ret = (DWORD_PTR) ShellBigIconList;
691 }
692 }
693
694 /* icon handle */
695 if (SUCCEEDED(hr) && (flags & SHGFI_ICON) && IconNotYetLoaded)
696 {
697 if (flags & SHGFI_SMALLICON)
698 psfi->hIcon = ImageList_GetIcon( ShellSmallIconList, psfi->iIcon, ILD_NORMAL);
699 else
700 psfi->hIcon = ImageList_GetIcon( ShellBigIconList, psfi->iIcon, ILD_NORMAL);
701 }
702
703 if (flags & ~SHGFI_KNOWN_FLAGS)
704 FIXME("unknown flags %08x\n", flags & ~SHGFI_KNOWN_FLAGS);
705
706 if (hr != S_OK)
707 ret = FALSE;
708
709 SHFree(pidlLast);
710
711 #ifdef MORE_DEBUG
712 TRACE ("icon=%p index=0x%08x attr=0x%08x name=%s type=%s ret=0x%08lx\n",
713 psfi->hIcon, psfi->iIcon, psfi->dwAttributes,
714 debugstr_w(psfi->szDisplayName), debugstr_w(psfi->szTypeName), ret);
715 #endif
716
717 return ret;
718 }
719
720 /*************************************************************************
721 * SHGetFileInfoA [SHELL32.@]
722 *
723 * Note:
724 * MSVBVM60.__vbaNew2 expects this function to return a value in range
725 * 1 .. 0x7fff when the function succeeds and flags does not contain
726 * SHGFI_EXETYPE or SHGFI_SYSICONINDEX (see bug 7701)
727 */
728 DWORD_PTR WINAPI SHGetFileInfoA(LPCSTR path,DWORD dwFileAttributes,
729 SHFILEINFOA *psfi, UINT sizeofpsfi,
730 UINT flags )
731 {
732 INT len;
733 LPWSTR temppath = NULL;
734 LPCWSTR pathW;
735 DWORD ret;
736 SHFILEINFOW temppsfi;
737
738 if (flags & SHGFI_PIDL)
739 {
740 /* path contains a pidl */
741 pathW = (LPCWSTR)path;
742 }
743 else
744 {
745 len = MultiByteToWideChar(CP_ACP, 0, path, -1, NULL, 0);
746 temppath = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
747 MultiByteToWideChar(CP_ACP, 0, path, -1, temppath, len);
748 pathW = temppath;
749 }
750
751 if (psfi && (flags & SHGFI_ATTR_SPECIFIED))
752 temppsfi.dwAttributes=psfi->dwAttributes;
753
754 if (psfi == NULL)
755 ret = SHGetFileInfoW(pathW, dwFileAttributes, NULL, sizeof(temppsfi), flags);
756 else
757 ret = SHGetFileInfoW(pathW, dwFileAttributes, &temppsfi, sizeof(temppsfi), flags);
758
759 if (psfi)
760 {
761 if(flags & SHGFI_ICON)
762 psfi->hIcon=temppsfi.hIcon;
763 if(flags & (SHGFI_SYSICONINDEX|SHGFI_ICON|SHGFI_ICONLOCATION))
764 psfi->iIcon=temppsfi.iIcon;
765 if(flags & SHGFI_ATTRIBUTES)
766 psfi->dwAttributes=temppsfi.dwAttributes;
767 if(flags & (SHGFI_DISPLAYNAME|SHGFI_ICONLOCATION))
768 {
769 WideCharToMultiByte(CP_ACP, 0, temppsfi.szDisplayName, -1,
770 psfi->szDisplayName, sizeof(psfi->szDisplayName), NULL, NULL);
771 }
772 if(flags & SHGFI_TYPENAME)
773 {
774 WideCharToMultiByte(CP_ACP, 0, temppsfi.szTypeName, -1,
775 psfi->szTypeName, sizeof(psfi->szTypeName), NULL, NULL);
776 }
777 }
778
779 HeapFree(GetProcessHeap(), 0, temppath);
780
781 return ret;
782 }
783
784 /*************************************************************************
785 * DuplicateIcon [SHELL32.@]
786 */
787 EXTERN_C HICON WINAPI DuplicateIcon( HINSTANCE hInstance, HICON hIcon)
788 {
789 ICONINFO IconInfo;
790 HICON hDupIcon = 0;
791
792 TRACE("%p %p\n", hInstance, hIcon);
793
794 if (GetIconInfo(hIcon, &IconInfo))
795 {
796 hDupIcon = CreateIconIndirect(&IconInfo);
797
798 /* clean up hbmMask and hbmColor */
799 DeleteObject(IconInfo.hbmMask);
800 DeleteObject(IconInfo.hbmColor);
801 }
802
803 return hDupIcon;
804 }
805
806 /*************************************************************************
807 * ExtractIconA [SHELL32.@]
808 */
809 HICON WINAPI ExtractIconA(HINSTANCE hInstance, LPCSTR lpszFile, UINT nIconIndex)
810 {
811 HICON ret;
812 INT len = MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, NULL, 0);
813 LPWSTR lpwstrFile = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
814
815 TRACE("%p %s %d\n", hInstance, lpszFile, nIconIndex);
816
817 MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, lpwstrFile, len);
818 ret = ExtractIconW(hInstance, lpwstrFile, nIconIndex);
819 HeapFree(GetProcessHeap(), 0, lpwstrFile);
820
821 return ret;
822 }
823
824 /*************************************************************************
825 * ExtractIconW [SHELL32.@]
826 */
827 HICON WINAPI ExtractIconW(HINSTANCE hInstance, LPCWSTR lpszFile, UINT nIconIndex)
828 {
829 HICON hIcon = NULL;
830 UINT ret;
831 UINT cx = GetSystemMetrics(SM_CXICON), cy = GetSystemMetrics(SM_CYICON);
832
833 TRACE("%p %s %d\n", hInstance, debugstr_w(lpszFile), nIconIndex);
834
835 if (nIconIndex == 0xFFFFFFFF)
836 {
837 ret = PrivateExtractIconsW(lpszFile, 0, cx, cy, NULL, NULL, 0, LR_DEFAULTCOLOR);
838 if (ret != 0xFFFFFFFF && ret)
839 return (HICON)(UINT_PTR)ret;
840 return NULL;
841 }
842 else
843 ret = PrivateExtractIconsW(lpszFile, nIconIndex, cx, cy, &hIcon, NULL, 1, LR_DEFAULTCOLOR);
844
845 if (ret == 0xFFFFFFFF)
846 return (HICON)1;
847 else if (ret > 0 && hIcon)
848 return hIcon;
849
850 return NULL;
851 }
852
853 /*************************************************************************
854 * Printer_LoadIconsW [SHELL32.205]
855 */
856 EXTERN_C VOID WINAPI Printer_LoadIconsW(LPCWSTR wsPrinterName, HICON * pLargeIcon, HICON * pSmallIcon)
857 {
858 INT iconindex=IDI_SHELL_PRINTERS_FOLDER;
859
860 TRACE("(%s, %p, %p)\n", debugstr_w(wsPrinterName), pLargeIcon, pSmallIcon);
861
862 /* We should check if wsPrinterName is
863 1. the Default Printer or not
864 2. connected or not
865 3. a Local Printer or a Network-Printer
866 and use different Icons
867 */
868 if((wsPrinterName != NULL) && (wsPrinterName[0] != 0))
869 {
870 FIXME("(select Icon by PrinterName %s not implemented)\n", debugstr_w(wsPrinterName));
871 }
872
873 if(pLargeIcon != NULL)
874 *pLargeIcon = (HICON)LoadImageW(shell32_hInstance,
875 (LPCWSTR) MAKEINTRESOURCE(iconindex), IMAGE_ICON,
876 0, 0, LR_DEFAULTCOLOR|LR_DEFAULTSIZE);
877
878 if(pSmallIcon != NULL)
879 *pSmallIcon = (HICON)LoadImageW(shell32_hInstance,
880 (LPCWSTR) MAKEINTRESOURCE(iconindex), IMAGE_ICON,
881 16, 16, LR_DEFAULTCOLOR);
882 }
883
884 /*************************************************************************
885 * Printers_RegisterWindowW [SHELL32.213]
886 * used by "printui.dll":
887 * find the Window of the given Type for the specific Printer and
888 * return the already existent hwnd or open a new window
889 */
890 EXTERN_C BOOL WINAPI Printers_RegisterWindowW(LPCWSTR wsPrinter, DWORD dwType,
891 HANDLE * phClassPidl, HWND * phwnd)
892 {
893 FIXME("(%s, %x, %p (%p), %p (%p)) stub!\n", debugstr_w(wsPrinter), dwType,
894 phClassPidl, (phClassPidl != NULL) ? *(phClassPidl) : NULL,
895 phwnd, (phwnd != NULL) ? *(phwnd) : NULL);
896
897 return FALSE;
898 }
899
900 /*************************************************************************
901 * Printers_UnregisterWindow [SHELL32.214]
902 */
903 EXTERN_C VOID WINAPI Printers_UnregisterWindow(HANDLE hClassPidl, HWND hwnd)
904 {
905 FIXME("(%p, %p) stub!\n", hClassPidl, hwnd);
906 }
907
908 /*************************************************************************/
909
910 typedef struct
911 {
912 LPCWSTR szApp;
913 LPCWSTR szOtherStuff;
914 HICON hIcon;
915 } ABOUT_INFO;
916
917 #define DROP_FIELD_TOP (-15)
918 #define DROP_FIELD_HEIGHT 15
919
920 /*************************************************************************
921 * SHAppBarMessage [SHELL32.@]
922 */
923 UINT_PTR WINAPI SHAppBarMessage(DWORD msg, PAPPBARDATA data)
924 {
925 int width=data->rc.right - data->rc.left;
926 int height=data->rc.bottom - data->rc.top;
927 RECT rec=data->rc;
928
929 TRACE("msg=%d, data={cb=%d, hwnd=%p, callback=%x, edge=%d, rc=%s, lparam=%lx}\n",
930 msg, data->cbSize, data->hWnd, data->uCallbackMessage, data->uEdge,
931 wine_dbgstr_rect(&data->rc), data->lParam);
932
933 switch (msg)
934 {
935 case ABM_GETSTATE:
936 return ABS_ALWAYSONTOP | ABS_AUTOHIDE;
937
938 case ABM_GETTASKBARPOS:
939 GetWindowRect(data->hWnd, &rec);
940 data->rc=rec;
941 return TRUE;
942
943 case ABM_ACTIVATE:
944 SetActiveWindow(data->hWnd);
945 return TRUE;
946
947 case ABM_GETAUTOHIDEBAR:
948 return 0; /* pretend there is no autohide bar */
949
950 case ABM_NEW:
951 /* cbSize, hWnd, and uCallbackMessage are used. All other ignored */
952 SetWindowPos(data->hWnd,HWND_TOP,0,0,0,0,SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE);
953 return TRUE;
954
955 case ABM_QUERYPOS:
956 GetWindowRect(data->hWnd, &(data->rc));
957 return TRUE;
958
959 case ABM_REMOVE:
960 FIXME("ABM_REMOVE broken\n");
961 /* FIXME: this is wrong; should it be DestroyWindow instead? */
962 /*CloseHandle(data->hWnd);*/
963 return TRUE;
964
965 case ABM_SETAUTOHIDEBAR:
966 SetWindowPos(data->hWnd,HWND_TOP,rec.left+1000,rec.top,
967 width,height,SWP_SHOWWINDOW);
968 return TRUE;
969
970 case ABM_SETPOS:
971 data->uEdge=(ABE_RIGHT | ABE_LEFT);
972 SetWindowPos(data->hWnd,HWND_TOP,data->rc.left,data->rc.top,
973 width,height,SWP_SHOWWINDOW);
974 return TRUE;
975
976 case ABM_WINDOWPOSCHANGED:
977 return TRUE;
978 }
979
980 return FALSE;
981 }
982
983 /*************************************************************************
984 * SHHelpShortcuts_RunDLLA [SHELL32.@]
985 *
986 */
987 EXTERN_C DWORD WINAPI SHHelpShortcuts_RunDLLA(DWORD dwArg1, DWORD dwArg2, DWORD dwArg3, DWORD dwArg4)
988 {
989 FIXME("(%x, %x, %x, %x) stub!\n", dwArg1, dwArg2, dwArg3, dwArg4);
990 return 0;
991 }
992
993 /*************************************************************************
994 * SHHelpShortcuts_RunDLLA [SHELL32.@]
995 *
996 */
997 EXTERN_C DWORD WINAPI SHHelpShortcuts_RunDLLW(DWORD dwArg1, DWORD dwArg2, DWORD dwArg3, DWORD dwArg4)
998 {
999 FIXME("(%x, %x, %x, %x) stub!\n", dwArg1, dwArg2, dwArg3, dwArg4);
1000 return 0;
1001 }
1002
1003 /*************************************************************************
1004 * SHLoadInProc [SHELL32.@]
1005 * Create an instance of specified object class from within
1006 * the shell process and release it immediately
1007 */
1008 EXTERN_C HRESULT WINAPI SHLoadInProc (REFCLSID rclsid)
1009 {
1010 CComPtr<IUnknown> ptr;
1011
1012 TRACE("%s\n", debugstr_guid(&rclsid));
1013
1014 CoCreateInstance(rclsid, NULL, CLSCTX_INPROC_SERVER, IID_IUnknown, (void **)&ptr);
1015 if (ptr)
1016 return NOERROR;
1017 return DISP_E_MEMBERNOTFOUND;
1018 }
1019
1020 static VOID SetRegTextData(HWND hWnd, HKEY hKey, LPCWSTR Value, UINT uID)
1021 {
1022 DWORD dwBufferSize;
1023 DWORD dwType;
1024 LPWSTR lpBuffer;
1025
1026 if( RegQueryValueExW(hKey, Value, NULL, &dwType, NULL, &dwBufferSize) == ERROR_SUCCESS )
1027 {
1028 if(dwType == REG_SZ)
1029 {
1030 lpBuffer = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, dwBufferSize);
1031
1032 if(lpBuffer)
1033 {
1034 if( RegQueryValueExW(hKey, Value, NULL, &dwType, (LPBYTE)lpBuffer, &dwBufferSize) == ERROR_SUCCESS )
1035 {
1036 SetDlgItemTextW(hWnd, uID, lpBuffer);
1037 }
1038
1039 HeapFree(GetProcessHeap(), 0, lpBuffer);
1040 }
1041 }
1042 }
1043 }
1044
1045 INT_PTR CALLBACK AboutAuthorsDlgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
1046 {
1047 switch(msg)
1048 {
1049 case WM_INITDIALOG:
1050 {
1051 const char* const *pstr = SHELL_Authors;
1052
1053 // Add the authors to the list
1054 SendDlgItemMessageW( hWnd, IDC_ABOUT_AUTHORS_LISTBOX, WM_SETREDRAW, FALSE, 0 );
1055
1056 while (*pstr)
1057 {
1058 WCHAR name[64];
1059
1060 /* authors list is in utf-8 format */
1061 MultiByteToWideChar( CP_UTF8, 0, *pstr, -1, name, sizeof(name)/sizeof(WCHAR) );
1062 SendDlgItemMessageW( hWnd, IDC_ABOUT_AUTHORS_LISTBOX, LB_ADDSTRING, (WPARAM)-1, (LPARAM)name );
1063 pstr++;
1064 }
1065
1066 SendDlgItemMessageW( hWnd, IDC_ABOUT_AUTHORS_LISTBOX, WM_SETREDRAW, TRUE, 0 );
1067
1068 return TRUE;
1069 }
1070 }
1071
1072 return FALSE;
1073 }
1074 /*************************************************************************
1075 * AboutDlgProc (internal)
1076 */
1077 INT_PTR CALLBACK AboutDlgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
1078 {
1079 static DWORD cxLogoBmp;
1080 static DWORD cyLogoBmp;
1081 static HBITMAP hLogoBmp;
1082 static HWND hWndAuthors;
1083
1084 switch(msg)
1085 {
1086 case WM_INITDIALOG:
1087 {
1088 ABOUT_INFO *info = (ABOUT_INFO *)lParam;
1089
1090 if (info)
1091 {
1092 const WCHAR szRegKey[] = L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion";
1093 HKEY hRegKey;
1094 MEMORYSTATUSEX MemStat;
1095 WCHAR szAppTitle[512];
1096 WCHAR szAppTitleTemplate[512];
1097 WCHAR szAuthorsText[20];
1098
1099 // Preload the ROS bitmap
1100 hLogoBmp = (HBITMAP)LoadImage(shell32_hInstance, MAKEINTRESOURCE(IDB_SHELL_ABOUT_LOGO_24BPP), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
1101
1102 if(hLogoBmp)
1103 {
1104 BITMAP bmpLogo;
1105
1106 GetObject( hLogoBmp, sizeof(BITMAP), &bmpLogo );
1107
1108 cxLogoBmp = bmpLogo.bmWidth;
1109 cyLogoBmp = bmpLogo.bmHeight;
1110 }
1111
1112 // Set App-specific stuff (icon, app name, szOtherStuff string)
1113 SendDlgItemMessageW(hWnd, IDC_ABOUT_ICON, STM_SETICON, (WPARAM)info->hIcon, 0);
1114
1115 GetWindowTextW( hWnd, szAppTitleTemplate, sizeof(szAppTitleTemplate) / sizeof(WCHAR) );
1116 swprintf( szAppTitle, szAppTitleTemplate, info->szApp );
1117 SetWindowTextW( hWnd, szAppTitle );
1118
1119 SetDlgItemTextW( hWnd, IDC_ABOUT_APPNAME, info->szApp );
1120 SetDlgItemTextW( hWnd, IDC_ABOUT_OTHERSTUFF, info->szOtherStuff );
1121
1122 // Set the registered user and organization name
1123 if(RegOpenKeyExW( HKEY_LOCAL_MACHINE, szRegKey, 0, KEY_QUERY_VALUE, &hRegKey ) == ERROR_SUCCESS)
1124 {
1125 SetRegTextData( hWnd, hRegKey, L"RegisteredOwner", IDC_ABOUT_REG_USERNAME );
1126 SetRegTextData( hWnd, hRegKey, L"RegisteredOrganization", IDC_ABOUT_REG_ORGNAME );
1127
1128 RegCloseKey( hRegKey );
1129 }
1130
1131 // Set the value for the installed physical memory
1132 MemStat.dwLength = sizeof(MemStat);
1133 if( GlobalMemoryStatusEx(&MemStat) )
1134 {
1135 WCHAR szBuf[12];
1136
1137 if (MemStat.ullTotalPhys > 1024 * 1024 * 1024)
1138 {
1139 double dTotalPhys;
1140 WCHAR szDecimalSeparator[4];
1141 WCHAR szUnits[3];
1142
1143 // We're dealing with GBs or more
1144 MemStat.ullTotalPhys /= 1024 * 1024;
1145
1146 if (MemStat.ullTotalPhys > 1024 * 1024)
1147 {
1148 // We're dealing with TBs or more
1149 MemStat.ullTotalPhys /= 1024;
1150
1151 if (MemStat.ullTotalPhys > 1024 * 1024)
1152 {
1153 // We're dealing with PBs or more
1154 MemStat.ullTotalPhys /= 1024;
1155
1156 dTotalPhys = (double)MemStat.ullTotalPhys / 1024;
1157 wcscpy( szUnits, L"PB" );
1158 }
1159 else
1160 {
1161 dTotalPhys = (double)MemStat.ullTotalPhys / 1024;
1162 wcscpy( szUnits, L"TB" );
1163 }
1164 }
1165 else
1166 {
1167 dTotalPhys = (double)MemStat.ullTotalPhys / 1024;
1168 wcscpy( szUnits, L"GB" );
1169 }
1170
1171 // We need the decimal point of the current locale to display the RAM size correctly
1172 if (GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL,
1173 szDecimalSeparator,
1174 sizeof(szDecimalSeparator) / sizeof(WCHAR)) > 0)
1175 {
1176 UCHAR uDecimals;
1177 UINT uIntegral;
1178
1179 uIntegral = (UINT)dTotalPhys;
1180 uDecimals = (UCHAR)((UINT)(dTotalPhys * 100) - uIntegral * 100);
1181
1182 // Display the RAM size with 2 decimals
1183 swprintf(szBuf, L"%u%s%02u %s", uIntegral, szDecimalSeparator, uDecimals, szUnits);
1184 }
1185 }
1186 else
1187 {
1188 // We're dealing with MBs, don't show any decimals
1189 swprintf( szBuf, L"%u MB", (UINT)MemStat.ullTotalPhys / 1024 / 1024 );
1190 }
1191
1192 SetDlgItemTextW( hWnd, IDC_ABOUT_PHYSMEM, szBuf);
1193 }
1194
1195 // Add the Authors dialog
1196 hWndAuthors = CreateDialogW( shell32_hInstance, MAKEINTRESOURCEW(IDD_ABOUT_AUTHORS), hWnd, AboutAuthorsDlgProc );
1197 LoadStringW( shell32_hInstance, IDS_SHELL_ABOUT_AUTHORS, szAuthorsText, sizeof(szAuthorsText) / sizeof(WCHAR) );
1198 SetDlgItemTextW( hWnd, IDC_ABOUT_AUTHORS, szAuthorsText );
1199 }
1200
1201 return TRUE;
1202 }
1203
1204 case WM_PAINT:
1205 {
1206 if(hLogoBmp)
1207 {
1208 PAINTSTRUCT ps;
1209 HDC hdc;
1210 HDC hdcMem;
1211
1212 hdc = BeginPaint(hWnd, &ps);
1213 hdcMem = CreateCompatibleDC(hdc);
1214
1215 if(hdcMem)
1216 {
1217 SelectObject(hdcMem, hLogoBmp);
1218 BitBlt(hdc, 0, 0, cxLogoBmp, cyLogoBmp, hdcMem, 0, 0, SRCCOPY);
1219
1220 DeleteDC(hdcMem);
1221 }
1222
1223 EndPaint(hWnd, &ps);
1224 }
1225 }; break;
1226
1227 case WM_COMMAND:
1228 {
1229 switch(wParam)
1230 {
1231 case IDOK:
1232 case IDCANCEL:
1233 EndDialog(hWnd, TRUE);
1234 return TRUE;
1235
1236 case IDC_ABOUT_AUTHORS:
1237 {
1238 static BOOL bShowingAuthors = FALSE;
1239 WCHAR szAuthorsText[20];
1240
1241 if(bShowingAuthors)
1242 {
1243 LoadStringW( shell32_hInstance, IDS_SHELL_ABOUT_AUTHORS, szAuthorsText, sizeof(szAuthorsText) / sizeof(WCHAR) );
1244 ShowWindow( hWndAuthors, SW_HIDE );
1245 }
1246 else
1247 {
1248 LoadStringW( shell32_hInstance, IDS_SHELL_ABOUT_BACK, szAuthorsText, sizeof(szAuthorsText) / sizeof(WCHAR) );
1249 ShowWindow( hWndAuthors, SW_SHOW );
1250 }
1251
1252 SetDlgItemTextW( hWnd, IDC_ABOUT_AUTHORS, szAuthorsText );
1253 bShowingAuthors = !bShowingAuthors;
1254 return TRUE;
1255 }
1256 }
1257 }; break;
1258
1259 case WM_CLOSE:
1260 EndDialog(hWnd, TRUE);
1261 break;
1262 }
1263
1264 return FALSE;
1265 }
1266
1267
1268 /*************************************************************************
1269 * ShellAboutA [SHELL32.288]
1270 */
1271 BOOL WINAPI ShellAboutA( HWND hWnd, LPCSTR szApp, LPCSTR szOtherStuff, HICON hIcon )
1272 {
1273 BOOL ret;
1274 LPWSTR appW = NULL, otherW = NULL;
1275 int len;
1276
1277 if (szApp)
1278 {
1279 len = MultiByteToWideChar(CP_ACP, 0, szApp, -1, NULL, 0);
1280 appW = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1281 MultiByteToWideChar(CP_ACP, 0, szApp, -1, appW, len);
1282 }
1283 if (szOtherStuff)
1284 {
1285 len = MultiByteToWideChar(CP_ACP, 0, szOtherStuff, -1, NULL, 0);
1286 otherW = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1287 MultiByteToWideChar(CP_ACP, 0, szOtherStuff, -1, otherW, len);
1288 }
1289
1290 ret = ShellAboutW(hWnd, appW, otherW, hIcon);
1291
1292 HeapFree(GetProcessHeap(), 0, otherW);
1293 HeapFree(GetProcessHeap(), 0, appW);
1294 return ret;
1295 }
1296
1297
1298 /*************************************************************************
1299 * ShellAboutW [SHELL32.289]
1300 */
1301 BOOL WINAPI ShellAboutW( HWND hWnd, LPCWSTR szApp, LPCWSTR szOtherStuff,
1302 HICON hIcon )
1303 {
1304 ABOUT_INFO info;
1305 HRSRC hRes;
1306 DLGTEMPLATE *DlgTemplate;
1307 BOOL bRet;
1308
1309 TRACE("\n");
1310
1311 // DialogBoxIndirectParamW will be called with the hInstance of the calling application, so we have to preload the dialog template
1312 hRes = FindResourceW(shell32_hInstance, MAKEINTRESOURCEW(IDD_ABOUT), (LPWSTR)RT_DIALOG);
1313 if(!hRes)
1314 return FALSE;
1315
1316 DlgTemplate = (DLGTEMPLATE *)LoadResource(shell32_hInstance, hRes);
1317 if(!DlgTemplate)
1318 return FALSE;
1319
1320 info.szApp = szApp;
1321 info.szOtherStuff = szOtherStuff;
1322 info.hIcon = hIcon ? hIcon : LoadIconW( 0, (LPWSTR)IDI_WINLOGO );
1323
1324 bRet = DialogBoxIndirectParamW((HINSTANCE)GetWindowLongPtrW( hWnd, GWLP_HINSTANCE ),
1325 DlgTemplate, hWnd, AboutDlgProc, (LPARAM)&info );
1326 return bRet;
1327 }
1328
1329 /*************************************************************************
1330 * FreeIconList (SHELL32.@)
1331 */
1332 EXTERN_C void WINAPI FreeIconList( DWORD dw )
1333 {
1334 FIXME("%x: stub\n",dw);
1335 }
1336
1337 /*************************************************************************
1338 * SHLoadNonloadedIconOverlayIdentifiers (SHELL32.@)
1339 */
1340 EXTERN_C HRESULT WINAPI SHLoadNonloadedIconOverlayIdentifiers(VOID)
1341 {
1342 FIXME("stub\n");
1343 return S_OK;
1344 }
1345
1346 class CShell32Module : public CComModule
1347 {
1348 public:
1349 };
1350
1351
1352 BEGIN_OBJECT_MAP(ObjectMap)
1353 OBJECT_ENTRY(CLSID_ShellFSFolder, CFSFolder)
1354 OBJECT_ENTRY(CLSID_MyComputer, CDrivesFolder)
1355 OBJECT_ENTRY(CLSID_ShellDesktop, CDesktopFolder)
1356 OBJECT_ENTRY(CLSID_ShellItem, CShellItem)
1357 OBJECT_ENTRY(CLSID_ShellLink, CShellLink)
1358 OBJECT_ENTRY(CLSID_DragDropHelper, CDropTargetHelper)
1359 OBJECT_ENTRY(CLSID_ControlPanel, CControlPanelFolder)
1360 OBJECT_ENTRY(CLSID_AutoComplete, CAutoComplete)
1361 OBJECT_ENTRY(CLSID_MyDocuments, CMyDocsFolder)
1362 OBJECT_ENTRY(CLSID_NetworkPlaces, CNetFolder)
1363 OBJECT_ENTRY(CLSID_FontsFolderShortcut, CFontsFolder)
1364 OBJECT_ENTRY(CLSID_Printers, CPrinterFolder)
1365 OBJECT_ENTRY(CLSID_AdminFolderShortcut, CAdminToolsFolder)
1366 OBJECT_ENTRY(CLSID_RecycleBin, CRecycleBin)
1367 OBJECT_ENTRY(CLSID_OpenWithMenu, COpenWithMenu)
1368 OBJECT_ENTRY(CLSID_NewMenu, CNewMenu)
1369 OBJECT_ENTRY(CLSID_StartMenu, CStartMenu)
1370 OBJECT_ENTRY(CLSID_MenuBandSite, CMenuBandSite)
1371 OBJECT_ENTRY(CLSID_MenuBand, CMenuBand)
1372 END_OBJECT_MAP()
1373
1374 CShell32Module gModule;
1375
1376
1377 /***********************************************************************
1378 * DllGetVersion [SHELL32.@]
1379 *
1380 * Retrieves version information of the 'SHELL32.DLL'
1381 *
1382 * PARAMS
1383 * pdvi [O] pointer to version information structure.
1384 *
1385 * RETURNS
1386 * Success: S_OK
1387 * Failure: E_INVALIDARG
1388 *
1389 * NOTES
1390 * Returns version of a shell32.dll from IE4.01 SP1.
1391 */
1392
1393 STDAPI DllGetVersion(DLLVERSIONINFO *pdvi)
1394 {
1395 /* FIXME: shouldn't these values come from the version resource? */
1396 if (pdvi->cbSize == sizeof(DLLVERSIONINFO) ||
1397 pdvi->cbSize == sizeof(DLLVERSIONINFO2))
1398 {
1399 pdvi->dwMajorVersion = WINE_FILEVERSION_MAJOR;
1400 pdvi->dwMinorVersion = WINE_FILEVERSION_MINOR;
1401 pdvi->dwBuildNumber = WINE_FILEVERSION_BUILD;
1402 pdvi->dwPlatformID = WINE_FILEVERSION_PLATFORMID;
1403 if (pdvi->cbSize == sizeof(DLLVERSIONINFO2))
1404 {
1405 DLLVERSIONINFO2 *pdvi2 = (DLLVERSIONINFO2 *)pdvi;
1406
1407 pdvi2->dwFlags = 0;
1408 pdvi2->ullVersion = MAKEDLLVERULL(WINE_FILEVERSION_MAJOR,
1409 WINE_FILEVERSION_MINOR,
1410 WINE_FILEVERSION_BUILD,
1411 WINE_FILEVERSION_PLATFORMID);
1412 }
1413 TRACE("%u.%u.%u.%u\n",
1414 pdvi->dwMajorVersion, pdvi->dwMinorVersion,
1415 pdvi->dwBuildNumber, pdvi->dwPlatformID);
1416 return S_OK;
1417 }
1418 else
1419 {
1420 WARN("wrong DLLVERSIONINFO size from app\n");
1421 return E_INVALIDARG;
1422 }
1423 }
1424
1425 /*************************************************************************
1426 * global variables of the shell32.dll
1427 * all are once per process
1428 *
1429 */
1430 HINSTANCE shell32_hInstance;
1431 HIMAGELIST ShellSmallIconList = 0;
1432 HIMAGELIST ShellBigIconList = 0;
1433
1434 void *operator new (size_t, void *buf)
1435 {
1436 return buf;
1437 }
1438
1439 /*************************************************************************
1440 * SHELL32 DllMain
1441 *
1442 * NOTES
1443 * calling oleinitialize here breaks sone apps.
1444 */
1445 STDAPI_(BOOL) DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID fImpLoad)
1446 {
1447 TRACE("%p 0x%x %p\n", hInstance, dwReason, fImpLoad);
1448 if (dwReason == DLL_PROCESS_ATTACH)
1449 {
1450 /* HACK - the global constructors don't run, so I placement new them here */
1451 new (&gModule) CShell32Module;
1452 new (&_AtlWinModule) CAtlWinModule;
1453 new (&_AtlBaseModule) CAtlBaseModule;
1454 new (&_AtlComModule) CAtlComModule;
1455
1456 shell32_hInstance = hInstance;
1457 gModule.Init(ObjectMap, hInstance, NULL);
1458
1459 DisableThreadLibraryCalls (hInstance);
1460
1461 /* get full path to this DLL for IExtractIconW_fnGetIconLocation() */
1462 GetModuleFileNameW(hInstance, swShell32Name, MAX_PATH);
1463 swShell32Name[MAX_PATH - 1] = '\0';
1464
1465 InitCommonControlsEx(NULL);
1466
1467 SIC_Initialize();
1468 InitChangeNotifications();
1469 InitIconOverlays();
1470 }
1471 else if (dwReason == DLL_PROCESS_DETACH)
1472 {
1473 shell32_hInstance = NULL;
1474 SIC_Destroy();
1475 FreeChangeNotifications();
1476 gModule.Term();
1477 }
1478 return TRUE;
1479 }
1480
1481 /***********************************************************************
1482 * DllCanUnloadNow (SHELL32.@)
1483 */
1484 STDAPI DllCanUnloadNow()
1485 {
1486 return gModule.DllCanUnloadNow();
1487 }
1488
1489 /*************************************************************************
1490 * DllGetClassObject [SHELL32.@]
1491 * SHDllGetClassObject [SHELL32.128]
1492 */
1493 STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
1494 {
1495 HRESULT hResult;
1496
1497 TRACE("CLSID:%s,IID:%s\n", shdebugstr_guid(&rclsid), shdebugstr_guid(&riid));
1498
1499 hResult = gModule.DllGetClassObject(rclsid, riid, ppv);
1500 TRACE("-- pointer to class factory: %p\n", *ppv);
1501 return hResult;
1502 }
1503
1504 /***********************************************************************
1505 * DllRegisterServer (SHELL32.@)
1506 */
1507 STDAPI DllRegisterServer()
1508 {
1509 HRESULT hr;
1510
1511 hr = gModule.DllRegisterServer(FALSE);
1512 if (FAILED(hr))
1513 return hr;
1514
1515 hr = gModule.UpdateRegistryFromResource(IDR_FOLDEROPTIONS, TRUE, NULL);
1516 if (FAILED(hr))
1517 return hr;
1518
1519 hr = SHELL_RegisterShellFolders();
1520 if (FAILED(hr))
1521 return hr;
1522
1523 return S_OK;
1524 }
1525
1526 /***********************************************************************
1527 * DllUnregisterServer (SHELL32.@)
1528 */
1529 STDAPI DllUnregisterServer()
1530 {
1531 HRESULT hr;
1532
1533 hr = gModule.DllUnregisterServer(FALSE);
1534 if (FAILED(hr))
1535 return hr;
1536
1537 hr = gModule.UpdateRegistryFromResource(IDR_FOLDEROPTIONS, FALSE, NULL);
1538 if (FAILED(hr))
1539 return hr;
1540
1541 return S_OK;
1542 }
1543
1544 /*************************************************************************
1545 * DllInstall [SHELL32.@]
1546 *
1547 * PARAMETERS
1548 *
1549 * BOOL bInstall - TRUE for install, FALSE for uninstall
1550 * LPCWSTR pszCmdLine - command line (unused by shell32?)
1551 */
1552
1553 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
1554 {
1555 FIXME("%s %s: stub\n", bInstall ? "TRUE":"FALSE", debugstr_w(cmdline));
1556 return S_OK; /* indicate success */
1557 }