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
;
428 HIMAGELIST big_icons
, small_icons
;
430 TRACE("%s fattr=0x%x sfi=%p(attr=0x%08x) size=0x%x flags=0x%x\n",
431 (flags
& SHGFI_PIDL
)? "pidl" : debugstr_w(path
), dwFileAttributes
,
432 psfi
, psfi
->dwAttributes
, sizeofpsfi
, flags
);
437 /* windows initializes these values regardless of the flags */
440 psfi
->szDisplayName
[0] = '\0';
441 psfi
->szTypeName
[0] = '\0';
445 if (!(flags
& SHGFI_PIDL
))
447 /* SHGetFileInfo should work with absolute and relative paths */
448 if (PathIsRelativeW(path
))
450 GetCurrentDirectoryW(MAX_PATH
, szLocation
);
451 PathCombineW(szFullPath
, szLocation
, path
);
455 lstrcpynW(szFullPath
, path
, MAX_PATH
);
459 if (flags
& SHGFI_EXETYPE
)
461 if (flags
!= SHGFI_EXETYPE
)
463 return shgfi_get_exe_type(szFullPath
);
467 * psfi is NULL normally to query EXE type. If it is NULL, none of the
468 * below makes sense anyway. Windows allows this and just returns FALSE
474 * translate the path into a pidl only when SHGFI_USEFILEATTRIBUTES
476 * The pidl functions fail on not existing file names
479 if (flags
& SHGFI_PIDL
)
481 pidl
= ILClone((LPCITEMIDLIST
)path
);
483 else if (!(flags
& SHGFI_USEFILEATTRIBUTES
))
485 hr
= SHILCreateFromPathW(szFullPath
, &pidl
, &dwAttributes
);
488 if ((flags
& SHGFI_PIDL
) || !(flags
& SHGFI_USEFILEATTRIBUTES
))
490 /* get the parent shellfolder */
493 hr
= SHBindToParent( pidl
, &IID_IShellFolder
, (LPVOID
*)&psfParent
,
494 (LPCITEMIDLIST
*)&pidlLast
);
496 pidlLast
= ILClone(pidlLast
);
501 ERR("pidl is null!\n");
506 /* get the attributes of the child */
507 if (SUCCEEDED(hr
) && (flags
& SHGFI_ATTRIBUTES
))
509 if (!(flags
& SHGFI_ATTR_SPECIFIED
))
511 psfi
->dwAttributes
= 0xffffffff;
514 IShellFolder_GetAttributesOf( psfParent
, 1, (LPCITEMIDLIST
*)&pidlLast
,
515 &(psfi
->dwAttributes
) );
518 /* get the displayname */
519 if (SUCCEEDED(hr
) && (flags
& SHGFI_DISPLAYNAME
))
521 if (flags
& SHGFI_USEFILEATTRIBUTES
&& !(flags
& SHGFI_PIDL
))
523 lstrcpyW (psfi
->szDisplayName
, PathFindFileNameW(szFullPath
));
528 hr
= IShellFolder_GetDisplayNameOf( psfParent
, pidlLast
,
529 SHGDN_INFOLDER
, &str
);
530 StrRetToStrNW (psfi
->szDisplayName
, MAX_PATH
, &str
, pidlLast
);
534 /* get the type name */
535 if (SUCCEEDED(hr
) && (flags
& SHGFI_TYPENAME
))
537 static const WCHAR szFile
[] = { 'F','i','l','e',0 };
538 static const WCHAR szDashFile
[] = { '-','f','i','l','e',0 };
540 if (!(flags
& SHGFI_USEFILEATTRIBUTES
) || (flags
& SHGFI_PIDL
))
544 _ILGetFileType(pidlLast
, ftype
, 80);
545 MultiByteToWideChar(CP_ACP
, 0, ftype
, -1, psfi
->szTypeName
, 80 );
549 if (dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
550 strcatW (psfi
->szTypeName
, szFile
);
555 lstrcpyW(sTemp
,PathFindExtensionW(szFullPath
));
556 if (!( HCR_MapTypeToValueW(sTemp
, sTemp
, 64, TRUE
) &&
557 HCR_MapTypeToValueW(sTemp
, psfi
->szTypeName
, 80, FALSE
)))
559 lstrcpynW (psfi
->szTypeName
, sTemp
, 64);
560 strcatW (psfi
->szTypeName
, szDashFile
);
568 Shell_GetImageLists( &big_icons
, &small_icons
);
570 if (flags
& SHGFI_OPENICON
)
571 uGilFlags
|= GIL_OPENICON
;
573 if (flags
& SHGFI_LINKOVERLAY
)
574 uGilFlags
|= GIL_FORSHORTCUT
;
575 else if ((flags
&SHGFI_ADDOVERLAYS
) ||
576 (flags
&(SHGFI_ICON
|SHGFI_SMALLICON
))==SHGFI_ICON
)
578 if (SHELL_IsShortcut(pidlLast
))
579 uGilFlags
|= GIL_FORSHORTCUT
;
582 if (flags
& SHGFI_OVERLAYINDEX
)
583 FIXME("SHGFI_OVERLAYINDEX unhandled\n");
585 if (flags
& SHGFI_SELECTED
)
586 FIXME("set icon to selected, stub\n");
588 if (flags
& SHGFI_SHELLICONSIZE
)
589 FIXME("set icon to shell size, stub\n");
591 /* get the iconlocation */
592 if (SUCCEEDED(hr
) && (flags
& SHGFI_ICONLOCATION
))
596 if (flags
& SHGFI_USEFILEATTRIBUTES
&& !(flags
& SHGFI_PIDL
))
598 if (dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
600 lstrcpyW(psfi
->szDisplayName
, swShell32Name
);
601 psfi
->iIcon
= -IDI_SHELL_FOLDER
;
606 static const WCHAR p1W
[] = {'%','1',0};
607 WCHAR sTemp
[MAX_PATH
];
609 szExt
= PathFindExtensionW(szFullPath
);
610 TRACE("szExt=%s\n", debugstr_w(szExt
));
612 HCR_MapTypeToValueW(szExt
, sTemp
, MAX_PATH
, TRUE
) &&
613 HCR_GetDefaultIconW(sTemp
, sTemp
, MAX_PATH
, &psfi
->iIcon
))
615 if (lstrcmpW(p1W
, sTemp
))
616 strcpyW(psfi
->szDisplayName
, sTemp
);
619 /* the icon is in the file */
620 strcpyW(psfi
->szDisplayName
, szFullPath
);
629 hr
= IShellFolder_GetUIObjectOf(psfParent
, 0, 1,
630 (LPCITEMIDLIST
*)&pidlLast
, &IID_IExtractIconW
,
631 &uDummy
, (LPVOID
*)&pei
);
634 hr
= IExtractIconW_GetIconLocation(pei
, uGilFlags
,
635 szLocation
, MAX_PATH
, &iIndex
, &uFlags
);
637 if (uFlags
& GIL_NOTFILENAME
)
641 lstrcpyW (psfi
->szDisplayName
, szLocation
);
642 psfi
->iIcon
= iIndex
;
644 IExtractIconW_Release(pei
);
649 /* get icon index (or load icon)*/
650 if (SUCCEEDED(hr
) && (flags
& (SHGFI_ICON
| SHGFI_SYSICONINDEX
)))
652 if (flags
& SHGFI_USEFILEATTRIBUTES
&& !(flags
& SHGFI_PIDL
))
654 WCHAR sTemp
[MAX_PATH
];
658 lstrcpynW(sTemp
, szFullPath
, MAX_PATH
);
660 if (dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
661 psfi
->iIcon
= SIC_GetIconIndex(swShell32Name
, -IDI_SHELL_FOLDER
, 0);
664 static const WCHAR p1W
[] = {'%','1',0};
667 szExt
= PathFindExtensionW(sTemp
);
669 HCR_MapTypeToValueW(szExt
, sTemp
, MAX_PATH
, TRUE
) &&
670 HCR_GetDefaultIconW(sTemp
, sTemp
, MAX_PATH
, &icon_idx
))
672 if (!lstrcmpW(p1W
,sTemp
)) /* icon is in the file */
673 strcpyW(sTemp
, szFullPath
);
675 if (flags
& SHGFI_SYSICONINDEX
)
677 psfi
->iIcon
= SIC_GetIconIndex(sTemp
,icon_idx
,0);
678 if (psfi
->iIcon
== -1)
684 if (flags
& SHGFI_SMALLICON
)
685 ret
= PrivateExtractIconsW( sTemp
,icon_idx
,
686 GetSystemMetrics( SM_CXSMICON
),
687 GetSystemMetrics( SM_CYSMICON
),
688 &psfi
->hIcon
, 0, 1, 0);
690 ret
= PrivateExtractIconsW( sTemp
, icon_idx
,
691 GetSystemMetrics( SM_CXICON
),
692 GetSystemMetrics( SM_CYICON
),
693 &psfi
->hIcon
, 0, 1, 0);
694 if (ret
!= 0 && ret
!= (UINT
)-1)
696 IconNotYetLoaded
=FALSE
;
697 psfi
->iIcon
= icon_idx
;
705 if (!(PidlToSicIndex(psfParent
, pidlLast
, !(flags
& SHGFI_SMALLICON
),
706 uGilFlags
, &(psfi
->iIcon
))))
711 if (ret
&& (flags
& SHGFI_SYSICONINDEX
))
713 if (flags
& SHGFI_SMALLICON
)
714 ret
= (DWORD_PTR
)small_icons
;
716 ret
= (DWORD_PTR
)big_icons
;
721 if (SUCCEEDED(hr
) && (flags
& SHGFI_ICON
) && IconNotYetLoaded
)
723 if (flags
& SHGFI_SMALLICON
)
724 psfi
->hIcon
= ImageList_GetIcon( small_icons
, psfi
->iIcon
, ILD_NORMAL
);
726 psfi
->hIcon
= ImageList_GetIcon( big_icons
, psfi
->iIcon
, ILD_NORMAL
);
729 if (flags
& ~SHGFI_KNOWN_FLAGS
)
730 FIXME("unknown flags %08x\n", flags
& ~SHGFI_KNOWN_FLAGS
);
733 IShellFolder_Release(psfParent
);
740 TRACE ("icon=%p index=0x%08x attr=0x%08x name=%s type=%s ret=0x%08lx\n",
741 psfi
->hIcon
, psfi
->iIcon
, psfi
->dwAttributes
,
742 debugstr_w(psfi
->szDisplayName
), debugstr_w(psfi
->szTypeName
), ret
);
747 /*************************************************************************
748 * SHGetFileInfoA [SHELL32.@]
751 * MSVBVM60.__vbaNew2 expects this function to return a value in range
752 * 1 .. 0x7fff when the function succeeds and flags does not contain
753 * SHGFI_EXETYPE or SHGFI_SYSICONINDEX (see bug 7701)
755 DWORD_PTR WINAPI
SHGetFileInfoA(LPCSTR path
,DWORD dwFileAttributes
,
756 SHFILEINFOA
*psfi
, UINT sizeofpsfi
,
760 LPWSTR temppath
= NULL
;
763 SHFILEINFOW temppsfi
;
765 if (flags
& SHGFI_PIDL
)
767 /* path contains a pidl */
768 pathW
= (LPCWSTR
)path
;
772 len
= MultiByteToWideChar(CP_ACP
, 0, path
, -1, NULL
, 0);
773 temppath
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
774 MultiByteToWideChar(CP_ACP
, 0, path
, -1, temppath
, len
);
778 if (psfi
&& (flags
& SHGFI_ATTR_SPECIFIED
))
779 temppsfi
.dwAttributes
=psfi
->dwAttributes
;
782 ret
= SHGetFileInfoW(pathW
, dwFileAttributes
, NULL
, sizeof(temppsfi
), flags
);
784 ret
= SHGetFileInfoW(pathW
, dwFileAttributes
, &temppsfi
, sizeof(temppsfi
), flags
);
788 if(flags
& SHGFI_ICON
)
789 psfi
->hIcon
=temppsfi
.hIcon
;
790 if(flags
& (SHGFI_SYSICONINDEX
|SHGFI_ICON
|SHGFI_ICONLOCATION
))
791 psfi
->iIcon
=temppsfi
.iIcon
;
792 if(flags
& SHGFI_ATTRIBUTES
)
793 psfi
->dwAttributes
=temppsfi
.dwAttributes
;
794 if(flags
& (SHGFI_DISPLAYNAME
|SHGFI_ICONLOCATION
))
796 WideCharToMultiByte(CP_ACP
, 0, temppsfi
.szDisplayName
, -1,
797 psfi
->szDisplayName
, sizeof(psfi
->szDisplayName
), NULL
, NULL
);
799 if(flags
& SHGFI_TYPENAME
)
801 WideCharToMultiByte(CP_ACP
, 0, temppsfi
.szTypeName
, -1,
802 psfi
->szTypeName
, sizeof(psfi
->szTypeName
), NULL
, NULL
);
806 HeapFree(GetProcessHeap(), 0, temppath
);
811 /*************************************************************************
812 * DuplicateIcon [SHELL32.@]
814 HICON WINAPI
DuplicateIcon( HINSTANCE hInstance
, HICON hIcon
)
819 TRACE("%p %p\n", hInstance
, hIcon
);
821 if (GetIconInfo(hIcon
, &IconInfo
))
823 hDupIcon
= CreateIconIndirect(&IconInfo
);
825 /* clean up hbmMask and hbmColor */
826 DeleteObject(IconInfo
.hbmMask
);
827 DeleteObject(IconInfo
.hbmColor
);
833 /*************************************************************************
834 * ExtractIconA [SHELL32.@]
836 HICON WINAPI
ExtractIconA(HINSTANCE hInstance
, LPCSTR lpszFile
, UINT nIconIndex
)
839 INT len
= MultiByteToWideChar(CP_ACP
, 0, lpszFile
, -1, NULL
, 0);
840 LPWSTR lpwstrFile
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
842 TRACE("%p %s %d\n", hInstance
, lpszFile
, nIconIndex
);
844 MultiByteToWideChar(CP_ACP
, 0, lpszFile
, -1, lpwstrFile
, len
);
845 ret
= ExtractIconW(hInstance
, lpwstrFile
, nIconIndex
);
846 HeapFree(GetProcessHeap(), 0, lpwstrFile
);
851 /*************************************************************************
852 * ExtractIconW [SHELL32.@]
854 HICON WINAPI
ExtractIconW(HINSTANCE hInstance
, LPCWSTR lpszFile
, UINT nIconIndex
)
858 UINT cx
= GetSystemMetrics(SM_CXICON
), cy
= GetSystemMetrics(SM_CYICON
);
860 TRACE("%p %s %d\n", hInstance
, debugstr_w(lpszFile
), nIconIndex
);
862 if (nIconIndex
== (UINT
)-1)
864 ret
= PrivateExtractIconsW(lpszFile
, 0, cx
, cy
, NULL
, NULL
, 0, LR_DEFAULTCOLOR
);
865 if (ret
!= (UINT
)-1 && ret
)
866 return (HICON
)(UINT_PTR
)ret
;
870 ret
= PrivateExtractIconsW(lpszFile
, nIconIndex
, cx
, cy
, &hIcon
, NULL
, 1, LR_DEFAULTCOLOR
);
874 else if (ret
> 0 && hIcon
)
880 HRESULT WINAPI
SHCreateFileExtractIconW(LPCWSTR file
, DWORD attribs
, REFIID riid
, void **ppv
)
882 FIXME("%s, %x, %s, %p\n", debugstr_w(file
), attribs
, debugstr_guid(riid
), ppv
);
887 /*************************************************************************
888 * Printer_LoadIconsW [SHELL32.205]
890 VOID WINAPI
Printer_LoadIconsW(LPCWSTR wsPrinterName
, HICON
* pLargeIcon
, HICON
* pSmallIcon
)
892 INT iconindex
=IDI_SHELL_PRINTER
;
894 TRACE("(%s, %p, %p)\n", debugstr_w(wsPrinterName
), pLargeIcon
, pSmallIcon
);
896 /* We should check if wsPrinterName is
897 1. the Default Printer or not
899 3. a Local Printer or a Network-Printer
900 and use different Icons
902 if((wsPrinterName
!= NULL
) && (wsPrinterName
[0] != 0))
904 FIXME("(select Icon by PrinterName %s not implemented)\n", debugstr_w(wsPrinterName
));
907 if(pLargeIcon
!= NULL
)
908 *pLargeIcon
= LoadImageW(shell32_hInstance
,
909 (LPCWSTR
) MAKEINTRESOURCE(iconindex
), IMAGE_ICON
,
910 0, 0, LR_DEFAULTCOLOR
|LR_DEFAULTSIZE
);
912 if(pSmallIcon
!= NULL
)
913 *pSmallIcon
= LoadImageW(shell32_hInstance
,
914 (LPCWSTR
) MAKEINTRESOURCE(iconindex
), IMAGE_ICON
,
915 16, 16, LR_DEFAULTCOLOR
);
918 /*************************************************************************
919 * Printers_RegisterWindowW [SHELL32.213]
920 * used by "printui.dll":
921 * find the Window of the given Type for the specific Printer and
922 * return the already existent hwnd or open a new window
924 BOOL WINAPI
Printers_RegisterWindowW(LPCWSTR wsPrinter
, DWORD dwType
,
925 HANDLE
* phClassPidl
, HWND
* phwnd
)
927 FIXME("(%s, %x, %p (%p), %p (%p)) stub!\n", debugstr_w(wsPrinter
), dwType
,
928 phClassPidl
, (phClassPidl
!= NULL
) ? *(phClassPidl
) : NULL
,
929 phwnd
, (phwnd
!= NULL
) ? *(phwnd
) : NULL
);
934 /*************************************************************************
935 * Printers_UnregisterWindow [SHELL32.214]
937 VOID WINAPI
Printers_UnregisterWindow(HANDLE hClassPidl
, HWND hwnd
)
939 FIXME("(%p, %p) stub!\n", hClassPidl
, hwnd
);
942 /*************************************************************************
943 * SHGetPropertyStoreFromParsingName [SHELL32.@]
945 HRESULT WINAPI
SHGetPropertyStoreFromParsingName(PCWSTR pszPath
, IBindCtx
*pbc
, GETPROPERTYSTOREFLAGS flags
, REFIID riid
, void **ppv
)
947 FIXME("(%s %p %u %p %p) stub!\n", debugstr_w(pszPath
), pbc
, flags
, riid
, ppv
);
951 /*************************************************************************/
956 LPCWSTR szOtherStuff
;
961 #define DROP_FIELD_TOP (-12)
963 static void paint_dropline( HDC hdc
, HWND hWnd
)
965 HWND hWndCtl
= GetDlgItem(hWnd
, IDC_ABOUT_WINE_TEXT
);
968 if (!hWndCtl
) return;
969 GetWindowRect( hWndCtl
, &rect
);
970 MapWindowPoints( 0, hWnd
, (LPPOINT
)&rect
, 2 );
971 rect
.top
+= DROP_FIELD_TOP
;
972 rect
.bottom
= rect
.top
+ 2;
973 DrawEdge( hdc
, &rect
, BDR_SUNKENOUTER
, BF_RECT
);
976 /*************************************************************************
977 * SHHelpShortcuts_RunDLLA [SHELL32.@]
980 DWORD WINAPI
SHHelpShortcuts_RunDLLA(DWORD dwArg1
, DWORD dwArg2
, DWORD dwArg3
, DWORD dwArg4
)
982 FIXME("(%x, %x, %x, %x) stub!\n", dwArg1
, dwArg2
, dwArg3
, dwArg4
);
986 /*************************************************************************
987 * SHHelpShortcuts_RunDLLA [SHELL32.@]
990 DWORD WINAPI
SHHelpShortcuts_RunDLLW(DWORD dwArg1
, DWORD dwArg2
, DWORD dwArg3
, DWORD dwArg4
)
992 FIXME("(%x, %x, %x, %x) stub!\n", dwArg1
, dwArg2
, dwArg3
, dwArg4
);
996 /*************************************************************************
997 * SHLoadInProc [SHELL32.@]
998 * Create an instance of specified object class from within
999 * the shell process and release it immediately
1001 HRESULT WINAPI
SHLoadInProc (REFCLSID rclsid
)
1005 TRACE("%s\n", debugstr_guid(rclsid
));
1007 CoCreateInstance(rclsid
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
,&ptr
);
1010 IUnknown
* pUnk
= ptr
;
1011 IUnknown_Release(pUnk
);
1014 return DISP_E_MEMBERNOTFOUND
;
1017 static void add_authors( HWND list
)
1019 static const WCHAR eol
[] = {'\r','\n',0};
1020 static const WCHAR authors
[] = {'A','U','T','H','O','R','S',0};
1021 WCHAR
*strW
, *start
, *end
;
1022 HRSRC rsrc
= FindResourceW( shell32_hInstance
, authors
, (LPCWSTR
)RT_RCDATA
);
1023 char *strA
= LockResource( LoadResource( shell32_hInstance
, rsrc
));
1024 DWORD sizeW
, sizeA
= SizeofResource( shell32_hInstance
, rsrc
);
1027 sizeW
= MultiByteToWideChar( CP_UTF8
, 0, strA
, sizeA
, NULL
, 0 ) + 1;
1028 if (!(strW
= HeapAlloc( GetProcessHeap(), 0, sizeW
* sizeof(WCHAR
) ))) return;
1029 MultiByteToWideChar( CP_UTF8
, 0, strA
, sizeA
, strW
, sizeW
);
1030 strW
[sizeW
- 1] = 0;
1032 start
= strpbrkW( strW
, eol
); /* skip the header line */
1035 while (*start
&& strchrW( eol
, *start
)) start
++;
1037 end
= strpbrkW( start
, eol
);
1038 if (end
) *end
++ = 0;
1039 SendMessageW( list
, LB_ADDSTRING
, -1, (LPARAM
)start
);
1042 HeapFree( GetProcessHeap(), 0, strW
);
1045 /*************************************************************************
1046 * AboutDlgProc (internal)
1048 static INT_PTR CALLBACK
AboutDlgProc( HWND hWnd
, UINT msg
, WPARAM wParam
,
1059 ABOUT_INFO
*info
= (ABOUT_INFO
*)lParam
;
1060 WCHAR
template[512], buffer
[512], version
[64];
1061 extern const char *wine_get_build_id(void);
1065 SendDlgItemMessageW(hWnd
, stc1
, STM_SETICON
,(WPARAM
)info
->hIcon
, 0);
1066 GetWindowTextW( hWnd
, template, sizeof(template)/sizeof(WCHAR
) );
1067 sprintfW( buffer
, template, info
->szApp
);
1068 SetWindowTextW( hWnd
, buffer
);
1069 SetWindowTextW( GetDlgItem(hWnd
, IDC_ABOUT_STATIC_TEXT1
), info
->szApp
);
1070 SetWindowTextW( GetDlgItem(hWnd
, IDC_ABOUT_STATIC_TEXT2
), info
->szOtherStuff
);
1071 GetWindowTextW( GetDlgItem(hWnd
, IDC_ABOUT_STATIC_TEXT3
),
1072 template, sizeof(template)/sizeof(WCHAR
) );
1073 MultiByteToWideChar( CP_UTF8
, 0, wine_get_build_id(), -1,
1074 version
, sizeof(version
)/sizeof(WCHAR
) );
1075 sprintfW( buffer
, template, version
);
1076 SetWindowTextW( GetDlgItem(hWnd
, IDC_ABOUT_STATIC_TEXT3
), buffer
);
1077 hWndCtl
= GetDlgItem(hWnd
, IDC_ABOUT_LISTBOX
);
1078 SendMessageW( hWndCtl
, WM_SETREDRAW
, 0, 0 );
1079 SendMessageW( hWndCtl
, WM_SETFONT
, (WPARAM
)info
->hFont
, 0 );
1080 add_authors( hWndCtl
);
1081 SendMessageW( hWndCtl
, WM_SETREDRAW
, 1, 0 );
1089 HDC hDC
= BeginPaint( hWnd
, &ps
);
1090 paint_dropline( hDC
, hWnd
);
1091 EndPaint( hWnd
, &ps
);
1096 if (wParam
== IDOK
|| wParam
== IDCANCEL
)
1098 EndDialog(hWnd
, TRUE
);
1101 if (wParam
== IDC_ABOUT_LICENSE
)
1103 MSGBOXPARAMSW params
;
1105 params
.cbSize
= sizeof(params
);
1106 params
.hwndOwner
= hWnd
;
1107 params
.hInstance
= shell32_hInstance
;
1108 params
.lpszText
= MAKEINTRESOURCEW(IDS_LICENSE
);
1109 params
.lpszCaption
= MAKEINTRESOURCEW(IDS_LICENSE_CAPTION
);
1110 params
.dwStyle
= MB_ICONINFORMATION
| MB_OK
;
1111 params
.lpszIcon
= 0;
1112 params
.dwContextHelpId
= 0;
1113 params
.lpfnMsgBoxCallback
= NULL
;
1114 params
.dwLanguageId
= LANG_NEUTRAL
;
1115 MessageBoxIndirectW( ¶ms
);
1119 EndDialog(hWnd
, TRUE
);
1127 /*************************************************************************
1128 * ShellAboutA [SHELL32.288]
1130 BOOL WINAPI
ShellAboutA( HWND hWnd
, LPCSTR szApp
, LPCSTR szOtherStuff
, HICON hIcon
)
1133 LPWSTR appW
= NULL
, otherW
= NULL
;
1138 len
= MultiByteToWideChar(CP_ACP
, 0, szApp
, -1, NULL
, 0);
1139 appW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1140 MultiByteToWideChar(CP_ACP
, 0, szApp
, -1, appW
, len
);
1144 len
= MultiByteToWideChar(CP_ACP
, 0, szOtherStuff
, -1, NULL
, 0);
1145 otherW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1146 MultiByteToWideChar(CP_ACP
, 0, szOtherStuff
, -1, otherW
, len
);
1149 ret
= ShellAboutW(hWnd
, appW
, otherW
, hIcon
);
1151 HeapFree(GetProcessHeap(), 0, otherW
);
1152 HeapFree(GetProcessHeap(), 0, appW
);
1157 /*************************************************************************
1158 * ShellAboutW [SHELL32.289]
1160 BOOL WINAPI
ShellAboutW( HWND hWnd
, LPCWSTR szApp
, LPCWSTR szOtherStuff
,
1166 static const WCHAR wszSHELL_ABOUT_MSGBOX
[] =
1167 {'S','H','E','L','L','_','A','B','O','U','T','_','M','S','G','B','O','X',0};
1171 if (!hIcon
) hIcon
= LoadImageW( 0, (LPWSTR
)IDI_WINLOGO
, IMAGE_ICON
, 48, 48, LR_SHARED
);
1173 info
.szOtherStuff
= szOtherStuff
;
1176 SystemParametersInfoW( SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0 );
1177 info
.hFont
= CreateFontIndirectW( &logFont
);
1179 bRet
= DialogBoxParamW( shell32_hInstance
, wszSHELL_ABOUT_MSGBOX
, hWnd
, AboutDlgProc
, (LPARAM
)&info
);
1180 DeleteObject(info
.hFont
);
1184 /*************************************************************************
1185 * FreeIconList (SHELL32.@)
1187 void WINAPI
FreeIconList( DWORD dw
)
1189 FIXME("%x: stub\n",dw
);
1192 /*************************************************************************
1193 * SHLoadNonloadedIconOverlayIdentifiers (SHELL32.@)
1195 HRESULT WINAPI
SHLoadNonloadedIconOverlayIdentifiers( VOID
)
1201 /***********************************************************************
1202 * DllGetVersion [SHELL32.@]
1204 * Retrieves version information of the 'SHELL32.DLL'
1207 * pdvi [O] pointer to version information structure.
1211 * Failure: E_INVALIDARG
1214 * Returns version of a shell32.dll from IE4.01 SP1.
1217 HRESULT WINAPI
DllGetVersion (DLLVERSIONINFO
*pdvi
)
1219 /* FIXME: shouldn't these values come from the version resource? */
1220 if (pdvi
->cbSize
== sizeof(DLLVERSIONINFO
) ||
1221 pdvi
->cbSize
== sizeof(DLLVERSIONINFO2
))
1223 pdvi
->dwMajorVersion
= WINE_FILEVERSION_MAJOR
;
1224 pdvi
->dwMinorVersion
= WINE_FILEVERSION_MINOR
;
1225 pdvi
->dwBuildNumber
= WINE_FILEVERSION_BUILD
;
1226 pdvi
->dwPlatformID
= WINE_FILEVERSION_PLATFORMID
;
1227 if (pdvi
->cbSize
== sizeof(DLLVERSIONINFO2
))
1229 DLLVERSIONINFO2
*pdvi2
= (DLLVERSIONINFO2
*)pdvi
;
1232 pdvi2
->ullVersion
= MAKEDLLVERULL(WINE_FILEVERSION_MAJOR
,
1233 WINE_FILEVERSION_MINOR
,
1234 WINE_FILEVERSION_BUILD
,
1235 WINE_FILEVERSION_PLATFORMID
);
1237 TRACE("%u.%u.%u.%u\n",
1238 pdvi
->dwMajorVersion
, pdvi
->dwMinorVersion
,
1239 pdvi
->dwBuildNumber
, pdvi
->dwPlatformID
);
1244 WARN("wrong DLLVERSIONINFO size from app\n");
1245 return E_INVALIDARG
;
1249 /*************************************************************************
1250 * global variables of the shell32.dll
1251 * all are once per process
1254 HINSTANCE shell32_hInstance
= 0;
1257 /*************************************************************************
1261 * calling oleinitialize here breaks some apps.
1263 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID fImpLoad
)
1265 TRACE("%p 0x%x %p\n", hinstDLL
, fdwReason
, fImpLoad
);
1269 case DLL_PROCESS_ATTACH
:
1270 shell32_hInstance
= hinstDLL
;
1271 DisableThreadLibraryCalls(shell32_hInstance
);
1273 /* get full path to this DLL for IExtractIconW_fnGetIconLocation() */
1274 GetModuleFileNameW(hinstDLL
, swShell32Name
, MAX_PATH
);
1275 swShell32Name
[MAX_PATH
- 1] = '\0';
1277 InitChangeNotifications();
1280 case DLL_PROCESS_DETACH
:
1281 if (fImpLoad
) break;
1283 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
));