[rshell]
[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 uDummy,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_IExtractIconW,
606 &uDummy, (LPVOID*)&pei);
607 if (SUCCEEDED(hr))
608 {
609 hr = pei->GetIconLocation(uGilFlags,
610 szLocation, MAX_PATH, &iIndex, &uFlags);
611
612 if (uFlags & GIL_NOTFILENAME)
613 ret = FALSE;
614 else
615 {
616 wcscpy (psfi->szDisplayName, szLocation);
617 psfi->iIcon = iIndex;
618 }
619 }
620 }
621 }
622
623 /* get icon index (or load icon)*/
624 if (SUCCEEDED(hr) && (flags & (SHGFI_ICON | SHGFI_SYSICONINDEX)))
625 {
626 if (flags & SHGFI_USEFILEATTRIBUTES && !(flags & SHGFI_PIDL))
627 {
628 WCHAR sTemp [MAX_PATH];
629 WCHAR * szExt;
630 int icon_idx=0;
631
632 lstrcpynW(sTemp, szFullPath, MAX_PATH);
633
634 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
635 psfi->iIcon = SIC_GetIconIndex(swShell32Name, -IDI_SHELL_FOLDER, 0);
636 else
637 {
638 static const WCHAR p1W[] = {'%','1',0};
639
640 psfi->iIcon = 0;
641 szExt = PathFindExtensionW(sTemp);
642 if ( szExt &&
643 HCR_MapTypeToValueW(szExt, sTemp, MAX_PATH, TRUE) &&
644 HCR_GetIconW(sTemp, sTemp, NULL, MAX_PATH, &icon_idx))
645 {
646 if (!lstrcmpW(p1W,sTemp)) /* icon is in the file */
647 wcscpy(sTemp, szFullPath);
648
649 if (flags & SHGFI_SYSICONINDEX)
650 {
651 psfi->iIcon = SIC_GetIconIndex(sTemp,icon_idx,0);
652 if (psfi->iIcon == -1)
653 psfi->iIcon = 0;
654 }
655 else
656 {
657 UINT ret;
658 if (flags & SHGFI_SMALLICON)
659 ret = PrivateExtractIconsW( sTemp,icon_idx,
660 GetSystemMetrics( SM_CXSMICON ),
661 GetSystemMetrics( SM_CYSMICON ),
662 &psfi->hIcon, 0, 1, 0);
663 else
664 ret = PrivateExtractIconsW( sTemp, icon_idx,
665 GetSystemMetrics( SM_CXICON),
666 GetSystemMetrics( SM_CYICON),
667 &psfi->hIcon, 0, 1, 0);
668
669 if (ret != 0 && ret != 0xFFFFFFFF)
670 {
671 IconNotYetLoaded=FALSE;
672 psfi->iIcon = icon_idx;
673 }
674 }
675 }
676 }
677 }
678 else
679 {
680 if (!(PidlToSicIndex(psfParent, pidlLast, !(flags & SHGFI_SMALLICON),
681 uGilFlags, &(psfi->iIcon))))
682 {
683 ret = FALSE;
684 }
685 }
686 if (ret && (flags & SHGFI_SYSICONINDEX))
687 {
688 if (flags & SHGFI_SMALLICON)
689 ret = (DWORD_PTR) ShellSmallIconList;
690 else
691 ret = (DWORD_PTR) ShellBigIconList;
692 }
693 }
694
695 /* icon handle */
696 if (SUCCEEDED(hr) && (flags & SHGFI_ICON) && IconNotYetLoaded)
697 {
698 if (flags & SHGFI_SMALLICON)
699 psfi->hIcon = ImageList_GetIcon( ShellSmallIconList, psfi->iIcon, ILD_NORMAL);
700 else
701 psfi->hIcon = ImageList_GetIcon( ShellBigIconList, psfi->iIcon, ILD_NORMAL);
702 }
703
704 if (flags & ~SHGFI_KNOWN_FLAGS)
705 FIXME("unknown flags %08x\n", flags & ~SHGFI_KNOWN_FLAGS);
706
707 if (hr != S_OK)
708 ret = FALSE;
709
710 SHFree(pidlLast);
711
712 #ifdef MORE_DEBUG
713 TRACE ("icon=%p index=0x%08x attr=0x%08x name=%s type=%s ret=0x%08lx\n",
714 psfi->hIcon, psfi->iIcon, psfi->dwAttributes,
715 debugstr_w(psfi->szDisplayName), debugstr_w(psfi->szTypeName), ret);
716 #endif
717
718 return ret;
719 }
720
721 /*************************************************************************
722 * SHGetFileInfoA [SHELL32.@]
723 *
724 * Note:
725 * MSVBVM60.__vbaNew2 expects this function to return a value in range
726 * 1 .. 0x7fff when the function succeeds and flags does not contain
727 * SHGFI_EXETYPE or SHGFI_SYSICONINDEX (see bug 7701)
728 */
729 DWORD_PTR WINAPI SHGetFileInfoA(LPCSTR path,DWORD dwFileAttributes,
730 SHFILEINFOA *psfi, UINT sizeofpsfi,
731 UINT flags )
732 {
733 INT len;
734 LPWSTR temppath = NULL;
735 LPCWSTR pathW;
736 DWORD ret;
737 SHFILEINFOW temppsfi;
738
739 if (flags & SHGFI_PIDL)
740 {
741 /* path contains a pidl */
742 pathW = (LPCWSTR)path;
743 }
744 else
745 {
746 len = MultiByteToWideChar(CP_ACP, 0, path, -1, NULL, 0);
747 temppath = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
748 MultiByteToWideChar(CP_ACP, 0, path, -1, temppath, len);
749 pathW = temppath;
750 }
751
752 if (psfi && (flags & SHGFI_ATTR_SPECIFIED))
753 temppsfi.dwAttributes=psfi->dwAttributes;
754
755 if (psfi == NULL)
756 ret = SHGetFileInfoW(pathW, dwFileAttributes, NULL, sizeof(temppsfi), flags);
757 else
758 ret = SHGetFileInfoW(pathW, dwFileAttributes, &temppsfi, sizeof(temppsfi), flags);
759
760 if (psfi)
761 {
762 if(flags & SHGFI_ICON)
763 psfi->hIcon=temppsfi.hIcon;
764 if(flags & (SHGFI_SYSICONINDEX|SHGFI_ICON|SHGFI_ICONLOCATION))
765 psfi->iIcon=temppsfi.iIcon;
766 if(flags & SHGFI_ATTRIBUTES)
767 psfi->dwAttributes=temppsfi.dwAttributes;
768 if(flags & (SHGFI_DISPLAYNAME|SHGFI_ICONLOCATION))
769 {
770 WideCharToMultiByte(CP_ACP, 0, temppsfi.szDisplayName, -1,
771 psfi->szDisplayName, sizeof(psfi->szDisplayName), NULL, NULL);
772 }
773 if(flags & SHGFI_TYPENAME)
774 {
775 WideCharToMultiByte(CP_ACP, 0, temppsfi.szTypeName, -1,
776 psfi->szTypeName, sizeof(psfi->szTypeName), NULL, NULL);
777 }
778 }
779
780 HeapFree(GetProcessHeap(), 0, temppath);
781
782 return ret;
783 }
784
785 /*************************************************************************
786 * DuplicateIcon [SHELL32.@]
787 */
788 EXTERN_C HICON WINAPI DuplicateIcon( HINSTANCE hInstance, HICON hIcon)
789 {
790 ICONINFO IconInfo;
791 HICON hDupIcon = 0;
792
793 TRACE("%p %p\n", hInstance, hIcon);
794
795 if (GetIconInfo(hIcon, &IconInfo))
796 {
797 hDupIcon = CreateIconIndirect(&IconInfo);
798
799 /* clean up hbmMask and hbmColor */
800 DeleteObject(IconInfo.hbmMask);
801 DeleteObject(IconInfo.hbmColor);
802 }
803
804 return hDupIcon;
805 }
806
807 /*************************************************************************
808 * ExtractIconA [SHELL32.@]
809 */
810 HICON WINAPI ExtractIconA(HINSTANCE hInstance, LPCSTR lpszFile, UINT nIconIndex)
811 {
812 HICON ret;
813 INT len = MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, NULL, 0);
814 LPWSTR lpwstrFile = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
815
816 TRACE("%p %s %d\n", hInstance, lpszFile, nIconIndex);
817
818 MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, lpwstrFile, len);
819 ret = ExtractIconW(hInstance, lpwstrFile, nIconIndex);
820 HeapFree(GetProcessHeap(), 0, lpwstrFile);
821
822 return ret;
823 }
824
825 /*************************************************************************
826 * ExtractIconW [SHELL32.@]
827 */
828 HICON WINAPI ExtractIconW(HINSTANCE hInstance, LPCWSTR lpszFile, UINT nIconIndex)
829 {
830 HICON hIcon = NULL;
831 UINT ret;
832 UINT cx = GetSystemMetrics(SM_CXICON), cy = GetSystemMetrics(SM_CYICON);
833
834 TRACE("%p %s %d\n", hInstance, debugstr_w(lpszFile), nIconIndex);
835
836 if (nIconIndex == 0xFFFFFFFF)
837 {
838 ret = PrivateExtractIconsW(lpszFile, 0, cx, cy, NULL, NULL, 0, LR_DEFAULTCOLOR);
839 if (ret != 0xFFFFFFFF && ret)
840 return (HICON)(UINT_PTR)ret;
841 return NULL;
842 }
843 else
844 ret = PrivateExtractIconsW(lpszFile, nIconIndex, cx, cy, &hIcon, NULL, 1, LR_DEFAULTCOLOR);
845
846 if (ret == 0xFFFFFFFF)
847 return (HICON)1;
848 else if (ret > 0 && hIcon)
849 return hIcon;
850
851 return NULL;
852 }
853
854 /*************************************************************************
855 * Printer_LoadIconsW [SHELL32.205]
856 */
857 EXTERN_C VOID WINAPI Printer_LoadIconsW(LPCWSTR wsPrinterName, HICON * pLargeIcon, HICON * pSmallIcon)
858 {
859 INT iconindex=IDI_SHELL_PRINTERS_FOLDER;
860
861 TRACE("(%s, %p, %p)\n", debugstr_w(wsPrinterName), pLargeIcon, pSmallIcon);
862
863 /* We should check if wsPrinterName is
864 1. the Default Printer or not
865 2. connected or not
866 3. a Local Printer or a Network-Printer
867 and use different Icons
868 */
869 if((wsPrinterName != NULL) && (wsPrinterName[0] != 0))
870 {
871 FIXME("(select Icon by PrinterName %s not implemented)\n", debugstr_w(wsPrinterName));
872 }
873
874 if(pLargeIcon != NULL)
875 *pLargeIcon = (HICON)LoadImageW(shell32_hInstance,
876 (LPCWSTR) MAKEINTRESOURCE(iconindex), IMAGE_ICON,
877 0, 0, LR_DEFAULTCOLOR|LR_DEFAULTSIZE);
878
879 if(pSmallIcon != NULL)
880 *pSmallIcon = (HICON)LoadImageW(shell32_hInstance,
881 (LPCWSTR) MAKEINTRESOURCE(iconindex), IMAGE_ICON,
882 16, 16, LR_DEFAULTCOLOR);
883 }
884
885 /*************************************************************************
886 * Printers_RegisterWindowW [SHELL32.213]
887 * used by "printui.dll":
888 * find the Window of the given Type for the specific Printer and
889 * return the already existent hwnd or open a new window
890 */
891 EXTERN_C BOOL WINAPI Printers_RegisterWindowW(LPCWSTR wsPrinter, DWORD dwType,
892 HANDLE * phClassPidl, HWND * phwnd)
893 {
894 FIXME("(%s, %x, %p (%p), %p (%p)) stub!\n", debugstr_w(wsPrinter), dwType,
895 phClassPidl, (phClassPidl != NULL) ? *(phClassPidl) : NULL,
896 phwnd, (phwnd != NULL) ? *(phwnd) : NULL);
897
898 return FALSE;
899 }
900
901 /*************************************************************************
902 * Printers_UnregisterWindow [SHELL32.214]
903 */
904 EXTERN_C VOID WINAPI Printers_UnregisterWindow(HANDLE hClassPidl, HWND hwnd)
905 {
906 FIXME("(%p, %p) stub!\n", hClassPidl, hwnd);
907 }
908
909 /*************************************************************************/
910
911 typedef struct
912 {
913 LPCWSTR szApp;
914 LPCWSTR szOtherStuff;
915 HICON hIcon;
916 } ABOUT_INFO;
917
918 #define DROP_FIELD_TOP (-15)
919 #define DROP_FIELD_HEIGHT 15
920
921 /*************************************************************************
922 * SHAppBarMessage [SHELL32.@]
923 */
924 UINT_PTR WINAPI SHAppBarMessage(DWORD msg, PAPPBARDATA data)
925 {
926 int width=data->rc.right - data->rc.left;
927 int height=data->rc.bottom - data->rc.top;
928 RECT rec=data->rc;
929
930 TRACE("msg=%d, data={cb=%d, hwnd=%p, callback=%x, edge=%d, rc=%s, lparam=%lx}\n",
931 msg, data->cbSize, data->hWnd, data->uCallbackMessage, data->uEdge,
932 wine_dbgstr_rect(&data->rc), data->lParam);
933
934 switch (msg)
935 {
936 case ABM_GETSTATE:
937 return ABS_ALWAYSONTOP | ABS_AUTOHIDE;
938
939 case ABM_GETTASKBARPOS:
940 GetWindowRect(data->hWnd, &rec);
941 data->rc=rec;
942 return TRUE;
943
944 case ABM_ACTIVATE:
945 SetActiveWindow(data->hWnd);
946 return TRUE;
947
948 case ABM_GETAUTOHIDEBAR:
949 return 0; /* pretend there is no autohide bar */
950
951 case ABM_NEW:
952 /* cbSize, hWnd, and uCallbackMessage are used. All other ignored */
953 SetWindowPos(data->hWnd,HWND_TOP,0,0,0,0,SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE);
954 return TRUE;
955
956 case ABM_QUERYPOS:
957 GetWindowRect(data->hWnd, &(data->rc));
958 return TRUE;
959
960 case ABM_REMOVE:
961 FIXME("ABM_REMOVE broken\n");
962 /* FIXME: this is wrong; should it be DestroyWindow instead? */
963 /*CloseHandle(data->hWnd);*/
964 return TRUE;
965
966 case ABM_SETAUTOHIDEBAR:
967 SetWindowPos(data->hWnd,HWND_TOP,rec.left+1000,rec.top,
968 width,height,SWP_SHOWWINDOW);
969 return TRUE;
970
971 case ABM_SETPOS:
972 data->uEdge=(ABE_RIGHT | ABE_LEFT);
973 SetWindowPos(data->hWnd,HWND_TOP,data->rc.left,data->rc.top,
974 width,height,SWP_SHOWWINDOW);
975 return TRUE;
976
977 case ABM_WINDOWPOSCHANGED:
978 return TRUE;
979 }
980
981 return FALSE;
982 }
983
984 /*************************************************************************
985 * SHHelpShortcuts_RunDLLA [SHELL32.@]
986 *
987 */
988 EXTERN_C DWORD WINAPI SHHelpShortcuts_RunDLLA(DWORD dwArg1, DWORD dwArg2, DWORD dwArg3, DWORD dwArg4)
989 {
990 FIXME("(%x, %x, %x, %x) stub!\n", dwArg1, dwArg2, dwArg3, dwArg4);
991 return 0;
992 }
993
994 /*************************************************************************
995 * SHHelpShortcuts_RunDLLA [SHELL32.@]
996 *
997 */
998 EXTERN_C DWORD WINAPI SHHelpShortcuts_RunDLLW(DWORD dwArg1, DWORD dwArg2, DWORD dwArg3, DWORD dwArg4)
999 {
1000 FIXME("(%x, %x, %x, %x) stub!\n", dwArg1, dwArg2, dwArg3, dwArg4);
1001 return 0;
1002 }
1003
1004 /*************************************************************************
1005 * SHLoadInProc [SHELL32.@]
1006 * Create an instance of specified object class from within
1007 * the shell process and release it immediately
1008 */
1009 EXTERN_C HRESULT WINAPI SHLoadInProc (REFCLSID rclsid)
1010 {
1011 CComPtr<IUnknown> ptr;
1012
1013 TRACE("%s\n", debugstr_guid(&rclsid));
1014
1015 CoCreateInstance(rclsid, NULL, CLSCTX_INPROC_SERVER, IID_IUnknown, (void **)&ptr);
1016 if (ptr)
1017 return S_OK;
1018 return DISP_E_MEMBERNOTFOUND;
1019 }
1020
1021 static VOID SetRegTextData(HWND hWnd, HKEY hKey, LPCWSTR Value, UINT uID)
1022 {
1023 DWORD dwBufferSize;
1024 DWORD dwType;
1025 LPWSTR lpBuffer;
1026
1027 if( RegQueryValueExW(hKey, Value, NULL, &dwType, NULL, &dwBufferSize) == ERROR_SUCCESS )
1028 {
1029 if(dwType == REG_SZ)
1030 {
1031 lpBuffer = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, dwBufferSize);
1032
1033 if(lpBuffer)
1034 {
1035 if( RegQueryValueExW(hKey, Value, NULL, &dwType, (LPBYTE)lpBuffer, &dwBufferSize) == ERROR_SUCCESS )
1036 {
1037 SetDlgItemTextW(hWnd, uID, lpBuffer);
1038 }
1039
1040 HeapFree(GetProcessHeap(), 0, lpBuffer);
1041 }
1042 }
1043 }
1044 }
1045
1046 INT_PTR CALLBACK AboutAuthorsDlgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
1047 {
1048 switch(msg)
1049 {
1050 case WM_INITDIALOG:
1051 {
1052 const char* const *pstr = SHELL_Authors;
1053
1054 // Add the authors to the list
1055 SendDlgItemMessageW( hWnd, IDC_ABOUT_AUTHORS_LISTBOX, WM_SETREDRAW, FALSE, 0 );
1056
1057 while (*pstr)
1058 {
1059 WCHAR name[64];
1060
1061 /* authors list is in utf-8 format */
1062 MultiByteToWideChar( CP_UTF8, 0, *pstr, -1, name, sizeof(name)/sizeof(WCHAR) );
1063 SendDlgItemMessageW( hWnd, IDC_ABOUT_AUTHORS_LISTBOX, LB_ADDSTRING, (WPARAM)-1, (LPARAM)name );
1064 pstr++;
1065 }
1066
1067 SendDlgItemMessageW( hWnd, IDC_ABOUT_AUTHORS_LISTBOX, WM_SETREDRAW, TRUE, 0 );
1068
1069 return TRUE;
1070 }
1071 }
1072
1073 return FALSE;
1074 }
1075 /*************************************************************************
1076 * AboutDlgProc (internal)
1077 */
1078 INT_PTR CALLBACK AboutDlgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
1079 {
1080 static DWORD cxLogoBmp;
1081 static DWORD cyLogoBmp;
1082 static HBITMAP hLogoBmp;
1083 static HWND hWndAuthors;
1084
1085 switch(msg)
1086 {
1087 case WM_INITDIALOG:
1088 {
1089 ABOUT_INFO *info = (ABOUT_INFO *)lParam;
1090
1091 if (info)
1092 {
1093 const WCHAR szRegKey[] = L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion";
1094 HKEY hRegKey;
1095 MEMORYSTATUSEX MemStat;
1096 WCHAR szAppTitle[512];
1097 WCHAR szAppTitleTemplate[512];
1098 WCHAR szAuthorsText[20];
1099
1100 // Preload the ROS bitmap
1101 hLogoBmp = (HBITMAP)LoadImage(shell32_hInstance, MAKEINTRESOURCE(IDB_SHELL_ABOUT_LOGO_24BPP), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
1102
1103 if(hLogoBmp)
1104 {
1105 BITMAP bmpLogo;
1106
1107 GetObject( hLogoBmp, sizeof(BITMAP), &bmpLogo );
1108
1109 cxLogoBmp = bmpLogo.bmWidth;
1110 cyLogoBmp = bmpLogo.bmHeight;
1111 }
1112
1113 // Set App-specific stuff (icon, app name, szOtherStuff string)
1114 SendDlgItemMessageW(hWnd, IDC_ABOUT_ICON, STM_SETICON, (WPARAM)info->hIcon, 0);
1115
1116 GetWindowTextW( hWnd, szAppTitleTemplate, sizeof(szAppTitleTemplate) / sizeof(WCHAR) );
1117 swprintf( szAppTitle, szAppTitleTemplate, info->szApp );
1118 SetWindowTextW( hWnd, szAppTitle );
1119
1120 SetDlgItemTextW( hWnd, IDC_ABOUT_APPNAME, info->szApp );
1121 SetDlgItemTextW( hWnd, IDC_ABOUT_OTHERSTUFF, info->szOtherStuff );
1122
1123 // Set the registered user and organization name
1124 if(RegOpenKeyExW( HKEY_LOCAL_MACHINE, szRegKey, 0, KEY_QUERY_VALUE, &hRegKey ) == ERROR_SUCCESS)
1125 {
1126 SetRegTextData( hWnd, hRegKey, L"RegisteredOwner", IDC_ABOUT_REG_USERNAME );
1127 SetRegTextData( hWnd, hRegKey, L"RegisteredOrganization", IDC_ABOUT_REG_ORGNAME );
1128
1129 RegCloseKey( hRegKey );
1130 }
1131
1132 // Set the value for the installed physical memory
1133 MemStat.dwLength = sizeof(MemStat);
1134 if( GlobalMemoryStatusEx(&MemStat) )
1135 {
1136 WCHAR szBuf[12];
1137
1138 if (MemStat.ullTotalPhys > 1024 * 1024 * 1024)
1139 {
1140 double dTotalPhys;
1141 WCHAR szDecimalSeparator[4];
1142 WCHAR szUnits[3];
1143
1144 // We're dealing with GBs or more
1145 MemStat.ullTotalPhys /= 1024 * 1024;
1146
1147 if (MemStat.ullTotalPhys > 1024 * 1024)
1148 {
1149 // We're dealing with TBs or more
1150 MemStat.ullTotalPhys /= 1024;
1151
1152 if (MemStat.ullTotalPhys > 1024 * 1024)
1153 {
1154 // We're dealing with PBs or more
1155 MemStat.ullTotalPhys /= 1024;
1156
1157 dTotalPhys = (double)MemStat.ullTotalPhys / 1024;
1158 wcscpy( szUnits, L"PB" );
1159 }
1160 else
1161 {
1162 dTotalPhys = (double)MemStat.ullTotalPhys / 1024;
1163 wcscpy( szUnits, L"TB" );
1164 }
1165 }
1166 else
1167 {
1168 dTotalPhys = (double)MemStat.ullTotalPhys / 1024;
1169 wcscpy( szUnits, L"GB" );
1170 }
1171
1172 // We need the decimal point of the current locale to display the RAM size correctly
1173 if (GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL,
1174 szDecimalSeparator,
1175 sizeof(szDecimalSeparator) / sizeof(WCHAR)) > 0)
1176 {
1177 UCHAR uDecimals;
1178 UINT uIntegral;
1179
1180 uIntegral = (UINT)dTotalPhys;
1181 uDecimals = (UCHAR)((UINT)(dTotalPhys * 100) - uIntegral * 100);
1182
1183 // Display the RAM size with 2 decimals
1184 swprintf(szBuf, L"%u%s%02u %s", uIntegral, szDecimalSeparator, uDecimals, szUnits);
1185 }
1186 }
1187 else
1188 {
1189 // We're dealing with MBs, don't show any decimals
1190 swprintf( szBuf, L"%u MB", (UINT)MemStat.ullTotalPhys / 1024 / 1024 );
1191 }
1192
1193 SetDlgItemTextW( hWnd, IDC_ABOUT_PHYSMEM, szBuf);
1194 }
1195
1196 // Add the Authors dialog
1197 hWndAuthors = CreateDialogW( shell32_hInstance, MAKEINTRESOURCEW(IDD_ABOUT_AUTHORS), hWnd, AboutAuthorsDlgProc );
1198 LoadStringW( shell32_hInstance, IDS_SHELL_ABOUT_AUTHORS, szAuthorsText, sizeof(szAuthorsText) / sizeof(WCHAR) );
1199 SetDlgItemTextW( hWnd, IDC_ABOUT_AUTHORS, szAuthorsText );
1200 }
1201
1202 return TRUE;
1203 }
1204
1205 case WM_PAINT:
1206 {
1207 if(hLogoBmp)
1208 {
1209 PAINTSTRUCT ps;
1210 HDC hdc;
1211 HDC hdcMem;
1212
1213 hdc = BeginPaint(hWnd, &ps);
1214 hdcMem = CreateCompatibleDC(hdc);
1215
1216 if(hdcMem)
1217 {
1218 SelectObject(hdcMem, hLogoBmp);
1219 BitBlt(hdc, 0, 0, cxLogoBmp, cyLogoBmp, hdcMem, 0, 0, SRCCOPY);
1220
1221 DeleteDC(hdcMem);
1222 }
1223
1224 EndPaint(hWnd, &ps);
1225 }
1226 }; break;
1227
1228 case WM_COMMAND:
1229 {
1230 switch(wParam)
1231 {
1232 case IDOK:
1233 case IDCANCEL:
1234 EndDialog(hWnd, TRUE);
1235 return TRUE;
1236
1237 case IDC_ABOUT_AUTHORS:
1238 {
1239 static BOOL bShowingAuthors = FALSE;
1240 WCHAR szAuthorsText[20];
1241
1242 if(bShowingAuthors)
1243 {
1244 LoadStringW( shell32_hInstance, IDS_SHELL_ABOUT_AUTHORS, szAuthorsText, sizeof(szAuthorsText) / sizeof(WCHAR) );
1245 ShowWindow( hWndAuthors, SW_HIDE );
1246 }
1247 else
1248 {
1249 LoadStringW( shell32_hInstance, IDS_SHELL_ABOUT_BACK, szAuthorsText, sizeof(szAuthorsText) / sizeof(WCHAR) );
1250 ShowWindow( hWndAuthors, SW_SHOW );
1251 }
1252
1253 SetDlgItemTextW( hWnd, IDC_ABOUT_AUTHORS, szAuthorsText );
1254 bShowingAuthors = !bShowingAuthors;
1255 return TRUE;
1256 }
1257 }
1258 }; break;
1259
1260 case WM_CLOSE:
1261 EndDialog(hWnd, TRUE);
1262 break;
1263 }
1264
1265 return FALSE;
1266 }
1267
1268
1269 /*************************************************************************
1270 * ShellAboutA [SHELL32.288]
1271 */
1272 BOOL WINAPI ShellAboutA( HWND hWnd, LPCSTR szApp, LPCSTR szOtherStuff, HICON hIcon )
1273 {
1274 BOOL ret;
1275 LPWSTR appW = NULL, otherW = NULL;
1276 int len;
1277
1278 if (szApp)
1279 {
1280 len = MultiByteToWideChar(CP_ACP, 0, szApp, -1, NULL, 0);
1281 appW = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1282 MultiByteToWideChar(CP_ACP, 0, szApp, -1, appW, len);
1283 }
1284 if (szOtherStuff)
1285 {
1286 len = MultiByteToWideChar(CP_ACP, 0, szOtherStuff, -1, NULL, 0);
1287 otherW = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1288 MultiByteToWideChar(CP_ACP, 0, szOtherStuff, -1, otherW, len);
1289 }
1290
1291 ret = ShellAboutW(hWnd, appW, otherW, hIcon);
1292
1293 HeapFree(GetProcessHeap(), 0, otherW);
1294 HeapFree(GetProcessHeap(), 0, appW);
1295 return ret;
1296 }
1297
1298
1299 /*************************************************************************
1300 * ShellAboutW [SHELL32.289]
1301 */
1302 BOOL WINAPI ShellAboutW( HWND hWnd, LPCWSTR szApp, LPCWSTR szOtherStuff,
1303 HICON hIcon )
1304 {
1305 ABOUT_INFO info;
1306 HRSRC hRes;
1307 DLGTEMPLATE *DlgTemplate;
1308 BOOL bRet;
1309
1310 TRACE("\n");
1311
1312 // DialogBoxIndirectParamW will be called with the hInstance of the calling application, so we have to preload the dialog template
1313 hRes = FindResourceW(shell32_hInstance, MAKEINTRESOURCEW(IDD_ABOUT), (LPWSTR)RT_DIALOG);
1314 if(!hRes)
1315 return FALSE;
1316
1317 DlgTemplate = (DLGTEMPLATE *)LoadResource(shell32_hInstance, hRes);
1318 if(!DlgTemplate)
1319 return FALSE;
1320
1321 info.szApp = szApp;
1322 info.szOtherStuff = szOtherStuff;
1323 info.hIcon = hIcon ? hIcon : LoadIconW( 0, (LPWSTR)IDI_WINLOGO );
1324
1325 bRet = DialogBoxIndirectParamW((HINSTANCE)GetWindowLongPtrW( hWnd, GWLP_HINSTANCE ),
1326 DlgTemplate, hWnd, AboutDlgProc, (LPARAM)&info );
1327 return bRet;
1328 }
1329
1330 /*************************************************************************
1331 * FreeIconList (SHELL32.@)
1332 */
1333 EXTERN_C void WINAPI FreeIconList( DWORD dw )
1334 {
1335 FIXME("%x: stub\n",dw);
1336 }
1337
1338 /*************************************************************************
1339 * SHLoadNonloadedIconOverlayIdentifiers (SHELL32.@)
1340 */
1341 EXTERN_C HRESULT WINAPI SHLoadNonloadedIconOverlayIdentifiers(VOID)
1342 {
1343 FIXME("stub\n");
1344 return S_OK;
1345 }
1346
1347 class CShell32Module : public CComModule
1348 {
1349 public:
1350 };
1351
1352
1353 BEGIN_OBJECT_MAP(ObjectMap)
1354 OBJECT_ENTRY(CLSID_ShellFSFolder, CFSFolder)
1355 OBJECT_ENTRY(CLSID_MyComputer, CDrivesFolder)
1356 OBJECT_ENTRY(CLSID_ShellDesktop, CDesktopFolder)
1357 OBJECT_ENTRY(CLSID_ShellItem, CShellItem)
1358 OBJECT_ENTRY(CLSID_ShellLink, CShellLink)
1359 OBJECT_ENTRY(CLSID_DragDropHelper, CDropTargetHelper)
1360 OBJECT_ENTRY(CLSID_ControlPanel, CControlPanelFolder)
1361 OBJECT_ENTRY(CLSID_AutoComplete, CAutoComplete)
1362 OBJECT_ENTRY(CLSID_MyDocuments, CMyDocsFolder)
1363 OBJECT_ENTRY(CLSID_NetworkPlaces, CNetFolder)
1364 OBJECT_ENTRY(CLSID_FontsFolderShortcut, CFontsFolder)
1365 OBJECT_ENTRY(CLSID_Printers, CPrinterFolder)
1366 OBJECT_ENTRY(CLSID_AdminFolderShortcut, CAdminToolsFolder)
1367 OBJECT_ENTRY(CLSID_RecycleBin, CRecycleBin)
1368 OBJECT_ENTRY(CLSID_OpenWithMenu, COpenWithMenu)
1369 OBJECT_ENTRY(CLSID_NewMenu, CNewMenu)
1370 OBJECT_ENTRY(CLSID_StartMenu, CStartMenu)
1371 OBJECT_ENTRY(CLSID_MenuBandSite, CMenuBandSite)
1372 OBJECT_ENTRY(CLSID_MenuBand, CMenuBand)
1373 OBJECT_ENTRY(CLSID_MenuDeskBar, CMenuDeskBar)
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 }