Make the dsound tests run with DirectX < 8.
[wine] / dlls / shell32 / shell32_main.c
1 /*
2  *                              Shell basics
3  *
4  * Copyright 1998 Marcus Meissner
5  * Copyright 1998 Juergen Schmied (jsch)  *  <juergen.schmied@metronet.de>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include "config.h"
23
24 #include <stdlib.h>
25 #include <string.h>
26 #include <stdarg.h>
27 #include <stdio.h>
28
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winerror.h"
32 #include "winreg.h"
33 #include "dlgs.h"
34 #include "shellapi.h"
35 #include "winuser.h"
36 #include "wingdi.h"
37 #include "shlobj.h"
38 #include "shlguid.h"
39 #include "shlwapi.h"
40
41 #include "undocshell.h"
42 #include "pidl.h"
43 #include "shell32_main.h"
44
45 #include "wine/debug.h"
46 #include "wine/unicode.h"
47
48 WINE_DEFAULT_DEBUG_CHANNEL(shell);
49
50 extern const char * const SHELL_Authors[];
51
52 #define MORE_DEBUG 1
53 /*************************************************************************
54  * CommandLineToArgvW                   [SHELL32.@]
55  *
56  * We must interpret the quotes in the command line to rebuild the argv
57  * array correctly:
58  * - arguments are separated by spaces or tabs
59  * - quotes serve as optional argument delimiters
60  *   '"a b"'   -> 'a b'
61  * - escaped quotes must be converted back to '"'
62  *   '\"'      -> '"'
63  * - an odd number of '\'s followed by '"' correspond to half that number
64  *   of '\' followed by a '"' (extension of the above)
65  *   '\\\"'    -> '\"'
66  *   '\\\\\"'  -> '\\"'
67  * - an even number of '\'s followed by a '"' correspond to half that number
68  *   of '\', plus a regular quote serving as an argument delimiter (which
69  *   means it does not appear in the result)
70  *   'a\\"b c"'   -> 'a\b c'
71  *   'a\\\\"b c"' -> 'a\\b c'
72  * - '\' that are not followed by a '"' are copied literally
73  *   'a\b'     -> 'a\b'
74  *   'a\\b'    -> 'a\\b'
75  *
76  * Note:
77  * '\t' == 0x0009
78  * ' '  == 0x0020
79  * '"'  == 0x0022
80  * '\\' == 0x005c
81  */
82 LPWSTR* WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int* numargs)
83 {
84     DWORD argc;
85     HGLOBAL hargv;
86     LPWSTR  *argv;
87     LPCWSTR cs;
88     LPWSTR arg,s,d;
89     LPWSTR cmdline;
90     int in_quotes,bcount;
91
92     if (*lpCmdline==0) {
93         /* Return the path to the executable */
94         DWORD len, size=16;
95
96         hargv=GlobalAlloc(size, 0);
97         argv=GlobalLock(hargv);
98         for (;;) {
99             len = GetModuleFileNameW(0, (LPWSTR)(argv+1), size-sizeof(LPWSTR));
100             if (!len) {
101                 GlobalFree(hargv);
102                 return NULL;
103             }
104             if (len < size) break;
105             size*=2;
106             hargv=GlobalReAlloc(hargv, size, 0);
107             argv=GlobalLock(hargv);
108         }
109         argv[0]=(LPWSTR)(argv+1);
110         if (numargs)
111             *numargs=2;
112
113         return argv;
114     }
115
116     /* to get a writeable copy */
117     argc=0;
118     bcount=0;
119     in_quotes=0;
120     cs=lpCmdline;
121     while (1) {
122         if (*cs==0 || ((*cs==0x0009 || *cs==0x0020) && !in_quotes)) {
123             /* space */
124             argc++;
125             /* skip the remaining spaces */
126             while (*cs==0x0009 || *cs==0x0020) {
127                 cs++;
128             }
129             if (*cs==0)
130                 break;
131             bcount=0;
132             continue;
133         } else if (*cs==0x005c) {
134             /* '\', count them */
135             bcount++;
136         } else if ((*cs==0x0022) && ((bcount & 1)==0)) {
137             /* unescaped '"' */
138             in_quotes=!in_quotes;
139             bcount=0;
140         } else {
141             /* a regular character */
142             bcount=0;
143         }
144         cs++;
145     }
146     /* Allocate in a single lump, the string array, and the strings that go with it.
147      * This way the caller can make a single GlobalFree call to free both, as per MSDN.
148      */
149     hargv=GlobalAlloc(0, argc*sizeof(LPWSTR)+(strlenW(lpCmdline)+1)*sizeof(WCHAR));
150     argv=GlobalLock(hargv);
151     if (!argv)
152         return NULL;
153     cmdline=(LPWSTR)(argv+argc);
154     strcpyW(cmdline, lpCmdline);
155
156     argc=0;
157     bcount=0;
158     in_quotes=0;
159     arg=d=s=cmdline;
160     while (*s) {
161         if ((*s==0x0009 || *s==0x0020) && !in_quotes) {
162             /* Close the argument and copy it */
163             *d=0;
164             argv[argc++]=arg;
165
166             /* skip the remaining spaces */
167             do {
168                 s++;
169             } while (*s==0x0009 || *s==0x0020);
170
171             /* Start with a new argument */
172             arg=d=s;
173             bcount=0;
174         } else if (*s==0x005c) {
175             /* '\\' */
176             *d++=*s++;
177             bcount++;
178         } else if (*s==0x0022) {
179             /* '"' */
180             if ((bcount & 1)==0) {
181                 /* Preceeded by an even number of '\', this is half that
182                  * number of '\', plus a quote which we erase.
183                  */
184                 d-=bcount/2;
185                 in_quotes=!in_quotes;
186                 s++;
187             } else {
188                 /* Preceeded by an odd number of '\', this is half that
189                  * number of '\' followed by a '"'
190                  */
191                 d=d-bcount/2-1;
192                 *d++='"';
193                 s++;
194             }
195             bcount=0;
196         } else {
197             /* a regular character */
198             *d++=*s++;
199             bcount=0;
200         }
201     }
202     if (*arg) {
203         *d='\0';
204         argv[argc++]=arg;
205     }
206     if (numargs)
207         *numargs=argc;
208
209     return argv;
210 }
211
212 /*************************************************************************
213  * SHGetFileInfoA                       [SHELL32.@]
214  *
215  */
216
217 DWORD WINAPI SHGetFileInfoW(LPCWSTR path,DWORD dwFileAttributes,
218                               SHFILEINFOW *psfi, UINT sizeofpsfi,
219                               UINT flags )
220 {
221         WCHAR szLocation[MAX_PATH], szFullPath[MAX_PATH];
222         int iIndex;
223         DWORD ret = TRUE, dwAttributes = 0;
224         IShellFolder * psfParent = NULL;
225         IExtractIconW * pei = NULL;
226         LPITEMIDLIST    pidlLast = NULL, pidl = NULL;
227         HRESULT hr = S_OK;
228         BOOL IconNotYetLoaded=TRUE;
229
230         TRACE("(%s fattr=0x%lx sfi=%p(attr=0x%08lx) size=0x%x flags=0x%x)\n",
231           (flags & SHGFI_PIDL)? "pidl" : debugstr_w(path), dwFileAttributes, psfi, psfi->dwAttributes, sizeofpsfi, flags);
232
233         if ((flags & SHGFI_USEFILEATTRIBUTES) && (flags & (SHGFI_ATTRIBUTES|SHGFI_EXETYPE|SHGFI_PIDL)))
234           return FALSE;
235
236         /* windows initializes this values regardless of the flags */
237         if (psfi != NULL) {
238             psfi->szDisplayName[0] = '\0';
239             psfi->szTypeName[0] = '\0';
240             psfi->iIcon = 0;
241         }
242
243        if (!(flags & SHGFI_PIDL)){
244             /* SHGitFileInfo should work with absolute and relative paths */
245             if (PathIsRelativeW(path)){
246                 GetCurrentDirectoryW(MAX_PATH, szLocation);
247                 PathCombineW(szFullPath, szLocation, path);
248             } else {
249                 lstrcpynW(szFullPath, path, MAX_PATH);
250             }
251         }
252
253         if (flags & SHGFI_EXETYPE) {
254           BOOL status = FALSE;
255           HANDLE hfile;
256           DWORD BinaryType;
257           IMAGE_DOS_HEADER mz_header;
258           IMAGE_NT_HEADERS nt;
259           DWORD len;
260           char magic[4];
261
262           if (flags != SHGFI_EXETYPE) return 0;
263
264          status = GetBinaryTypeW (szFullPath, &BinaryType);
265           if (!status) return 0;
266           if ((BinaryType == SCS_DOS_BINARY)
267                 || (BinaryType == SCS_PIF_BINARY)) return 0x4d5a;
268
269          hfile = CreateFileW( szFullPath, GENERIC_READ, FILE_SHARE_READ,
270                 NULL, OPEN_EXISTING, 0, 0 );
271           if ( hfile == INVALID_HANDLE_VALUE ) return 0;
272
273         /* The next section is adapted from MODULE_GetBinaryType, as we need
274          * to examine the image header to get OS and version information. We
275          * know from calling GetBinaryTypeA that the image is valid and either
276          * an NE or PE, so much error handling can be omitted.
277          * Seek to the start of the file and read the header information.
278          */
279
280           SetFilePointer( hfile, 0, NULL, SEEK_SET );
281           ReadFile( hfile, &mz_header, sizeof(mz_header), &len, NULL );
282
283          SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
284          ReadFile( hfile, magic, sizeof(magic), &len, NULL );
285          if ( *(DWORD*)magic      == IMAGE_NT_SIGNATURE )
286          {
287              SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
288              ReadFile( hfile, &nt, sizeof(nt), &len, NULL );
289               CloseHandle( hfile );
290               if (nt.OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI) {
291                  return IMAGE_NT_SIGNATURE
292                         | (nt.OptionalHeader.MajorSubsystemVersion << 24)
293                         | (nt.OptionalHeader.MinorSubsystemVersion << 16);
294               }
295               return IMAGE_NT_SIGNATURE;
296           }
297          else if ( *(WORD*)magic == IMAGE_OS2_SIGNATURE )
298          {
299              IMAGE_OS2_HEADER ne;
300              SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
301              ReadFile( hfile, &ne, sizeof(ne), &len, NULL );
302               CloseHandle( hfile );
303              if (ne.ne_exetyp == 2) return IMAGE_OS2_SIGNATURE
304                         | (ne.ne_expver << 16);
305               return 0;
306           }
307           CloseHandle( hfile );
308           return 0;
309       }
310
311       /* psfi is NULL normally to query EXE type. If it is NULL, none of the
312        * below makes sense anyway. Windows allows this and just returns FALSE */
313       if (psfi == NULL) return FALSE;
314
315         /* translate the path into a pidl only when SHGFI_USEFILEATTRIBUTES
316          * is not specified.
317            The pidl functions fail on not existing file names */
318
319         if (flags & SHGFI_PIDL) {
320             pidl = ILClone((LPCITEMIDLIST)path);
321         } else if (!(flags & SHGFI_USEFILEATTRIBUTES)) {
322            hr = SHILCreateFromPathW(szFullPath, &pidl, &dwAttributes);
323         }
324
325         if ((flags & SHGFI_PIDL) || !(flags & SHGFI_USEFILEATTRIBUTES))
326         {
327            /* get the parent shellfolder */
328            if (pidl) {
329               hr = SHBindToParent(pidl, &IID_IShellFolder, (LPVOID*)&psfParent, (LPCITEMIDLIST*)&pidlLast);
330               ILFree(pidl);
331            } else {
332               ERR("pidl is null!\n");
333               return FALSE;
334            }
335         }
336
337         /* get the attributes of the child */
338         if (SUCCEEDED(hr) && (flags & SHGFI_ATTRIBUTES))
339         {
340           if (!(flags & SHGFI_ATTR_SPECIFIED))
341           {
342             psfi->dwAttributes = 0xffffffff;
343           }
344           IShellFolder_GetAttributesOf(psfParent, 1, (LPCITEMIDLIST*)&pidlLast, &(psfi->dwAttributes));
345         }
346
347         /* get the displayname */
348         if (SUCCEEDED(hr) && (flags & SHGFI_DISPLAYNAME))
349         {
350           if (flags & SHGFI_USEFILEATTRIBUTES)
351           {
352            lstrcpyW (psfi->szDisplayName, PathFindFileNameW(szFullPath));
353           }
354           else
355           {
356             STRRET str;
357             hr = IShellFolder_GetDisplayNameOf(psfParent, pidlLast, SHGDN_INFOLDER, &str);
358             StrRetToStrNW (psfi->szDisplayName, MAX_PATH, &str, pidlLast);
359           }
360         }
361
362         /* get the type name */
363         if (SUCCEEDED(hr) && (flags & SHGFI_TYPENAME))
364         {
365             static const WCHAR szFile[] = { 'F','i','l','e',0 };
366             static const WCHAR szDashFile[] = { '-','f','i','l','e',0 };
367             if (!(flags & SHGFI_USEFILEATTRIBUTES))
368             {
369                 char ftype[80];
370                 _ILGetFileType(pidlLast, ftype, 80);
371                 MultiByteToWideChar(CP_ACP, 0, ftype, -1, psfi->szTypeName, 80 );
372             }
373             else
374             {
375                 if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
376                    strcatW (psfi->szTypeName, szFile);
377                 else 
378                 {
379                    WCHAR sTemp[64];
380                    lstrcpyW(sTemp,PathFindExtensionW(szFullPath));
381                    if (!( HCR_MapTypeToValueW(sTemp, sTemp, 64, TRUE)
382                         && HCR_MapTypeToValueW(sTemp, psfi->szTypeName, 80, FALSE )))
383                    {
384                        lstrcpynW (psfi->szTypeName, sTemp, 64);
385                        strcatW (psfi->szTypeName, szDashFile);
386                    }
387                 }
388             }
389         }
390
391         /* ### icons ###*/
392         if (flags & SHGFI_LINKOVERLAY)
393           FIXME("set icon to link, stub\n");
394
395         if (flags & SHGFI_SELECTED)
396           FIXME("set icon to selected, stub\n");
397
398         if (flags & SHGFI_SHELLICONSIZE)
399           FIXME("set icon to shell size, stub\n");
400
401         /* get the iconlocation */
402         if (SUCCEEDED(hr) && (flags & SHGFI_ICONLOCATION ))
403         {
404           UINT uDummy,uFlags;
405           hr = IShellFolder_GetUIObjectOf(psfParent, 0, 1, (LPCITEMIDLIST*)&pidlLast, &IID_IExtractIconA, &uDummy, (LPVOID*)&pei);
406
407           if (SUCCEEDED(hr))
408           {
409            hr = IExtractIconW_GetIconLocation(pei, (flags & SHGFI_OPENICON)? GIL_OPENICON : 0,szLocation, MAX_PATH, &iIndex, &uFlags);
410            psfi->iIcon = iIndex;
411
412             if(uFlags != GIL_NOTFILENAME)
413               lstrcpyW (psfi->szDisplayName, szLocation);
414             else
415               ret = FALSE;
416
417             IExtractIconA_Release(pei);
418           }
419         }
420
421         /* get icon index (or load icon)*/
422         if (SUCCEEDED(hr) && (flags & (SHGFI_ICON | SHGFI_SYSICONINDEX)))
423         {
424
425           if (flags & SHGFI_USEFILEATTRIBUTES)
426           {
427             WCHAR sTemp [MAX_PATH];
428             WCHAR * szExt;
429             DWORD dwNr=0;
430
431             lstrcpynW(sTemp, szFullPath, MAX_PATH);
432
433             if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
434                psfi->iIcon = 2;
435             else
436             {
437                static const WCHAR p1W[] = {'%','1',0};
438                psfi->iIcon = 0;
439                szExt = (LPWSTR) PathFindExtensionW(sTemp);
440                if ( szExt && HCR_MapTypeToValueW(szExt, sTemp, MAX_PATH, TRUE)
441                    && HCR_GetDefaultIconW(sTemp, sTemp, MAX_PATH, &dwNr))
442                {
443                   if (!lstrcmpW(p1W,sTemp))            /* icon is in the file */
444                      strcpyW(sTemp, szFullPath);
445
446                   if (flags & SHGFI_SYSICONINDEX) 
447                   {
448                       psfi->iIcon = SIC_GetIconIndex(sTemp,dwNr);
449                       if (psfi->iIcon == -1) psfi->iIcon = 0;
450                   }
451                   else 
452                   {
453                       IconNotYetLoaded=FALSE;
454                       PrivateExtractIconsW(sTemp,dwNr,(flags & SHGFI_SMALLICON) ? 
455                         GetSystemMetrics(SM_CXSMICON) : GetSystemMetrics(SM_CXICON),
456                         (flags & SHGFI_SMALLICON) ? GetSystemMetrics(SM_CYSMICON) :
457                         GetSystemMetrics(SM_CYICON), &psfi->hIcon,0,1,0);
458                       psfi->iIcon = dwNr;
459                   }
460                }
461             }
462           }
463           else
464           {
465             if (!(PidlToSicIndex(psfParent, pidlLast, !(flags & SHGFI_SMALLICON),
466               (flags & SHGFI_OPENICON)? GIL_OPENICON : 0, &(psfi->iIcon))))
467             {
468               ret = FALSE;
469             }
470           }
471           if (ret)
472           {
473             ret = (DWORD) ((flags & SHGFI_SMALLICON) ? ShellSmallIconList : ShellBigIconList);
474           }
475         }
476
477         /* icon handle */
478         if (SUCCEEDED(hr) && (flags & SHGFI_ICON) && IconNotYetLoaded)
479           psfi->hIcon = ImageList_GetIcon((flags & SHGFI_SMALLICON) ? ShellSmallIconList:ShellBigIconList, psfi->iIcon, ILD_NORMAL);
480
481         if (flags & (SHGFI_UNKNOWN1 | SHGFI_UNKNOWN2 | SHGFI_UNKNOWN3))
482           FIXME("unknown attribute!\n");
483
484         if (psfParent)
485           IShellFolder_Release(psfParent);
486
487         if (hr != S_OK)
488           ret = FALSE;
489
490         if(pidlLast) SHFree(pidlLast);
491 #ifdef MORE_DEBUG
492         TRACE ("icon=%p index=0x%08x attr=0x%08lx name=%s type=%s ret=0x%08lx\n",
493                 psfi->hIcon, psfi->iIcon, psfi->dwAttributes, debugstr_w(psfi->szDisplayName), debugstr_w(psfi->szTypeName), ret);
494 #endif
495         return ret;
496 }
497
498 /*************************************************************************
499  * SHGetFileInfoW                       [SHELL32.@]
500  */
501
502 DWORD WINAPI SHGetFileInfoA(LPCSTR path,DWORD dwFileAttributes,
503                               SHFILEINFOA *psfi, UINT sizeofpsfi,
504                               UINT flags )
505 {
506         INT len;
507         LPWSTR temppath;
508         DWORD ret;
509         SHFILEINFOW temppsfi;
510
511         if (flags & SHGFI_PIDL) {
512           /* path contains a pidl */
513           temppath = (LPWSTR) path;
514         } else {
515           len = MultiByteToWideChar(CP_ACP, 0, path, -1, NULL, 0);
516           temppath = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
517           MultiByteToWideChar(CP_ACP, 0, path, -1, temppath, len);
518         }
519
520         if(psfi && (flags & SHGFI_ATTR_SPECIFIED))
521                temppsfi.dwAttributes=psfi->dwAttributes;
522
523         ret = SHGetFileInfoW(temppath, dwFileAttributes, (psfi == NULL)? NULL : &temppsfi, sizeof(temppsfi), flags);
524
525         if (psfi)
526         {
527             if(flags & SHGFI_ICON)
528                 psfi->hIcon=temppsfi.hIcon;
529             if(flags & (SHGFI_SYSICONINDEX|SHGFI_ICON|SHGFI_ICONLOCATION))
530                 psfi->iIcon=temppsfi.iIcon;
531             if(flags & SHGFI_ATTRIBUTES)
532                 psfi->dwAttributes=temppsfi.dwAttributes;
533             if(flags & (SHGFI_DISPLAYNAME|SHGFI_ICONLOCATION))
534                 WideCharToMultiByte(CP_ACP, 0, temppsfi.szDisplayName, -1, psfi->szDisplayName, sizeof(psfi->szDisplayName), NULL, NULL);
535             if(flags & SHGFI_TYPENAME)
536                 WideCharToMultiByte(CP_ACP, 0, temppsfi.szTypeName, -1, psfi->szTypeName, sizeof(psfi->szTypeName), NULL, NULL);
537         }
538         if(!(flags & SHGFI_PIDL)) HeapFree(GetProcessHeap(), 0, temppath);
539         return ret;
540 }
541
542 /*************************************************************************
543  * SHGetFileInfo                        [SHELL32.@]
544  */
545 DWORD WINAPI SHGetFileInfoAW(
546         LPCVOID path,
547         DWORD dwFileAttributes,
548         LPVOID psfi,
549         UINT sizeofpsfi,
550         UINT flags)
551 {
552         if(SHELL_OsIsUnicode())
553           return SHGetFileInfoW(path, dwFileAttributes, psfi, sizeofpsfi, flags );
554         return SHGetFileInfoA(path, dwFileAttributes, psfi, sizeofpsfi, flags );
555 }
556
557 /*************************************************************************
558  * DuplicateIcon                        [SHELL32.@]
559  */
560 HICON WINAPI DuplicateIcon( HINSTANCE hInstance, HICON hIcon)
561 {
562     ICONINFO IconInfo;
563     HICON hDupIcon = 0;
564
565     TRACE("(%p, %p)\n", hInstance, hIcon);
566
567     if(GetIconInfo(hIcon, &IconInfo))
568     {
569         hDupIcon = CreateIconIndirect(&IconInfo);
570
571         /* clean up hbmMask and hbmColor */
572         DeleteObject(IconInfo.hbmMask);
573         DeleteObject(IconInfo.hbmColor);
574     }
575
576     return hDupIcon;
577 }
578
579 /*************************************************************************
580  * ExtractIconA                         [SHELL32.@]
581  */
582 HICON WINAPI ExtractIconA(HINSTANCE hInstance, LPCSTR lpszFile, UINT nIconIndex)
583 {   
584   HICON ret;
585   INT len = MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, NULL, 0);
586   LPWSTR lpwstrFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
587
588   TRACE("%p %s %d\n", hInstance, lpszFile, nIconIndex);
589
590   MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, lpwstrFile, len);
591   ret = ExtractIconW(hInstance, lpwstrFile, nIconIndex);
592   HeapFree(GetProcessHeap(), 0, lpwstrFile);
593   return ret;
594 }
595
596 /*************************************************************************
597  * ExtractIconW                         [SHELL32.@]
598  */
599 HICON WINAPI ExtractIconW(HINSTANCE hInstance, LPCWSTR lpszFile, UINT nIconIndex)
600 {
601         HICON  hIcon = NULL;
602         UINT ret;
603         UINT cx = GetSystemMetrics(SM_CXICON), cy = GetSystemMetrics(SM_CYICON);
604
605         TRACE("%p %s %d\n", hInstance, debugstr_w(lpszFile), nIconIndex);
606
607         if (nIconIndex == 0xFFFFFFFF) {
608           ret = PrivateExtractIconsW(lpszFile, 0, cx, cy, NULL, NULL, 0, LR_DEFAULTCOLOR);
609           if (ret != 0xFFFFFFFF && ret)
610             return (HICON)ret;
611           return NULL;
612         }
613         else
614           ret = PrivateExtractIconsW(lpszFile, nIconIndex, cx, cy, &hIcon, NULL, 1, LR_DEFAULTCOLOR);
615
616         if (ret == 0xFFFFFFFF)
617           return (HICON)1;
618         else if (ret > 0 && hIcon)
619           return hIcon;
620         return NULL;
621 }
622
623 typedef struct
624 {
625     LPCWSTR  szApp;
626     LPCWSTR  szOtherStuff;
627     HICON hIcon;
628     HFONT hFont;
629 } ABOUT_INFO;
630
631 #define         IDC_STATIC_TEXT         100
632 #define         IDC_LISTBOX             99
633 #define         IDC_WINE_TEXT           98
634
635 #define         DROP_FIELD_TOP          (-15)
636 #define         DROP_FIELD_HEIGHT       15
637
638 static BOOL __get_dropline( HWND hWnd, LPRECT lprect )
639 { HWND hWndCtl = GetDlgItem(hWnd, IDC_WINE_TEXT);
640     if( hWndCtl )
641   { GetWindowRect( hWndCtl, lprect );
642         MapWindowPoints( 0, hWnd, (LPPOINT)lprect, 2 );
643         lprect->bottom = (lprect->top += DROP_FIELD_TOP);
644         return TRUE;
645     }
646     return FALSE;
647 }
648
649 /*************************************************************************
650  * SHAppBarMessage                      [SHELL32.@]
651  */
652 UINT WINAPI SHAppBarMessage(DWORD msg, PAPPBARDATA data)
653 {
654         int width=data->rc.right - data->rc.left;
655         int height=data->rc.bottom - data->rc.top;
656         RECT rec=data->rc;
657         switch (msg)
658         { case ABM_GETSTATE:
659                return ABS_ALWAYSONTOP | ABS_AUTOHIDE;
660           case ABM_GETTASKBARPOS:
661                GetWindowRect(data->hWnd, &rec);
662                data->rc=rec;
663                return TRUE;
664           case ABM_ACTIVATE:
665                SetActiveWindow(data->hWnd);
666                return TRUE;
667           case ABM_GETAUTOHIDEBAR:
668                data->hWnd=GetActiveWindow();
669                return TRUE;
670           case ABM_NEW:
671                SetWindowPos(data->hWnd,HWND_TOP,rec.left,rec.top,
672                                         width,height,SWP_SHOWWINDOW);
673                return TRUE;
674           case ABM_QUERYPOS:
675                GetWindowRect(data->hWnd, &(data->rc));
676                return TRUE;
677           case ABM_REMOVE:
678                FIXME("ABM_REMOVE broken\n");
679                /* FIXME: this is wrong; should it be DestroyWindow instead? */
680                /*CloseHandle(data->hWnd);*/
681                return TRUE;
682           case ABM_SETAUTOHIDEBAR:
683                SetWindowPos(data->hWnd,HWND_TOP,rec.left+1000,rec.top,
684                                        width,height,SWP_SHOWWINDOW);
685                return TRUE;
686           case ABM_SETPOS:
687                data->uEdge=(ABE_RIGHT | ABE_LEFT);
688                SetWindowPos(data->hWnd,HWND_TOP,data->rc.left,data->rc.top,
689                                   width,height,SWP_SHOWWINDOW);
690                return TRUE;
691           case ABM_WINDOWPOSCHANGED:
692                return TRUE;
693           }
694       return FALSE;
695 }
696
697 /*************************************************************************
698  * SHHelpShortcuts_RunDLL               [SHELL32.@]
699  *
700  */
701 DWORD WINAPI SHHelpShortcuts_RunDLL (DWORD dwArg1, DWORD dwArg2, DWORD dwArg3, DWORD dwArg4)
702 { FIXME("(%lx, %lx, %lx, %lx) empty stub!\n",
703         dwArg1, dwArg2, dwArg3, dwArg4);
704
705   return 0;
706 }
707
708 /*************************************************************************
709  * SHLoadInProc                         [SHELL32.@]
710  * Create an instance of specified object class from within
711  * the shell process and release it immediately
712  */
713
714 HRESULT WINAPI SHLoadInProc (REFCLSID rclsid)
715 {
716     void *ptr = NULL;
717
718     TRACE("%s\n", debugstr_guid(rclsid));
719
720     CoCreateInstance(rclsid, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown,&ptr);
721     if(ptr)
722     {
723         IUnknown * pUnk = ptr;
724         IUnknown_Release(pUnk);
725         return NOERROR;
726     }
727     return DISP_E_MEMBERNOTFOUND;
728 }
729
730 /*************************************************************************
731  * AboutDlgProc                 (internal)
732  */
733 INT_PTR CALLBACK AboutDlgProc( HWND hWnd, UINT msg, WPARAM wParam,
734                               LPARAM lParam )
735 {
736     HWND hWndCtl;
737
738     TRACE("\n");
739
740     switch(msg)
741     {
742     case WM_INITDIALOG:
743         {
744             ABOUT_INFO *info = (ABOUT_INFO *)lParam;
745             WCHAR Template[512], AppTitle[512];
746
747             if (info)
748             {
749                 const char* const *pstr = SHELL_Authors;
750                 SendDlgItemMessageW(hWnd, stc1, STM_SETICON,(WPARAM)info->hIcon, 0);
751                 GetWindowTextW( hWnd, Template, sizeof(Template)/sizeof(WCHAR) );
752                 sprintfW( AppTitle, Template, info->szApp );
753                 SetWindowTextW( hWnd, AppTitle );
754                 SetWindowTextW( GetDlgItem(hWnd, IDC_STATIC_TEXT), info->szOtherStuff );
755                 hWndCtl = GetDlgItem(hWnd, IDC_LISTBOX);
756                 SendMessageW( hWndCtl, WM_SETREDRAW, 0, 0 );
757                 SendMessageW( hWndCtl, WM_SETFONT, (WPARAM)info->hFont, 0 );
758                 while (*pstr)
759                 {
760                     WCHAR name[64];
761                     /* authors list is in iso-8859-1 format */
762                     MultiByteToWideChar( 28591, 0, *pstr, -1, name, sizeof(name)/sizeof(WCHAR) );
763                     SendMessageW( hWndCtl, LB_ADDSTRING, (WPARAM)-1, (LPARAM)name );
764                     pstr++;
765                 }
766                 SendMessageW( hWndCtl, WM_SETREDRAW, 1, 0 );
767             }
768         }
769         return 1;
770
771     case WM_PAINT:
772       { RECT rect;
773             PAINTSTRUCT ps;
774             HDC hDC = BeginPaint( hWnd, &ps );
775
776             if( __get_dropline( hWnd, &rect ) ) {
777                 SelectObject( hDC, GetStockObject( BLACK_PEN ) );
778                 MoveToEx( hDC, rect.left, rect.top, NULL );
779                 LineTo( hDC, rect.right, rect.bottom );
780             }
781             EndPaint( hWnd, &ps );
782         }
783         break;
784
785     case WM_COMMAND:
786         if (wParam == IDOK || wParam == IDCANCEL)
787         {
788             EndDialog(hWnd, TRUE);
789             return TRUE;
790         }
791         break;
792     case WM_CLOSE:
793       EndDialog(hWnd, TRUE);
794       break;
795     }
796
797     return 0;
798 }
799
800
801 /*************************************************************************
802  * ShellAboutA                          [SHELL32.288]
803  */
804 BOOL WINAPI ShellAboutA( HWND hWnd, LPCSTR szApp, LPCSTR szOtherStuff, HICON hIcon )
805 {
806     BOOL ret;
807     LPWSTR appW = NULL, otherW = NULL;
808     int len;
809
810     if (szApp)
811     {
812         len = MultiByteToWideChar(CP_ACP, 0, szApp, -1, NULL, 0);
813         appW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
814         MultiByteToWideChar(CP_ACP, 0, szApp, -1, appW, len);
815     }
816     if (szOtherStuff)
817     {
818         len = MultiByteToWideChar(CP_ACP, 0, szOtherStuff, -1, NULL, 0);
819         otherW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
820         MultiByteToWideChar(CP_ACP, 0, szOtherStuff, -1, otherW, len);
821     }
822
823     ret = ShellAboutW(hWnd, appW, otherW, hIcon);
824
825     if (otherW) HeapFree(GetProcessHeap(), 0, otherW);
826     if (appW) HeapFree(GetProcessHeap(), 0, appW);
827     return ret;
828 }
829
830
831 /*************************************************************************
832  * ShellAboutW                          [SHELL32.289]
833  */
834 BOOL WINAPI ShellAboutW( HWND hWnd, LPCWSTR szApp, LPCWSTR szOtherStuff,
835                              HICON hIcon )
836 {
837     ABOUT_INFO info;
838     LOGFONTW logFont;
839     HRSRC hRes;
840     LPVOID template;
841     BOOL bRet;
842
843     TRACE("\n");
844
845     if(!(hRes = FindResourceA(shell32_hInstance, "SHELL_ABOUT_MSGBOX", (LPSTR)RT_DIALOG)))
846         return FALSE;
847     if(!(template = (LPVOID)LoadResource(shell32_hInstance, hRes)))
848         return FALSE;
849     info.szApp        = szApp;
850     info.szOtherStuff = szOtherStuff;
851     info.hIcon        = hIcon ? hIcon : LoadIconW( 0, (LPWSTR)IDI_WINLOGO );
852
853     SystemParametersInfoW( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 );
854     info.hFont = CreateFontIndirectW( &logFont );
855
856     bRet = DialogBoxIndirectParamW((HINSTANCE)GetWindowLongW( hWnd, GWL_HINSTANCE ),
857                                    template, hWnd, AboutDlgProc, (LPARAM)&info );
858     DeleteObject(info.hFont);
859     return bRet;
860 }
861
862 /*************************************************************************
863  * FreeIconList (SHELL32.@)
864  */
865 void WINAPI FreeIconList( DWORD dw )
866 { FIXME("(%lx): stub\n",dw);
867 }
868
869
870 /*************************************************************************
871  * ShellDDEInit (SHELL32.@)
872  */
873 void WINAPI ShellDDEInit(BOOL start)
874 {
875     FIXME("stub: %d\n", start);
876 }
877
878 /***********************************************************************
879  * DllGetVersion [SHELL32.@]
880  *
881  * Retrieves version information of the 'SHELL32.DLL'
882  *
883  * PARAMS
884  *     pdvi [O] pointer to version information structure.
885  *
886  * RETURNS
887  *     Success: S_OK
888  *     Failure: E_INVALIDARG
889  *
890  * NOTES
891  *     Returns version of a shell32.dll from IE4.01 SP1.
892  */
893
894 HRESULT WINAPI SHELL32_DllGetVersion (DLLVERSIONINFO *pdvi)
895 {
896         if (pdvi->cbSize != sizeof(DLLVERSIONINFO))
897         {
898           WARN("wrong DLLVERSIONINFO size from app\n");
899           return E_INVALIDARG;
900         }
901
902         pdvi->dwMajorVersion = 4;
903         pdvi->dwMinorVersion = 72;
904         pdvi->dwBuildNumber = 3110;
905         pdvi->dwPlatformID = 1;
906
907         TRACE("%lu.%lu.%lu.%lu\n",
908            pdvi->dwMajorVersion, pdvi->dwMinorVersion,
909            pdvi->dwBuildNumber, pdvi->dwPlatformID);
910
911         return S_OK;
912 }
913 /*************************************************************************
914  * global variables of the shell32.dll
915  * all are once per process
916  *
917  */
918 HINSTANCE       shell32_hInstance = 0;
919 HIMAGELIST      ShellSmallIconList = 0;
920 HIMAGELIST      ShellBigIconList = 0;
921
922
923 /*************************************************************************
924  * SHELL32 DllMain
925  *
926  * NOTES
927  *  calling oleinitialize here breaks sone apps.
928  */
929
930 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
931 {
932         TRACE("%p 0x%lx %p\n", hinstDLL, fdwReason, fImpLoad);
933
934         switch (fdwReason)
935         {
936           case DLL_PROCESS_ATTACH:
937             shell32_hInstance = hinstDLL;
938             DisableThreadLibraryCalls(shell32_hInstance);
939
940             /* get full path to this DLL for IExtractIconW_fnGetIconLocation() */
941             GetModuleFileNameW(hinstDLL, swShell32Name, MAX_PATH);
942             swShell32Name[MAX_PATH - 1] = '\0';
943
944             InitCommonControlsEx(NULL);
945
946             SIC_Initialize();
947             SYSTRAY_Init();
948             InitChangeNotifications();
949             break;
950
951           case DLL_PROCESS_DETACH:
952               shell32_hInstance = 0;
953               SIC_Destroy();
954               FreeChangeNotifications();
955               break;
956         }
957         return TRUE;
958 }
959
960 /*************************************************************************
961  * DllInstall         [SHELL32.@]
962  *
963  * PARAMETERS
964  *
965  *    BOOL bInstall - TRUE for install, FALSE for uninstall
966  *    LPCWSTR pszCmdLine - command line (unused by shell32?)
967  */
968
969 HRESULT WINAPI SHELL32_DllInstall(BOOL bInstall, LPCWSTR cmdline)
970 {
971    FIXME("(%s, %s): stub!\n", bInstall ? "TRUE":"FALSE", debugstr_w(cmdline));
972
973    return S_OK;         /* indicate success */
974 }
975
976 /***********************************************************************
977  *              DllCanUnloadNow (SHELL32.@)
978  */
979 HRESULT WINAPI SHELL32_DllCanUnloadNow(void)
980 {
981     FIXME("(void): stub\n");
982
983     return S_FALSE;
984 }