5b914d40222d62752f35a1727f43ed65abef3ad6
[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
24 #include "shell32_version.h"
25 #include <reactos/version.h>
26
27 WINE_DEFAULT_DEBUG_CHANNEL(shell);
28
29 const char * const SHELL_Authors[] = { "Copyright 1993-"COPYRIGHT_YEAR" WINE team", "Copyright 1998-"COPYRIGHT_YEAR" ReactOS Team", 0 };
30
31 #define MORE_DEBUG 1
32 /*************************************************************************
33 * CommandLineToArgvW [SHELL32.@]
34 *
35 * We must interpret the quotes in the command line to rebuild the argv
36 * array correctly:
37 * - arguments are separated by spaces or tabs
38 * - quotes serve as optional argument delimiters
39 * '"a b"' -> 'a b'
40 * - escaped quotes must be converted back to '"'
41 * '\"' -> '"'
42 * - consecutive backslashes preceding a quote see their number halved with
43 * the remainder escaping the quote:
44 * 2n backslashes + quote -> n backslashes + quote as an argument delimiter
45 * 2n+1 backslashes + quote -> n backslashes + literal quote
46 * - backslashes that are not followed by a quote are copied literally:
47 * 'a\b' -> 'a\b'
48 * 'a\\b' -> 'a\\b'
49 * - in quoted strings, consecutive quotes see their number divided by three
50 * with the remainder modulo 3 deciding whether to close the string or not.
51 * Note that the opening quote must be counted in the consecutive quotes,
52 * that's the (1+) below:
53 * (1+) 3n quotes -> n quotes
54 * (1+) 3n+1 quotes -> n quotes plus closes the quoted string
55 * (1+) 3n+2 quotes -> n+1 quotes plus closes the quoted string
56 * - in unquoted strings, the first quote opens the quoted string and the
57 * remaining consecutive quotes follow the above rule.
58 */
59 LPWSTR* WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int* numargs)
60 {
61 DWORD argc;
62 LPWSTR *argv;
63 LPCWSTR s;
64 LPWSTR d;
65 LPWSTR cmdline;
66 int qcount,bcount;
67
68 if(!numargs)
69 {
70 SetLastError(ERROR_INVALID_PARAMETER);
71 return NULL;
72 }
73
74 if (*lpCmdline==0)
75 {
76 /* Return the path to the executable */
77 DWORD len, deslen=MAX_PATH, size;
78
79 size = sizeof(LPWSTR) + deslen*sizeof(WCHAR) + sizeof(LPWSTR);
80 for (;;)
81 {
82 if (!(argv = (LPWSTR *)LocalAlloc(LMEM_FIXED, size))) return NULL;
83 len = GetModuleFileNameW(0, (LPWSTR)(argv+1), deslen);
84 if (!len)
85 {
86 LocalFree(argv);
87 return NULL;
88 }
89 if (len < deslen) break;
90 deslen*=2;
91 size = sizeof(LPWSTR) + deslen*sizeof(WCHAR) + sizeof(LPWSTR);
92 LocalFree( argv );
93 }
94 argv[0]=(LPWSTR)(argv+1);
95 *numargs=1;
96
97 return argv;
98 }
99
100 /* --- First count the arguments */
101 argc=1;
102 s=lpCmdline;
103 /* The first argument, the executable path, follows special rules */
104 if (*s=='"')
105 {
106 /* The executable path ends at the next quote, no matter what */
107 s++;
108 while (*s)
109 if (*s++=='"')
110 break;
111 }
112 else
113 {
114 /* The executable path ends at the next space, no matter what */
115 while (*s && *s!=' ' && *s!='\t')
116 s++;
117 }
118 /* skip to the first argument, if any */
119 while (*s==' ' || *s=='\t')
120 s++;
121 if (*s)
122 argc++;
123
124 /* Analyze the remaining arguments */
125 qcount=bcount=0;
126 while (*s)
127 {
128 if ((*s==' ' || *s=='\t') && qcount==0)
129 {
130 /* skip to the next argument and count it if any */
131 while (*s==' ' || *s=='\t')
132 s++;
133 if (*s)
134 argc++;
135 bcount=0;
136 }
137 else if (*s=='\\')
138 {
139 /* '\', count them */
140 bcount++;
141 s++;
142 }
143 else if (*s=='"')
144 {
145 /* '"' */
146 if ((bcount & 1)==0)
147 qcount++; /* unescaped '"' */
148 s++;
149 bcount=0;
150 /* consecutive quotes, see comment in copying code below */
151 while (*s=='"')
152 {
153 qcount++;
154 s++;
155 }
156 qcount=qcount % 3;
157 if (qcount==2)
158 qcount=0;
159 }
160 else
161 {
162 /* a regular character */
163 bcount=0;
164 s++;
165 }
166 }
167
168 /* Allocate in a single lump, the string array, and the strings that go
169 * with it. This way the caller can make a single LocalFree() call to free
170 * both, as per MSDN.
171 */
172 argv=(LPWSTR *)LocalAlloc(LMEM_FIXED, argc*sizeof(LPWSTR)+(strlenW(lpCmdline)+1)*sizeof(WCHAR));
173 if (!argv)
174 return NULL;
175 cmdline=(LPWSTR)(argv+argc);
176 strcpyW(cmdline, lpCmdline);
177
178 /* --- Then split and copy the arguments */
179 argv[0]=d=cmdline;
180 argc=1;
181 /* The first argument, the executable path, follows special rules */
182 if (*d=='"')
183 {
184 /* The executable path ends at the next quote, no matter what */
185 s=d+1;
186 while (*s)
187 {
188 if (*s=='"')
189 {
190 s++;
191 break;
192 }
193 *d++=*s++;
194 }
195 }
196 else
197 {
198 /* The executable path ends at the next space, no matter what */
199 while (*d && *d!=' ' && *d!='\t')
200 d++;
201 s=d;
202 if (*s)
203 s++;
204 }
205 /* close the executable path */
206 *d++=0;
207 /* skip to the first argument and initialize it if any */
208 while (*s==' ' || *s=='\t')
209 s++;
210 if (!*s)
211 {
212 /* There are no parameters so we are all done */
213 *numargs=argc;
214 return argv;
215 }
216
217 /* Split and copy the remaining arguments */
218 argv[argc++]=d;
219 qcount=bcount=0;
220 while (*s)
221 {
222 if ((*s==' ' || *s=='\t') && qcount==0)
223 {
224 /* close the argument */
225 *d++=0;
226 bcount=0;
227
228 /* skip to the next one and initialize it if any */
229 do {
230 s++;
231 } while (*s==' ' || *s=='\t');
232 if (*s)
233 argv[argc++]=d;
234 }
235 else if (*s=='\\')
236 {
237 *d++=*s++;
238 bcount++;
239 }
240 else if (*s=='"')
241 {
242 if ((bcount & 1)==0)
243 {
244 /* Preceded by an even number of '\', this is half that
245 * number of '\', plus a quote which we erase.
246 */
247 d-=bcount/2;
248 qcount++;
249 }
250 else
251 {
252 /* Preceded by an odd number of '\', this is half that
253 * number of '\' followed by a '"'
254 */
255 d=d-bcount/2-1;
256 *d++='"';
257 }
258 s++;
259 bcount=0;
260 /* Now count the number of consecutive quotes. Note that qcount
261 * already takes into account the opening quote if any, as well as
262 * the quote that lead us here.
263 */
264 while (*s=='"')
265 {
266 if (++qcount==3)
267 {
268 *d++='"';
269 qcount=0;
270 }
271 s++;
272 }
273 if (qcount==2)
274 qcount=0;
275 }
276 else
277 {
278 /* a regular character */
279 *d++=*s++;
280 bcount=0;
281 }
282 }
283 *d='\0';
284 *numargs=argc;
285
286 return argv;
287 }
288
289 static DWORD shgfi_get_exe_type(LPCWSTR szFullPath)
290 {
291 BOOL status = FALSE;
292 HANDLE hfile;
293 DWORD BinaryType;
294 IMAGE_DOS_HEADER mz_header;
295 IMAGE_NT_HEADERS nt;
296 DWORD len;
297 char magic[4];
298
299 status = GetBinaryTypeW (szFullPath, &BinaryType);
300 if (!status)
301 return 0;
302 if (BinaryType == SCS_DOS_BINARY || BinaryType == SCS_PIF_BINARY)
303 return 0x4d5a;
304
305 hfile = CreateFileW( szFullPath, GENERIC_READ, FILE_SHARE_READ,
306 NULL, OPEN_EXISTING, 0, 0 );
307 if ( hfile == INVALID_HANDLE_VALUE )
308 return 0;
309
310 /*
311 * The next section is adapted from MODULE_GetBinaryType, as we need
312 * to examine the image header to get OS and version information. We
313 * know from calling GetBinaryTypeA that the image is valid and either
314 * an NE or PE, so much error handling can be omitted.
315 * Seek to the start of the file and read the header information.
316 */
317
318 SetFilePointer( hfile, 0, NULL, SEEK_SET );
319 ReadFile( hfile, &mz_header, sizeof(mz_header), &len, NULL );
320
321 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
322 ReadFile( hfile, magic, sizeof(magic), &len, NULL );
323
324 if ( *(DWORD*)magic == IMAGE_NT_SIGNATURE )
325 {
326 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
327 ReadFile( hfile, &nt, sizeof(nt), &len, NULL );
328 CloseHandle( hfile );
329
330 /* DLL files are not executable and should return 0 */
331 if (nt.FileHeader.Characteristics & IMAGE_FILE_DLL)
332 return 0;
333
334 if (nt.OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI)
335 {
336 return IMAGE_NT_SIGNATURE |
337 (nt.OptionalHeader.MajorSubsystemVersion << 24) |
338 (nt.OptionalHeader.MinorSubsystemVersion << 16);
339 }
340 return IMAGE_NT_SIGNATURE;
341 }
342 else if ( *(WORD*)magic == IMAGE_OS2_SIGNATURE )
343 {
344 IMAGE_OS2_HEADER ne;
345 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
346 ReadFile( hfile, &ne, sizeof(ne), &len, NULL );
347 CloseHandle( hfile );
348
349 if (ne.ne_exetyp == 2)
350 return IMAGE_OS2_SIGNATURE | (ne.ne_expver << 16);
351 return 0;
352 }
353 CloseHandle( hfile );
354 return 0;
355 }
356
357 /*************************************************************************
358 * SHELL_IsShortcut [internal]
359 *
360 * Decide if an item id list points to a shell shortcut
361 */
362 BOOL SHELL_IsShortcut(LPCITEMIDLIST pidlLast)
363 {
364 char szTemp[MAX_PATH];
365 HKEY keyCls;
366 BOOL ret = FALSE;
367
368 if (_ILGetExtension(pidlLast, szTemp, MAX_PATH) &&
369 HCR_MapTypeToValueA(szTemp, szTemp, MAX_PATH, TRUE))
370 {
371 if (ERROR_SUCCESS == RegOpenKeyExA(HKEY_CLASSES_ROOT, szTemp, 0, KEY_QUERY_VALUE, &keyCls))
372 {
373 if (ERROR_SUCCESS == RegQueryValueExA(keyCls, "IsShortcut", NULL, NULL, NULL, NULL))
374 ret = TRUE;
375
376 RegCloseKey(keyCls);
377 }
378 }
379
380 return ret;
381 }
382
383 #define SHGFI_KNOWN_FLAGS \
384 (SHGFI_SMALLICON | SHGFI_OPENICON | SHGFI_SHELLICONSIZE | SHGFI_PIDL | \
385 SHGFI_USEFILEATTRIBUTES | SHGFI_ADDOVERLAYS | SHGFI_OVERLAYINDEX | \
386 SHGFI_ICON | SHGFI_DISPLAYNAME | SHGFI_TYPENAME | SHGFI_ATTRIBUTES | \
387 SHGFI_ICONLOCATION | SHGFI_EXETYPE | SHGFI_SYSICONINDEX | \
388 SHGFI_LINKOVERLAY | SHGFI_SELECTED | SHGFI_ATTR_SPECIFIED)
389
390 /*************************************************************************
391 * SHGetFileInfoW [SHELL32.@]
392 *
393 */
394 DWORD_PTR WINAPI SHGetFileInfoW(LPCWSTR path,DWORD dwFileAttributes,
395 SHFILEINFOW *psfi, UINT sizeofpsfi, UINT flags )
396 {
397 WCHAR szLocation[MAX_PATH], szFullPath[MAX_PATH];
398 int iIndex;
399 DWORD_PTR ret = TRUE;
400 DWORD dwAttributes = 0;
401 CComPtr<IShellFolder> psfParent;
402 CComPtr<IExtractIconW> pei;
403 LPITEMIDLIST pidlLast = NULL, pidl = NULL;
404 HRESULT hr = S_OK;
405 BOOL IconNotYetLoaded=TRUE;
406 UINT uGilFlags = 0;
407
408 TRACE("%s fattr=0x%x sfi=%p(attr=0x%08x) size=0x%x flags=0x%x\n",
409 (flags & SHGFI_PIDL)? "pidl" : debugstr_w(path), dwFileAttributes,
410 psfi, psfi->dwAttributes, sizeofpsfi, flags);
411
412 if (!path)
413 return FALSE;
414
415 /* windows initializes these values regardless of the flags */
416 if (psfi != NULL)
417 {
418 psfi->szDisplayName[0] = '\0';
419 psfi->szTypeName[0] = '\0';
420 psfi->iIcon = 0;
421 }
422
423 if (!(flags & SHGFI_PIDL))
424 {
425 /* SHGetFileInfo should work with absolute and relative paths */
426 if (PathIsRelativeW(path))
427 {
428 GetCurrentDirectoryW(MAX_PATH, szLocation);
429 PathCombineW(szFullPath, szLocation, path);
430 }
431 else
432 {
433 lstrcpynW(szFullPath, path, MAX_PATH);
434 }
435 }
436
437 if (flags & SHGFI_EXETYPE)
438 {
439 if (flags != SHGFI_EXETYPE)
440 return 0;
441 return shgfi_get_exe_type(szFullPath);
442 }
443
444 /*
445 * psfi is NULL normally to query EXE type. If it is NULL, none of the
446 * below makes sense anyway. Windows allows this and just returns FALSE
447 */
448 if (psfi == NULL)
449 return FALSE;
450
451 /*
452 * translate the path into a pidl only when SHGFI_USEFILEATTRIBUTES
453 * is not specified.
454 * The pidl functions fail on not existing file names
455 */
456
457 if (flags & SHGFI_PIDL)
458 {
459 pidl = ILClone((LPCITEMIDLIST)path);
460 }
461 else if (!(flags & SHGFI_USEFILEATTRIBUTES))
462 {
463 hr = SHILCreateFromPathW(szFullPath, &pidl, &dwAttributes);
464 }
465
466 if ((flags & SHGFI_PIDL) || !(flags & SHGFI_USEFILEATTRIBUTES))
467 {
468 /* get the parent shellfolder */
469 if (pidl)
470 {
471 hr = SHBindToParent( pidl, IID_PPV_ARG(IShellFolder, &psfParent),
472 (LPCITEMIDLIST*)&pidlLast );
473 if (SUCCEEDED(hr))
474 pidlLast = ILClone(pidlLast);
475 ILFree(pidl);
476 }
477 else
478 {
479 ERR("pidl is null!\n");
480 return FALSE;
481 }
482 }
483
484 /* get the attributes of the child */
485 if (SUCCEEDED(hr) && (flags & SHGFI_ATTRIBUTES))
486 {
487 if (!(flags & SHGFI_ATTR_SPECIFIED))
488 {
489 psfi->dwAttributes = 0xffffffff;
490 }
491 if (psfParent != NULL)
492 psfParent->GetAttributesOf(1, (LPCITEMIDLIST*)&pidlLast,
493 &(psfi->dwAttributes) );
494 }
495
496 /* get the displayname */
497 if (SUCCEEDED(hr) && (flags & SHGFI_DISPLAYNAME))
498 {
499 if (flags & SHGFI_USEFILEATTRIBUTES)
500 {
501 wcscpy (psfi->szDisplayName, PathFindFileNameW(szFullPath));
502 }
503 else
504 {
505 STRRET str;
506 hr = psfParent->GetDisplayNameOf(pidlLast,
507 SHGDN_INFOLDER, &str);
508 StrRetToStrNW (psfi->szDisplayName, MAX_PATH, &str, pidlLast);
509 }
510 }
511
512 /* get the type name */
513 if (SUCCEEDED(hr) && (flags & SHGFI_TYPENAME))
514 {
515 static const WCHAR szFile[] = { 'F','i','l','e',0 };
516 static const WCHAR szDashFile[] = { '-','f','i','l','e',0 };
517
518 if (!(flags & SHGFI_USEFILEATTRIBUTES))
519 {
520 char ftype[80];
521
522 _ILGetFileType(pidlLast, ftype, 80);
523 MultiByteToWideChar(CP_ACP, 0, ftype, -1, psfi->szTypeName, 80 );
524 }
525 else
526 {
527 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
528 wcscat (psfi->szTypeName, szFile);
529 else
530 {
531 WCHAR sTemp[64];
532
533 wcscpy(sTemp,PathFindExtensionW(szFullPath));
534 if (!( HCR_MapTypeToValueW(sTemp, sTemp, 64, TRUE) &&
535 HCR_MapTypeToValueW(sTemp, psfi->szTypeName, 80, FALSE )))
536 {
537 lstrcpynW (psfi->szTypeName, sTemp, 64);
538 wcscat (psfi->szTypeName, szDashFile);
539 }
540 }
541 }
542 }
543
544 /* ### icons ###*/
545 if (flags & SHGFI_OPENICON)
546 uGilFlags |= GIL_OPENICON;
547
548 if (flags & SHGFI_LINKOVERLAY)
549 uGilFlags |= GIL_FORSHORTCUT;
550 else if ((flags&SHGFI_ADDOVERLAYS) ||
551 (flags&(SHGFI_ICON|SHGFI_SMALLICON))==SHGFI_ICON)
552 {
553 if (SHELL_IsShortcut(pidlLast))
554 uGilFlags |= GIL_FORSHORTCUT;
555 }
556
557 if (flags & SHGFI_OVERLAYINDEX)
558 FIXME("SHGFI_OVERLAYINDEX unhandled\n");
559
560 if (flags & SHGFI_SELECTED)
561 FIXME("set icon to selected, stub\n");
562
563 if (flags & SHGFI_SHELLICONSIZE)
564 FIXME("set icon to shell size, stub\n");
565
566 /* get the iconlocation */
567 if (SUCCEEDED(hr) && (flags & SHGFI_ICONLOCATION ))
568 {
569 UINT uFlags;
570
571 if (flags & SHGFI_USEFILEATTRIBUTES)
572 {
573 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
574 {
575 wcscpy(psfi->szDisplayName, swShell32Name);
576 psfi->iIcon = -IDI_SHELL_FOLDER;
577 }
578 else
579 {
580 WCHAR* szExt;
581 static const WCHAR p1W[] = {'%','1',0};
582 WCHAR sTemp [MAX_PATH];
583
584 szExt = PathFindExtensionW(szFullPath);
585 TRACE("szExt=%s\n", debugstr_w(szExt));
586 if ( szExt &&
587 HCR_MapTypeToValueW(szExt, sTemp, MAX_PATH, TRUE) &&
588 HCR_GetIconW(sTemp, sTemp, NULL, MAX_PATH, &psfi->iIcon))
589 {
590 if (lstrcmpW(p1W, sTemp))
591 wcscpy(psfi->szDisplayName, sTemp);
592 else
593 {
594 /* the icon is in the file */
595 wcscpy(psfi->szDisplayName, szFullPath);
596 }
597 }
598 else
599 ret = FALSE;
600 }
601 }
602 else
603 {
604 hr = psfParent->GetUIObjectOf(0, 1,
605 (LPCITEMIDLIST*)&pidlLast, IID_NULL_PPV_ARG(IExtractIconW, &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_GetIconW(sTemp, sTemp, NULL, 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 S_OK;
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 static 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_REACTOS), 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 OBJECT_ENTRY(CLSID_MenuDeskBar, CMenuDeskBar)
1373 OBJECT_ENTRY(CLSID_ExeDropHandler, CExeDropHandler)
1374 END_OBJECT_MAP()
1375
1376 CShell32Module gModule;
1377
1378
1379 /***********************************************************************
1380 * DllGetVersion [SHELL32.@]
1381 *
1382 * Retrieves version information of the 'SHELL32.DLL'
1383 *
1384 * PARAMS
1385 * pdvi [O] pointer to version information structure.
1386 *
1387 * RETURNS
1388 * Success: S_OK
1389 * Failure: E_INVALIDARG
1390 *
1391 * NOTES
1392 * Returns version of a shell32.dll from IE4.01 SP1.
1393 */
1394
1395 STDAPI DllGetVersion(DLLVERSIONINFO *pdvi)
1396 {
1397 /* FIXME: shouldn't these values come from the version resource? */
1398 if (pdvi->cbSize == sizeof(DLLVERSIONINFO) ||
1399 pdvi->cbSize == sizeof(DLLVERSIONINFO2))
1400 {
1401 pdvi->dwMajorVersion = WINE_FILEVERSION_MAJOR;
1402 pdvi->dwMinorVersion = WINE_FILEVERSION_MINOR;
1403 pdvi->dwBuildNumber = WINE_FILEVERSION_BUILD;
1404 pdvi->dwPlatformID = WINE_FILEVERSION_PLATFORMID;
1405 if (pdvi->cbSize == sizeof(DLLVERSIONINFO2))
1406 {
1407 DLLVERSIONINFO2 *pdvi2 = (DLLVERSIONINFO2 *)pdvi;
1408
1409 pdvi2->dwFlags = 0;
1410 pdvi2->ullVersion = MAKEDLLVERULL(WINE_FILEVERSION_MAJOR,
1411 WINE_FILEVERSION_MINOR,
1412 WINE_FILEVERSION_BUILD,
1413 WINE_FILEVERSION_PLATFORMID);
1414 }
1415 TRACE("%u.%u.%u.%u\n",
1416 pdvi->dwMajorVersion, pdvi->dwMinorVersion,
1417 pdvi->dwBuildNumber, pdvi->dwPlatformID);
1418 return S_OK;
1419 }
1420 else
1421 {
1422 WARN("wrong DLLVERSIONINFO size from app\n");
1423 return E_INVALIDARG;
1424 }
1425 }
1426
1427 /*************************************************************************
1428 * global variables of the shell32.dll
1429 * all are once per process
1430 *
1431 */
1432 HINSTANCE shell32_hInstance;
1433 HIMAGELIST ShellSmallIconList = 0;
1434 HIMAGELIST ShellBigIconList = 0;
1435
1436 void *operator new (size_t, void *buf)
1437 {
1438 return buf;
1439 }
1440
1441 /*************************************************************************
1442 * SHELL32 DllMain
1443 *
1444 * NOTES
1445 * calling oleinitialize here breaks sone apps.
1446 */
1447 STDAPI_(BOOL) DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID fImpLoad)
1448 {
1449 TRACE("%p 0x%x %p\n", hInstance, dwReason, fImpLoad);
1450 if (dwReason == DLL_PROCESS_ATTACH)
1451 {
1452 /* HACK - the global constructors don't run, so I placement new them here */
1453 new (&gModule) CShell32Module;
1454 new (&_AtlWinModule) CAtlWinModule;
1455 new (&_AtlBaseModule) CAtlBaseModule;
1456 new (&_AtlComModule) CAtlComModule;
1457
1458 shell32_hInstance = hInstance;
1459 gModule.Init(ObjectMap, hInstance, NULL);
1460
1461 DisableThreadLibraryCalls (hInstance);
1462
1463 /* get full path to this DLL for IExtractIconW_fnGetIconLocation() */
1464 GetModuleFileNameW(hInstance, swShell32Name, MAX_PATH);
1465 swShell32Name[MAX_PATH - 1] = '\0';
1466
1467 /* Initialize comctl32 */
1468 INITCOMMONCONTROLSEX InitCtrls;
1469 InitCtrls.dwSize = sizeof(INITCOMMONCONTROLSEX);
1470 InitCtrls.dwICC = ICC_WIN95_CLASSES | ICC_DATE_CLASSES | ICC_USEREX_CLASSES;
1471 InitCommonControlsEx(&InitCtrls);
1472
1473 SIC_Initialize();
1474 InitChangeNotifications();
1475 InitIconOverlays();
1476 }
1477 else if (dwReason == DLL_PROCESS_DETACH)
1478 {
1479 shell32_hInstance = NULL;
1480 SIC_Destroy();
1481 FreeChangeNotifications();
1482 gModule.Term();
1483 }
1484 return TRUE;
1485 }
1486
1487 /***********************************************************************
1488 * DllCanUnloadNow (SHELL32.@)
1489 */
1490 STDAPI DllCanUnloadNow()
1491 {
1492 return gModule.DllCanUnloadNow();
1493 }
1494
1495 /*************************************************************************
1496 * DllGetClassObject [SHELL32.@]
1497 * SHDllGetClassObject [SHELL32.128]
1498 */
1499 STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
1500 {
1501 HRESULT hResult;
1502
1503 TRACE("CLSID:%s,IID:%s\n", shdebugstr_guid(&rclsid), shdebugstr_guid(&riid));
1504
1505 hResult = gModule.DllGetClassObject(rclsid, riid, ppv);
1506 TRACE("-- pointer to class factory: %p\n", *ppv);
1507 return hResult;
1508 }
1509
1510 /***********************************************************************
1511 * DllRegisterServer (SHELL32.@)
1512 */
1513 STDAPI DllRegisterServer()
1514 {
1515 HRESULT hr;
1516
1517 hr = gModule.DllRegisterServer(FALSE);
1518 if (FAILED(hr))
1519 return hr;
1520
1521 hr = gModule.UpdateRegistryFromResource(IDR_FOLDEROPTIONS, TRUE, NULL);
1522 if (FAILED(hr))
1523 return hr;
1524
1525 hr = SHELL_RegisterShellFolders();
1526 if (FAILED(hr))
1527 return hr;
1528
1529 return S_OK;
1530 }
1531
1532 /***********************************************************************
1533 * DllUnregisterServer (SHELL32.@)
1534 */
1535 STDAPI DllUnregisterServer()
1536 {
1537 HRESULT hr;
1538
1539 hr = gModule.DllUnregisterServer(FALSE);
1540 if (FAILED(hr))
1541 return hr;
1542
1543 hr = gModule.UpdateRegistryFromResource(IDR_FOLDEROPTIONS, FALSE, NULL);
1544 if (FAILED(hr))
1545 return hr;
1546
1547 return S_OK;
1548 }
1549
1550 /*************************************************************************
1551 * DllInstall [SHELL32.@]
1552 *
1553 * PARAMETERS
1554 *
1555 * BOOL bInstall - TRUE for install, FALSE for uninstall
1556 * LPCWSTR pszCmdLine - command line (unused by shell32?)
1557 */
1558
1559 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
1560 {
1561 FIXME("%s %s: stub\n", bInstall ? "TRUE":"FALSE", debugstr_w(cmdline));
1562 return S_OK; /* indicate success */
1563 }