shell32_main.c 43.1 KB
Newer Older
Alexandre Julliard's avatar
Alexandre Julliard committed
1
/*
2
 *                 Shell basics
Alexandre Julliard's avatar
Alexandre Julliard committed
3
 *
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 * Copyright 1998 Marcus Meissner
 * Copyright 1998 Juergen Schmied (jsch)  *  <juergen.schmied@metronet.de>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * 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
Alexandre Julliard's avatar
Alexandre Julliard committed
20
 */
21 22 23

#include "config.h"

Alexandre Julliard's avatar
Alexandre Julliard committed
24 25
#include <stdlib.h>
#include <string.h>
26
#include <stdarg.h>
27
#include <stdio.h>
28

29 30
#define COBJMACROS

31
#include "windef.h"
32
#include "winbase.h"
33 34
#include "winerror.h"
#include "winreg.h"
35 36
#include "dlgs.h"
#include "shellapi.h"
37 38
#include "winuser.h"
#include "wingdi.h"
39
#include "shlobj.h"
40
#include "rpcproxy.h"
41
#include "shlwapi.h"
42
#include "propsys.h"
43

44
#include "undocshell.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
45
#include "pidl.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
46
#include "shell32_main.h"
47
#include "version.h"
48
#include "shresdef.h"
49 50
#include "initguid.h"
#include "shfldr.h"
51

52
#include "wine/debug.h"
53
#include "wine/unicode.h"
54

55
WINE_DEFAULT_DEBUG_CHANNEL(shell);
56

Alexandre Julliard's avatar
Alexandre Julliard committed
57
/*************************************************************************
58
 * CommandLineToArgvW            [SHELL32.@]
59
 *
60
 * We must interpret the quotes in the command line to rebuild the argv
61 62 63 64 65 66
 * array correctly:
 * - arguments are separated by spaces or tabs
 * - quotes serve as optional argument delimiters
 *   '"a b"'   -> 'a b'
 * - escaped quotes must be converted back to '"'
 *   '\"'      -> '"'
67 68 69 70 71
 * - consecutive backslashes preceding a quote see their number halved with
 *   the remainder escaping the quote:
 *   2n   backslashes + quote -> n backslashes + quote as an argument delimiter
 *   2n+1 backslashes + quote -> n backslashes + literal quote
 * - backslashes that are not followed by a quote are copied literally:
72 73
 *   'a\b'     -> 'a\b'
 *   'a\\b'    -> 'a\\b'
74 75 76 77 78 79 80 81 82
 * - in quoted strings, consecutive quotes see their number divided by three
 *   with the remainder modulo 3 deciding whether to close the string or not.
 *   Note that the opening quote must be counted in the consecutive quotes,
 *   that's the (1+) below:
 *   (1+) 3n   quotes -> n quotes
 *   (1+) 3n+1 quotes -> n quotes plus closes the quoted string
 *   (1+) 3n+2 quotes -> n+1 quotes plus closes the quoted string
 * - in unquoted strings, the first quote opens the quoted string and the
 *   remaining consecutive quotes follow the above rule.
Alexandre Julliard's avatar
Alexandre Julliard committed
83
 */
84
LPWSTR* WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int* numargs)
85 86 87
{
    DWORD argc;
    LPWSTR  *argv;
88 89
    LPCWSTR s;
    LPWSTR d;
90
    LPWSTR cmdline;
91
    int qcount,bcount;
92

93 94 95 96 97 98
    if(!numargs)
    {
        SetLastError(ERROR_INVALID_PARAMETER);
        return NULL;
    }

99 100
    if (*lpCmdline==0)
    {
101
        /* Return the path to the executable */
102
        DWORD len, deslen=MAX_PATH, size;
103

104
        size = sizeof(LPWSTR)*2 + deslen*sizeof(WCHAR);
105 106
        for (;;)
        {
107
            if (!(argv = LocalAlloc(LMEM_FIXED, size))) return NULL;
108
            len = GetModuleFileNameW(0, (LPWSTR)(argv+2), deslen);
109 110
            if (!len)
            {
111
                LocalFree(argv);
112 113
                return NULL;
            }
114 115
            if (len < deslen) break;
            deslen*=2;
116
            size = sizeof(LPWSTR)*2 + deslen*sizeof(WCHAR);
117
            LocalFree( argv );
118
        }
119 120
        argv[0]=(LPWSTR)(argv+2);
        argv[1]=NULL;
121
        *numargs=1;
122 123 124 125

        return argv;
    }

126 127 128
    /* --- First count the arguments */
    argc=1;
    s=lpCmdline;
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
    /* The first argument, the executable path, follows special rules */
    if (*s=='"')
    {
        /* The executable path ends at the next quote, no matter what */
        s++;
        while (*s)
            if (*s++=='"')
                break;
    }
    else
    {
        /* The executable path ends at the next space, no matter what */
        while (*s && *s!=' ' && *s!='\t')
            s++;
    }
    /* skip to the first argument, if any */
    while (*s==' ' || *s=='\t')
        s++;
    if (*s)
        argc++;

    /* Analyze the remaining arguments */
    qcount=bcount=0;
152
    while (*s)
153
    {
154
        if ((*s==' ' || *s=='\t') && qcount==0)
155
        {
156 157 158 159 160
            /* skip to the next argument and count it if any */
            while (*s==' ' || *s=='\t')
                s++;
            if (*s)
                argc++;
161
            bcount=0;
162
        }
163
        else if (*s=='\\')
164
        {
165 166
            /* '\', count them */
            bcount++;
167
            s++;
168
        }
169
        else if (*s=='"')
170
        {
171 172 173 174
            /* '"' */
            if ((bcount & 1)==0)
                qcount++; /* unescaped '"' */
            s++;
175
            bcount=0;
176 177 178 179 180 181 182 183 184
            /* consecutive quotes, see comment in copying code below */
            while (*s=='"')
            {
                qcount++;
                s++;
            }
            qcount=qcount % 3;
            if (qcount==2)
                qcount=0;
185 186 187
        }
        else
        {
188 189
            /* a regular character */
            bcount=0;
190
            s++;
191 192
        }
    }
193 194 195 196

    /* Allocate in a single lump, the string array, and the strings that go
     * with it. This way the caller can make a single LocalFree() call to free
     * both, as per MSDN.
197
     */
198
    argv=LocalAlloc(LMEM_FIXED, (argc+1)*sizeof(LPWSTR)+(strlenW(lpCmdline)+1)*sizeof(WCHAR));
199 200
    if (!argv)
        return NULL;
201
    cmdline=(LPWSTR)(argv+argc+1);
202
    strcpyW(cmdline, lpCmdline);
203

204
    /* --- Then split and copy the arguments */
205
    argv[0]=d=cmdline;
206
    argc=1;
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
    /* The first argument, the executable path, follows special rules */
    if (*d=='"')
    {
        /* The executable path ends at the next quote, no matter what */
        s=d+1;
        while (*s)
        {
            if (*s=='"')
            {
                s++;
                break;
            }
            *d++=*s++;
        }
    }
    else
    {
        /* The executable path ends at the next space, no matter what */
        while (*d && *d!=' ' && *d!='\t')
            d++;
        s=d;
        if (*s)
            s++;
    }
231
    /* close the executable path */
232 233 234 235
    *d++=0;
    /* skip to the first argument and initialize it if any */
    while (*s==' ' || *s=='\t')
        s++;
236 237 238
    if (!*s)
    {
        /* There are no parameters so we are all done */
239
        argv[argc]=NULL;
240 241 242
        *numargs=argc;
        return argv;
    }
243 244

    /* Split and copy the remaining arguments */
245
    argv[argc++]=d;
246
    qcount=bcount=0;
247 248
    while (*s)
    {
249
        if ((*s==' ' || *s=='\t') && qcount==0)
250
        {
251 252 253
            /* close the argument */
            *d++=0;
            bcount=0;
254

255
            /* skip to the next one and initialize it if any */
256 257
            do {
                s++;
258 259 260
            } while (*s==' ' || *s=='\t');
            if (*s)
                argv[argc++]=d;
261
        }
262
        else if (*s=='\\')
263
        {
264 265
            *d++=*s++;
            bcount++;
266
        }
267
        else if (*s=='"')
268 269 270
        {
            if ((bcount & 1)==0)
            {
271
                /* Preceded by an even number of '\', this is half that
272 273 274
                 * number of '\', plus a quote which we erase.
                 */
                d-=bcount/2;
275
                qcount++;
276 277 278
            }
            else
            {
279
                /* Preceded by an odd number of '\', this is half that
280 281 282 283 284
                 * number of '\' followed by a '"'
                 */
                d=d-bcount/2-1;
                *d++='"';
            }
285
            s++;
286
            bcount=0;
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
            /* Now count the number of consecutive quotes. Note that qcount
             * already takes into account the opening quote if any, as well as
             * the quote that lead us here.
             */
            while (*s=='"')
            {
                if (++qcount==3)
                {
                    *d++='"';
                    qcount=0;
                }
                s++;
            }
            if (qcount==2)
                qcount=0;
302 303 304
        }
        else
        {
305 306 307 308 309
            /* a regular character */
            *d++=*s++;
            bcount=0;
        }
    }
310
    *d='\0';
311
    argv[argc]=NULL;
312
    *numargs=argc;
313 314

    return argv;
Alexandre Julliard's avatar
Alexandre Julliard committed
315 316
}

317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
static DWORD shgfi_get_exe_type(LPCWSTR szFullPath)
{
    BOOL status = FALSE;
    HANDLE hfile;
    DWORD BinaryType;
    IMAGE_DOS_HEADER mz_header;
    IMAGE_NT_HEADERS nt;
    DWORD len;
    char magic[4];

    status = GetBinaryTypeW (szFullPath, &BinaryType);
    if (!status)
        return 0;
    if (BinaryType == SCS_DOS_BINARY || BinaryType == SCS_PIF_BINARY)
        return 0x4d5a;

    hfile = CreateFileW( szFullPath, GENERIC_READ, FILE_SHARE_READ,
                         NULL, OPEN_EXISTING, 0, 0 );
    if ( hfile == INVALID_HANDLE_VALUE )
        return 0;

    /*
     * The next section is adapted from MODULE_GetBinaryType, as we need
     * to examine the image header to get OS and version information. We
     * know from calling GetBinaryTypeA that the image is valid and either
     * an NE or PE, so much error handling can be omitted.
     * Seek to the start of the file and read the header information.
     */

    SetFilePointer( hfile, 0, NULL, SEEK_SET );
    ReadFile( hfile, &mz_header, sizeof(mz_header), &len, NULL );

    SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
    ReadFile( hfile, magic, sizeof(magic), &len, NULL );
    if ( *(DWORD*)magic == IMAGE_NT_SIGNATURE )
    {
        SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
        ReadFile( hfile, &nt, sizeof(nt), &len, NULL );
        CloseHandle( hfile );
356 357 358
        /* DLL files are not executable and should return 0 */
        if (nt.FileHeader.Characteristics & IMAGE_FILE_DLL)
            return 0;
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
        if (nt.OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI)
        {
             return IMAGE_NT_SIGNATURE | 
                   (nt.OptionalHeader.MajorSubsystemVersion << 24) |
                   (nt.OptionalHeader.MinorSubsystemVersion << 16);
        }
        return IMAGE_NT_SIGNATURE;
    }
    else if ( *(WORD*)magic == IMAGE_OS2_SIGNATURE )
    {
        IMAGE_OS2_HEADER ne;
        SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
        ReadFile( hfile, &ne, sizeof(ne), &len, NULL );
        CloseHandle( hfile );
        if (ne.ne_exetyp == 2)
            return IMAGE_OS2_SIGNATURE | (ne.ne_expver << 16);
        return 0;
    }
    CloseHandle( hfile );
    return 0;
}

381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406
/*************************************************************************
 * SHELL_IsShortcut		[internal]
 *
 * Decide if an item id list points to a shell shortcut
 */
BOOL SHELL_IsShortcut(LPCITEMIDLIST pidlLast)
{
    char szTemp[MAX_PATH];
    HKEY keyCls;
    BOOL ret = FALSE;

    if (_ILGetExtension(pidlLast, szTemp, MAX_PATH) &&
          HCR_MapTypeToValueA(szTemp, szTemp, MAX_PATH, TRUE))
    {
        if (ERROR_SUCCESS == RegOpenKeyExA(HKEY_CLASSES_ROOT, szTemp, 0, KEY_QUERY_VALUE, &keyCls))
        {
          if (ERROR_SUCCESS == RegQueryValueExA(keyCls, "IsShortcut", NULL, NULL, NULL, NULL))
            ret = TRUE;

          RegCloseKey(keyCls);
        }
    }

    return ret;
}

407 408 409 410 411 412 413
#define SHGFI_KNOWN_FLAGS \
    (SHGFI_SMALLICON | SHGFI_OPENICON | SHGFI_SHELLICONSIZE | SHGFI_PIDL | \
     SHGFI_USEFILEATTRIBUTES | SHGFI_ADDOVERLAYS | SHGFI_OVERLAYINDEX | \
     SHGFI_ICON | SHGFI_DISPLAYNAME | SHGFI_TYPENAME | SHGFI_ATTRIBUTES | \
     SHGFI_ICONLOCATION | SHGFI_EXETYPE | SHGFI_SYSICONINDEX | \
     SHGFI_LINKOVERLAY | SHGFI_SELECTED | SHGFI_ATTR_SPECIFIED)

Alexandre Julliard's avatar
Alexandre Julliard committed
414
/*************************************************************************
415
 * SHGetFileInfoW            [SHELL32.@]
416
 *
Alexandre Julliard's avatar
Alexandre Julliard committed
417
 */
Kevin Koltzau's avatar
Kevin Koltzau committed
418 419
DWORD_PTR WINAPI SHGetFileInfoW(LPCWSTR path,DWORD dwFileAttributes,
                                SHFILEINFOW *psfi, UINT sizeofpsfi, UINT flags )
420
{
421 422
    WCHAR szLocation[MAX_PATH], szFullPath[MAX_PATH];
    int iIndex;
Kevin Koltzau's avatar
Kevin Koltzau committed
423 424
    DWORD_PTR ret = TRUE;
    DWORD dwAttributes = 0;
425 426 427 428 429
    IShellFolder * psfParent = NULL;
    IExtractIconW * pei = NULL;
    LPITEMIDLIST    pidlLast = NULL, pidl = NULL;
    HRESULT hr = S_OK;
    BOOL IconNotYetLoaded=TRUE;
430
    UINT uGilFlags = 0;
431
    HIMAGELIST big_icons, small_icons;
432

433
    TRACE("%s fattr=0x%x sfi=%p(attr=0x%08x) size=0x%x flags=0x%x\n",
434 435 436
          (flags & SHGFI_PIDL)? "pidl" : debugstr_w(path), dwFileAttributes,
          psfi, psfi->dwAttributes, sizeofpsfi, flags);

437 438 439
    if (!path)
        return FALSE;

440
    /* windows initializes these values regardless of the flags */
441 442 443 444 445 446 447 448 449
    if (psfi != NULL)
    {
        psfi->szDisplayName[0] = '\0';
        psfi->szTypeName[0] = '\0';
        psfi->iIcon = 0;
    }

    if (!(flags & SHGFI_PIDL))
    {
450
        /* SHGetFileInfo should work with absolute and relative paths */
451 452 453 454 455 456 457 458
        if (PathIsRelativeW(path))
        {
            GetCurrentDirectoryW(MAX_PATH, szLocation);
            PathCombineW(szFullPath, szLocation, path);
        }
        else
        {
            lstrcpynW(szFullPath, path, MAX_PATH);
459
        }
460
    }
461

462 463 464 465
    if (flags & SHGFI_EXETYPE)
    {
        if (flags != SHGFI_EXETYPE)
            return 0;
466
        return shgfi_get_exe_type(szFullPath);
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497
    }

    /*
     * psfi is NULL normally to query EXE type. If it is NULL, none of the
     * below makes sense anyway. Windows allows this and just returns FALSE
     */
    if (psfi == NULL)
        return FALSE;

    /*
     * translate the path into a pidl only when SHGFI_USEFILEATTRIBUTES
     * is not specified.
     * The pidl functions fail on not existing file names
     */

    if (flags & SHGFI_PIDL)
    {
        pidl = ILClone((LPCITEMIDLIST)path);
    }
    else if (!(flags & SHGFI_USEFILEATTRIBUTES))
    {
        hr = SHILCreateFromPathW(szFullPath, &pidl, &dwAttributes);
    }

    if ((flags & SHGFI_PIDL) || !(flags & SHGFI_USEFILEATTRIBUTES))
    {
        /* get the parent shellfolder */
        if (pidl)
        {
            hr = SHBindToParent( pidl, &IID_IShellFolder, (LPVOID*)&psfParent,
                                (LPCITEMIDLIST*)&pidlLast );
498 499
            if (SUCCEEDED(hr))
                pidlLast = ILClone(pidlLast);
500 501 502 503 504 505
            ILFree(pidl);
        }
        else
        {
            ERR("pidl is null!\n");
            return FALSE;
506
        }
507
    }
508

509 510 511 512
    /* get the attributes of the child */
    if (SUCCEEDED(hr) && (flags & SHGFI_ATTRIBUTES))
    {
        if (!(flags & SHGFI_ATTR_SPECIFIED))
513
        {
514
            psfi->dwAttributes = 0xffffffff;
515
        }
516 517
        if (psfParent)
            IShellFolder_GetAttributesOf( psfParent, 1, (LPCITEMIDLIST*)&pidlLast,
518 519
                                      &(psfi->dwAttributes) );
    }
520

521 522 523
    /* get the displayname */
    if (SUCCEEDED(hr) && (flags & SHGFI_DISPLAYNAME))
    {
524
        if (flags & SHGFI_USEFILEATTRIBUTES && !(flags & SHGFI_PIDL))
525
        {
526 527 528 529 530 531 532 533 534 535 536 537 538 539
            lstrcpyW (psfi->szDisplayName, PathFindFileNameW(szFullPath));
        }
        else
        {
            STRRET str;
            hr = IShellFolder_GetDisplayNameOf( psfParent, pidlLast,
                                                SHGDN_INFOLDER, &str);
            StrRetToStrNW (psfi->szDisplayName, MAX_PATH, &str, pidlLast);
        }
    }

    /* get the type name */
    if (SUCCEEDED(hr) && (flags & SHGFI_TYPENAME))
    {
540
        static const WCHAR szFolder[] = { 'F','o','l','d','e','r',0 };
541
        static const WCHAR szFile[] = { 'F','i','l','e',0 };
542
        static const WCHAR szSpaceFile[] = { ' ','f','i','l','e',0 };
543

544
        if (!(flags & SHGFI_USEFILEATTRIBUTES) || (flags & SHGFI_PIDL))
545 546 547 548 549 550 551 552 553
        {
            char ftype[80];

            _ILGetFileType(pidlLast, ftype, 80);
            MultiByteToWideChar(CP_ACP, 0, ftype, -1, psfi->szTypeName, 80 );
        }
        else
        {
            if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
554
                strcatW (psfi->szTypeName, szFolder);
555
            else 
556
            {
557 558 559
                WCHAR sTemp[64];

                lstrcpyW(sTemp,PathFindExtensionW(szFullPath));
560 561 562 563 564 565
                if (sTemp[0] == 0 || (sTemp[0] == '.' && sTemp[1] == 0))
                {
                    /* "name" or "name." => "File" */
                    lstrcpynW (psfi->szTypeName, szFile, 64);
                }
                else if (!( HCR_MapTypeToValueW(sTemp, sTemp, 64, TRUE) &&
566
                    HCR_MapTypeToValueW(sTemp, psfi->szTypeName, 80, FALSE )))
567
                {
568 569 570 571 572 573 574 575 576
                    if (sTemp[0])
                    {
                        lstrcpynW (psfi->szTypeName, sTemp, 64);
                        strcatW (psfi->szTypeName, szSpaceFile);
                    }
                    else
                    {
                        lstrcpynW (psfi->szTypeName, szFile, 64);
                    }
577 578
                }
            }
579
        }
580
    }
581

582
    /* ### icons ###*/
583 584 585

    Shell_GetImageLists( &big_icons, &small_icons );

586 587 588 589 590 591 592 593 594 595 596
    if (flags & SHGFI_OPENICON)
        uGilFlags |= GIL_OPENICON;

    if (flags & SHGFI_LINKOVERLAY)
        uGilFlags |= GIL_FORSHORTCUT;
    else if ((flags&SHGFI_ADDOVERLAYS) ||
             (flags&(SHGFI_ICON|SHGFI_SMALLICON))==SHGFI_ICON)
    {
        if (SHELL_IsShortcut(pidlLast))
            uGilFlags |= GIL_FORSHORTCUT;
    }
597

598 599
    if (flags & SHGFI_OVERLAYINDEX)
        FIXME("SHGFI_OVERLAYINDEX unhandled\n");
600

601 602
    if (flags & SHGFI_SELECTED)
        FIXME("set icon to selected, stub\n");
603

604 605
    if (flags & SHGFI_SHELLICONSIZE)
        FIXME("set icon to shell size, stub\n");
606

607 608 609 610
    /* get the iconlocation */
    if (SUCCEEDED(hr) && (flags & SHGFI_ICONLOCATION ))
    {
        UINT uDummy,uFlags;
611

612
        if (flags & SHGFI_USEFILEATTRIBUTES && !(flags & SHGFI_PIDL))
613
        {
614 615 616 617 618
            if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
            {
                lstrcpyW(psfi->szDisplayName, swShell32Name);
                psfi->iIcon = -IDI_SHELL_FOLDER;
            }
619
            else
620 621 622 623 624
            {
                WCHAR* szExt;
                static const WCHAR p1W[] = {'%','1',0};
                WCHAR sTemp [MAX_PATH];

625
                szExt = PathFindExtensionW(szFullPath);
626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651
                TRACE("szExt=%s\n", debugstr_w(szExt));
                if ( szExt &&
                     HCR_MapTypeToValueW(szExt, sTemp, MAX_PATH, TRUE) &&
                     HCR_GetDefaultIconW(sTemp, sTemp, MAX_PATH, &psfi->iIcon))
                {
                    if (lstrcmpW(p1W, sTemp))
                        strcpyW(psfi->szDisplayName, sTemp);
                    else
                    {
                        /* the icon is in the file */
                        strcpyW(psfi->szDisplayName, szFullPath);
                    }
                }
                else
                    ret = FALSE;
            }
        }
        else
        {
            hr = IShellFolder_GetUIObjectOf(psfParent, 0, 1,
                (LPCITEMIDLIST*)&pidlLast, &IID_IExtractIconW,
                &uDummy, (LPVOID*)&pei);
            if (SUCCEEDED(hr))
            {
                hr = IExtractIconW_GetIconLocation(pei, uGilFlags,
                    szLocation, MAX_PATH, &iIndex, &uFlags);
652

653 654 655 656 657 658 659 660 661
                if (uFlags & GIL_NOTFILENAME)
                    ret = FALSE;
                else
                {
                    lstrcpyW (psfi->szDisplayName, szLocation);
                    psfi->iIcon = iIndex;
                }
                IExtractIconW_Release(pei);
            }
662 663
        }
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
664

665 666 667
    /* get icon index (or load icon)*/
    if (SUCCEEDED(hr) && (flags & (SHGFI_ICON | SHGFI_SYSICONINDEX)))
    {
668
        if (flags & SHGFI_USEFILEATTRIBUTES && !(flags & SHGFI_PIDL))
669 670 671
        {
            WCHAR sTemp [MAX_PATH];
            WCHAR * szExt;
672
            int icon_idx=0;
673

674
            lstrcpynW(sTemp, szFullPath, MAX_PATH);
675 676

            if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
677
                psfi->iIcon = SIC_GetIconIndex(swShell32Name, -IDI_SHELL_FOLDER, 0);
678
            else
679
            {
680 681 682
                static const WCHAR p1W[] = {'%','1',0};

                psfi->iIcon = 0;
683
                szExt = PathFindExtensionW(sTemp);
684 685
                if ( szExt &&
                     HCR_MapTypeToValueW(szExt, sTemp, MAX_PATH, TRUE) &&
686
                     HCR_GetDefaultIconW(sTemp, sTemp, MAX_PATH, &icon_idx))
687 688 689 690 691 692
                {
                    if (!lstrcmpW(p1W,sTemp))            /* icon is in the file */
                        strcpyW(sTemp, szFullPath);

                    if (flags & SHGFI_SYSICONINDEX) 
                    {
693
                        psfi->iIcon = SIC_GetIconIndex(sTemp,icon_idx,0);
694 695 696 697 698
                        if (psfi->iIcon == -1)
                            psfi->iIcon = 0;
                    }
                    else 
                    {
699
                        UINT ret;
700
                        if (flags & SHGFI_SMALLICON)
701
                            ret = PrivateExtractIconsW( sTemp,icon_idx,
702 703 704 705
                                GetSystemMetrics( SM_CXSMICON ),
                                GetSystemMetrics( SM_CYSMICON ),
                                &psfi->hIcon, 0, 1, 0);
                        else
706
                            ret = PrivateExtractIconsW( sTemp, icon_idx,
707 708 709
                                GetSystemMetrics( SM_CXICON),
                                GetSystemMetrics( SM_CYICON),
                                &psfi->hIcon, 0, 1, 0);
710
                        if (ret != 0 && ret != (UINT)-1)
711 712 713 714
                        {
                            IconNotYetLoaded=FALSE;
                            psfi->iIcon = icon_idx;
                        }
715 716
                    }
                }
717
            }
718 719 720 721
        }
        else
        {
            if (!(PidlToSicIndex(psfParent, pidlLast, !(flags & SHGFI_SMALLICON),
722
                uGilFlags, &(psfi->iIcon))))
723 724 725 726
            {
                ret = FALSE;
            }
        }
727
        if (ret && (flags & SHGFI_SYSICONINDEX))
728 729
        {
            if (flags & SHGFI_SMALLICON)
730
                ret = (DWORD_PTR)small_icons;
731
            else
732
                ret = (DWORD_PTR)big_icons;
733 734 735 736 737 738 739
        }
    }

    /* icon handle */
    if (SUCCEEDED(hr) && (flags & SHGFI_ICON) && IconNotYetLoaded)
    {
        if (flags & SHGFI_SMALLICON)
740
            psfi->hIcon = ImageList_GetIcon( small_icons, psfi->iIcon, ILD_NORMAL);
741
        else
742
            psfi->hIcon = ImageList_GetIcon( big_icons, psfi->iIcon, ILD_NORMAL);
743 744 745 746 747 748 749 750 751 752 753
    }

    if (flags & ~SHGFI_KNOWN_FLAGS)
        FIXME("unknown flags %08x\n", flags & ~SHGFI_KNOWN_FLAGS);

    if (psfParent)
        IShellFolder_Release(psfParent);

    if (hr != S_OK)
        ret = FALSE;

754
    SHFree(pidlLast);
755

756
    TRACE ("icon=%p index=0x%08x attr=0x%08x name=%s type=%s ret=0x%08lx\n",
757 758 759 760
           psfi->hIcon, psfi->iIcon, psfi->dwAttributes,
           debugstr_w(psfi->szDisplayName), debugstr_w(psfi->szTypeName), ret);

    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
761 762
}

763
/*************************************************************************
764
 * SHGetFileInfoA            [SHELL32.@]
765 766 767 768 769
 *
 * Note:
 *    MSVBVM60.__vbaNew2 expects this function to return a value in range
 *    1 .. 0x7fff when the function succeeds and flags does not contain
 *    SHGFI_EXETYPE or SHGFI_SYSICONINDEX (see bug 7701)
770
 */
Kevin Koltzau's avatar
Kevin Koltzau committed
771 772 773
DWORD_PTR WINAPI SHGetFileInfoA(LPCSTR path,DWORD dwFileAttributes,
                                SHFILEINFOA *psfi, UINT sizeofpsfi,
                                UINT flags )
774
{
775
    INT len;
776 777
    LPWSTR temppath = NULL;
    LPCWSTR pathW;
778
    DWORD_PTR ret;
779 780 781 782 783
    SHFILEINFOW temppsfi;

    if (flags & SHGFI_PIDL)
    {
        /* path contains a pidl */
784
        pathW = (LPCWSTR)path;
785 786 787 788 789 790
    }
    else
    {
        len = MultiByteToWideChar(CP_ACP, 0, path, -1, NULL, 0);
        temppath = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
        MultiByteToWideChar(CP_ACP, 0, path, -1, temppath, len);
791
        pathW = temppath;
792 793 794 795 796 797
    }

    if (psfi && (flags & SHGFI_ATTR_SPECIFIED))
        temppsfi.dwAttributes=psfi->dwAttributes;

    if (psfi == NULL)
798
        ret = SHGetFileInfoW(pathW, dwFileAttributes, NULL, sizeof(temppsfi), flags);
799
    else
800
        ret = SHGetFileInfoW(pathW, dwFileAttributes, &temppsfi, sizeof(temppsfi), flags);
801 802 803 804 805 806 807 808 809 810 811 812 813 814 815

    if (psfi)
    {
        if(flags & SHGFI_ICON)
            psfi->hIcon=temppsfi.hIcon;
        if(flags & (SHGFI_SYSICONINDEX|SHGFI_ICON|SHGFI_ICONLOCATION))
            psfi->iIcon=temppsfi.iIcon;
        if(flags & SHGFI_ATTRIBUTES)
            psfi->dwAttributes=temppsfi.dwAttributes;
        if(flags & (SHGFI_DISPLAYNAME|SHGFI_ICONLOCATION))
        {
            WideCharToMultiByte(CP_ACP, 0, temppsfi.szDisplayName, -1,
                  psfi->szDisplayName, sizeof(psfi->szDisplayName), NULL, NULL);
        }
        if(flags & SHGFI_TYPENAME)
816
        {
817 818
            WideCharToMultiByte(CP_ACP, 0, temppsfi.szTypeName, -1,
                  psfi->szTypeName, sizeof(psfi->szTypeName), NULL, NULL);
819
        }
820 821
    }

822
    HeapFree(GetProcessHeap(), 0, temppath);
823 824

    return ret;
825 826
}

827
/*************************************************************************
828
 * DuplicateIcon            [SHELL32.@]
829 830 831 832
 */
HICON WINAPI DuplicateIcon( HINSTANCE hInstance, HICON hIcon)
{
    ICONINFO IconInfo;
833
    HICON hDupIcon = 0;
834

835
    TRACE("%p %p\n", hInstance, hIcon);
836

837
    if (GetIconInfo(hIcon, &IconInfo))
838 839 840 841
    {
        hDupIcon = CreateIconIndirect(&IconInfo);

        /* clean up hbmMask and hbmColor */
842 843
        DeleteObject(IconInfo.hbmMask);
        DeleteObject(IconInfo.hbmColor);
844
    }
845

846 847
    return hDupIcon;
}
848

Alexandre Julliard's avatar
Alexandre Julliard committed
849
/*************************************************************************
850
 * ExtractIconA                [SHELL32.@]
Alexandre Julliard's avatar
Alexandre Julliard committed
851
 */
852 853
HICON WINAPI ExtractIconA(HINSTANCE hInstance, LPCSTR lpszFile, UINT nIconIndex)
{   
854 855 856
    HICON ret;
    INT len = MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, NULL, 0);
    LPWSTR lpwstrFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
857

858
    TRACE("%p %s %d\n", hInstance, lpszFile, nIconIndex);
859

860 861 862 863 864
    MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, lpwstrFile, len);
    ret = ExtractIconW(hInstance, lpwstrFile, nIconIndex);
    HeapFree(GetProcessHeap(), 0, lpwstrFile);

    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
865 866 867
}

/*************************************************************************
868
 * ExtractIconW                [SHELL32.@]
Alexandre Julliard's avatar
Alexandre Julliard committed
869
 */
870 871
HICON WINAPI ExtractIconW(HINSTANCE hInstance, LPCWSTR lpszFile, UINT nIconIndex)
{
872 873 874 875 876 877
    HICON  hIcon = NULL;
    UINT ret;
    UINT cx = GetSystemMetrics(SM_CXICON), cy = GetSystemMetrics(SM_CYICON);

    TRACE("%p %s %d\n", hInstance, debugstr_w(lpszFile), nIconIndex);

878
    if (nIconIndex == (UINT)-1)
879 880
    {
        ret = PrivateExtractIconsW(lpszFile, 0, cx, cy, NULL, NULL, 0, LR_DEFAULTCOLOR);
881
        if (ret != (UINT)-1 && ret)
Kevin Koltzau's avatar
Kevin Koltzau committed
882
            return (HICON)(UINT_PTR)ret;
883 884 885 886 887
        return NULL;
    }
    else
        ret = PrivateExtractIconsW(lpszFile, nIconIndex, cx, cy, &hIcon, NULL, 1, LR_DEFAULTCOLOR);

888
    if (ret == (UINT)-1)
889 890 891 892 893
        return (HICON)1;
    else if (ret > 0 && hIcon)
        return hIcon;

    return NULL;
Alexandre Julliard's avatar
Alexandre Julliard committed
894 895
}

896 897 898 899 900 901 902
HRESULT WINAPI SHCreateFileExtractIconW(LPCWSTR file, DWORD attribs, REFIID riid, void **ppv)
{
  FIXME("%s, %x, %s, %p\n", debugstr_w(file), attribs, debugstr_guid(riid), ppv);
  *ppv = NULL;
  return E_NOTIMPL;
}

903 904 905 906 907 908 909 910 911 912 913 914 915 916 917
/*************************************************************************
 * Printer_LoadIconsW        [SHELL32.205]
 */
VOID WINAPI Printer_LoadIconsW(LPCWSTR wsPrinterName, HICON * pLargeIcon, HICON * pSmallIcon)
{
    INT iconindex=IDI_SHELL_PRINTER;

    TRACE("(%s, %p, %p)\n", debugstr_w(wsPrinterName), pLargeIcon, pSmallIcon);

    /* We should check if wsPrinterName is
       1. the Default Printer or not
       2. connected or not
       3. a Local Printer or a Network-Printer
       and use different Icons
    */
918 919 920 921
    if((wsPrinterName != NULL) && (wsPrinterName[0] != 0))
    {
        FIXME("(select Icon by PrinterName %s not implemented)\n", debugstr_w(wsPrinterName));
    }
922 923 924 925 926 927 928 929 930 931 932 933

    if(pLargeIcon != NULL)
        *pLargeIcon = LoadImageW(shell32_hInstance,
                                 (LPCWSTR) MAKEINTRESOURCE(iconindex), IMAGE_ICON,
                                 0, 0, LR_DEFAULTCOLOR|LR_DEFAULTSIZE);

    if(pSmallIcon != NULL)
        *pSmallIcon = LoadImageW(shell32_hInstance,
                                 (LPCWSTR) MAKEINTRESOURCE(iconindex), IMAGE_ICON,
                                 16, 16, LR_DEFAULTCOLOR);
}

934 935 936 937 938 939 940 941 942
/*************************************************************************
 * Printers_RegisterWindowW        [SHELL32.213]
 * used by "printui.dll":
 * find the Window of the given Type for the specific Printer and 
 * return the already existent hwnd or open a new window
 */
BOOL WINAPI Printers_RegisterWindowW(LPCWSTR wsPrinter, DWORD dwType,
            HANDLE * phClassPidl, HWND * phwnd)
{
943
    FIXME("(%s, %x, %p (%p), %p (%p)) stub!\n", debugstr_w(wsPrinter), dwType,
944 945 946 947 948 949 950 951 952 953 954 955 956 957
                phClassPidl, (phClassPidl != NULL) ? *(phClassPidl) : NULL,
                phwnd, (phwnd != NULL) ? *(phwnd) : NULL);

    return FALSE;
} 

/*************************************************************************
 * Printers_UnregisterWindow      [SHELL32.214]
 */
VOID WINAPI Printers_UnregisterWindow(HANDLE hClassPidl, HWND hwnd)
{
    FIXME("(%p, %p) stub!\n", hClassPidl, hwnd);
} 

958 959 960 961 962 963 964 965 966
/*************************************************************************
 * SHGetPropertyStoreForWindow [SHELL32.@]
 */
HRESULT WINAPI SHGetPropertyStoreForWindow(HWND hwnd, REFIID riid, void **ppv)
{
    FIXME("(%p %p %p) stub!\n", hwnd, riid, ppv);
    return E_NOTIMPL;
}

967 968
/*************************************************************************/

Alexandre Julliard's avatar
Alexandre Julliard committed
969
typedef struct
970 971 972
{
    LPCWSTR  szApp;
    LPCWSTR  szOtherStuff;
973
    HICON hIcon;
974
    HFONT hFont;
Alexandre Julliard's avatar
Alexandre Julliard committed
975 976
} ABOUT_INFO;

977
#define DROP_FIELD_TOP    (-12)
Alexandre Julliard's avatar
Alexandre Julliard committed
978

979
static void paint_dropline( HDC hdc, HWND hWnd )
980
{
981
    HWND hWndCtl = GetDlgItem(hWnd, IDC_ABOUT_WINE_TEXT);
982 983 984 985 986 987 988 989
    RECT rect;

    if (!hWndCtl) return;
    GetWindowRect( hWndCtl, &rect );
    MapWindowPoints( 0, hWnd, (LPPOINT)&rect, 2 );
    rect.top += DROP_FIELD_TOP;
    rect.bottom = rect.top + 2;
    DrawEdge( hdc, &rect, BDR_SUNKENOUTER, BF_RECT );
Alexandre Julliard's avatar
Alexandre Julliard committed
990 991 992
}

/*************************************************************************
993
 * SHHelpShortcuts_RunDLLA        [SHELL32.@]
Alexandre Julliard's avatar
Alexandre Julliard committed
994 995
 *
 */
996 997
DWORD WINAPI SHHelpShortcuts_RunDLLA(DWORD dwArg1, DWORD dwArg2, DWORD dwArg3, DWORD dwArg4)
{
998
    FIXME("(%x, %x, %x, %x) stub!\n", dwArg1, dwArg2, dwArg3, dwArg4);
999 1000 1001 1002 1003 1004 1005 1006
    return 0;
}

/*************************************************************************
 * SHHelpShortcuts_RunDLLA        [SHELL32.@]
 *
 */
DWORD WINAPI SHHelpShortcuts_RunDLLW(DWORD dwArg1, DWORD dwArg2, DWORD dwArg3, DWORD dwArg4)
1007
{
1008
    FIXME("(%x, %x, %x, %x) stub!\n", dwArg1, dwArg2, dwArg3, dwArg4);
1009
    return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
1010 1011 1012
}

/*************************************************************************
1013
 * SHLoadInProc                [SHELL32.@]
1014
 * Create an instance of specified object class from within
1015
 * the shell process and release it immediately
Alexandre Julliard's avatar
Alexandre Julliard committed
1016
 */
1017
HRESULT WINAPI SHLoadInProc (REFCLSID rclsid)
1018
{
1019
    void *ptr = NULL;
1020

1021 1022 1023 1024 1025 1026 1027
    TRACE("%s\n", debugstr_guid(rclsid));

    CoCreateInstance(rclsid, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown,&ptr);
    if(ptr)
    {
        IUnknown * pUnk = ptr;
        IUnknown_Release(pUnk);
1028
        return S_OK;
1029 1030
    }
    return DISP_E_MEMBERNOTFOUND;
Alexandre Julliard's avatar
Alexandre Julliard committed
1031 1032
}

1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060
static void add_authors( HWND list )
{
    static const WCHAR eol[] = {'\r','\n',0};
    static const WCHAR authors[] = {'A','U','T','H','O','R','S',0};
    WCHAR *strW, *start, *end;
    HRSRC rsrc = FindResourceW( shell32_hInstance, authors, (LPCWSTR)RT_RCDATA );
    char *strA = LockResource( LoadResource( shell32_hInstance, rsrc ));
    DWORD sizeW, sizeA = SizeofResource( shell32_hInstance, rsrc );

    if (!strA) return;
    sizeW = MultiByteToWideChar( CP_UTF8, 0, strA, sizeA, NULL, 0 ) + 1;
    if (!(strW = HeapAlloc( GetProcessHeap(), 0, sizeW * sizeof(WCHAR) ))) return;
    MultiByteToWideChar( CP_UTF8, 0, strA, sizeA, strW, sizeW );
    strW[sizeW - 1] = 0;

    start = strpbrkW( strW, eol );  /* skip the header line */
    while (start)
    {
        while (*start && strchrW( eol, *start )) start++;
        if (!*start) break;
        end = strpbrkW( start, eol );
        if (end) *end++ = 0;
        SendMessageW( list, LB_ADDSTRING, -1, (LPARAM)start );
        start = end;
    }
    HeapFree( GetProcessHeap(), 0, strW );
}

Alexandre Julliard's avatar
Alexandre Julliard committed
1061
/*************************************************************************
1062
 * AboutDlgProc            (internal)
Alexandre Julliard's avatar
Alexandre Julliard committed
1063
 */
1064 1065
static INT_PTR CALLBACK AboutDlgProc( HWND hWnd, UINT msg, WPARAM wParam,
                                      LPARAM lParam )
1066 1067
{
    HWND hWndCtl;
Alexandre Julliard's avatar
Alexandre Julliard committed
1068

1069
    TRACE("\n");
Alexandre Julliard's avatar
Alexandre Julliard committed
1070 1071

    switch(msg)
1072 1073 1074 1075
    {
    case WM_INITDIALOG:
        {
            ABOUT_INFO *info = (ABOUT_INFO *)lParam;
1076 1077
            WCHAR template[512], buffer[512], version[64];
            extern const char *wine_get_build_id(void);
1078

Alexandre Julliard's avatar
Alexandre Julliard committed
1079
            if (info)
1080 1081
            {
                SendDlgItemMessageW(hWnd, stc1, STM_SETICON,(WPARAM)info->hIcon, 0);
1082 1083 1084
                GetWindowTextW( hWnd, template, sizeof(template)/sizeof(WCHAR) );
                sprintfW( buffer, template, info->szApp );
                SetWindowTextW( hWnd, buffer );
1085 1086
                SetWindowTextW( GetDlgItem(hWnd, IDC_ABOUT_STATIC_TEXT1), info->szApp );
                SetWindowTextW( GetDlgItem(hWnd, IDC_ABOUT_STATIC_TEXT2), info->szOtherStuff );
1087 1088 1089 1090 1091 1092
                GetWindowTextW( GetDlgItem(hWnd, IDC_ABOUT_STATIC_TEXT3),
                                template, sizeof(template)/sizeof(WCHAR) );
                MultiByteToWideChar( CP_UTF8, 0, wine_get_build_id(), -1,
                                     version, sizeof(version)/sizeof(WCHAR) );
                sprintfW( buffer, template, version );
                SetWindowTextW( GetDlgItem(hWnd, IDC_ABOUT_STATIC_TEXT3), buffer );
1093
                hWndCtl = GetDlgItem(hWnd, IDC_ABOUT_LISTBOX);
1094
                SendMessageW( hWndCtl, WM_SETREDRAW, 0, 0 );
1095
                SendMessageW( hWndCtl, WM_SETFONT, (WPARAM)info->hFont, 0 );
1096
                add_authors( hWndCtl );
1097
                SendMessageW( hWndCtl, WM_SETREDRAW, 1, 0 );
Alexandre Julliard's avatar
Alexandre Julliard committed
1098 1099 1100 1101 1102
            }
        }
        return 1;

    case WM_PAINT:
1103 1104 1105
        {
            PAINTSTRUCT ps;
            HDC hDC = BeginPaint( hWnd, &ps );
1106
            paint_dropline( hDC, hWnd );
1107 1108 1109
            EndPaint( hWnd, &ps );
        }
    break;
Alexandre Julliard's avatar
Alexandre Julliard committed
1110 1111

    case WM_COMMAND:
1112 1113 1114
        if (wParam == IDOK || wParam == IDCANCEL)
        {
            EndDialog(hWnd, TRUE);
Alexandre Julliard's avatar
Alexandre Julliard committed
1115 1116
            return TRUE;
        }
1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132
        if (wParam == IDC_ABOUT_LICENSE)
        {
            MSGBOXPARAMSW params;

            params.cbSize = sizeof(params);
            params.hwndOwner = hWnd;
            params.hInstance = shell32_hInstance;
            params.lpszText = MAKEINTRESOURCEW(IDS_LICENSE);
            params.lpszCaption = MAKEINTRESOURCEW(IDS_LICENSE_CAPTION);
            params.dwStyle = MB_ICONINFORMATION | MB_OK;
            params.lpszIcon = 0;
            params.dwContextHelpId = 0;
            params.lpfnMsgBoxCallback = NULL;
            params.dwLanguageId = LANG_NEUTRAL;
            MessageBoxIndirectW( &params );
        }
Alexandre Julliard's avatar
Alexandre Julliard committed
1133
        break;
1134 1135 1136
    case WM_CLOSE:
      EndDialog(hWnd, TRUE);
      break;
Alexandre Julliard's avatar
Alexandre Julliard committed
1137
    }
1138

Alexandre Julliard's avatar
Alexandre Julliard committed
1139 1140 1141 1142 1143
    return 0;
}


/*************************************************************************
1144
 * ShellAboutA                [SHELL32.288]
Alexandre Julliard's avatar
Alexandre Julliard committed
1145
 */
1146 1147 1148
BOOL WINAPI ShellAboutA( HWND hWnd, LPCSTR szApp, LPCSTR szOtherStuff, HICON hIcon )
{
    BOOL ret;
1149 1150
    LPWSTR appW = NULL, otherW = NULL;
    int len;
1151

1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166
    if (szApp)
    {
        len = MultiByteToWideChar(CP_ACP, 0, szApp, -1, NULL, 0);
        appW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
        MultiByteToWideChar(CP_ACP, 0, szApp, -1, appW, len);
    }
    if (szOtherStuff)
    {
        len = MultiByteToWideChar(CP_ACP, 0, szOtherStuff, -1, NULL, 0);
        otherW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
        MultiByteToWideChar(CP_ACP, 0, szOtherStuff, -1, otherW, len);
    }

    ret = ShellAboutW(hWnd, appW, otherW, hIcon);

1167 1168
    HeapFree(GetProcessHeap(), 0, otherW);
    HeapFree(GetProcessHeap(), 0, appW);
1169
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1170 1171 1172 1173
}


/*************************************************************************
1174
 * ShellAboutW                [SHELL32.289]
Alexandre Julliard's avatar
Alexandre Julliard committed
1175
 */
1176 1177
BOOL WINAPI ShellAboutW( HWND hWnd, LPCWSTR szApp, LPCWSTR szOtherStuff,
                             HICON hIcon )
1178
{
Alexandre Julliard's avatar
Alexandre Julliard committed
1179
    ABOUT_INFO info;
1180 1181
    LOGFONTW logFont;
    BOOL bRet;
Jacek Caban's avatar
Jacek Caban committed
1182 1183
    static const WCHAR wszSHELL_ABOUT_MSGBOX[] =
        {'S','H','E','L','L','_','A','B','O','U','T','_','M','S','G','B','O','X',0};
Alexandre Julliard's avatar
Alexandre Julliard committed
1184

1185
    TRACE("\n");
1186

1187
    if (!hIcon) hIcon = LoadImageW( 0, (LPWSTR)IDI_WINLOGO, IMAGE_ICON, 48, 48, LR_SHARED );
1188 1189
    info.szApp        = szApp;
    info.szOtherStuff = szOtherStuff;
1190
    info.hIcon        = hIcon;
1191 1192 1193 1194

    SystemParametersInfoW( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 );
    info.hFont = CreateFontIndirectW( &logFont );

1195
    bRet = DialogBoxParamW( shell32_hInstance, wszSHELL_ABOUT_MSGBOX, hWnd, AboutDlgProc, (LPARAM)&info );
1196 1197
    DeleteObject(info.hFont);
    return bRet;
Alexandre Julliard's avatar
Alexandre Julliard committed
1198 1199 1200
}

/*************************************************************************
1201
 * FreeIconList (SHELL32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
1202 1203
 */
void WINAPI FreeIconList( DWORD dw )
1204
{
1205
    FIXME("%x: stub\n",dw);
Alexandre Julliard's avatar
Alexandre Julliard committed
1206 1207
}

1208 1209 1210
/*************************************************************************
 * SHLoadNonloadedIconOverlayIdentifiers (SHELL32.@)
 */
1211
HRESULT WINAPI SHLoadNonloadedIconOverlayIdentifiers( VOID )
1212 1213 1214 1215
{
    FIXME("stub\n");
    return S_OK;
}
1216

1217
/***********************************************************************
1218
 * DllGetVersion [SHELL32.@]
1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232
 *
 * Retrieves version information of the 'SHELL32.DLL'
 *
 * PARAMS
 *     pdvi [O] pointer to version information structure.
 *
 * RETURNS
 *     Success: S_OK
 *     Failure: E_INVALIDARG
 *
 * NOTES
 *     Returns version of a shell32.dll from IE4.01 SP1.
 */

1233
HRESULT WINAPI DllGetVersion (DLLVERSIONINFO *pdvi)
1234
{
1235 1236
    /* FIXME: shouldn't these values come from the version resource? */
    if (pdvi->cbSize == sizeof(DLLVERSIONINFO) ||
1237
        pdvi->cbSize == sizeof(DLLVERSIONINFO2))
1238
    {
1239 1240 1241 1242
        pdvi->dwMajorVersion = WINE_FILEVERSION_MAJOR;
        pdvi->dwMinorVersion = WINE_FILEVERSION_MINOR;
        pdvi->dwBuildNumber = WINE_FILEVERSION_BUILD;
        pdvi->dwPlatformID = WINE_FILEVERSION_PLATFORMID;
1243 1244 1245
        if (pdvi->cbSize == sizeof(DLLVERSIONINFO2))
        {
            DLLVERSIONINFO2 *pdvi2 = (DLLVERSIONINFO2 *)pdvi;
1246

1247
            pdvi2->dwFlags = 0;
1248 1249 1250 1251
            pdvi2->ullVersion = MAKEDLLVERULL(WINE_FILEVERSION_MAJOR,
                                              WINE_FILEVERSION_MINOR,
                                              WINE_FILEVERSION_BUILD,
                                              WINE_FILEVERSION_PLATFORMID);
1252
        }
1253
        TRACE("%u.%u.%u.%u\n",
1254 1255
              pdvi->dwMajorVersion, pdvi->dwMinorVersion,
              pdvi->dwBuildNumber, pdvi->dwPlatformID);
1256 1257 1258
        return S_OK;
    }
    else
1259
    {
1260 1261 1262
        WARN("wrong DLLVERSIONINFO size from app\n");
        return E_INVALIDARG;
    }
1263
}
1264

1265 1266
/*************************************************************************
 * global variables of the shell32.dll
1267
 * all are once per process
1268 1269
 *
 */
1270
HINSTANCE    shell32_hInstance = 0;
1271

Alexandre Julliard's avatar
Alexandre Julliard committed
1272

1273
/*************************************************************************
1274
 * SHELL32 DllMain
1275 1276
 *
 * NOTES
1277
 *  calling oleinitialize here breaks some apps.
1278
 */
1279
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
1280
{
1281
    TRACE("%p 0x%x %p\n", hinstDLL, fdwReason, fImpLoad);
1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296

    switch (fdwReason)
    {
    case DLL_PROCESS_ATTACH:
        shell32_hInstance = hinstDLL;
        DisableThreadLibraryCalls(shell32_hInstance);

        /* get full path to this DLL for IExtractIconW_fnGetIconLocation() */
        GetModuleFileNameW(hinstDLL, swShell32Name, MAX_PATH);
        swShell32Name[MAX_PATH - 1] = '\0';

        InitChangeNotifications();
        break;

    case DLL_PROCESS_DETACH:
1297
        if (fImpLoad) break;
1298 1299
        SIC_Destroy();
        FreeChangeNotifications();
1300
        release_desktop_folder();
1301
        release_typelib();
1302 1303 1304
        break;
    }
    return TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
1305
}
1306 1307

/*************************************************************************
1308
 * DllInstall         [SHELL32.@]
1309 1310
 *
 * PARAMETERS
1311
 *
1312 1313 1314 1315
 *    BOOL bInstall - TRUE for install, FALSE for uninstall
 *    LPCWSTR pszCmdLine - command line (unused by shell32?)
 */

1316
HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
1317
{
1318 1319
    FIXME("%s %s: stub\n", bInstall ? "TRUE":"FALSE", debugstr_w(cmdline));
    return S_OK;        /* indicate success */
1320
}
Andreas Mohr's avatar
Andreas Mohr committed
1321 1322 1323 1324

/***********************************************************************
 *              DllCanUnloadNow (SHELL32.@)
 */
1325
HRESULT WINAPI DllCanUnloadNow(void)
Andreas Mohr's avatar
Andreas Mohr committed
1326 1327 1328
{
    return S_FALSE;
}
1329

1330 1331 1332 1333 1334
/***********************************************************************
 *		DllRegisterServer (SHELL32.@)
 */
HRESULT WINAPI DllRegisterServer(void)
{
1335
    HRESULT hr = __wine_register_resources( shell32_hInstance );
1336 1337 1338 1339 1340 1341 1342 1343 1344
    if (SUCCEEDED(hr)) hr = SHELL_RegisterShellFolders();
    return hr;
}

/***********************************************************************
 *		DllUnregisterServer (SHELL32.@)
 */
HRESULT WINAPI DllUnregisterServer(void)
{
1345
    return __wine_unregister_resources( shell32_hInstance );
1346 1347
}

1348 1349 1350 1351 1352 1353 1354 1355
/***********************************************************************
 *              ExtractVersionResource16W (SHELL32.@)
 */
BOOL WINAPI ExtractVersionResource16W(LPWSTR s, DWORD d)
{
    FIXME("(%s %x) stub!\n", debugstr_w(s), d);
    return FALSE;
}
1356 1357 1358 1359 1360 1361 1362 1363 1364

/***********************************************************************
 *              InitNetworkAddressControl (SHELL32.@)
 */
BOOL WINAPI InitNetworkAddressControl(void)
{
    FIXME("stub\n");
    return FALSE;
}
1365 1366 1367 1368 1369 1370 1371 1372 1373

/***********************************************************************
 *              ShellHookProc (SHELL32.@)
 */
LRESULT CALLBACK ShellHookProc(DWORD a, DWORD b, DWORD c)
{
    FIXME("Stub\n");
    return 0;
}
1374

1375 1376 1377
/***********************************************************************
 *              SHGetLocalizedName (SHELL32.@)
 */
1378 1379 1380 1381 1382
HRESULT WINAPI SHGetLocalizedName(LPCWSTR path, LPWSTR module, UINT size, INT *res)
{
    FIXME("%s %p %u %p: stub\n", debugstr_w(path), module, size, res);
    return E_NOTIMPL;
}
1383

1384 1385 1386
/***********************************************************************
 *              SetCurrentProcessExplicitAppUserModelID (SHELL32.@)
 */
1387 1388 1389 1390 1391
HRESULT WINAPI SetCurrentProcessExplicitAppUserModelID(PCWSTR appid)
{
    FIXME("%s: stub\n", debugstr_w(appid));
    return E_NOTIMPL;
}
1392

1393 1394 1395 1396 1397 1398 1399 1400 1401 1402
/***********************************************************************
 *              GetCurrentProcessExplicitAppUserModelID (SHELL32.@)
 */
HRESULT WINAPI GetCurrentProcessExplicitAppUserModelID(PWSTR *appid)
{
    FIXME("%p: stub\n", appid);
    *appid = NULL;
    return E_NOTIMPL;
}

1403 1404 1405 1406 1407 1408 1409 1410
/***********************************************************************
 *              SHSetUnreadMailCountW (SHELL32.@)
 */
HRESULT WINAPI SHSetUnreadMailCountW(LPCWSTR mailaddress, DWORD count, LPCWSTR executecommand)
{
    FIXME("%s %x %s: stub\n", debugstr_w(mailaddress), count, debugstr_w(executecommand));
    return E_NOTIMPL;
}
1411 1412 1413 1414 1415 1416 1417 1418 1419

/***********************************************************************
 *              SHEnumerateUnreadMailAccountsW (SHELL32.@)
 */
HRESULT WINAPI SHEnumerateUnreadMailAccountsW(HKEY user, DWORD idx, LPWSTR mailaddress, INT mailaddresslen)
{
    FIXME("%p %d %p %d: stub\n", user, idx, mailaddress, mailaddresslen);
    return E_NOTIMPL;
}
1420 1421 1422 1423 1424 1425 1426 1427 1428 1429

/***********************************************************************
 *              SHQueryUserNotificationState (SHELL32.@)
 */
HRESULT WINAPI SHQueryUserNotificationState(QUERY_USER_NOTIFICATION_STATE *state)
{
    FIXME("%p: stub\n", state);
    *state = QUNS_ACCEPTS_NOTIFICATIONS;
    return S_OK;
}