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