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