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
)*2 + deslen
*sizeof(WCHAR
);
107 if (!(argv
= LocalAlloc(LMEM_FIXED
, size
))) return NULL
;
108 len
= GetModuleFileNameW(0, (LPWSTR
)(argv
+2), deslen
);
114 if (len
< deslen
) break;
116 size
= sizeof(LPWSTR
)*2 + deslen
*sizeof(WCHAR
);
119 argv
[0]=(LPWSTR
)(argv
+2);
126 /* --- First count the arguments */
129 /* The first argument, the executable path, follows special rules */
132 /* The executable path ends at the next quote, no matter what */
140 /* The executable path ends at the next space, no matter what */
141 while (*s
&& *s
!=' ' && *s
!='\t')
144 /* skip to the first argument, if any */
145 while (*s
==' ' || *s
=='\t')
150 /* Analyze the remaining arguments */
154 if ((*s
==' ' || *s
=='\t') && qcount
==0)
156 /* skip to the next argument and count it if any */
157 while (*s
==' ' || *s
=='\t')
165 /* '\', count them */
173 qcount
++; /* unescaped '"' */
176 /* consecutive quotes, see comment in copying code below */
188 /* a regular character */
194 /* Allocate in a single lump, the string array, and the strings that go
195 * with it. This way the caller can make a single LocalFree() call to free
198 argv
=LocalAlloc(LMEM_FIXED
, (argc
+1)*sizeof(LPWSTR
)+(strlenW(lpCmdline
)+1)*sizeof(WCHAR
));
201 cmdline
=(LPWSTR
)(argv
+argc
+1);
202 strcpyW(cmdline
, lpCmdline
);
204 /* --- Then split and copy the arguments */
207 /* The first argument, the executable path, follows special rules */
210 /* The executable path ends at the next quote, no matter what */
224 /* The executable path ends at the next space, no matter what */
225 while (*d
&& *d
!=' ' && *d
!='\t')
231 /* close the executable path */
233 /* skip to the first argument and initialize it if any */
234 while (*s
==' ' || *s
=='\t')
238 /* There are no parameters so we are all done */
244 /* Split and copy the remaining arguments */
249 if ((*s
==' ' || *s
=='\t') && qcount
==0)
251 /* close the argument */
255 /* skip to the next one and initialize it if any */
258 } while (*s
==' ' || *s
=='\t');
271 /* Preceded by an even number of '\', this is half that
272 * number of '\', plus a quote which we erase.
279 /* Preceded by an odd number of '\', this is half that
280 * number of '\' followed by a '"'
287 /* Now count the number of consecutive quotes. Note that qcount
288 * already takes into account the opening quote if any, as well as
289 * the quote that lead us here.
305 /* a regular character */
317 static DWORD
shgfi_get_exe_type(LPCWSTR szFullPath
)
322 IMAGE_DOS_HEADER mz_header
;
327 status
= GetBinaryTypeW (szFullPath
, &BinaryType
);
330 if (BinaryType
== SCS_DOS_BINARY
|| BinaryType
== SCS_PIF_BINARY
)
333 hfile
= CreateFileW( szFullPath
, GENERIC_READ
, FILE_SHARE_READ
,
334 NULL
, OPEN_EXISTING
, 0, 0 );
335 if ( hfile
== INVALID_HANDLE_VALUE
)
339 * The next section is adapted from MODULE_GetBinaryType, as we need
340 * to examine the image header to get OS and version information. We
341 * know from calling GetBinaryTypeA that the image is valid and either
342 * an NE or PE, so much error handling can be omitted.
343 * Seek to the start of the file and read the header information.
346 SetFilePointer( hfile
, 0, NULL
, SEEK_SET
);
347 ReadFile( hfile
, &mz_header
, sizeof(mz_header
), &len
, NULL
);
349 SetFilePointer( hfile
, mz_header
.e_lfanew
, NULL
, SEEK_SET
);
350 ReadFile( hfile
, magic
, sizeof(magic
), &len
, NULL
);
351 if ( *(DWORD
*)magic
== IMAGE_NT_SIGNATURE
)
353 SetFilePointer( hfile
, mz_header
.e_lfanew
, NULL
, SEEK_SET
);
354 ReadFile( hfile
, &nt
, sizeof(nt
), &len
, NULL
);
355 CloseHandle( hfile
);
356 /* DLL files are not executable and should return 0 */
357 if (nt
.FileHeader
.Characteristics
& IMAGE_FILE_DLL
)
359 if (nt
.OptionalHeader
.Subsystem
== IMAGE_SUBSYSTEM_WINDOWS_GUI
)
361 return IMAGE_NT_SIGNATURE
|
362 (nt
.OptionalHeader
.MajorSubsystemVersion
<< 24) |
363 (nt
.OptionalHeader
.MinorSubsystemVersion
<< 16);
365 return IMAGE_NT_SIGNATURE
;
367 else if ( *(WORD
*)magic
== IMAGE_OS2_SIGNATURE
)
370 SetFilePointer( hfile
, mz_header
.e_lfanew
, NULL
, SEEK_SET
);
371 ReadFile( hfile
, &ne
, sizeof(ne
), &len
, NULL
);
372 CloseHandle( hfile
);
373 if (ne
.ne_exetyp
== 2)
374 return IMAGE_OS2_SIGNATURE
| (ne
.ne_expver
<< 16);
377 CloseHandle( hfile
);
381 /*************************************************************************
382 * SHELL_IsShortcut [internal]
384 * Decide if an item id list points to a shell shortcut
386 BOOL
SHELL_IsShortcut(LPCITEMIDLIST pidlLast
)
388 char szTemp
[MAX_PATH
];
392 if (_ILGetExtension(pidlLast
, szTemp
, MAX_PATH
) &&
393 HCR_MapTypeToValueA(szTemp
, szTemp
, MAX_PATH
, TRUE
))
395 if (ERROR_SUCCESS
== RegOpenKeyExA(HKEY_CLASSES_ROOT
, szTemp
, 0, KEY_QUERY_VALUE
, &keyCls
))
397 if (ERROR_SUCCESS
== RegQueryValueExA(keyCls
, "IsShortcut", NULL
, NULL
, NULL
, NULL
))
407 #define SHGFI_KNOWN_FLAGS \
408 (SHGFI_SMALLICON | SHGFI_OPENICON | SHGFI_SHELLICONSIZE | SHGFI_PIDL | \
409 SHGFI_USEFILEATTRIBUTES | SHGFI_ADDOVERLAYS | SHGFI_OVERLAYINDEX | \
410 SHGFI_ICON | SHGFI_DISPLAYNAME | SHGFI_TYPENAME | SHGFI_ATTRIBUTES | \
411 SHGFI_ICONLOCATION | SHGFI_EXETYPE | SHGFI_SYSICONINDEX | \
412 SHGFI_LINKOVERLAY | SHGFI_SELECTED | SHGFI_ATTR_SPECIFIED)
414 /*************************************************************************
415 * SHGetFileInfoW [SHELL32.@]
418 DWORD_PTR WINAPI
SHGetFileInfoW(LPCWSTR path
,DWORD dwFileAttributes
,
419 SHFILEINFOW
*psfi
, UINT sizeofpsfi
, UINT flags
)
421 WCHAR szLocation
[MAX_PATH
], szFullPath
[MAX_PATH
];
423 DWORD_PTR ret
= TRUE
;
424 DWORD dwAttributes
= 0;
425 IShellFolder
* psfParent
= NULL
;
426 IExtractIconW
* pei
= NULL
;
427 LPITEMIDLIST pidlLast
= NULL
, pidl
= NULL
;
429 BOOL IconNotYetLoaded
=TRUE
;
431 HIMAGELIST big_icons
, small_icons
;
433 TRACE("%s fattr=0x%x sfi=%p(attr=0x%08x) size=0x%x flags=0x%x\n",
434 (flags
& SHGFI_PIDL
)? "pidl" : debugstr_w(path
), dwFileAttributes
,
435 psfi
, psfi
->dwAttributes
, sizeofpsfi
, flags
);
440 /* windows initializes these values regardless of the flags */
443 psfi
->szDisplayName
[0] = '\0';
444 psfi
->szTypeName
[0] = '\0';
448 if (!(flags
& SHGFI_PIDL
))
450 /* SHGetFileInfo should work with absolute and relative paths */
451 if (PathIsRelativeW(path
))
453 GetCurrentDirectoryW(MAX_PATH
, szLocation
);
454 PathCombineW(szFullPath
, szLocation
, path
);
458 lstrcpynW(szFullPath
, path
, MAX_PATH
);
462 if (flags
& SHGFI_EXETYPE
)
464 if (flags
!= SHGFI_EXETYPE
)
466 return shgfi_get_exe_type(szFullPath
);
470 * psfi is NULL normally to query EXE type. If it is NULL, none of the
471 * below makes sense anyway. Windows allows this and just returns FALSE
477 * translate the path into a pidl only when SHGFI_USEFILEATTRIBUTES
479 * The pidl functions fail on not existing file names
482 if (flags
& SHGFI_PIDL
)
484 pidl
= ILClone((LPCITEMIDLIST
)path
);
486 else if (!(flags
& SHGFI_USEFILEATTRIBUTES
))
488 hr
= SHILCreateFromPathW(szFullPath
, &pidl
, &dwAttributes
);
491 if ((flags
& SHGFI_PIDL
) || !(flags
& SHGFI_USEFILEATTRIBUTES
))
493 /* get the parent shellfolder */
496 hr
= SHBindToParent( pidl
, &IID_IShellFolder
, (LPVOID
*)&psfParent
,
497 (LPCITEMIDLIST
*)&pidlLast
);
499 pidlLast
= ILClone(pidlLast
);
504 ERR("pidl is null!\n");
509 /* get the attributes of the child */
510 if (SUCCEEDED(hr
) && (flags
& SHGFI_ATTRIBUTES
))
512 if (!(flags
& SHGFI_ATTR_SPECIFIED
))
514 psfi
->dwAttributes
= 0xffffffff;
517 IShellFolder_GetAttributesOf( psfParent
, 1, (LPCITEMIDLIST
*)&pidlLast
,
518 &(psfi
->dwAttributes
) );
521 /* get the displayname */
522 if (SUCCEEDED(hr
) && (flags
& SHGFI_DISPLAYNAME
))
524 if (flags
& SHGFI_USEFILEATTRIBUTES
&& !(flags
& SHGFI_PIDL
))
526 lstrcpyW (psfi
->szDisplayName
, PathFindFileNameW(szFullPath
));
531 hr
= IShellFolder_GetDisplayNameOf( psfParent
, pidlLast
,
532 SHGDN_INFOLDER
, &str
);
533 StrRetToStrNW (psfi
->szDisplayName
, MAX_PATH
, &str
, pidlLast
);
537 /* get the type name */
538 if (SUCCEEDED(hr
) && (flags
& SHGFI_TYPENAME
))
540 static const WCHAR szFile
[] = { 'F','i','l','e',0 };
541 static const WCHAR szDashFile
[] = { '-','f','i','l','e',0 };
543 if (!(flags
& SHGFI_USEFILEATTRIBUTES
) || (flags
& SHGFI_PIDL
))
547 _ILGetFileType(pidlLast
, ftype
, 80);
548 MultiByteToWideChar(CP_ACP
, 0, ftype
, -1, psfi
->szTypeName
, 80 );
552 if (dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
553 strcatW (psfi
->szTypeName
, szFile
);
558 lstrcpyW(sTemp
,PathFindExtensionW(szFullPath
));
559 if (!( HCR_MapTypeToValueW(sTemp
, sTemp
, 64, TRUE
) &&
560 HCR_MapTypeToValueW(sTemp
, psfi
->szTypeName
, 80, FALSE
)))
562 lstrcpynW (psfi
->szTypeName
, sTemp
, 64);
563 strcatW (psfi
->szTypeName
, szDashFile
);
571 Shell_GetImageLists( &big_icons
, &small_icons
);
573 if (flags
& SHGFI_OPENICON
)
574 uGilFlags
|= GIL_OPENICON
;
576 if (flags
& SHGFI_LINKOVERLAY
)
577 uGilFlags
|= GIL_FORSHORTCUT
;
578 else if ((flags
&SHGFI_ADDOVERLAYS
) ||
579 (flags
&(SHGFI_ICON
|SHGFI_SMALLICON
))==SHGFI_ICON
)
581 if (SHELL_IsShortcut(pidlLast
))
582 uGilFlags
|= GIL_FORSHORTCUT
;
585 if (flags
& SHGFI_OVERLAYINDEX
)
586 FIXME("SHGFI_OVERLAYINDEX unhandled\n");
588 if (flags
& SHGFI_SELECTED
)
589 FIXME("set icon to selected, stub\n");
591 if (flags
& SHGFI_SHELLICONSIZE
)
592 FIXME("set icon to shell size, stub\n");
594 /* get the iconlocation */
595 if (SUCCEEDED(hr
) && (flags
& SHGFI_ICONLOCATION
))
599 if (flags
& SHGFI_USEFILEATTRIBUTES
&& !(flags
& SHGFI_PIDL
))
601 if (dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
603 lstrcpyW(psfi
->szDisplayName
, swShell32Name
);
604 psfi
->iIcon
= -IDI_SHELL_FOLDER
;
609 static const WCHAR p1W
[] = {'%','1',0};
610 WCHAR sTemp
[MAX_PATH
];
612 szExt
= PathFindExtensionW(szFullPath
);
613 TRACE("szExt=%s\n", debugstr_w(szExt
));
615 HCR_MapTypeToValueW(szExt
, sTemp
, MAX_PATH
, TRUE
) &&
616 HCR_GetDefaultIconW(sTemp
, sTemp
, MAX_PATH
, &psfi
->iIcon
))
618 if (lstrcmpW(p1W
, sTemp
))
619 strcpyW(psfi
->szDisplayName
, sTemp
);
622 /* the icon is in the file */
623 strcpyW(psfi
->szDisplayName
, szFullPath
);
632 hr
= IShellFolder_GetUIObjectOf(psfParent
, 0, 1,
633 (LPCITEMIDLIST
*)&pidlLast
, &IID_IExtractIconW
,
634 &uDummy
, (LPVOID
*)&pei
);
637 hr
= IExtractIconW_GetIconLocation(pei
, uGilFlags
,
638 szLocation
, MAX_PATH
, &iIndex
, &uFlags
);
640 if (uFlags
& GIL_NOTFILENAME
)
644 lstrcpyW (psfi
->szDisplayName
, szLocation
);
645 psfi
->iIcon
= iIndex
;
647 IExtractIconW_Release(pei
);
652 /* get icon index (or load icon)*/
653 if (SUCCEEDED(hr
) && (flags
& (SHGFI_ICON
| SHGFI_SYSICONINDEX
)))
655 if (flags
& SHGFI_USEFILEATTRIBUTES
&& !(flags
& SHGFI_PIDL
))
657 WCHAR sTemp
[MAX_PATH
];
661 lstrcpynW(sTemp
, szFullPath
, MAX_PATH
);
663 if (dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
664 psfi
->iIcon
= SIC_GetIconIndex(swShell32Name
, -IDI_SHELL_FOLDER
, 0);
667 static const WCHAR p1W
[] = {'%','1',0};
670 szExt
= PathFindExtensionW(sTemp
);
672 HCR_MapTypeToValueW(szExt
, sTemp
, MAX_PATH
, TRUE
) &&
673 HCR_GetDefaultIconW(sTemp
, sTemp
, MAX_PATH
, &icon_idx
))
675 if (!lstrcmpW(p1W
,sTemp
)) /* icon is in the file */
676 strcpyW(sTemp
, szFullPath
);
678 if (flags
& SHGFI_SYSICONINDEX
)
680 psfi
->iIcon
= SIC_GetIconIndex(sTemp
,icon_idx
,0);
681 if (psfi
->iIcon
== -1)
687 if (flags
& SHGFI_SMALLICON
)
688 ret
= PrivateExtractIconsW( sTemp
,icon_idx
,
689 GetSystemMetrics( SM_CXSMICON
),
690 GetSystemMetrics( SM_CYSMICON
),
691 &psfi
->hIcon
, 0, 1, 0);
693 ret
= PrivateExtractIconsW( sTemp
, icon_idx
,
694 GetSystemMetrics( SM_CXICON
),
695 GetSystemMetrics( SM_CYICON
),
696 &psfi
->hIcon
, 0, 1, 0);
697 if (ret
!= 0 && ret
!= (UINT
)-1)
699 IconNotYetLoaded
=FALSE
;
700 psfi
->iIcon
= icon_idx
;
708 if (!(PidlToSicIndex(psfParent
, pidlLast
, !(flags
& SHGFI_SMALLICON
),
709 uGilFlags
, &(psfi
->iIcon
))))
714 if (ret
&& (flags
& SHGFI_SYSICONINDEX
))
716 if (flags
& SHGFI_SMALLICON
)
717 ret
= (DWORD_PTR
)small_icons
;
719 ret
= (DWORD_PTR
)big_icons
;
724 if (SUCCEEDED(hr
) && (flags
& SHGFI_ICON
) && IconNotYetLoaded
)
726 if (flags
& SHGFI_SMALLICON
)
727 psfi
->hIcon
= ImageList_GetIcon( small_icons
, psfi
->iIcon
, ILD_NORMAL
);
729 psfi
->hIcon
= ImageList_GetIcon( big_icons
, psfi
->iIcon
, ILD_NORMAL
);
732 if (flags
& ~SHGFI_KNOWN_FLAGS
)
733 FIXME("unknown flags %08x\n", flags
& ~SHGFI_KNOWN_FLAGS
);
736 IShellFolder_Release(psfParent
);
743 TRACE ("icon=%p index=0x%08x attr=0x%08x name=%s type=%s ret=0x%08lx\n",
744 psfi
->hIcon
, psfi
->iIcon
, psfi
->dwAttributes
,
745 debugstr_w(psfi
->szDisplayName
), debugstr_w(psfi
->szTypeName
), ret
);
750 /*************************************************************************
751 * SHGetFileInfoA [SHELL32.@]
754 * MSVBVM60.__vbaNew2 expects this function to return a value in range
755 * 1 .. 0x7fff when the function succeeds and flags does not contain
756 * SHGFI_EXETYPE or SHGFI_SYSICONINDEX (see bug 7701)
758 DWORD_PTR WINAPI
SHGetFileInfoA(LPCSTR path
,DWORD dwFileAttributes
,
759 SHFILEINFOA
*psfi
, UINT sizeofpsfi
,
763 LPWSTR temppath
= NULL
;
766 SHFILEINFOW temppsfi
;
768 if (flags
& SHGFI_PIDL
)
770 /* path contains a pidl */
771 pathW
= (LPCWSTR
)path
;
775 len
= MultiByteToWideChar(CP_ACP
, 0, path
, -1, NULL
, 0);
776 temppath
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
777 MultiByteToWideChar(CP_ACP
, 0, path
, -1, temppath
, len
);
781 if (psfi
&& (flags
& SHGFI_ATTR_SPECIFIED
))
782 temppsfi
.dwAttributes
=psfi
->dwAttributes
;
785 ret
= SHGetFileInfoW(pathW
, dwFileAttributes
, NULL
, sizeof(temppsfi
), flags
);
787 ret
= SHGetFileInfoW(pathW
, dwFileAttributes
, &temppsfi
, sizeof(temppsfi
), flags
);
791 if(flags
& SHGFI_ICON
)
792 psfi
->hIcon
=temppsfi
.hIcon
;
793 if(flags
& (SHGFI_SYSICONINDEX
|SHGFI_ICON
|SHGFI_ICONLOCATION
))
794 psfi
->iIcon
=temppsfi
.iIcon
;
795 if(flags
& SHGFI_ATTRIBUTES
)
796 psfi
->dwAttributes
=temppsfi
.dwAttributes
;
797 if(flags
& (SHGFI_DISPLAYNAME
|SHGFI_ICONLOCATION
))
799 WideCharToMultiByte(CP_ACP
, 0, temppsfi
.szDisplayName
, -1,
800 psfi
->szDisplayName
, sizeof(psfi
->szDisplayName
), NULL
, NULL
);
802 if(flags
& SHGFI_TYPENAME
)
804 WideCharToMultiByte(CP_ACP
, 0, temppsfi
.szTypeName
, -1,
805 psfi
->szTypeName
, sizeof(psfi
->szTypeName
), NULL
, NULL
);
809 HeapFree(GetProcessHeap(), 0, temppath
);
814 /*************************************************************************
815 * DuplicateIcon [SHELL32.@]
817 HICON WINAPI
DuplicateIcon( HINSTANCE hInstance
, HICON hIcon
)
822 TRACE("%p %p\n", hInstance
, hIcon
);
824 if (GetIconInfo(hIcon
, &IconInfo
))
826 hDupIcon
= CreateIconIndirect(&IconInfo
);
828 /* clean up hbmMask and hbmColor */
829 DeleteObject(IconInfo
.hbmMask
);
830 DeleteObject(IconInfo
.hbmColor
);
836 /*************************************************************************
837 * ExtractIconA [SHELL32.@]
839 HICON WINAPI
ExtractIconA(HINSTANCE hInstance
, LPCSTR lpszFile
, UINT nIconIndex
)
842 INT len
= MultiByteToWideChar(CP_ACP
, 0, lpszFile
, -1, NULL
, 0);
843 LPWSTR lpwstrFile
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
845 TRACE("%p %s %d\n", hInstance
, lpszFile
, nIconIndex
);
847 MultiByteToWideChar(CP_ACP
, 0, lpszFile
, -1, lpwstrFile
, len
);
848 ret
= ExtractIconW(hInstance
, lpwstrFile
, nIconIndex
);
849 HeapFree(GetProcessHeap(), 0, lpwstrFile
);
854 /*************************************************************************
855 * ExtractIconW [SHELL32.@]
857 HICON WINAPI
ExtractIconW(HINSTANCE hInstance
, LPCWSTR lpszFile
, UINT nIconIndex
)
861 UINT cx
= GetSystemMetrics(SM_CXICON
), cy
= GetSystemMetrics(SM_CYICON
);
863 TRACE("%p %s %d\n", hInstance
, debugstr_w(lpszFile
), nIconIndex
);
865 if (nIconIndex
== (UINT
)-1)
867 ret
= PrivateExtractIconsW(lpszFile
, 0, cx
, cy
, NULL
, NULL
, 0, LR_DEFAULTCOLOR
);
868 if (ret
!= (UINT
)-1 && ret
)
869 return (HICON
)(UINT_PTR
)ret
;
873 ret
= PrivateExtractIconsW(lpszFile
, nIconIndex
, cx
, cy
, &hIcon
, NULL
, 1, LR_DEFAULTCOLOR
);
877 else if (ret
> 0 && hIcon
)
883 HRESULT WINAPI
SHCreateFileExtractIconW(LPCWSTR file
, DWORD attribs
, REFIID riid
, void **ppv
)
885 FIXME("%s, %x, %s, %p\n", debugstr_w(file
), attribs
, debugstr_guid(riid
), ppv
);
890 /*************************************************************************
891 * Printer_LoadIconsW [SHELL32.205]
893 VOID WINAPI
Printer_LoadIconsW(LPCWSTR wsPrinterName
, HICON
* pLargeIcon
, HICON
* pSmallIcon
)
895 INT iconindex
=IDI_SHELL_PRINTER
;
897 TRACE("(%s, %p, %p)\n", debugstr_w(wsPrinterName
), pLargeIcon
, pSmallIcon
);
899 /* We should check if wsPrinterName is
900 1. the Default Printer or not
902 3. a Local Printer or a Network-Printer
903 and use different Icons
905 if((wsPrinterName
!= NULL
) && (wsPrinterName
[0] != 0))
907 FIXME("(select Icon by PrinterName %s not implemented)\n", debugstr_w(wsPrinterName
));
910 if(pLargeIcon
!= NULL
)
911 *pLargeIcon
= LoadImageW(shell32_hInstance
,
912 (LPCWSTR
) MAKEINTRESOURCE(iconindex
), IMAGE_ICON
,
913 0, 0, LR_DEFAULTCOLOR
|LR_DEFAULTSIZE
);
915 if(pSmallIcon
!= NULL
)
916 *pSmallIcon
= LoadImageW(shell32_hInstance
,
917 (LPCWSTR
) MAKEINTRESOURCE(iconindex
), IMAGE_ICON
,
918 16, 16, LR_DEFAULTCOLOR
);
921 /*************************************************************************
922 * Printers_RegisterWindowW [SHELL32.213]
923 * used by "printui.dll":
924 * find the Window of the given Type for the specific Printer and
925 * return the already existent hwnd or open a new window
927 BOOL WINAPI
Printers_RegisterWindowW(LPCWSTR wsPrinter
, DWORD dwType
,
928 HANDLE
* phClassPidl
, HWND
* phwnd
)
930 FIXME("(%s, %x, %p (%p), %p (%p)) stub!\n", debugstr_w(wsPrinter
), dwType
,
931 phClassPidl
, (phClassPidl
!= NULL
) ? *(phClassPidl
) : NULL
,
932 phwnd
, (phwnd
!= NULL
) ? *(phwnd
) : NULL
);
937 /*************************************************************************
938 * Printers_UnregisterWindow [SHELL32.214]
940 VOID WINAPI
Printers_UnregisterWindow(HANDLE hClassPidl
, HWND hwnd
)
942 FIXME("(%p, %p) stub!\n", hClassPidl
, hwnd
);
945 /*************************************************************************
946 * SHGetPropertyStoreFromParsingName [SHELL32.@]
948 HRESULT WINAPI
SHGetPropertyStoreFromParsingName(PCWSTR pszPath
, IBindCtx
*pbc
, GETPROPERTYSTOREFLAGS flags
, REFIID riid
, void **ppv
)
950 FIXME("(%s %p %u %p %p) stub!\n", debugstr_w(pszPath
), pbc
, flags
, riid
, ppv
);
954 /*************************************************************************/
959 LPCWSTR szOtherStuff
;
964 #define DROP_FIELD_TOP (-12)
966 static void paint_dropline( HDC hdc
, HWND hWnd
)
968 HWND hWndCtl
= GetDlgItem(hWnd
, IDC_ABOUT_WINE_TEXT
);
971 if (!hWndCtl
) return;
972 GetWindowRect( hWndCtl
, &rect
);
973 MapWindowPoints( 0, hWnd
, (LPPOINT
)&rect
, 2 );
974 rect
.top
+= DROP_FIELD_TOP
;
975 rect
.bottom
= rect
.top
+ 2;
976 DrawEdge( hdc
, &rect
, BDR_SUNKENOUTER
, BF_RECT
);
979 /*************************************************************************
980 * SHHelpShortcuts_RunDLLA [SHELL32.@]
983 DWORD WINAPI
SHHelpShortcuts_RunDLLA(DWORD dwArg1
, DWORD dwArg2
, DWORD dwArg3
, DWORD dwArg4
)
985 FIXME("(%x, %x, %x, %x) stub!\n", dwArg1
, dwArg2
, dwArg3
, dwArg4
);
989 /*************************************************************************
990 * SHHelpShortcuts_RunDLLA [SHELL32.@]
993 DWORD WINAPI
SHHelpShortcuts_RunDLLW(DWORD dwArg1
, DWORD dwArg2
, DWORD dwArg3
, DWORD dwArg4
)
995 FIXME("(%x, %x, %x, %x) stub!\n", dwArg1
, dwArg2
, dwArg3
, dwArg4
);
999 /*************************************************************************
1000 * SHLoadInProc [SHELL32.@]
1001 * Create an instance of specified object class from within
1002 * the shell process and release it immediately
1004 HRESULT WINAPI
SHLoadInProc (REFCLSID rclsid
)
1008 TRACE("%s\n", debugstr_guid(rclsid
));
1010 CoCreateInstance(rclsid
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
,&ptr
);
1013 IUnknown
* pUnk
= ptr
;
1014 IUnknown_Release(pUnk
);
1017 return DISP_E_MEMBERNOTFOUND
;
1020 static void add_authors( HWND list
)
1022 static const WCHAR eol
[] = {'\r','\n',0};
1023 static const WCHAR authors
[] = {'A','U','T','H','O','R','S',0};
1024 WCHAR
*strW
, *start
, *end
;
1025 HRSRC rsrc
= FindResourceW( shell32_hInstance
, authors
, (LPCWSTR
)RT_RCDATA
);
1026 char *strA
= LockResource( LoadResource( shell32_hInstance
, rsrc
));
1027 DWORD sizeW
, sizeA
= SizeofResource( shell32_hInstance
, rsrc
);
1030 sizeW
= MultiByteToWideChar( CP_UTF8
, 0, strA
, sizeA
, NULL
, 0 ) + 1;
1031 if (!(strW
= HeapAlloc( GetProcessHeap(), 0, sizeW
* sizeof(WCHAR
) ))) return;
1032 MultiByteToWideChar( CP_UTF8
, 0, strA
, sizeA
, strW
, sizeW
);
1033 strW
[sizeW
- 1] = 0;
1035 start
= strpbrkW( strW
, eol
); /* skip the header line */
1038 while (*start
&& strchrW( eol
, *start
)) start
++;
1040 end
= strpbrkW( start
, eol
);
1041 if (end
) *end
++ = 0;
1042 SendMessageW( list
, LB_ADDSTRING
, -1, (LPARAM
)start
);
1045 HeapFree( GetProcessHeap(), 0, strW
);
1048 /*************************************************************************
1049 * AboutDlgProc (internal)
1051 static INT_PTR CALLBACK
AboutDlgProc( HWND hWnd
, UINT msg
, WPARAM wParam
,
1062 ABOUT_INFO
*info
= (ABOUT_INFO
*)lParam
;
1063 WCHAR
template[512], buffer
[512], version
[64];
1064 extern const char *wine_get_build_id(void);
1068 SendDlgItemMessageW(hWnd
, stc1
, STM_SETICON
,(WPARAM
)info
->hIcon
, 0);
1069 GetWindowTextW( hWnd
, template, sizeof(template)/sizeof(WCHAR
) );
1070 sprintfW( buffer
, template, info
->szApp
);
1071 SetWindowTextW( hWnd
, buffer
);
1072 SetWindowTextW( GetDlgItem(hWnd
, IDC_ABOUT_STATIC_TEXT1
), info
->szApp
);
1073 SetWindowTextW( GetDlgItem(hWnd
, IDC_ABOUT_STATIC_TEXT2
), info
->szOtherStuff
);
1074 GetWindowTextW( GetDlgItem(hWnd
, IDC_ABOUT_STATIC_TEXT3
),
1075 template, sizeof(template)/sizeof(WCHAR
) );
1076 MultiByteToWideChar( CP_UTF8
, 0, wine_get_build_id(), -1,
1077 version
, sizeof(version
)/sizeof(WCHAR
) );
1078 sprintfW( buffer
, template, version
);
1079 SetWindowTextW( GetDlgItem(hWnd
, IDC_ABOUT_STATIC_TEXT3
), buffer
);
1080 hWndCtl
= GetDlgItem(hWnd
, IDC_ABOUT_LISTBOX
);
1081 SendMessageW( hWndCtl
, WM_SETREDRAW
, 0, 0 );
1082 SendMessageW( hWndCtl
, WM_SETFONT
, (WPARAM
)info
->hFont
, 0 );
1083 add_authors( hWndCtl
);
1084 SendMessageW( hWndCtl
, WM_SETREDRAW
, 1, 0 );
1092 HDC hDC
= BeginPaint( hWnd
, &ps
);
1093 paint_dropline( hDC
, hWnd
);
1094 EndPaint( hWnd
, &ps
);
1099 if (wParam
== IDOK
|| wParam
== IDCANCEL
)
1101 EndDialog(hWnd
, TRUE
);
1104 if (wParam
== IDC_ABOUT_LICENSE
)
1106 MSGBOXPARAMSW params
;
1108 params
.cbSize
= sizeof(params
);
1109 params
.hwndOwner
= hWnd
;
1110 params
.hInstance
= shell32_hInstance
;
1111 params
.lpszText
= MAKEINTRESOURCEW(IDS_LICENSE
);
1112 params
.lpszCaption
= MAKEINTRESOURCEW(IDS_LICENSE_CAPTION
);
1113 params
.dwStyle
= MB_ICONINFORMATION
| MB_OK
;
1114 params
.lpszIcon
= 0;
1115 params
.dwContextHelpId
= 0;
1116 params
.lpfnMsgBoxCallback
= NULL
;
1117 params
.dwLanguageId
= LANG_NEUTRAL
;
1118 MessageBoxIndirectW( ¶ms
);
1122 EndDialog(hWnd
, TRUE
);
1130 /*************************************************************************
1131 * ShellAboutA [SHELL32.288]
1133 BOOL WINAPI
ShellAboutA( HWND hWnd
, LPCSTR szApp
, LPCSTR szOtherStuff
, HICON hIcon
)
1136 LPWSTR appW
= NULL
, otherW
= NULL
;
1141 len
= MultiByteToWideChar(CP_ACP
, 0, szApp
, -1, NULL
, 0);
1142 appW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1143 MultiByteToWideChar(CP_ACP
, 0, szApp
, -1, appW
, len
);
1147 len
= MultiByteToWideChar(CP_ACP
, 0, szOtherStuff
, -1, NULL
, 0);
1148 otherW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1149 MultiByteToWideChar(CP_ACP
, 0, szOtherStuff
, -1, otherW
, len
);
1152 ret
= ShellAboutW(hWnd
, appW
, otherW
, hIcon
);
1154 HeapFree(GetProcessHeap(), 0, otherW
);
1155 HeapFree(GetProcessHeap(), 0, appW
);
1160 /*************************************************************************
1161 * ShellAboutW [SHELL32.289]
1163 BOOL WINAPI
ShellAboutW( HWND hWnd
, LPCWSTR szApp
, LPCWSTR szOtherStuff
,
1169 static const WCHAR wszSHELL_ABOUT_MSGBOX
[] =
1170 {'S','H','E','L','L','_','A','B','O','U','T','_','M','S','G','B','O','X',0};
1174 if (!hIcon
) hIcon
= LoadImageW( 0, (LPWSTR
)IDI_WINLOGO
, IMAGE_ICON
, 48, 48, LR_SHARED
);
1176 info
.szOtherStuff
= szOtherStuff
;
1179 SystemParametersInfoW( SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0 );
1180 info
.hFont
= CreateFontIndirectW( &logFont
);
1182 bRet
= DialogBoxParamW( shell32_hInstance
, wszSHELL_ABOUT_MSGBOX
, hWnd
, AboutDlgProc
, (LPARAM
)&info
);
1183 DeleteObject(info
.hFont
);
1187 /*************************************************************************
1188 * FreeIconList (SHELL32.@)
1190 void WINAPI
FreeIconList( DWORD dw
)
1192 FIXME("%x: stub\n",dw
);
1195 /*************************************************************************
1196 * SHLoadNonloadedIconOverlayIdentifiers (SHELL32.@)
1198 HRESULT WINAPI
SHLoadNonloadedIconOverlayIdentifiers( VOID
)
1204 /***********************************************************************
1205 * DllGetVersion [SHELL32.@]
1207 * Retrieves version information of the 'SHELL32.DLL'
1210 * pdvi [O] pointer to version information structure.
1214 * Failure: E_INVALIDARG
1217 * Returns version of a shell32.dll from IE4.01 SP1.
1220 HRESULT WINAPI
DllGetVersion (DLLVERSIONINFO
*pdvi
)
1222 /* FIXME: shouldn't these values come from the version resource? */
1223 if (pdvi
->cbSize
== sizeof(DLLVERSIONINFO
) ||
1224 pdvi
->cbSize
== sizeof(DLLVERSIONINFO2
))
1226 pdvi
->dwMajorVersion
= WINE_FILEVERSION_MAJOR
;
1227 pdvi
->dwMinorVersion
= WINE_FILEVERSION_MINOR
;
1228 pdvi
->dwBuildNumber
= WINE_FILEVERSION_BUILD
;
1229 pdvi
->dwPlatformID
= WINE_FILEVERSION_PLATFORMID
;
1230 if (pdvi
->cbSize
== sizeof(DLLVERSIONINFO2
))
1232 DLLVERSIONINFO2
*pdvi2
= (DLLVERSIONINFO2
*)pdvi
;
1235 pdvi2
->ullVersion
= MAKEDLLVERULL(WINE_FILEVERSION_MAJOR
,
1236 WINE_FILEVERSION_MINOR
,
1237 WINE_FILEVERSION_BUILD
,
1238 WINE_FILEVERSION_PLATFORMID
);
1240 TRACE("%u.%u.%u.%u\n",
1241 pdvi
->dwMajorVersion
, pdvi
->dwMinorVersion
,
1242 pdvi
->dwBuildNumber
, pdvi
->dwPlatformID
);
1247 WARN("wrong DLLVERSIONINFO size from app\n");
1248 return E_INVALIDARG
;
1252 /*************************************************************************
1253 * global variables of the shell32.dll
1254 * all are once per process
1257 HINSTANCE shell32_hInstance
= 0;
1260 /*************************************************************************
1264 * calling oleinitialize here breaks some apps.
1266 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID fImpLoad
)
1268 TRACE("%p 0x%x %p\n", hinstDLL
, fdwReason
, fImpLoad
);
1272 case DLL_PROCESS_ATTACH
:
1273 shell32_hInstance
= hinstDLL
;
1274 DisableThreadLibraryCalls(shell32_hInstance
);
1276 /* get full path to this DLL for IExtractIconW_fnGetIconLocation() */
1277 GetModuleFileNameW(hinstDLL
, swShell32Name
, MAX_PATH
);
1278 swShell32Name
[MAX_PATH
- 1] = '\0';
1280 InitChangeNotifications();
1283 case DLL_PROCESS_DETACH
:
1284 if (fImpLoad
) break;
1286 FreeChangeNotifications();
1287 release_desktop_folder();
1294 /*************************************************************************
1295 * DllInstall [SHELL32.@]
1299 * BOOL bInstall - TRUE for install, FALSE for uninstall
1300 * LPCWSTR pszCmdLine - command line (unused by shell32?)
1303 HRESULT WINAPI
DllInstall(BOOL bInstall
, LPCWSTR cmdline
)
1305 FIXME("%s %s: stub\n", bInstall
? "TRUE":"FALSE", debugstr_w(cmdline
));
1306 return S_OK
; /* indicate success */
1309 /***********************************************************************
1310 * DllCanUnloadNow (SHELL32.@)
1312 HRESULT WINAPI
DllCanUnloadNow(void)
1317 /***********************************************************************
1318 * DllRegisterServer (SHELL32.@)
1320 HRESULT WINAPI
DllRegisterServer(void)
1322 HRESULT hr
= __wine_register_resources( shell32_hInstance
);
1323 if (SUCCEEDED(hr
)) hr
= SHELL_RegisterShellFolders();
1327 /***********************************************************************
1328 * DllUnregisterServer (SHELL32.@)
1330 HRESULT WINAPI
DllUnregisterServer(void)
1332 return __wine_unregister_resources( shell32_hInstance
);
1335 /***********************************************************************
1336 * ExtractVersionResource16W (SHELL32.@)
1338 BOOL WINAPI
ExtractVersionResource16W(LPWSTR s
, DWORD d
)
1340 FIXME("(%s %x) stub!\n", debugstr_w(s
), d
);
1344 /***********************************************************************
1345 * InitNetworkAddressControl (SHELL32.@)
1347 BOOL WINAPI
InitNetworkAddressControl(void)
1353 /***********************************************************************
1354 * ShellHookProc (SHELL32.@)
1356 LRESULT CALLBACK
ShellHookProc(DWORD a
, DWORD b
, DWORD c
)
1362 /***********************************************************************
1363 * SHGetLocalizedName (SHELL32.@)
1365 HRESULT WINAPI
SHGetLocalizedName(LPCWSTR path
, LPWSTR module
, UINT size
, INT
*res
)
1367 FIXME("%s %p %u %p: stub\n", debugstr_w(path
), module
, size
, res
);
1371 /***********************************************************************
1372 * SetCurrentProcessExplicitAppUserModelID (SHELL32.@)
1374 HRESULT WINAPI
SetCurrentProcessExplicitAppUserModelID(PCWSTR appid
)
1376 FIXME("%s: stub\n", debugstr_w(appid
));
1380 /***********************************************************************
1381 * SHSetUnreadMailCountW (SHELL32.@)
1383 HRESULT WINAPI
SHSetUnreadMailCountW(LPCWSTR mailaddress
, DWORD count
, LPCWSTR executecommand
)
1385 FIXME("%s %x %s: stub\n", debugstr_w(mailaddress
), count
, debugstr_w(executecommand
));
1389 /***********************************************************************
1390 * SHEnumerateUnreadMailAccountsW (SHELL32.@)
1392 HRESULT WINAPI
SHEnumerateUnreadMailAccountsW(HKEY user
, DWORD idx
, LPWSTR mailaddress
, INT mailaddresslen
)
1394 FIXME("%p %d %p %d: stub\n", user
, idx
, mailaddress
, mailaddresslen
);