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