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