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
44 #include "undocshell.h"
46 #include "shell32_main.h"
52 #include "wine/debug.h"
53 #include "wine/unicode.h"
55 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
57 /*************************************************************************
58 * CommandLineToArgvW [SHELL32.@]
60 * We must interpret the quotes in the command line to rebuild the argv
62 * - arguments are separated by spaces or tabs
63 * - quotes serve as optional argument delimiters
65 * - escaped quotes must be converted back to '"'
67 * - consecutive backslashes preceding a quote see their number halved with
68 * the remainder escaping the quote:
69 * 2n backslashes + quote -> n backslashes + quote as an argument delimiter
70 * 2n+1 backslashes + quote -> n backslashes + literal quote
71 * - backslashes that are not followed by a quote are copied literally:
74 * - in quoted strings, consecutive quotes see their number divided by three
75 * with the remainder modulo 3 deciding whether to close the string or not.
76 * Note that the opening quote must be counted in the consecutive quotes,
77 * that's the (1+) below:
78 * (1+) 3n quotes -> n quotes
79 * (1+) 3n+1 quotes -> n quotes plus closes the quoted string
80 * (1+) 3n+2 quotes -> n+1 quotes plus closes the quoted string
81 * - in unquoted strings, the first quote opens the quoted string and the
82 * remaining consecutive quotes follow the above rule.
84 LPWSTR
* WINAPI
CommandLineToArgvW(LPCWSTR lpCmdline
, int* numargs
)
95 SetLastError(ERROR_INVALID_PARAMETER
);
101 /* Return the path to the executable */
102 DWORD len
, deslen
=MAX_PATH
, size
;
104 size
= sizeof(LPWSTR
) + deslen
*sizeof(WCHAR
) + sizeof(LPWSTR
);
107 if (!(argv
= LocalAlloc(LMEM_FIXED
, size
))) return NULL
;
108 len
= GetModuleFileNameW(0, (LPWSTR
)(argv
+1), deslen
);
114 if (len
< deslen
) break;
116 size
= sizeof(LPWSTR
) + deslen
*sizeof(WCHAR
) + sizeof(LPWSTR
);
119 argv
[0]=(LPWSTR
)(argv
+1);
125 /* --- First count the arguments */
128 /* The first argument, the executable path, follows special rules */
131 /* The executable path ends at the next quote, no matter what */
139 /* The executable path ends at the next space, no matter what */
140 while (*s
&& *s
!=' ' && *s
!='\t')
143 /* skip to the first argument, if any */
144 while (*s
==' ' || *s
=='\t')
149 /* Analyze the remaining arguments */
153 if ((*s
==' ' || *s
=='\t') && qcount
==0)
155 /* skip to the next argument and count it if any */
156 while (*s
==' ' || *s
=='\t')
164 /* '\', count them */
172 qcount
++; /* unescaped '"' */
175 /* consecutive quotes, see comment in copying code below */
187 /* a regular character */
193 /* Allocate in a single lump, the string array, and the strings that go
194 * with it. This way the caller can make a single LocalFree() call to free
197 argv
=LocalAlloc(LMEM_FIXED
, argc
*sizeof(LPWSTR
)+(strlenW(lpCmdline
)+1)*sizeof(WCHAR
));
200 cmdline
=(LPWSTR
)(argv
+argc
);
201 strcpyW(cmdline
, lpCmdline
);
203 /* --- Then split and copy the arguments */
206 /* The first argument, the executable path, follows special rules */
209 /* The executable path ends at the next quote, no matter what */
223 /* The executable path ends at the next space, no matter what */
224 while (*d
&& *d
!=' ' && *d
!='\t')
230 /* close the executable path */
232 /* skip to the first argument and initialize it if any */
233 while (*s
==' ' || *s
=='\t')
237 /* There are no parameters so we are all done */
242 /* Split and copy the remaining arguments */
247 if ((*s
==' ' || *s
=='\t') && qcount
==0)
249 /* close the argument */
253 /* skip to the next one and initialize it if any */
256 } while (*s
==' ' || *s
=='\t');
269 /* Preceded by an even number of '\', this is half that
270 * number of '\', plus a quote which we erase.
277 /* Preceded by an odd number of '\', this is half that
278 * number of '\' followed by a '"'
285 /* Now count the number of consecutive quotes. Note that qcount
286 * already takes into account the opening quote if any, as well as
287 * the quote that lead us here.
303 /* a regular character */
314 static DWORD
shgfi_get_exe_type(LPCWSTR szFullPath
)
319 IMAGE_DOS_HEADER mz_header
;
324 status
= GetBinaryTypeW (szFullPath
, &BinaryType
);
327 if (BinaryType
== SCS_DOS_BINARY
|| BinaryType
== SCS_PIF_BINARY
)
330 hfile
= CreateFileW( szFullPath
, GENERIC_READ
, FILE_SHARE_READ
,
331 NULL
, OPEN_EXISTING
, 0, 0 );
332 if ( hfile
== INVALID_HANDLE_VALUE
)
336 * The next section is adapted from MODULE_GetBinaryType, as we need
337 * to examine the image header to get OS and version information. We
338 * know from calling GetBinaryTypeA that the image is valid and either
339 * an NE or PE, so much error handling can be omitted.
340 * Seek to the start of the file and read the header information.
343 SetFilePointer( hfile
, 0, NULL
, SEEK_SET
);
344 ReadFile( hfile
, &mz_header
, sizeof(mz_header
), &len
, NULL
);
346 SetFilePointer( hfile
, mz_header
.e_lfanew
, NULL
, SEEK_SET
);
347 ReadFile( hfile
, magic
, sizeof(magic
), &len
, NULL
);
348 if ( *(DWORD
*)magic
== IMAGE_NT_SIGNATURE
)
350 SetFilePointer( hfile
, mz_header
.e_lfanew
, NULL
, SEEK_SET
);
351 ReadFile( hfile
, &nt
, sizeof(nt
), &len
, NULL
);
352 CloseHandle( hfile
);
353 /* DLL files are not executable and should return 0 */
354 if (nt
.FileHeader
.Characteristics
& IMAGE_FILE_DLL
)
356 if (nt
.OptionalHeader
.Subsystem
== IMAGE_SUBSYSTEM_WINDOWS_GUI
)
358 return IMAGE_NT_SIGNATURE
|
359 (nt
.OptionalHeader
.MajorSubsystemVersion
<< 24) |
360 (nt
.OptionalHeader
.MinorSubsystemVersion
<< 16);
362 return IMAGE_NT_SIGNATURE
;
364 else if ( *(WORD
*)magic
== IMAGE_OS2_SIGNATURE
)
367 SetFilePointer( hfile
, mz_header
.e_lfanew
, NULL
, SEEK_SET
);
368 ReadFile( hfile
, &ne
, sizeof(ne
), &len
, NULL
);
369 CloseHandle( hfile
);
370 if (ne
.ne_exetyp
== 2)
371 return IMAGE_OS2_SIGNATURE
| (ne
.ne_expver
<< 16);
374 CloseHandle( hfile
);
378 /*************************************************************************
379 * SHELL_IsShortcut [internal]
381 * Decide if an item id list points to a shell shortcut
383 BOOL
SHELL_IsShortcut(LPCITEMIDLIST pidlLast
)
385 char szTemp
[MAX_PATH
];
389 if (_ILGetExtension(pidlLast
, szTemp
, MAX_PATH
) &&
390 HCR_MapTypeToValueA(szTemp
, szTemp
, MAX_PATH
, TRUE
))
392 if (ERROR_SUCCESS
== RegOpenKeyExA(HKEY_CLASSES_ROOT
, szTemp
, 0, KEY_QUERY_VALUE
, &keyCls
))
394 if (ERROR_SUCCESS
== RegQueryValueExA(keyCls
, "IsShortcut", NULL
, NULL
, NULL
, NULL
))
404 #define SHGFI_KNOWN_FLAGS \
405 (SHGFI_SMALLICON | SHGFI_OPENICON | SHGFI_SHELLICONSIZE | SHGFI_PIDL | \
406 SHGFI_USEFILEATTRIBUTES | SHGFI_ADDOVERLAYS | SHGFI_OVERLAYINDEX | \
407 SHGFI_ICON | SHGFI_DISPLAYNAME | SHGFI_TYPENAME | SHGFI_ATTRIBUTES | \
408 SHGFI_ICONLOCATION | SHGFI_EXETYPE | SHGFI_SYSICONINDEX | \
409 SHGFI_LINKOVERLAY | SHGFI_SELECTED | SHGFI_ATTR_SPECIFIED)
411 /*************************************************************************
412 * SHGetFileInfoW [SHELL32.@]
415 DWORD_PTR WINAPI
SHGetFileInfoW(LPCWSTR path
,DWORD dwFileAttributes
,
416 SHFILEINFOW
*psfi
, UINT sizeofpsfi
, UINT flags
)
418 WCHAR szLocation
[MAX_PATH
], szFullPath
[MAX_PATH
];
420 DWORD_PTR ret
= TRUE
;
421 DWORD dwAttributes
= 0;
422 IShellFolder
* psfParent
= NULL
;
423 IExtractIconW
* pei
= NULL
;
424 LPITEMIDLIST pidlLast
= NULL
, pidl
= NULL
;
426 BOOL IconNotYetLoaded
=TRUE
;
429 TRACE("%s fattr=0x%x sfi=%p(attr=0x%08x) size=0x%x flags=0x%x\n",
430 (flags
& SHGFI_PIDL
)? "pidl" : debugstr_w(path
), dwFileAttributes
,
431 psfi
, psfi
->dwAttributes
, sizeofpsfi
, flags
);
436 /* windows initializes these values regardless of the flags */
439 psfi
->szDisplayName
[0] = '\0';
440 psfi
->szTypeName
[0] = '\0';
444 if (!(flags
& SHGFI_PIDL
))
446 /* SHGetFileInfo should work with absolute and relative paths */
447 if (PathIsRelativeW(path
))
449 GetCurrentDirectoryW(MAX_PATH
, szLocation
);
450 PathCombineW(szFullPath
, szLocation
, path
);
454 lstrcpynW(szFullPath
, path
, MAX_PATH
);
458 if (flags
& SHGFI_EXETYPE
)
460 if (flags
!= SHGFI_EXETYPE
)
462 return shgfi_get_exe_type(szFullPath
);
466 * psfi is NULL normally to query EXE type. If it is NULL, none of the
467 * below makes sense anyway. Windows allows this and just returns FALSE
473 * translate the path into a pidl only when SHGFI_USEFILEATTRIBUTES
475 * The pidl functions fail on not existing file names
478 if (flags
& SHGFI_PIDL
)
480 pidl
= ILClone((LPCITEMIDLIST
)path
);
482 else if (!(flags
& SHGFI_USEFILEATTRIBUTES
))
484 hr
= SHILCreateFromPathW(szFullPath
, &pidl
, &dwAttributes
);
487 if ((flags
& SHGFI_PIDL
) || !(flags
& SHGFI_USEFILEATTRIBUTES
))
489 /* get the parent shellfolder */
492 hr
= SHBindToParent( pidl
, &IID_IShellFolder
, (LPVOID
*)&psfParent
,
493 (LPCITEMIDLIST
*)&pidlLast
);
495 pidlLast
= ILClone(pidlLast
);
500 ERR("pidl is null!\n");
505 /* get the attributes of the child */
506 if (SUCCEEDED(hr
) && (flags
& SHGFI_ATTRIBUTES
))
508 if (!(flags
& SHGFI_ATTR_SPECIFIED
))
510 psfi
->dwAttributes
= 0xffffffff;
513 IShellFolder_GetAttributesOf( psfParent
, 1, (LPCITEMIDLIST
*)&pidlLast
,
514 &(psfi
->dwAttributes
) );
517 /* get the displayname */
518 if (SUCCEEDED(hr
) && (flags
& SHGFI_DISPLAYNAME
))
520 if (flags
& SHGFI_USEFILEATTRIBUTES
&& !(flags
& SHGFI_PIDL
))
522 lstrcpyW (psfi
->szDisplayName
, PathFindFileNameW(szFullPath
));
527 hr
= IShellFolder_GetDisplayNameOf( psfParent
, pidlLast
,
528 SHGDN_INFOLDER
, &str
);
529 StrRetToStrNW (psfi
->szDisplayName
, MAX_PATH
, &str
, pidlLast
);
533 /* get the type name */
534 if (SUCCEEDED(hr
) && (flags
& SHGFI_TYPENAME
))
536 static const WCHAR szFile
[] = { 'F','i','l','e',0 };
537 static const WCHAR szDashFile
[] = { '-','f','i','l','e',0 };
539 if (!(flags
& SHGFI_USEFILEATTRIBUTES
) || (flags
& SHGFI_PIDL
))
543 _ILGetFileType(pidlLast
, ftype
, 80);
544 MultiByteToWideChar(CP_ACP
, 0, ftype
, -1, psfi
->szTypeName
, 80 );
548 if (dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
549 strcatW (psfi
->szTypeName
, szFile
);
554 lstrcpyW(sTemp
,PathFindExtensionW(szFullPath
));
555 if (!( HCR_MapTypeToValueW(sTemp
, sTemp
, 64, TRUE
) &&
556 HCR_MapTypeToValueW(sTemp
, psfi
->szTypeName
, 80, FALSE
)))
558 lstrcpynW (psfi
->szTypeName
, sTemp
, 64);
559 strcatW (psfi
->szTypeName
, szDashFile
);
566 if (flags
& SHGFI_OPENICON
)
567 uGilFlags
|= GIL_OPENICON
;
569 if (flags
& SHGFI_LINKOVERLAY
)
570 uGilFlags
|= GIL_FORSHORTCUT
;
571 else if ((flags
&SHGFI_ADDOVERLAYS
) ||
572 (flags
&(SHGFI_ICON
|SHGFI_SMALLICON
))==SHGFI_ICON
)
574 if (SHELL_IsShortcut(pidlLast
))
575 uGilFlags
|= GIL_FORSHORTCUT
;
578 if (flags
& SHGFI_OVERLAYINDEX
)
579 FIXME("SHGFI_OVERLAYINDEX unhandled\n");
581 if (flags
& SHGFI_SELECTED
)
582 FIXME("set icon to selected, stub\n");
584 if (flags
& SHGFI_SHELLICONSIZE
)
585 FIXME("set icon to shell size, stub\n");
587 /* get the iconlocation */
588 if (SUCCEEDED(hr
) && (flags
& SHGFI_ICONLOCATION
))
592 if (flags
& SHGFI_USEFILEATTRIBUTES
&& !(flags
& SHGFI_PIDL
))
594 if (dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
596 lstrcpyW(psfi
->szDisplayName
, swShell32Name
);
597 psfi
->iIcon
= -IDI_SHELL_FOLDER
;
602 static const WCHAR p1W
[] = {'%','1',0};
603 WCHAR sTemp
[MAX_PATH
];
605 szExt
= PathFindExtensionW(szFullPath
);
606 TRACE("szExt=%s\n", debugstr_w(szExt
));
608 HCR_MapTypeToValueW(szExt
, sTemp
, MAX_PATH
, TRUE
) &&
609 HCR_GetDefaultIconW(sTemp
, sTemp
, MAX_PATH
, &psfi
->iIcon
))
611 if (lstrcmpW(p1W
, sTemp
))
612 strcpyW(psfi
->szDisplayName
, sTemp
);
615 /* the icon is in the file */
616 strcpyW(psfi
->szDisplayName
, szFullPath
);
625 hr
= IShellFolder_GetUIObjectOf(psfParent
, 0, 1,
626 (LPCITEMIDLIST
*)&pidlLast
, &IID_IExtractIconW
,
627 &uDummy
, (LPVOID
*)&pei
);
630 hr
= IExtractIconW_GetIconLocation(pei
, uGilFlags
,
631 szLocation
, MAX_PATH
, &iIndex
, &uFlags
);
633 if (uFlags
& GIL_NOTFILENAME
)
637 lstrcpyW (psfi
->szDisplayName
, szLocation
);
638 psfi
->iIcon
= iIndex
;
640 IExtractIconW_Release(pei
);
645 /* get icon index (or load icon)*/
646 if (SUCCEEDED(hr
) && (flags
& (SHGFI_ICON
| SHGFI_SYSICONINDEX
)))
648 if (flags
& SHGFI_USEFILEATTRIBUTES
&& !(flags
& SHGFI_PIDL
))
650 WCHAR sTemp
[MAX_PATH
];
654 lstrcpynW(sTemp
, szFullPath
, MAX_PATH
);
656 if (dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
657 psfi
->iIcon
= SIC_GetIconIndex(swShell32Name
, -IDI_SHELL_FOLDER
, 0);
660 static const WCHAR p1W
[] = {'%','1',0};
663 szExt
= PathFindExtensionW(sTemp
);
665 HCR_MapTypeToValueW(szExt
, sTemp
, MAX_PATH
, TRUE
) &&
666 HCR_GetDefaultIconW(sTemp
, sTemp
, MAX_PATH
, &icon_idx
))
668 if (!lstrcmpW(p1W
,sTemp
)) /* icon is in the file */
669 strcpyW(sTemp
, szFullPath
);
671 if (flags
& SHGFI_SYSICONINDEX
)
673 psfi
->iIcon
= SIC_GetIconIndex(sTemp
,icon_idx
,0);
674 if (psfi
->iIcon
== -1)
680 if (flags
& SHGFI_SMALLICON
)
681 ret
= PrivateExtractIconsW( sTemp
,icon_idx
,
682 GetSystemMetrics( SM_CXSMICON
),
683 GetSystemMetrics( SM_CYSMICON
),
684 &psfi
->hIcon
, 0, 1, 0);
686 ret
= PrivateExtractIconsW( sTemp
, icon_idx
,
687 GetSystemMetrics( SM_CXICON
),
688 GetSystemMetrics( SM_CYICON
),
689 &psfi
->hIcon
, 0, 1, 0);
690 if (ret
!= 0 && ret
!= (UINT
)-1)
692 IconNotYetLoaded
=FALSE
;
693 psfi
->iIcon
= icon_idx
;
701 if (!(PidlToSicIndex(psfParent
, pidlLast
, !(flags
& SHGFI_SMALLICON
),
702 uGilFlags
, &(psfi
->iIcon
))))
707 if (ret
&& (flags
& SHGFI_SYSICONINDEX
))
709 if (flags
& SHGFI_SMALLICON
)
710 ret
= (DWORD_PTR
) ShellSmallIconList
;
712 ret
= (DWORD_PTR
) ShellBigIconList
;
717 if (SUCCEEDED(hr
) && (flags
& SHGFI_ICON
) && IconNotYetLoaded
)
719 if (flags
& SHGFI_SMALLICON
)
720 psfi
->hIcon
= ImageList_GetIcon( ShellSmallIconList
, psfi
->iIcon
, ILD_NORMAL
);
722 psfi
->hIcon
= ImageList_GetIcon( ShellBigIconList
, psfi
->iIcon
, ILD_NORMAL
);
725 if (flags
& ~SHGFI_KNOWN_FLAGS
)
726 FIXME("unknown flags %08x\n", flags
& ~SHGFI_KNOWN_FLAGS
);
729 IShellFolder_Release(psfParent
);
736 TRACE ("icon=%p index=0x%08x attr=0x%08x name=%s type=%s ret=0x%08lx\n",
737 psfi
->hIcon
, psfi
->iIcon
, psfi
->dwAttributes
,
738 debugstr_w(psfi
->szDisplayName
), debugstr_w(psfi
->szTypeName
), ret
);
743 /*************************************************************************
744 * SHGetFileInfoA [SHELL32.@]
747 * MSVBVM60.__vbaNew2 expects this function to return a value in range
748 * 1 .. 0x7fff when the function succeeds and flags does not contain
749 * SHGFI_EXETYPE or SHGFI_SYSICONINDEX (see bug 7701)
751 DWORD_PTR WINAPI
SHGetFileInfoA(LPCSTR path
,DWORD dwFileAttributes
,
752 SHFILEINFOA
*psfi
, UINT sizeofpsfi
,
756 LPWSTR temppath
= NULL
;
759 SHFILEINFOW temppsfi
;
761 if (flags
& SHGFI_PIDL
)
763 /* path contains a pidl */
764 pathW
= (LPCWSTR
)path
;
768 len
= MultiByteToWideChar(CP_ACP
, 0, path
, -1, NULL
, 0);
769 temppath
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
770 MultiByteToWideChar(CP_ACP
, 0, path
, -1, temppath
, len
);
774 if (psfi
&& (flags
& SHGFI_ATTR_SPECIFIED
))
775 temppsfi
.dwAttributes
=psfi
->dwAttributes
;
778 ret
= SHGetFileInfoW(pathW
, dwFileAttributes
, NULL
, sizeof(temppsfi
), flags
);
780 ret
= SHGetFileInfoW(pathW
, dwFileAttributes
, &temppsfi
, sizeof(temppsfi
), flags
);
784 if(flags
& SHGFI_ICON
)
785 psfi
->hIcon
=temppsfi
.hIcon
;
786 if(flags
& (SHGFI_SYSICONINDEX
|SHGFI_ICON
|SHGFI_ICONLOCATION
))
787 psfi
->iIcon
=temppsfi
.iIcon
;
788 if(flags
& SHGFI_ATTRIBUTES
)
789 psfi
->dwAttributes
=temppsfi
.dwAttributes
;
790 if(flags
& (SHGFI_DISPLAYNAME
|SHGFI_ICONLOCATION
))
792 WideCharToMultiByte(CP_ACP
, 0, temppsfi
.szDisplayName
, -1,
793 psfi
->szDisplayName
, sizeof(psfi
->szDisplayName
), NULL
, NULL
);
795 if(flags
& SHGFI_TYPENAME
)
797 WideCharToMultiByte(CP_ACP
, 0, temppsfi
.szTypeName
, -1,
798 psfi
->szTypeName
, sizeof(psfi
->szTypeName
), NULL
, NULL
);
802 HeapFree(GetProcessHeap(), 0, temppath
);
807 /*************************************************************************
808 * DuplicateIcon [SHELL32.@]
810 HICON WINAPI
DuplicateIcon( HINSTANCE hInstance
, HICON hIcon
)
815 TRACE("%p %p\n", hInstance
, hIcon
);
817 if (GetIconInfo(hIcon
, &IconInfo
))
819 hDupIcon
= CreateIconIndirect(&IconInfo
);
821 /* clean up hbmMask and hbmColor */
822 DeleteObject(IconInfo
.hbmMask
);
823 DeleteObject(IconInfo
.hbmColor
);
829 /*************************************************************************
830 * ExtractIconA [SHELL32.@]
832 HICON WINAPI
ExtractIconA(HINSTANCE hInstance
, LPCSTR lpszFile
, UINT nIconIndex
)
835 INT len
= MultiByteToWideChar(CP_ACP
, 0, lpszFile
, -1, NULL
, 0);
836 LPWSTR lpwstrFile
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
838 TRACE("%p %s %d\n", hInstance
, lpszFile
, nIconIndex
);
840 MultiByteToWideChar(CP_ACP
, 0, lpszFile
, -1, lpwstrFile
, len
);
841 ret
= ExtractIconW(hInstance
, lpwstrFile
, nIconIndex
);
842 HeapFree(GetProcessHeap(), 0, lpwstrFile
);
847 /*************************************************************************
848 * ExtractIconW [SHELL32.@]
850 HICON WINAPI
ExtractIconW(HINSTANCE hInstance
, LPCWSTR lpszFile
, UINT nIconIndex
)
854 UINT cx
= GetSystemMetrics(SM_CXICON
), cy
= GetSystemMetrics(SM_CYICON
);
856 TRACE("%p %s %d\n", hInstance
, debugstr_w(lpszFile
), nIconIndex
);
858 if (nIconIndex
== (UINT
)-1)
860 ret
= PrivateExtractIconsW(lpszFile
, 0, cx
, cy
, NULL
, NULL
, 0, LR_DEFAULTCOLOR
);
861 if (ret
!= (UINT
)-1 && ret
)
862 return (HICON
)(UINT_PTR
)ret
;
866 ret
= PrivateExtractIconsW(lpszFile
, nIconIndex
, cx
, cy
, &hIcon
, NULL
, 1, LR_DEFAULTCOLOR
);
870 else if (ret
> 0 && hIcon
)
876 HRESULT WINAPI
SHCreateFileExtractIconW(LPCWSTR file
, DWORD attribs
, REFIID riid
, void **ppv
)
878 FIXME("%s, %x, %s, %p\n", debugstr_w(file
), attribs
, debugstr_guid(riid
), ppv
);
883 /*************************************************************************
884 * Printer_LoadIconsW [SHELL32.205]
886 VOID WINAPI
Printer_LoadIconsW(LPCWSTR wsPrinterName
, HICON
* pLargeIcon
, HICON
* pSmallIcon
)
888 INT iconindex
=IDI_SHELL_PRINTER
;
890 TRACE("(%s, %p, %p)\n", debugstr_w(wsPrinterName
), pLargeIcon
, pSmallIcon
);
892 /* We should check if wsPrinterName is
893 1. the Default Printer or not
895 3. a Local Printer or a Network-Printer
896 and use different Icons
898 if((wsPrinterName
!= NULL
) && (wsPrinterName
[0] != 0))
900 FIXME("(select Icon by PrinterName %s not implemented)\n", debugstr_w(wsPrinterName
));
903 if(pLargeIcon
!= NULL
)
904 *pLargeIcon
= LoadImageW(shell32_hInstance
,
905 (LPCWSTR
) MAKEINTRESOURCE(iconindex
), IMAGE_ICON
,
906 0, 0, LR_DEFAULTCOLOR
|LR_DEFAULTSIZE
);
908 if(pSmallIcon
!= NULL
)
909 *pSmallIcon
= LoadImageW(shell32_hInstance
,
910 (LPCWSTR
) MAKEINTRESOURCE(iconindex
), IMAGE_ICON
,
911 16, 16, LR_DEFAULTCOLOR
);
914 /*************************************************************************
915 * Printers_RegisterWindowW [SHELL32.213]
916 * used by "printui.dll":
917 * find the Window of the given Type for the specific Printer and
918 * return the already existent hwnd or open a new window
920 BOOL WINAPI
Printers_RegisterWindowW(LPCWSTR wsPrinter
, DWORD dwType
,
921 HANDLE
* phClassPidl
, HWND
* phwnd
)
923 FIXME("(%s, %x, %p (%p), %p (%p)) stub!\n", debugstr_w(wsPrinter
), dwType
,
924 phClassPidl
, (phClassPidl
!= NULL
) ? *(phClassPidl
) : NULL
,
925 phwnd
, (phwnd
!= NULL
) ? *(phwnd
) : NULL
);
930 /*************************************************************************
931 * Printers_UnregisterWindow [SHELL32.214]
933 VOID WINAPI
Printers_UnregisterWindow(HANDLE hClassPidl
, HWND hwnd
)
935 FIXME("(%p, %p) stub!\n", hClassPidl
, hwnd
);
938 /*************************************************************************
939 * SHGetPropertyStoreFromParsingName [SHELL32.@]
941 HRESULT WINAPI
SHGetPropertyStoreFromParsingName(PCWSTR pszPath
, IBindCtx
*pbc
, GETPROPERTYSTOREFLAGS flags
, REFIID riid
, void **ppv
)
943 FIXME("(%s %p %u %p %p) stub!\n", debugstr_w(pszPath
), pbc
, flags
, riid
, ppv
);
947 /*************************************************************************/
952 LPCWSTR szOtherStuff
;
957 #define DROP_FIELD_TOP (-12)
959 static void paint_dropline( HDC hdc
, HWND hWnd
)
961 HWND hWndCtl
= GetDlgItem(hWnd
, IDC_ABOUT_WINE_TEXT
);
964 if (!hWndCtl
) return;
965 GetWindowRect( hWndCtl
, &rect
);
966 MapWindowPoints( 0, hWnd
, (LPPOINT
)&rect
, 2 );
967 rect
.top
+= DROP_FIELD_TOP
;
968 rect
.bottom
= rect
.top
+ 2;
969 DrawEdge( hdc
, &rect
, BDR_SUNKENOUTER
, BF_RECT
);
972 /*************************************************************************
973 * SHHelpShortcuts_RunDLLA [SHELL32.@]
976 DWORD WINAPI
SHHelpShortcuts_RunDLLA(DWORD dwArg1
, DWORD dwArg2
, DWORD dwArg3
, DWORD dwArg4
)
978 FIXME("(%x, %x, %x, %x) stub!\n", dwArg1
, dwArg2
, dwArg3
, dwArg4
);
982 /*************************************************************************
983 * SHHelpShortcuts_RunDLLA [SHELL32.@]
986 DWORD WINAPI
SHHelpShortcuts_RunDLLW(DWORD dwArg1
, DWORD dwArg2
, DWORD dwArg3
, DWORD dwArg4
)
988 FIXME("(%x, %x, %x, %x) stub!\n", dwArg1
, dwArg2
, dwArg3
, dwArg4
);
992 /*************************************************************************
993 * SHLoadInProc [SHELL32.@]
994 * Create an instance of specified object class from within
995 * the shell process and release it immediately
997 HRESULT WINAPI
SHLoadInProc (REFCLSID rclsid
)
1001 TRACE("%s\n", debugstr_guid(rclsid
));
1003 CoCreateInstance(rclsid
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
,&ptr
);
1006 IUnknown
* pUnk
= ptr
;
1007 IUnknown_Release(pUnk
);
1010 return DISP_E_MEMBERNOTFOUND
;
1013 static void add_authors( HWND list
)
1015 static const WCHAR eol
[] = {'\r','\n',0};
1016 static const WCHAR authors
[] = {'A','U','T','H','O','R','S',0};
1017 WCHAR
*strW
, *start
, *end
;
1018 HRSRC rsrc
= FindResourceW( shell32_hInstance
, authors
, (LPCWSTR
)RT_RCDATA
);
1019 char *strA
= LockResource( LoadResource( shell32_hInstance
, rsrc
));
1020 DWORD sizeW
, sizeA
= SizeofResource( shell32_hInstance
, rsrc
);
1023 sizeW
= MultiByteToWideChar( CP_UTF8
, 0, strA
, sizeA
, NULL
, 0 ) + 1;
1024 if (!(strW
= HeapAlloc( GetProcessHeap(), 0, sizeW
* sizeof(WCHAR
) ))) return;
1025 MultiByteToWideChar( CP_UTF8
, 0, strA
, sizeA
, strW
, sizeW
);
1026 strW
[sizeW
- 1] = 0;
1028 start
= strpbrkW( strW
, eol
); /* skip the header line */
1031 while (*start
&& strchrW( eol
, *start
)) start
++;
1033 end
= strpbrkW( start
, eol
);
1034 if (end
) *end
++ = 0;
1035 SendMessageW( list
, LB_ADDSTRING
, -1, (LPARAM
)start
);
1038 HeapFree( GetProcessHeap(), 0, strW
);
1041 /*************************************************************************
1042 * AboutDlgProc (internal)
1044 static INT_PTR CALLBACK
AboutDlgProc( HWND hWnd
, UINT msg
, WPARAM wParam
,
1055 ABOUT_INFO
*info
= (ABOUT_INFO
*)lParam
;
1056 WCHAR
template[512], buffer
[512], version
[64];
1057 extern const char *wine_get_build_id(void);
1061 SendDlgItemMessageW(hWnd
, stc1
, STM_SETICON
,(WPARAM
)info
->hIcon
, 0);
1062 GetWindowTextW( hWnd
, template, sizeof(template)/sizeof(WCHAR
) );
1063 sprintfW( buffer
, template, info
->szApp
);
1064 SetWindowTextW( hWnd
, buffer
);
1065 SetWindowTextW( GetDlgItem(hWnd
, IDC_ABOUT_STATIC_TEXT1
), info
->szApp
);
1066 SetWindowTextW( GetDlgItem(hWnd
, IDC_ABOUT_STATIC_TEXT2
), info
->szOtherStuff
);
1067 GetWindowTextW( GetDlgItem(hWnd
, IDC_ABOUT_STATIC_TEXT3
),
1068 template, sizeof(template)/sizeof(WCHAR
) );
1069 MultiByteToWideChar( CP_UTF8
, 0, wine_get_build_id(), -1,
1070 version
, sizeof(version
)/sizeof(WCHAR
) );
1071 sprintfW( buffer
, template, version
);
1072 SetWindowTextW( GetDlgItem(hWnd
, IDC_ABOUT_STATIC_TEXT3
), buffer
);
1073 hWndCtl
= GetDlgItem(hWnd
, IDC_ABOUT_LISTBOX
);
1074 SendMessageW( hWndCtl
, WM_SETREDRAW
, 0, 0 );
1075 SendMessageW( hWndCtl
, WM_SETFONT
, (WPARAM
)info
->hFont
, 0 );
1076 add_authors( hWndCtl
);
1077 SendMessageW( hWndCtl
, WM_SETREDRAW
, 1, 0 );
1085 HDC hDC
= BeginPaint( hWnd
, &ps
);
1086 paint_dropline( hDC
, hWnd
);
1087 EndPaint( hWnd
, &ps
);
1092 if (wParam
== IDOK
|| wParam
== IDCANCEL
)
1094 EndDialog(hWnd
, TRUE
);
1097 if (wParam
== IDC_ABOUT_LICENSE
)
1099 MSGBOXPARAMSW params
;
1101 params
.cbSize
= sizeof(params
);
1102 params
.hwndOwner
= hWnd
;
1103 params
.hInstance
= shell32_hInstance
;
1104 params
.lpszText
= MAKEINTRESOURCEW(IDS_LICENSE
);
1105 params
.lpszCaption
= MAKEINTRESOURCEW(IDS_LICENSE_CAPTION
);
1106 params
.dwStyle
= MB_ICONINFORMATION
| MB_OK
;
1107 params
.lpszIcon
= 0;
1108 params
.dwContextHelpId
= 0;
1109 params
.lpfnMsgBoxCallback
= NULL
;
1110 params
.dwLanguageId
= LANG_NEUTRAL
;
1111 MessageBoxIndirectW( ¶ms
);
1115 EndDialog(hWnd
, TRUE
);
1123 /*************************************************************************
1124 * ShellAboutA [SHELL32.288]
1126 BOOL WINAPI
ShellAboutA( HWND hWnd
, LPCSTR szApp
, LPCSTR szOtherStuff
, HICON hIcon
)
1129 LPWSTR appW
= NULL
, otherW
= NULL
;
1134 len
= MultiByteToWideChar(CP_ACP
, 0, szApp
, -1, NULL
, 0);
1135 appW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1136 MultiByteToWideChar(CP_ACP
, 0, szApp
, -1, appW
, len
);
1140 len
= MultiByteToWideChar(CP_ACP
, 0, szOtherStuff
, -1, NULL
, 0);
1141 otherW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1142 MultiByteToWideChar(CP_ACP
, 0, szOtherStuff
, -1, otherW
, len
);
1145 ret
= ShellAboutW(hWnd
, appW
, otherW
, hIcon
);
1147 HeapFree(GetProcessHeap(), 0, otherW
);
1148 HeapFree(GetProcessHeap(), 0, appW
);
1153 /*************************************************************************
1154 * ShellAboutW [SHELL32.289]
1156 BOOL WINAPI
ShellAboutW( HWND hWnd
, LPCWSTR szApp
, LPCWSTR szOtherStuff
,
1162 static const WCHAR wszSHELL_ABOUT_MSGBOX
[] =
1163 {'S','H','E','L','L','_','A','B','O','U','T','_','M','S','G','B','O','X',0};
1167 if (!hIcon
) hIcon
= LoadImageW( 0, (LPWSTR
)IDI_WINLOGO
, IMAGE_ICON
, 48, 48, LR_SHARED
);
1169 info
.szOtherStuff
= szOtherStuff
;
1172 SystemParametersInfoW( SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0 );
1173 info
.hFont
= CreateFontIndirectW( &logFont
);
1175 bRet
= DialogBoxParamW( shell32_hInstance
, wszSHELL_ABOUT_MSGBOX
, hWnd
, AboutDlgProc
, (LPARAM
)&info
);
1176 DeleteObject(info
.hFont
);
1180 /*************************************************************************
1181 * FreeIconList (SHELL32.@)
1183 void WINAPI
FreeIconList( DWORD dw
)
1185 FIXME("%x: stub\n",dw
);
1188 /*************************************************************************
1189 * SHLoadNonloadedIconOverlayIdentifiers (SHELL32.@)
1191 HRESULT WINAPI
SHLoadNonloadedIconOverlayIdentifiers( VOID
)
1197 /***********************************************************************
1198 * DllGetVersion [SHELL32.@]
1200 * Retrieves version information of the 'SHELL32.DLL'
1203 * pdvi [O] pointer to version information structure.
1207 * Failure: E_INVALIDARG
1210 * Returns version of a shell32.dll from IE4.01 SP1.
1213 HRESULT WINAPI
DllGetVersion (DLLVERSIONINFO
*pdvi
)
1215 /* FIXME: shouldn't these values come from the version resource? */
1216 if (pdvi
->cbSize
== sizeof(DLLVERSIONINFO
) ||
1217 pdvi
->cbSize
== sizeof(DLLVERSIONINFO2
))
1219 pdvi
->dwMajorVersion
= WINE_FILEVERSION_MAJOR
;
1220 pdvi
->dwMinorVersion
= WINE_FILEVERSION_MINOR
;
1221 pdvi
->dwBuildNumber
= WINE_FILEVERSION_BUILD
;
1222 pdvi
->dwPlatformID
= WINE_FILEVERSION_PLATFORMID
;
1223 if (pdvi
->cbSize
== sizeof(DLLVERSIONINFO2
))
1225 DLLVERSIONINFO2
*pdvi2
= (DLLVERSIONINFO2
*)pdvi
;
1228 pdvi2
->ullVersion
= MAKEDLLVERULL(WINE_FILEVERSION_MAJOR
,
1229 WINE_FILEVERSION_MINOR
,
1230 WINE_FILEVERSION_BUILD
,
1231 WINE_FILEVERSION_PLATFORMID
);
1233 TRACE("%u.%u.%u.%u\n",
1234 pdvi
->dwMajorVersion
, pdvi
->dwMinorVersion
,
1235 pdvi
->dwBuildNumber
, pdvi
->dwPlatformID
);
1240 WARN("wrong DLLVERSIONINFO size from app\n");
1241 return E_INVALIDARG
;
1245 /*************************************************************************
1246 * global variables of the shell32.dll
1247 * all are once per process
1250 HINSTANCE shell32_hInstance
= 0;
1251 HIMAGELIST ShellSmallIconList
= 0;
1252 HIMAGELIST ShellBigIconList
= 0;
1255 /*************************************************************************
1259 * calling oleinitialize here breaks some apps.
1261 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID fImpLoad
)
1263 TRACE("%p 0x%x %p\n", hinstDLL
, fdwReason
, fImpLoad
);
1267 case DLL_PROCESS_ATTACH
:
1268 shell32_hInstance
= hinstDLL
;
1269 DisableThreadLibraryCalls(shell32_hInstance
);
1271 /* get full path to this DLL for IExtractIconW_fnGetIconLocation() */
1272 GetModuleFileNameW(hinstDLL
, swShell32Name
, MAX_PATH
);
1273 swShell32Name
[MAX_PATH
- 1] = '\0';
1275 InitCommonControlsEx(NULL
);
1278 InitChangeNotifications();
1281 case DLL_PROCESS_DETACH
:
1282 shell32_hInstance
= 0;
1284 FreeChangeNotifications();
1290 /*************************************************************************
1291 * DllInstall [SHELL32.@]
1295 * BOOL bInstall - TRUE for install, FALSE for uninstall
1296 * LPCWSTR pszCmdLine - command line (unused by shell32?)
1299 HRESULT WINAPI
DllInstall(BOOL bInstall
, LPCWSTR cmdline
)
1301 FIXME("%s %s: stub\n", bInstall
? "TRUE":"FALSE", debugstr_w(cmdline
));
1302 return S_OK
; /* indicate success */
1305 /***********************************************************************
1306 * DllCanUnloadNow (SHELL32.@)
1308 HRESULT WINAPI
DllCanUnloadNow(void)
1313 /***********************************************************************
1314 * DllRegisterServer (SHELL32.@)
1316 HRESULT WINAPI
DllRegisterServer(void)
1318 HRESULT hr
= __wine_register_resources( shell32_hInstance
);
1319 if (SUCCEEDED(hr
)) hr
= SHELL_RegisterShellFolders();
1323 /***********************************************************************
1324 * DllUnregisterServer (SHELL32.@)
1326 HRESULT WINAPI
DllUnregisterServer(void)
1328 return __wine_unregister_resources( shell32_hInstance
);
1331 /***********************************************************************
1332 * ExtractVersionResource16W (SHELL32.@)
1334 BOOL WINAPI
ExtractVersionResource16W(LPWSTR s
, DWORD d
)
1336 FIXME("(%s %x) stub!\n", debugstr_w(s
), d
);
1340 /***********************************************************************
1341 * InitNetworkAddressControl (SHELL32.@)
1343 BOOL WINAPI
InitNetworkAddressControl(void)
1349 /***********************************************************************
1350 * ShellHookProc (SHELL32.@)
1352 LRESULT CALLBACK
ShellHookProc(DWORD a
, DWORD b
, DWORD c
)
1358 /***********************************************************************
1359 * SHGetLocalizedName (SHELL32.@)
1361 HRESULT WINAPI
SHGetLocalizedName(LPCWSTR path
, LPWSTR module
, UINT size
, INT
*res
)
1363 FIXME("%s %p %u %p: stub\n", debugstr_w(path
), module
, size
, res
);
1367 /***********************************************************************
1368 * SetCurrentProcessExplicitAppUserModelID (SHELL32.@)
1370 HRESULT WINAPI
SetCurrentProcessExplicitAppUserModelID(PCWSTR appid
)
1372 FIXME("%s: stub\n", debugstr_w(appid
));
1376 /***********************************************************************
1377 * SHSetUnreadMailCountW (SHELL32.@)
1379 HRESULT WINAPI
SHSetUnreadMailCountW(LPCWSTR mailaddress
, DWORD count
, LPCWSTR executecommand
)
1381 FIXME("%s %x %s: stub\n", debugstr_w(mailaddress
), count
, debugstr_w(executecommand
));