pop fafc973c8c92ea6fa823adc8f5a7f591f01396fd
[wine/hacks.git] / dlls / shell32 / shell32_main.c
blob282426801e3b8840d62e099b576f9a69dd4f4b27
1 /*
2 * Shell basics
4 * Copyright 1998 Marcus Meissner
5 * Copyright 1998 Juergen Schmied (jsch) * <juergen.schmied@metronet.de>
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.
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.
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
22 #include "config.h"
24 #include <stdlib.h>
25 #include <string.h>
26 #include <stdarg.h>
27 #include <stdio.h>
29 #define COBJMACROS
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"
42 #include "undocshell.h"
43 #include "pidl.h"
44 #include "shell32_main.h"
45 #include "version.h"
46 #include "shresdef.h"
48 #include "wine/debug.h"
49 #include "wine/unicode.h"
51 WINE_DEFAULT_DEBUG_CHANNEL(shell);
53 extern const char * const SHELL_Authors[];
55 /*************************************************************************
56 * CommandLineToArgvW [SHELL32.@]
58 * We must interpret the quotes in the command line to rebuild the argv
59 * array correctly:
60 * - arguments are separated by spaces or tabs
61 * - quotes serve as optional argument delimiters
62 * '"a b"' -> 'a b'
63 * - escaped quotes must be converted back to '"'
64 * '\"' -> '"'
65 * - an odd number of '\'s followed by '"' correspond to half that number
66 * of '\' followed by a '"' (extension of the above)
67 * '\\\"' -> '\"'
68 * '\\\\\"' -> '\\"'
69 * - an even number of '\'s followed by a '"' correspond to half that number
70 * of '\', plus a regular quote serving as an argument delimiter (which
71 * means it does not appear in the result)
72 * 'a\\"b c"' -> 'a\b c'
73 * 'a\\\\"b c"' -> 'a\\b c'
74 * - '\' that are not followed by a '"' are copied literally
75 * 'a\b' -> 'a\b'
76 * 'a\\b' -> 'a\\b'
78 * Note:
79 * '\t' == 0x0009
80 * ' ' == 0x0020
81 * '"' == 0x0022
82 * '\\' == 0x005c
84 LPWSTR* WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int* numargs)
86 DWORD argc;
87 LPWSTR *argv;
88 LPCWSTR cs;
89 LPWSTR arg,s,d;
90 LPWSTR cmdline;
91 int in_quotes,bcount;
93 if (*lpCmdline==0)
95 /* Return the path to the executable */
96 DWORD len, size=16;
98 argv=LocalAlloc(LMEM_FIXED, size);
99 for (;;)
101 len = GetModuleFileNameW(0, (LPWSTR)(argv+1), (size-sizeof(LPWSTR))/sizeof(WCHAR));
102 if (!len)
104 LocalFree(argv);
105 return NULL;
107 if (len < size) break;
108 size*=2;
109 argv=LocalReAlloc(argv, size, 0);
111 argv[0]=(LPWSTR)(argv+1);
112 if (numargs)
113 *numargs=1;
115 return argv;
118 /* to get a writable copy */
119 argc=0;
120 bcount=0;
121 in_quotes=0;
122 cs=lpCmdline;
123 while (1)
125 if (*cs==0 || ((*cs==0x0009 || *cs==0x0020) && !in_quotes))
127 /* space */
128 argc++;
129 /* skip the remaining spaces */
130 while (*cs==0x0009 || *cs==0x0020) {
131 cs++;
133 if (*cs==0)
134 break;
135 bcount=0;
136 continue;
138 else if (*cs==0x005c)
140 /* '\', count them */
141 bcount++;
143 else if ((*cs==0x0022) && ((bcount & 1)==0))
145 /* unescaped '"' */
146 in_quotes=!in_quotes;
147 bcount=0;
149 else
151 /* a regular character */
152 bcount=0;
154 cs++;
156 /* Allocate in a single lump, the string array, and the strings that go with it.
157 * This way the caller can make a single GlobalFree call to free both, as per MSDN.
159 argv=LocalAlloc(LMEM_FIXED, argc*sizeof(LPWSTR)+(strlenW(lpCmdline)+1)*sizeof(WCHAR));
160 if (!argv)
161 return NULL;
162 cmdline=(LPWSTR)(argv+argc);
163 strcpyW(cmdline, lpCmdline);
165 argc=0;
166 bcount=0;
167 in_quotes=0;
168 arg=d=s=cmdline;
169 while (*s)
171 if ((*s==0x0009 || *s==0x0020) && !in_quotes)
173 /* Close the argument and copy it */
174 *d=0;
175 argv[argc++]=arg;
177 /* skip the remaining spaces */
178 do {
179 s++;
180 } while (*s==0x0009 || *s==0x0020);
182 /* Start with a new argument */
183 arg=d=s;
184 bcount=0;
186 else if (*s==0x005c)
188 /* '\\' */
189 *d++=*s++;
190 bcount++;
192 else if (*s==0x0022)
194 /* '"' */
195 if ((bcount & 1)==0)
197 /* Preceded by an even number of '\', this is half that
198 * number of '\', plus a quote which we erase.
200 d-=bcount/2;
201 in_quotes=!in_quotes;
202 s++;
204 else
206 /* Preceded by an odd number of '\', this is half that
207 * number of '\' followed by a '"'
209 d=d-bcount/2-1;
210 *d++='"';
211 s++;
213 bcount=0;
215 else
217 /* a regular character */
218 *d++=*s++;
219 bcount=0;
222 if (*arg)
224 *d='\0';
225 argv[argc++]=arg;
227 if (numargs)
228 *numargs=argc;
230 return argv;
233 static DWORD shgfi_get_exe_type(LPCWSTR szFullPath)
235 BOOL status = FALSE;
236 HANDLE hfile;
237 DWORD BinaryType;
238 IMAGE_DOS_HEADER mz_header;
239 IMAGE_NT_HEADERS nt;
240 DWORD len;
241 char magic[4];
243 status = GetBinaryTypeW (szFullPath, &BinaryType);
244 if (!status)
245 return 0;
246 if (BinaryType == SCS_DOS_BINARY || BinaryType == SCS_PIF_BINARY)
247 return 0x4d5a;
249 hfile = CreateFileW( szFullPath, GENERIC_READ, FILE_SHARE_READ,
250 NULL, OPEN_EXISTING, 0, 0 );
251 if ( hfile == INVALID_HANDLE_VALUE )
252 return 0;
255 * The next section is adapted from MODULE_GetBinaryType, as we need
256 * to examine the image header to get OS and version information. We
257 * know from calling GetBinaryTypeA that the image is valid and either
258 * an NE or PE, so much error handling can be omitted.
259 * Seek to the start of the file and read the header information.
262 SetFilePointer( hfile, 0, NULL, SEEK_SET );
263 ReadFile( hfile, &mz_header, sizeof(mz_header), &len, NULL );
265 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
266 ReadFile( hfile, magic, sizeof(magic), &len, NULL );
267 if ( *(DWORD*)magic == IMAGE_NT_SIGNATURE )
269 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
270 ReadFile( hfile, &nt, sizeof(nt), &len, NULL );
271 CloseHandle( hfile );
272 /* DLL files are not executable and should return 0 */
273 if (nt.FileHeader.Characteristics & IMAGE_FILE_DLL)
274 return 0;
275 if (nt.OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI)
277 return IMAGE_NT_SIGNATURE |
278 (nt.OptionalHeader.MajorSubsystemVersion << 24) |
279 (nt.OptionalHeader.MinorSubsystemVersion << 16);
281 return IMAGE_NT_SIGNATURE;
283 else if ( *(WORD*)magic == IMAGE_OS2_SIGNATURE )
285 IMAGE_OS2_HEADER ne;
286 SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
287 ReadFile( hfile, &ne, sizeof(ne), &len, NULL );
288 CloseHandle( hfile );
289 if (ne.ne_exetyp == 2)
290 return IMAGE_OS2_SIGNATURE | (ne.ne_expver << 16);
291 return 0;
293 CloseHandle( hfile );
294 return 0;
297 /*************************************************************************
298 * SHELL_IsShortcut [internal]
300 * Decide if an item id list points to a shell shortcut
302 BOOL SHELL_IsShortcut(LPCITEMIDLIST pidlLast)
304 char szTemp[MAX_PATH];
305 HKEY keyCls;
306 BOOL ret = FALSE;
308 if (_ILGetExtension(pidlLast, szTemp, MAX_PATH) &&
309 HCR_MapTypeToValueA(szTemp, szTemp, MAX_PATH, TRUE))
311 if (ERROR_SUCCESS == RegOpenKeyExA(HKEY_CLASSES_ROOT, szTemp, 0, KEY_QUERY_VALUE, &keyCls))
313 if (ERROR_SUCCESS == RegQueryValueExA(keyCls, "IsShortcut", NULL, NULL, NULL, NULL))
314 ret = TRUE;
316 RegCloseKey(keyCls);
320 return ret;
323 #define SHGFI_KNOWN_FLAGS \
324 (SHGFI_SMALLICON | SHGFI_OPENICON | SHGFI_SHELLICONSIZE | SHGFI_PIDL | \
325 SHGFI_USEFILEATTRIBUTES | SHGFI_ADDOVERLAYS | SHGFI_OVERLAYINDEX | \
326 SHGFI_ICON | SHGFI_DISPLAYNAME | SHGFI_TYPENAME | SHGFI_ATTRIBUTES | \
327 SHGFI_ICONLOCATION | SHGFI_EXETYPE | SHGFI_SYSICONINDEX | \
328 SHGFI_LINKOVERLAY | SHGFI_SELECTED | SHGFI_ATTR_SPECIFIED)
330 /*************************************************************************
331 * SHGetFileInfoW [SHELL32.@]
334 DWORD_PTR WINAPI SHGetFileInfoW(LPCWSTR path,DWORD dwFileAttributes,
335 SHFILEINFOW *psfi, UINT sizeofpsfi, UINT flags )
337 WCHAR szLocation[MAX_PATH], szFullPath[MAX_PATH];
338 int iIndex;
339 DWORD_PTR ret = TRUE;
340 DWORD dwAttributes = 0;
341 IShellFolder * psfParent = NULL;
342 IExtractIconW * pei = NULL;
343 LPITEMIDLIST pidlLast = NULL, pidl = NULL;
344 HRESULT hr = S_OK;
345 BOOL IconNotYetLoaded=TRUE;
346 UINT uGilFlags = 0;
348 TRACE("%s fattr=0x%x sfi=%p(attr=0x%08x) size=0x%x flags=0x%x\n",
349 (flags & SHGFI_PIDL)? "pidl" : debugstr_w(path), dwFileAttributes,
350 psfi, psfi->dwAttributes, sizeofpsfi, flags);
352 if (!path)
353 return FALSE;
355 /* windows initializes these values regardless of the flags */
356 if (psfi != NULL)
358 psfi->szDisplayName[0] = '\0';
359 psfi->szTypeName[0] = '\0';
360 psfi->iIcon = 0;
363 if (!(flags & SHGFI_PIDL))
365 /* SHGetFileInfo should work with absolute and relative paths */
366 if (PathIsRelativeW(path))
368 GetCurrentDirectoryW(MAX_PATH, szLocation);
369 PathCombineW(szFullPath, szLocation, path);
371 else
373 lstrcpynW(szFullPath, path, MAX_PATH);
377 if (flags & SHGFI_EXETYPE)
379 if (flags != SHGFI_EXETYPE)
380 return 0;
381 return shgfi_get_exe_type(szFullPath);
385 * psfi is NULL normally to query EXE type. If it is NULL, none of the
386 * below makes sense anyway. Windows allows this and just returns FALSE
388 if (psfi == NULL)
389 return FALSE;
392 * translate the path into a pidl only when SHGFI_USEFILEATTRIBUTES
393 * is not specified.
394 * The pidl functions fail on not existing file names
397 if (flags & SHGFI_PIDL)
399 pidl = ILClone((LPCITEMIDLIST)path);
401 else if (!(flags & SHGFI_USEFILEATTRIBUTES))
403 hr = SHILCreateFromPathW(szFullPath, &pidl, &dwAttributes);
406 if ((flags & SHGFI_PIDL) || !(flags & SHGFI_USEFILEATTRIBUTES))
408 /* get the parent shellfolder */
409 if (pidl)
411 hr = SHBindToParent( pidl, &IID_IShellFolder, (LPVOID*)&psfParent,
412 (LPCITEMIDLIST*)&pidlLast );
413 if (SUCCEEDED(hr))
414 pidlLast = ILClone(pidlLast);
415 ILFree(pidl);
417 else
419 ERR("pidl is null!\n");
420 return FALSE;
424 /* get the attributes of the child */
425 if (SUCCEEDED(hr) && (flags & SHGFI_ATTRIBUTES))
427 if (!(flags & SHGFI_ATTR_SPECIFIED))
429 psfi->dwAttributes = 0xffffffff;
431 if (psfParent)
432 IShellFolder_GetAttributesOf( psfParent, 1, (LPCITEMIDLIST*)&pidlLast,
433 &(psfi->dwAttributes) );
436 /* get the displayname */
437 if (SUCCEEDED(hr) && (flags & SHGFI_DISPLAYNAME))
439 if (flags & SHGFI_USEFILEATTRIBUTES)
441 lstrcpyW (psfi->szDisplayName, PathFindFileNameW(szFullPath));
443 else
445 STRRET str;
446 hr = IShellFolder_GetDisplayNameOf( psfParent, pidlLast,
447 SHGDN_INFOLDER, &str);
448 StrRetToStrNW (psfi->szDisplayName, MAX_PATH, &str, pidlLast);
452 /* get the type name */
453 if (SUCCEEDED(hr) && (flags & SHGFI_TYPENAME))
455 static const WCHAR szFile[] = { 'F','i','l','e',0 };
456 static const WCHAR szDashFile[] = { '-','f','i','l','e',0 };
458 if (!(flags & SHGFI_USEFILEATTRIBUTES))
460 char ftype[80];
462 _ILGetFileType(pidlLast, ftype, 80);
463 MultiByteToWideChar(CP_ACP, 0, ftype, -1, psfi->szTypeName, 80 );
465 else
467 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
468 strcatW (psfi->szTypeName, szFile);
469 else
471 WCHAR sTemp[64];
473 lstrcpyW(sTemp,PathFindExtensionW(szFullPath));
474 if (!( HCR_MapTypeToValueW(sTemp, sTemp, 64, TRUE) &&
475 HCR_MapTypeToValueW(sTemp, psfi->szTypeName, 80, FALSE )))
477 lstrcpynW (psfi->szTypeName, sTemp, 64);
478 strcatW (psfi->szTypeName, szDashFile);
484 /* ### icons ###*/
485 if (flags & SHGFI_OPENICON)
486 uGilFlags |= GIL_OPENICON;
488 if (flags & SHGFI_LINKOVERLAY)
489 uGilFlags |= GIL_FORSHORTCUT;
490 else if ((flags&SHGFI_ADDOVERLAYS) ||
491 (flags&(SHGFI_ICON|SHGFI_SMALLICON))==SHGFI_ICON)
493 if (SHELL_IsShortcut(pidlLast))
494 uGilFlags |= GIL_FORSHORTCUT;
497 if (flags & SHGFI_OVERLAYINDEX)
498 FIXME("SHGFI_OVERLAYINDEX unhandled\n");
500 if (flags & SHGFI_SELECTED)
501 FIXME("set icon to selected, stub\n");
503 if (flags & SHGFI_SHELLICONSIZE)
504 FIXME("set icon to shell size, stub\n");
506 /* get the iconlocation */
507 if (SUCCEEDED(hr) && (flags & SHGFI_ICONLOCATION ))
509 UINT uDummy,uFlags;
511 if (flags & SHGFI_USEFILEATTRIBUTES)
513 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
515 lstrcpyW(psfi->szDisplayName, swShell32Name);
516 psfi->iIcon = -IDI_SHELL_FOLDER;
518 else
520 WCHAR* szExt;
521 static const WCHAR p1W[] = {'%','1',0};
522 WCHAR sTemp [MAX_PATH];
524 szExt = PathFindExtensionW(szFullPath);
525 TRACE("szExt=%s\n", debugstr_w(szExt));
526 if ( szExt &&
527 HCR_MapTypeToValueW(szExt, sTemp, MAX_PATH, TRUE) &&
528 HCR_GetDefaultIconW(sTemp, sTemp, MAX_PATH, &psfi->iIcon))
530 if (lstrcmpW(p1W, sTemp))
531 strcpyW(psfi->szDisplayName, sTemp);
532 else
534 /* the icon is in the file */
535 strcpyW(psfi->szDisplayName, szFullPath);
538 else
539 ret = FALSE;
542 else
544 hr = IShellFolder_GetUIObjectOf(psfParent, 0, 1,
545 (LPCITEMIDLIST*)&pidlLast, &IID_IExtractIconW,
546 &uDummy, (LPVOID*)&pei);
547 if (SUCCEEDED(hr))
549 hr = IExtractIconW_GetIconLocation(pei, uGilFlags,
550 szLocation, MAX_PATH, &iIndex, &uFlags);
552 if (uFlags & GIL_NOTFILENAME)
553 ret = FALSE;
554 else
556 lstrcpyW (psfi->szDisplayName, szLocation);
557 psfi->iIcon = iIndex;
559 IExtractIconW_Release(pei);
564 /* get icon index (or load icon)*/
565 if (SUCCEEDED(hr) && (flags & (SHGFI_ICON | SHGFI_SYSICONINDEX)))
567 if (flags & SHGFI_USEFILEATTRIBUTES && !(flags & SHGFI_PIDL))
569 WCHAR sTemp [MAX_PATH];
570 WCHAR * szExt;
571 int icon_idx=0;
573 lstrcpynW(sTemp, szFullPath, MAX_PATH);
575 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
576 psfi->iIcon = SIC_GetIconIndex(swShell32Name, -IDI_SHELL_FOLDER, 0);
577 else
579 static const WCHAR p1W[] = {'%','1',0};
581 psfi->iIcon = 0;
582 szExt = PathFindExtensionW(sTemp);
583 if ( szExt &&
584 HCR_MapTypeToValueW(szExt, sTemp, MAX_PATH, TRUE) &&
585 HCR_GetDefaultIconW(sTemp, sTemp, MAX_PATH, &icon_idx))
587 if (!lstrcmpW(p1W,sTemp)) /* icon is in the file */
588 strcpyW(sTemp, szFullPath);
590 if (flags & SHGFI_SYSICONINDEX)
592 psfi->iIcon = SIC_GetIconIndex(sTemp,icon_idx,0);
593 if (psfi->iIcon == -1)
594 psfi->iIcon = 0;
596 else
598 UINT ret;
599 if (flags & SHGFI_SMALLICON)
600 ret = PrivateExtractIconsW( sTemp,icon_idx,
601 GetSystemMetrics( SM_CXSMICON ),
602 GetSystemMetrics( SM_CYSMICON ),
603 &psfi->hIcon, 0, 1, 0);
604 else
605 ret = PrivateExtractIconsW( sTemp, icon_idx,
606 GetSystemMetrics( SM_CXICON),
607 GetSystemMetrics( SM_CYICON),
608 &psfi->hIcon, 0, 1, 0);
609 if (ret != 0 && ret != (UINT)-1)
611 IconNotYetLoaded=FALSE;
612 psfi->iIcon = icon_idx;
618 else
620 if (!(PidlToSicIndex(psfParent, pidlLast, !(flags & SHGFI_SMALLICON),
621 uGilFlags, &(psfi->iIcon))))
623 ret = FALSE;
626 if (ret && (flags & SHGFI_SYSICONINDEX))
628 if (flags & SHGFI_SMALLICON)
629 ret = (DWORD_PTR) ShellSmallIconList;
630 else
631 ret = (DWORD_PTR) ShellBigIconList;
635 /* icon handle */
636 if (SUCCEEDED(hr) && (flags & SHGFI_ICON) && IconNotYetLoaded)
638 if (flags & SHGFI_SMALLICON)
639 psfi->hIcon = ImageList_GetIcon( ShellSmallIconList, psfi->iIcon, ILD_NORMAL);
640 else
641 psfi->hIcon = ImageList_GetIcon( ShellBigIconList, psfi->iIcon, ILD_NORMAL);
644 if (flags & ~SHGFI_KNOWN_FLAGS)
645 FIXME("unknown flags %08x\n", flags & ~SHGFI_KNOWN_FLAGS);
647 if (psfParent)
648 IShellFolder_Release(psfParent);
650 if (hr != S_OK)
651 ret = FALSE;
653 SHFree(pidlLast);
655 TRACE ("icon=%p index=0x%08x attr=0x%08x name=%s type=%s ret=0x%08lx\n",
656 psfi->hIcon, psfi->iIcon, psfi->dwAttributes,
657 debugstr_w(psfi->szDisplayName), debugstr_w(psfi->szTypeName), ret);
659 return ret;
662 /*************************************************************************
663 * SHGetFileInfoA [SHELL32.@]
665 * Note:
666 * MSVBVM60.__vbaNew2 expects this function to return a value in range
667 * 1 .. 0x7fff when the function succeeds and flags does not contain
668 * SHGFI_EXETYPE or SHGFI_SYSICONINDEX (see bug 7701)
670 DWORD_PTR WINAPI SHGetFileInfoA(LPCSTR path,DWORD dwFileAttributes,
671 SHFILEINFOA *psfi, UINT sizeofpsfi,
672 UINT flags )
674 INT len;
675 LPWSTR temppath = NULL;
676 LPCWSTR pathW;
677 DWORD ret;
678 SHFILEINFOW temppsfi;
680 if (flags & SHGFI_PIDL)
682 /* path contains a pidl */
683 pathW = (LPCWSTR)path;
685 else
687 len = MultiByteToWideChar(CP_ACP, 0, path, -1, NULL, 0);
688 temppath = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
689 MultiByteToWideChar(CP_ACP, 0, path, -1, temppath, len);
690 pathW = temppath;
693 if (psfi && (flags & SHGFI_ATTR_SPECIFIED))
694 temppsfi.dwAttributes=psfi->dwAttributes;
696 if (psfi == NULL)
697 ret = SHGetFileInfoW(pathW, dwFileAttributes, NULL, sizeof(temppsfi), flags);
698 else
699 ret = SHGetFileInfoW(pathW, dwFileAttributes, &temppsfi, sizeof(temppsfi), flags);
701 if (psfi)
703 if(flags & SHGFI_ICON)
704 psfi->hIcon=temppsfi.hIcon;
705 if(flags & (SHGFI_SYSICONINDEX|SHGFI_ICON|SHGFI_ICONLOCATION))
706 psfi->iIcon=temppsfi.iIcon;
707 if(flags & SHGFI_ATTRIBUTES)
708 psfi->dwAttributes=temppsfi.dwAttributes;
709 if(flags & (SHGFI_DISPLAYNAME|SHGFI_ICONLOCATION))
711 WideCharToMultiByte(CP_ACP, 0, temppsfi.szDisplayName, -1,
712 psfi->szDisplayName, sizeof(psfi->szDisplayName), NULL, NULL);
714 if(flags & SHGFI_TYPENAME)
716 WideCharToMultiByte(CP_ACP, 0, temppsfi.szTypeName, -1,
717 psfi->szTypeName, sizeof(psfi->szTypeName), NULL, NULL);
721 HeapFree(GetProcessHeap(), 0, temppath);
723 return ret;
726 /*************************************************************************
727 * DuplicateIcon [SHELL32.@]
729 HICON WINAPI DuplicateIcon( HINSTANCE hInstance, HICON hIcon)
731 ICONINFO IconInfo;
732 HICON hDupIcon = 0;
734 TRACE("%p %p\n", hInstance, hIcon);
736 if (GetIconInfo(hIcon, &IconInfo))
738 hDupIcon = CreateIconIndirect(&IconInfo);
740 /* clean up hbmMask and hbmColor */
741 DeleteObject(IconInfo.hbmMask);
742 DeleteObject(IconInfo.hbmColor);
745 return hDupIcon;
748 /*************************************************************************
749 * ExtractIconA [SHELL32.@]
751 HICON WINAPI ExtractIconA(HINSTANCE hInstance, LPCSTR lpszFile, UINT nIconIndex)
753 HICON ret;
754 INT len = MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, NULL, 0);
755 LPWSTR lpwstrFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
757 TRACE("%p %s %d\n", hInstance, lpszFile, nIconIndex);
759 MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, lpwstrFile, len);
760 ret = ExtractIconW(hInstance, lpwstrFile, nIconIndex);
761 HeapFree(GetProcessHeap(), 0, lpwstrFile);
763 return ret;
766 /*************************************************************************
767 * ExtractIconW [SHELL32.@]
769 HICON WINAPI ExtractIconW(HINSTANCE hInstance, LPCWSTR lpszFile, UINT nIconIndex)
771 HICON hIcon = NULL;
772 UINT ret;
773 UINT cx = GetSystemMetrics(SM_CXICON), cy = GetSystemMetrics(SM_CYICON);
775 TRACE("%p %s %d\n", hInstance, debugstr_w(lpszFile), nIconIndex);
777 if (nIconIndex == (UINT)-1)
779 ret = PrivateExtractIconsW(lpszFile, 0, cx, cy, NULL, NULL, 0, LR_DEFAULTCOLOR);
780 if (ret != (UINT)-1 && ret)
781 return (HICON)(UINT_PTR)ret;
782 return NULL;
784 else
785 ret = PrivateExtractIconsW(lpszFile, nIconIndex, cx, cy, &hIcon, NULL, 1, LR_DEFAULTCOLOR);
787 if (ret == (UINT)-1)
788 return (HICON)1;
789 else if (ret > 0 && hIcon)
790 return hIcon;
792 return NULL;
795 HRESULT WINAPI SHCreateFileExtractIconW(LPCWSTR file, DWORD attribs, REFIID riid, void **ppv)
797 FIXME("%s, %x, %s, %p\n", debugstr_w(file), attribs, debugstr_guid(riid), ppv);
798 *ppv = NULL;
799 return E_NOTIMPL;
802 /*************************************************************************
803 * Printer_LoadIconsW [SHELL32.205]
805 VOID WINAPI Printer_LoadIconsW(LPCWSTR wsPrinterName, HICON * pLargeIcon, HICON * pSmallIcon)
807 INT iconindex=IDI_SHELL_PRINTER;
809 TRACE("(%s, %p, %p)\n", debugstr_w(wsPrinterName), pLargeIcon, pSmallIcon);
811 /* We should check if wsPrinterName is
812 1. the Default Printer or not
813 2. connected or not
814 3. a Local Printer or a Network-Printer
815 and use different Icons
817 if((wsPrinterName != NULL) && (wsPrinterName[0] != 0))
819 FIXME("(select Icon by PrinterName %s not implemented)\n", debugstr_w(wsPrinterName));
822 if(pLargeIcon != NULL)
823 *pLargeIcon = LoadImageW(shell32_hInstance,
824 (LPCWSTR) MAKEINTRESOURCE(iconindex), IMAGE_ICON,
825 0, 0, LR_DEFAULTCOLOR|LR_DEFAULTSIZE);
827 if(pSmallIcon != NULL)
828 *pSmallIcon = LoadImageW(shell32_hInstance,
829 (LPCWSTR) MAKEINTRESOURCE(iconindex), IMAGE_ICON,
830 16, 16, LR_DEFAULTCOLOR);
833 /*************************************************************************
834 * Printers_RegisterWindowW [SHELL32.213]
835 * used by "printui.dll":
836 * find the Window of the given Type for the specific Printer and
837 * return the already existent hwnd or open a new window
839 BOOL WINAPI Printers_RegisterWindowW(LPCWSTR wsPrinter, DWORD dwType,
840 HANDLE * phClassPidl, HWND * phwnd)
842 FIXME("(%s, %x, %p (%p), %p (%p)) stub!\n", debugstr_w(wsPrinter), dwType,
843 phClassPidl, (phClassPidl != NULL) ? *(phClassPidl) : NULL,
844 phwnd, (phwnd != NULL) ? *(phwnd) : NULL);
846 return FALSE;
849 /*************************************************************************
850 * Printers_UnregisterWindow [SHELL32.214]
852 VOID WINAPI Printers_UnregisterWindow(HANDLE hClassPidl, HWND hwnd)
854 FIXME("(%p, %p) stub!\n", hClassPidl, hwnd);
857 /*************************************************************************/
859 typedef struct
861 LPCWSTR szApp;
862 LPCWSTR szOtherStuff;
863 HICON hIcon;
864 HFONT hFont;
865 } ABOUT_INFO;
867 #define DROP_FIELD_TOP (-12)
869 static void paint_dropline( HDC hdc, HWND hWnd )
871 HWND hWndCtl = GetDlgItem(hWnd, IDC_ABOUT_WINE_TEXT);
872 RECT rect;
874 if (!hWndCtl) return;
875 GetWindowRect( hWndCtl, &rect );
876 MapWindowPoints( 0, hWnd, (LPPOINT)&rect, 2 );
877 rect.top += DROP_FIELD_TOP;
878 rect.bottom = rect.top + 2;
879 DrawEdge( hdc, &rect, BDR_SUNKENOUTER, BF_RECT );
882 /*************************************************************************
883 * SHHelpShortcuts_RunDLLA [SHELL32.@]
886 DWORD WINAPI SHHelpShortcuts_RunDLLA(DWORD dwArg1, DWORD dwArg2, DWORD dwArg3, DWORD dwArg4)
888 FIXME("(%x, %x, %x, %x) stub!\n", dwArg1, dwArg2, dwArg3, dwArg4);
889 return 0;
892 /*************************************************************************
893 * SHHelpShortcuts_RunDLLA [SHELL32.@]
896 DWORD WINAPI SHHelpShortcuts_RunDLLW(DWORD dwArg1, DWORD dwArg2, DWORD dwArg3, DWORD dwArg4)
898 FIXME("(%x, %x, %x, %x) stub!\n", dwArg1, dwArg2, dwArg3, dwArg4);
899 return 0;
902 /*************************************************************************
903 * SHLoadInProc [SHELL32.@]
904 * Create an instance of specified object class from within
905 * the shell process and release it immediately
907 HRESULT WINAPI SHLoadInProc (REFCLSID rclsid)
909 void *ptr = NULL;
911 TRACE("%s\n", debugstr_guid(rclsid));
913 CoCreateInstance(rclsid, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown,&ptr);
914 if(ptr)
916 IUnknown * pUnk = ptr;
917 IUnknown_Release(pUnk);
918 return NOERROR;
920 return DISP_E_MEMBERNOTFOUND;
923 /*************************************************************************
924 * AboutDlgProc (internal)
926 static INT_PTR CALLBACK AboutDlgProc( HWND hWnd, UINT msg, WPARAM wParam,
927 LPARAM lParam )
929 HWND hWndCtl;
931 TRACE("\n");
933 switch(msg)
935 case WM_INITDIALOG:
937 ABOUT_INFO *info = (ABOUT_INFO *)lParam;
938 WCHAR template[512], buffer[512], version[64];
939 extern const char *wine_get_build_id(void);
941 if (info)
943 const char* const *pstr = SHELL_Authors;
944 SendDlgItemMessageW(hWnd, stc1, STM_SETICON,(WPARAM)info->hIcon, 0);
945 GetWindowTextW( hWnd, template, sizeof(template)/sizeof(WCHAR) );
946 sprintfW( buffer, template, info->szApp );
947 SetWindowTextW( hWnd, buffer );
948 SetWindowTextW( GetDlgItem(hWnd, IDC_ABOUT_STATIC_TEXT1), info->szApp );
949 SetWindowTextW( GetDlgItem(hWnd, IDC_ABOUT_STATIC_TEXT2), info->szOtherStuff );
950 GetWindowTextW( GetDlgItem(hWnd, IDC_ABOUT_STATIC_TEXT3),
951 template, sizeof(template)/sizeof(WCHAR) );
952 MultiByteToWideChar( CP_UTF8, 0, wine_get_build_id(), -1,
953 version, sizeof(version)/sizeof(WCHAR) );
954 sprintfW( buffer, template, version );
955 SetWindowTextW( GetDlgItem(hWnd, IDC_ABOUT_STATIC_TEXT3), buffer );
956 hWndCtl = GetDlgItem(hWnd, IDC_ABOUT_LISTBOX);
957 SendMessageW( hWndCtl, WM_SETREDRAW, 0, 0 );
958 SendMessageW( hWndCtl, WM_SETFONT, (WPARAM)info->hFont, 0 );
959 while (*pstr)
961 /* authors list is in utf-8 format */
962 MultiByteToWideChar( CP_UTF8, 0, *pstr, -1, buffer, sizeof(buffer)/sizeof(WCHAR) );
963 SendMessageW( hWndCtl, LB_ADDSTRING, -1, (LPARAM)buffer );
964 pstr++;
966 SendMessageW( hWndCtl, WM_SETREDRAW, 1, 0 );
969 return 1;
971 case WM_PAINT:
973 PAINTSTRUCT ps;
974 HDC hDC = BeginPaint( hWnd, &ps );
975 paint_dropline( hDC, hWnd );
976 EndPaint( hWnd, &ps );
978 break;
980 case WM_COMMAND:
981 if (wParam == IDOK || wParam == IDCANCEL)
983 EndDialog(hWnd, TRUE);
984 return TRUE;
986 if (wParam == IDC_ABOUT_LICENSE)
988 MSGBOXPARAMSW params;
990 params.cbSize = sizeof(params);
991 params.hwndOwner = hWnd;
992 params.hInstance = shell32_hInstance;
993 params.lpszText = MAKEINTRESOURCEW(IDS_LICENSE);
994 params.lpszCaption = MAKEINTRESOURCEW(IDS_LICENSE_CAPTION);
995 params.dwStyle = MB_ICONINFORMATION | MB_OK;
996 params.lpszIcon = 0;
997 params.dwContextHelpId = 0;
998 params.lpfnMsgBoxCallback = NULL;
999 params.dwLanguageId = LANG_NEUTRAL;
1000 MessageBoxIndirectW( &params );
1002 break;
1003 case WM_CLOSE:
1004 EndDialog(hWnd, TRUE);
1005 break;
1008 return 0;
1012 /*************************************************************************
1013 * ShellAboutA [SHELL32.288]
1015 BOOL WINAPI ShellAboutA( HWND hWnd, LPCSTR szApp, LPCSTR szOtherStuff, HICON hIcon )
1017 BOOL ret;
1018 LPWSTR appW = NULL, otherW = NULL;
1019 int len;
1021 if (szApp)
1023 len = MultiByteToWideChar(CP_ACP, 0, szApp, -1, NULL, 0);
1024 appW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1025 MultiByteToWideChar(CP_ACP, 0, szApp, -1, appW, len);
1027 if (szOtherStuff)
1029 len = MultiByteToWideChar(CP_ACP, 0, szOtherStuff, -1, NULL, 0);
1030 otherW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1031 MultiByteToWideChar(CP_ACP, 0, szOtherStuff, -1, otherW, len);
1034 ret = ShellAboutW(hWnd, appW, otherW, hIcon);
1036 HeapFree(GetProcessHeap(), 0, otherW);
1037 HeapFree(GetProcessHeap(), 0, appW);
1038 return ret;
1042 /*************************************************************************
1043 * ShellAboutW [SHELL32.289]
1045 BOOL WINAPI ShellAboutW( HWND hWnd, LPCWSTR szApp, LPCWSTR szOtherStuff,
1046 HICON hIcon )
1048 ABOUT_INFO info;
1049 LOGFONTW logFont;
1050 BOOL bRet;
1051 static const WCHAR wszSHELL_ABOUT_MSGBOX[] =
1052 {'S','H','E','L','L','_','A','B','O','U','T','_','M','S','G','B','O','X',0};
1054 TRACE("\n");
1056 if (!hIcon) hIcon = LoadImageW( 0, (LPWSTR)IDI_WINLOGO, IMAGE_ICON, 48, 48, LR_SHARED );
1057 info.szApp = szApp;
1058 info.szOtherStuff = szOtherStuff;
1059 info.hIcon = hIcon;
1061 SystemParametersInfoW( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 );
1062 info.hFont = CreateFontIndirectW( &logFont );
1064 bRet = DialogBoxParamW( shell32_hInstance, wszSHELL_ABOUT_MSGBOX, hWnd, AboutDlgProc, (LPARAM)&info );
1065 DeleteObject(info.hFont);
1066 return bRet;
1069 /*************************************************************************
1070 * FreeIconList (SHELL32.@)
1072 void WINAPI FreeIconList( DWORD dw )
1074 FIXME("%x: stub\n",dw);
1077 /*************************************************************************
1078 * SHLoadNonloadedIconOverlayIdentifiers (SHELL32.@)
1080 HRESULT WINAPI SHLoadNonloadedIconOverlayIdentifiers( VOID )
1082 FIXME("stub\n");
1083 return S_OK;
1086 /***********************************************************************
1087 * DllGetVersion [SHELL32.@]
1089 * Retrieves version information of the 'SHELL32.DLL'
1091 * PARAMS
1092 * pdvi [O] pointer to version information structure.
1094 * RETURNS
1095 * Success: S_OK
1096 * Failure: E_INVALIDARG
1098 * NOTES
1099 * Returns version of a shell32.dll from IE4.01 SP1.
1102 HRESULT WINAPI DllGetVersion (DLLVERSIONINFO *pdvi)
1104 /* FIXME: shouldn't these values come from the version resource? */
1105 if (pdvi->cbSize == sizeof(DLLVERSIONINFO) ||
1106 pdvi->cbSize == sizeof(DLLVERSIONINFO2))
1108 pdvi->dwMajorVersion = WINE_FILEVERSION_MAJOR;
1109 pdvi->dwMinorVersion = WINE_FILEVERSION_MINOR;
1110 pdvi->dwBuildNumber = WINE_FILEVERSION_BUILD;
1111 pdvi->dwPlatformID = WINE_FILEVERSION_PLATFORMID;
1112 if (pdvi->cbSize == sizeof(DLLVERSIONINFO2))
1114 DLLVERSIONINFO2 *pdvi2 = (DLLVERSIONINFO2 *)pdvi;
1116 pdvi2->dwFlags = 0;
1117 pdvi2->ullVersion = MAKEDLLVERULL(WINE_FILEVERSION_MAJOR,
1118 WINE_FILEVERSION_MINOR,
1119 WINE_FILEVERSION_BUILD,
1120 WINE_FILEVERSION_PLATFORMID);
1122 TRACE("%u.%u.%u.%u\n",
1123 pdvi->dwMajorVersion, pdvi->dwMinorVersion,
1124 pdvi->dwBuildNumber, pdvi->dwPlatformID);
1125 return S_OK;
1127 else
1129 WARN("wrong DLLVERSIONINFO size from app\n");
1130 return E_INVALIDARG;
1134 /*************************************************************************
1135 * global variables of the shell32.dll
1136 * all are once per process
1139 HINSTANCE shell32_hInstance = 0;
1140 HIMAGELIST ShellSmallIconList = 0;
1141 HIMAGELIST ShellBigIconList = 0;
1144 /*************************************************************************
1145 * SHELL32 DllMain
1147 * NOTES
1148 * calling oleinitialize here breaks sone apps.
1150 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
1152 TRACE("%p 0x%x %p\n", hinstDLL, fdwReason, fImpLoad);
1154 switch (fdwReason)
1156 case DLL_PROCESS_ATTACH:
1157 shell32_hInstance = hinstDLL;
1158 DisableThreadLibraryCalls(shell32_hInstance);
1160 /* get full path to this DLL for IExtractIconW_fnGetIconLocation() */
1161 GetModuleFileNameW(hinstDLL, swShell32Name, MAX_PATH);
1162 swShell32Name[MAX_PATH - 1] = '\0';
1164 InitCommonControlsEx(NULL);
1166 SIC_Initialize();
1167 InitChangeNotifications();
1168 break;
1170 case DLL_PROCESS_DETACH:
1171 shell32_hInstance = 0;
1172 SIC_Destroy();
1173 FreeChangeNotifications();
1174 break;
1176 return TRUE;
1179 /*************************************************************************
1180 * DllInstall [SHELL32.@]
1182 * PARAMETERS
1184 * BOOL bInstall - TRUE for install, FALSE for uninstall
1185 * LPCWSTR pszCmdLine - command line (unused by shell32?)
1188 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
1190 FIXME("%s %s: stub\n", bInstall ? "TRUE":"FALSE", debugstr_w(cmdline));
1191 return S_OK; /* indicate success */
1194 /***********************************************************************
1195 * DllCanUnloadNow (SHELL32.@)
1197 HRESULT WINAPI DllCanUnloadNow(void)
1199 return S_FALSE;
1202 /***********************************************************************
1203 * ExtractVersionResource16W (SHELL32.@)
1205 BOOL WINAPI ExtractVersionResource16W(LPWSTR s, DWORD d)
1207 FIXME("(%s %x) stub!\n", debugstr_w(s), d);
1208 return FALSE;
1211 /***********************************************************************
1212 * InitNetworkAddressControl (SHELL32.@)
1214 BOOL WINAPI InitNetworkAddressControl(void)
1216 FIXME("stub\n");
1217 return FALSE;
1220 /***********************************************************************
1221 * ShellHookProc (SHELL32.@)
1223 LRESULT CALLBACK ShellHookProc(DWORD a, DWORD b, DWORD c)
1225 FIXME("Stub\n");
1226 return 0;
1229 HRESULT WINAPI SHGetLocalizedName(LPCWSTR path, LPWSTR module, UINT size, INT *res)
1231 FIXME("%s %p %u %p: stub\n", debugstr_w(path), module, size, res);
1232 return E_NOTIMPL;