shell32_main.c 41.7 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 540 541 542
            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))
    {
        static const WCHAR szFile[] = { 'F','i','l','e',0 };
        static const WCHAR szDashFile[] = { '-','f','i','l','e',0 };

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

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

                lstrcpyW(sTemp,PathFindExtensionW(szFullPath));
                if (!( HCR_MapTypeToValueW(sTemp, sTemp, 64, TRUE) &&
                    HCR_MapTypeToValueW(sTemp, psfi->szTypeName, 80, FALSE )))
561
                {
562 563
                    lstrcpynW (psfi->szTypeName, sTemp, 64);
                    strcatW (psfi->szTypeName, szDashFile);
564 565
                }
            }
566
        }
567
    }
568

569
    /* ### icons ###*/
570 571 572

    Shell_GetImageLists( &big_icons, &small_icons );

573 574 575 576 577 578 579 580 581 582 583
    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;
    }
584

585 586
    if (flags & SHGFI_OVERLAYINDEX)
        FIXME("SHGFI_OVERLAYINDEX unhandled\n");
587

588 589
    if (flags & SHGFI_SELECTED)
        FIXME("set icon to selected, stub\n");
590

591 592
    if (flags & SHGFI_SHELLICONSIZE)
        FIXME("set icon to shell size, stub\n");
593

594 595 596 597
    /* get the iconlocation */
    if (SUCCEEDED(hr) && (flags & SHGFI_ICONLOCATION ))
    {
        UINT uDummy,uFlags;
598

599
        if (flags & SHGFI_USEFILEATTRIBUTES && !(flags & SHGFI_PIDL))
600
        {
601 602 603 604 605
            if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
            {
                lstrcpyW(psfi->szDisplayName, swShell32Name);
                psfi->iIcon = -IDI_SHELL_FOLDER;
            }
606
            else
607 608 609 610 611
            {
                WCHAR* szExt;
                static const WCHAR p1W[] = {'%','1',0};
                WCHAR sTemp [MAX_PATH];

612
                szExt = PathFindExtensionW(szFullPath);
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638
                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);
639

640 641 642 643 644 645 646 647 648
                if (uFlags & GIL_NOTFILENAME)
                    ret = FALSE;
                else
                {
                    lstrcpyW (psfi->szDisplayName, szLocation);
                    psfi->iIcon = iIndex;
                }
                IExtractIconW_Release(pei);
            }
649 650
        }
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
651

652 653 654
    /* get icon index (or load icon)*/
    if (SUCCEEDED(hr) && (flags & (SHGFI_ICON | SHGFI_SYSICONINDEX)))
    {
655
        if (flags & SHGFI_USEFILEATTRIBUTES && !(flags & SHGFI_PIDL))
656 657 658
        {
            WCHAR sTemp [MAX_PATH];
            WCHAR * szExt;
659
            int icon_idx=0;
660

661
            lstrcpynW(sTemp, szFullPath, MAX_PATH);
662 663

            if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
664
                psfi->iIcon = SIC_GetIconIndex(swShell32Name, -IDI_SHELL_FOLDER, 0);
665
            else
666
            {
667 668 669
                static const WCHAR p1W[] = {'%','1',0};

                psfi->iIcon = 0;
670
                szExt = PathFindExtensionW(sTemp);
671 672
                if ( szExt &&
                     HCR_MapTypeToValueW(szExt, sTemp, MAX_PATH, TRUE) &&
673
                     HCR_GetDefaultIconW(sTemp, sTemp, MAX_PATH, &icon_idx))
674 675 676 677 678 679
                {
                    if (!lstrcmpW(p1W,sTemp))            /* icon is in the file */
                        strcpyW(sTemp, szFullPath);

                    if (flags & SHGFI_SYSICONINDEX) 
                    {
680
                        psfi->iIcon = SIC_GetIconIndex(sTemp,icon_idx,0);
681 682 683 684 685
                        if (psfi->iIcon == -1)
                            psfi->iIcon = 0;
                    }
                    else 
                    {
686
                        UINT ret;
687
                        if (flags & SHGFI_SMALLICON)
688
                            ret = PrivateExtractIconsW( sTemp,icon_idx,
689 690 691 692
                                GetSystemMetrics( SM_CXSMICON ),
                                GetSystemMetrics( SM_CYSMICON ),
                                &psfi->hIcon, 0, 1, 0);
                        else
693
                            ret = PrivateExtractIconsW( sTemp, icon_idx,
694 695 696
                                GetSystemMetrics( SM_CXICON),
                                GetSystemMetrics( SM_CYICON),
                                &psfi->hIcon, 0, 1, 0);
697
                        if (ret != 0 && ret != (UINT)-1)
698 699 700 701
                        {
                            IconNotYetLoaded=FALSE;
                            psfi->iIcon = icon_idx;
                        }
702 703
                    }
                }
704
            }
705 706 707 708
        }
        else
        {
            if (!(PidlToSicIndex(psfParent, pidlLast, !(flags & SHGFI_SMALLICON),
709
                uGilFlags, &(psfi->iIcon))))
710 711 712 713
            {
                ret = FALSE;
            }
        }
714
        if (ret && (flags & SHGFI_SYSICONINDEX))
715 716
        {
            if (flags & SHGFI_SMALLICON)
717
                ret = (DWORD_PTR)small_icons;
718
            else
719
                ret = (DWORD_PTR)big_icons;
720 721 722 723 724 725 726
        }
    }

    /* icon handle */
    if (SUCCEEDED(hr) && (flags & SHGFI_ICON) && IconNotYetLoaded)
    {
        if (flags & SHGFI_SMALLICON)
727
            psfi->hIcon = ImageList_GetIcon( small_icons, psfi->iIcon, ILD_NORMAL);
728
        else
729
            psfi->hIcon = ImageList_GetIcon( big_icons, psfi->iIcon, ILD_NORMAL);
730 731 732 733 734 735 736 737 738 739 740
    }

    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;

741
    SHFree(pidlLast);
742

743
    TRACE ("icon=%p index=0x%08x attr=0x%08x name=%s type=%s ret=0x%08lx\n",
744 745 746 747
           psfi->hIcon, psfi->iIcon, psfi->dwAttributes,
           debugstr_w(psfi->szDisplayName), debugstr_w(psfi->szTypeName), ret);

    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
748 749
}

750
/*************************************************************************
751
 * SHGetFileInfoA            [SHELL32.@]
752 753 754 755 756
 *
 * 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)
757
 */
Kevin Koltzau's avatar
Kevin Koltzau committed
758 759 760
DWORD_PTR WINAPI SHGetFileInfoA(LPCSTR path,DWORD dwFileAttributes,
                                SHFILEINFOA *psfi, UINT sizeofpsfi,
                                UINT flags )
761
{
762
    INT len;
763 764
    LPWSTR temppath = NULL;
    LPCWSTR pathW;
765
    DWORD_PTR ret;
766 767 768 769 770
    SHFILEINFOW temppsfi;

    if (flags & SHGFI_PIDL)
    {
        /* path contains a pidl */
771
        pathW = (LPCWSTR)path;
772 773 774 775 776 777
    }
    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);
778
        pathW = temppath;
779 780 781 782 783 784
    }

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

    if (psfi == NULL)
785
        ret = SHGetFileInfoW(pathW, dwFileAttributes, NULL, sizeof(temppsfi), flags);
786
    else
787
        ret = SHGetFileInfoW(pathW, dwFileAttributes, &temppsfi, sizeof(temppsfi), flags);
788 789 790 791 792 793 794 795 796 797 798 799 800 801 802

    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)
803
        {
804 805
            WideCharToMultiByte(CP_ACP, 0, temppsfi.szTypeName, -1,
                  psfi->szTypeName, sizeof(psfi->szTypeName), NULL, NULL);
806
        }
807 808
    }

809
    HeapFree(GetProcessHeap(), 0, temppath);
810 811

    return ret;
812 813
}

814
/*************************************************************************
815
 * DuplicateIcon            [SHELL32.@]
816 817 818 819
 */
HICON WINAPI DuplicateIcon( HINSTANCE hInstance, HICON hIcon)
{
    ICONINFO IconInfo;
820
    HICON hDupIcon = 0;
821

822
    TRACE("%p %p\n", hInstance, hIcon);
823

824
    if (GetIconInfo(hIcon, &IconInfo))
825 826 827 828
    {
        hDupIcon = CreateIconIndirect(&IconInfo);

        /* clean up hbmMask and hbmColor */
829 830
        DeleteObject(IconInfo.hbmMask);
        DeleteObject(IconInfo.hbmColor);
831
    }
832

833 834
    return hDupIcon;
}
835

Alexandre Julliard's avatar
Alexandre Julliard committed
836
/*************************************************************************
837
 * ExtractIconA                [SHELL32.@]
Alexandre Julliard's avatar
Alexandre Julliard committed
838
 */
839 840
HICON WINAPI ExtractIconA(HINSTANCE hInstance, LPCSTR lpszFile, UINT nIconIndex)
{   
841 842 843
    HICON ret;
    INT len = MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, NULL, 0);
    LPWSTR lpwstrFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
844

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

847 848 849 850 851
    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
852 853 854
}

/*************************************************************************
855
 * ExtractIconW                [SHELL32.@]
Alexandre Julliard's avatar
Alexandre Julliard committed
856
 */
857 858
HICON WINAPI ExtractIconW(HINSTANCE hInstance, LPCWSTR lpszFile, UINT nIconIndex)
{
859 860 861 862 863 864
    HICON  hIcon = NULL;
    UINT ret;
    UINT cx = GetSystemMetrics(SM_CXICON), cy = GetSystemMetrics(SM_CYICON);

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

865
    if (nIconIndex == (UINT)-1)
866 867
    {
        ret = PrivateExtractIconsW(lpszFile, 0, cx, cy, NULL, NULL, 0, LR_DEFAULTCOLOR);
868
        if (ret != (UINT)-1 && ret)
Kevin Koltzau's avatar
Kevin Koltzau committed
869
            return (HICON)(UINT_PTR)ret;
870 871 872 873 874
        return NULL;
    }
    else
        ret = PrivateExtractIconsW(lpszFile, nIconIndex, cx, cy, &hIcon, NULL, 1, LR_DEFAULTCOLOR);

875
    if (ret == (UINT)-1)
876 877 878 879 880
        return (HICON)1;
    else if (ret > 0 && hIcon)
        return hIcon;

    return NULL;
Alexandre Julliard's avatar
Alexandre Julliard committed
881 882
}

883 884 885 886 887 888 889
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;
}

890 891 892 893 894 895 896 897 898 899 900 901 902 903 904
/*************************************************************************
 * 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
    */
905 906 907 908
    if((wsPrinterName != NULL) && (wsPrinterName[0] != 0))
    {
        FIXME("(select Icon by PrinterName %s not implemented)\n", debugstr_w(wsPrinterName));
    }
909 910 911 912 913 914 915 916 917 918 919 920

    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);
}

921 922 923 924 925 926 927 928 929
/*************************************************************************
 * 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)
{
930
    FIXME("(%s, %x, %p (%p), %p (%p)) stub!\n", debugstr_w(wsPrinter), dwType,
931 932 933 934 935 936 937 938 939 940 941 942 943 944
                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);
} 

945 946 947
/*************************************************************************
 * SHGetPropertyStoreFromParsingName [SHELL32.@]
 */
948
HRESULT WINAPI SHGetPropertyStoreFromParsingName(PCWSTR pszPath, IBindCtx *pbc, GETPROPERTYSTOREFLAGS flags, REFIID riid, void **ppv)
949 950 951 952 953
{
    FIXME("(%s %p %u %p %p) stub!\n", debugstr_w(pszPath), pbc, flags, riid, ppv);
    return E_NOTIMPL;
}

954 955
/*************************************************************************/

Alexandre Julliard's avatar
Alexandre Julliard committed
956
typedef struct
957 958 959
{
    LPCWSTR  szApp;
    LPCWSTR  szOtherStuff;
960
    HICON hIcon;
961
    HFONT hFont;
Alexandre Julliard's avatar
Alexandre Julliard committed
962 963
} ABOUT_INFO;

964
#define DROP_FIELD_TOP    (-12)
Alexandre Julliard's avatar
Alexandre Julliard committed
965

966
static void paint_dropline( HDC hdc, HWND hWnd )
967
{
968
    HWND hWndCtl = GetDlgItem(hWnd, IDC_ABOUT_WINE_TEXT);
969 970 971 972 973 974 975 976
    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
977 978 979
}

/*************************************************************************
980
 * SHHelpShortcuts_RunDLLA        [SHELL32.@]
Alexandre Julliard's avatar
Alexandre Julliard committed
981 982
 *
 */
983 984
DWORD WINAPI SHHelpShortcuts_RunDLLA(DWORD dwArg1, DWORD dwArg2, DWORD dwArg3, DWORD dwArg4)
{
985
    FIXME("(%x, %x, %x, %x) stub!\n", dwArg1, dwArg2, dwArg3, dwArg4);
986 987 988 989 990 991 992 993
    return 0;
}

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

/*************************************************************************
1000
 * SHLoadInProc                [SHELL32.@]
1001
 * Create an instance of specified object class from within
1002
 * the shell process and release it immediately
Alexandre Julliard's avatar
Alexandre Julliard committed
1003
 */
1004
HRESULT WINAPI SHLoadInProc (REFCLSID rclsid)
1005
{
1006
    void *ptr = NULL;
1007

1008 1009 1010 1011 1012 1013 1014
    TRACE("%s\n", debugstr_guid(rclsid));

    CoCreateInstance(rclsid, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown,&ptr);
    if(ptr)
    {
        IUnknown * pUnk = ptr;
        IUnknown_Release(pUnk);
1015
        return S_OK;
1016 1017
    }
    return DISP_E_MEMBERNOTFOUND;
Alexandre Julliard's avatar
Alexandre Julliard committed
1018 1019
}

1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047
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
1048
/*************************************************************************
1049
 * AboutDlgProc            (internal)
Alexandre Julliard's avatar
Alexandre Julliard committed
1050
 */
1051 1052
static INT_PTR CALLBACK AboutDlgProc( HWND hWnd, UINT msg, WPARAM wParam,
                                      LPARAM lParam )
1053 1054
{
    HWND hWndCtl;
Alexandre Julliard's avatar
Alexandre Julliard committed
1055

1056
    TRACE("\n");
Alexandre Julliard's avatar
Alexandre Julliard committed
1057 1058

    switch(msg)
1059 1060 1061 1062
    {
    case WM_INITDIALOG:
        {
            ABOUT_INFO *info = (ABOUT_INFO *)lParam;
1063 1064
            WCHAR template[512], buffer[512], version[64];
            extern const char *wine_get_build_id(void);
1065

Alexandre Julliard's avatar
Alexandre Julliard committed
1066
            if (info)
1067 1068
            {
                SendDlgItemMessageW(hWnd, stc1, STM_SETICON,(WPARAM)info->hIcon, 0);
1069 1070 1071
                GetWindowTextW( hWnd, template, sizeof(template)/sizeof(WCHAR) );
                sprintfW( buffer, template, info->szApp );
                SetWindowTextW( hWnd, buffer );
1072 1073
                SetWindowTextW( GetDlgItem(hWnd, IDC_ABOUT_STATIC_TEXT1), info->szApp );
                SetWindowTextW( GetDlgItem(hWnd, IDC_ABOUT_STATIC_TEXT2), info->szOtherStuff );
1074 1075 1076 1077 1078 1079
                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 );
1080
                hWndCtl = GetDlgItem(hWnd, IDC_ABOUT_LISTBOX);
1081
                SendMessageW( hWndCtl, WM_SETREDRAW, 0, 0 );
1082
                SendMessageW( hWndCtl, WM_SETFONT, (WPARAM)info->hFont, 0 );
1083
                add_authors( hWndCtl );
1084
                SendMessageW( hWndCtl, WM_SETREDRAW, 1, 0 );
Alexandre Julliard's avatar
Alexandre Julliard committed
1085 1086 1087 1088 1089
            }
        }
        return 1;

    case WM_PAINT:
1090 1091 1092
        {
            PAINTSTRUCT ps;
            HDC hDC = BeginPaint( hWnd, &ps );
1093
            paint_dropline( hDC, hWnd );
1094 1095 1096
            EndPaint( hWnd, &ps );
        }
    break;
Alexandre Julliard's avatar
Alexandre Julliard committed
1097 1098

    case WM_COMMAND:
1099 1100 1101
        if (wParam == IDOK || wParam == IDCANCEL)
        {
            EndDialog(hWnd, TRUE);
Alexandre Julliard's avatar
Alexandre Julliard committed
1102 1103
            return TRUE;
        }
1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119
        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
1120
        break;
1121 1122 1123
    case WM_CLOSE:
      EndDialog(hWnd, TRUE);
      break;
Alexandre Julliard's avatar
Alexandre Julliard committed
1124
    }
1125

Alexandre Julliard's avatar
Alexandre Julliard committed
1126 1127 1128 1129 1130
    return 0;
}


/*************************************************************************
1131
 * ShellAboutA                [SHELL32.288]
Alexandre Julliard's avatar
Alexandre Julliard committed
1132
 */
1133 1134 1135
BOOL WINAPI ShellAboutA( HWND hWnd, LPCSTR szApp, LPCSTR szOtherStuff, HICON hIcon )
{
    BOOL ret;
1136 1137
    LPWSTR appW = NULL, otherW = NULL;
    int len;
1138

1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153
    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);

1154 1155
    HeapFree(GetProcessHeap(), 0, otherW);
    HeapFree(GetProcessHeap(), 0, appW);
1156
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1157 1158 1159 1160
}


/*************************************************************************
1161
 * ShellAboutW                [SHELL32.289]
Alexandre Julliard's avatar
Alexandre Julliard committed
1162
 */
1163 1164
BOOL WINAPI ShellAboutW( HWND hWnd, LPCWSTR szApp, LPCWSTR szOtherStuff,
                             HICON hIcon )
1165
{
Alexandre Julliard's avatar
Alexandre Julliard committed
1166
    ABOUT_INFO info;
1167 1168
    LOGFONTW logFont;
    BOOL bRet;
Jacek Caban's avatar
Jacek Caban committed
1169 1170
    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
1171

1172
    TRACE("\n");
1173

1174
    if (!hIcon) hIcon = LoadImageW( 0, (LPWSTR)IDI_WINLOGO, IMAGE_ICON, 48, 48, LR_SHARED );
1175 1176
    info.szApp        = szApp;
    info.szOtherStuff = szOtherStuff;
1177
    info.hIcon        = hIcon;
1178 1179 1180 1181

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

1182
    bRet = DialogBoxParamW( shell32_hInstance, wszSHELL_ABOUT_MSGBOX, hWnd, AboutDlgProc, (LPARAM)&info );
1183 1184
    DeleteObject(info.hFont);
    return bRet;
Alexandre Julliard's avatar
Alexandre Julliard committed
1185 1186 1187
}

/*************************************************************************
1188
 * FreeIconList (SHELL32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
1189 1190
 */
void WINAPI FreeIconList( DWORD dw )
1191
{
1192
    FIXME("%x: stub\n",dw);
Alexandre Julliard's avatar
Alexandre Julliard committed
1193 1194
}

1195 1196 1197
/*************************************************************************
 * SHLoadNonloadedIconOverlayIdentifiers (SHELL32.@)
 */
1198
HRESULT WINAPI SHLoadNonloadedIconOverlayIdentifiers( VOID )
1199 1200 1201 1202
{
    FIXME("stub\n");
    return S_OK;
}
1203

1204
/***********************************************************************
1205
 * DllGetVersion [SHELL32.@]
1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219
 *
 * 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.
 */

1220
HRESULT WINAPI DllGetVersion (DLLVERSIONINFO *pdvi)
1221
{
1222 1223
    /* FIXME: shouldn't these values come from the version resource? */
    if (pdvi->cbSize == sizeof(DLLVERSIONINFO) ||
1224
        pdvi->cbSize == sizeof(DLLVERSIONINFO2))
1225
    {
1226 1227 1228 1229
        pdvi->dwMajorVersion = WINE_FILEVERSION_MAJOR;
        pdvi->dwMinorVersion = WINE_FILEVERSION_MINOR;
        pdvi->dwBuildNumber = WINE_FILEVERSION_BUILD;
        pdvi->dwPlatformID = WINE_FILEVERSION_PLATFORMID;
1230 1231 1232
        if (pdvi->cbSize == sizeof(DLLVERSIONINFO2))
        {
            DLLVERSIONINFO2 *pdvi2 = (DLLVERSIONINFO2 *)pdvi;
1233

1234
            pdvi2->dwFlags = 0;
1235 1236 1237 1238
            pdvi2->ullVersion = MAKEDLLVERULL(WINE_FILEVERSION_MAJOR,
                                              WINE_FILEVERSION_MINOR,
                                              WINE_FILEVERSION_BUILD,
                                              WINE_FILEVERSION_PLATFORMID);
1239
        }
1240
        TRACE("%u.%u.%u.%u\n",
1241 1242
              pdvi->dwMajorVersion, pdvi->dwMinorVersion,
              pdvi->dwBuildNumber, pdvi->dwPlatformID);
1243 1244 1245
        return S_OK;
    }
    else
1246
    {
1247 1248 1249
        WARN("wrong DLLVERSIONINFO size from app\n");
        return E_INVALIDARG;
    }
1250
}
1251

1252 1253
/*************************************************************************
 * global variables of the shell32.dll
1254
 * all are once per process
1255 1256
 *
 */
1257
HINSTANCE    shell32_hInstance = 0;
1258

Alexandre Julliard's avatar
Alexandre Julliard committed
1259

1260
/*************************************************************************
1261
 * SHELL32 DllMain
1262 1263
 *
 * NOTES
1264
 *  calling oleinitialize here breaks some apps.
1265
 */
1266
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
1267
{
1268
    TRACE("%p 0x%x %p\n", hinstDLL, fdwReason, fImpLoad);
1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283

    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:
1284
        if (fImpLoad) break;
1285 1286
        SIC_Destroy();
        FreeChangeNotifications();
1287
        release_desktop_folder();
1288
        release_typelib();
1289 1290 1291
        break;
    }
    return TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
1292
}
1293 1294

/*************************************************************************
1295
 * DllInstall         [SHELL32.@]
1296 1297
 *
 * PARAMETERS
1298
 *
1299 1300 1301 1302
 *    BOOL bInstall - TRUE for install, FALSE for uninstall
 *    LPCWSTR pszCmdLine - command line (unused by shell32?)
 */

1303
HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
1304
{
1305 1306
    FIXME("%s %s: stub\n", bInstall ? "TRUE":"FALSE", debugstr_w(cmdline));
    return S_OK;        /* indicate success */
1307
}
Andreas Mohr's avatar
Andreas Mohr committed
1308 1309 1310 1311

/***********************************************************************
 *              DllCanUnloadNow (SHELL32.@)
 */
1312
HRESULT WINAPI DllCanUnloadNow(void)
Andreas Mohr's avatar
Andreas Mohr committed
1313 1314 1315
{
    return S_FALSE;
}
1316

1317 1318 1319 1320 1321
/***********************************************************************
 *		DllRegisterServer (SHELL32.@)
 */
HRESULT WINAPI DllRegisterServer(void)
{
1322
    HRESULT hr = __wine_register_resources( shell32_hInstance );
1323 1324 1325 1326 1327 1328 1329 1330 1331
    if (SUCCEEDED(hr)) hr = SHELL_RegisterShellFolders();
    return hr;
}

/***********************************************************************
 *		DllUnregisterServer (SHELL32.@)
 */
HRESULT WINAPI DllUnregisterServer(void)
{
1332
    return __wine_unregister_resources( shell32_hInstance );
1333 1334
}

1335 1336 1337 1338 1339 1340 1341 1342
/***********************************************************************
 *              ExtractVersionResource16W (SHELL32.@)
 */
BOOL WINAPI ExtractVersionResource16W(LPWSTR s, DWORD d)
{
    FIXME("(%s %x) stub!\n", debugstr_w(s), d);
    return FALSE;
}
1343 1344 1345 1346 1347 1348 1349 1350 1351

/***********************************************************************
 *              InitNetworkAddressControl (SHELL32.@)
 */
BOOL WINAPI InitNetworkAddressControl(void)
{
    FIXME("stub\n");
    return FALSE;
}
1352 1353 1354 1355 1356 1357 1358 1359 1360

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

1362 1363 1364
/***********************************************************************
 *              SHGetLocalizedName (SHELL32.@)
 */
1365 1366 1367 1368 1369
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;
}
1370

1371 1372 1373
/***********************************************************************
 *              SetCurrentProcessExplicitAppUserModelID (SHELL32.@)
 */
1374 1375 1376 1377 1378
HRESULT WINAPI SetCurrentProcessExplicitAppUserModelID(PCWSTR appid)
{
    FIXME("%s: stub\n", debugstr_w(appid));
    return E_NOTIMPL;
}
1379 1380 1381 1382 1383 1384 1385 1386 1387

/***********************************************************************
 *              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;
}