ordinal.c 115 KB
Newer Older
1 2
/*
 * SHLWAPI ordinal functions
3
 *
4 5
 * Copyright 1997 Marcus Meissner
 *           1998 Jrgen Schmied
6
 *           2001-2003 Jon Griffiths
7 8 9 10 11 12 13 14 15 16 17 18 19 20
 *
 * 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
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21 22
 */

23
#define COM_NO_WINDOWS_H
24 25 26
#include "config.h"
#include "wine/port.h"

27
#include <stdarg.h>
28
#include <stdio.h>
29
#include <string.h>
30

31
#define COBJMACROS
32 33
#define NONAMELESSUNION
#define NONAMELESSSTRUCT
34

35
#include "windef.h"
36
#include "winbase.h"
37 38
#include "winuser.h"
#include "winnls.h"
39
#include "objbase.h"
40 41 42
#include "docobj.h"
#include "exdisp.h"
#include "shlguid.h"
43
#include "wingdi.h"
44 45 46
#include "shlobj.h"
#include "shellapi.h"
#include "commdlg.h"
47
#include "wine/unicode.h"
48
#include "winreg.h"
49
#include "wine/debug.h"
50
#include "shlwapi.h"
51

52

53
WINE_DEFAULT_DEBUG_CHANNEL(shell);
54

55 56 57 58 59
/* Get a function pointer from a DLL handle */
#define GET_FUNC(func, module, name, fail) \
  do { \
    if (!func) { \
      if (!SHLWAPI_h##module && !(SHLWAPI_h##module = LoadLibraryA(#module ".dll"))) return fail; \
60 61
      func = (fn##func)GetProcAddress(SHLWAPI_h##module, name); \
      if (!func) return fail; \
62 63 64 65
    } \
  } while (0)

/* DLL handles for late bound calls */
66
extern HINSTANCE shlwapi_hInstance;
67 68 69
extern HMODULE SHLWAPI_hshell32;
extern HMODULE SHLWAPI_hwinmm;
extern HMODULE SHLWAPI_hcomdlg32;
70
extern HMODULE SHLWAPI_hcomctl32;
71
extern HMODULE SHLWAPI_hmpr;
72
extern HMODULE SHLWAPI_hurlmon;
73 74 75
extern HMODULE SHLWAPI_hversion;

extern DWORD SHLWAPI_ThreadRef_index;
76

77 78 79 80
/* following is GUID for IObjectWithSite::SetSite  -- see _174           */
static DWORD id1[4] = {0xfc4801a3, 0x11cf2ba9, 0xaa0029a2, 0x52733d00};
/* following is GUID for IPersistMoniker::GetClassID  -- see _174        */
static DWORD id2[4] = {0x79eac9ee, 0x11cebaf9, 0xaa00828c, 0x0ba94b00};
Guy Albertelli's avatar
Guy Albertelli committed
81

82
/* Function pointers for GET_FUNC macro; these need to be global because of gcc bug */
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
typedef LPITEMIDLIST (WINAPI *fnpSHBrowseForFolderW)(LPBROWSEINFOW);
static  fnpSHBrowseForFolderW pSHBrowseForFolderW;
typedef BOOL    (WINAPI *fnpPlaySoundW)(LPCWSTR, HMODULE, DWORD);
static  fnpPlaySoundW pPlaySoundW;
typedef DWORD   (WINAPI *fnpSHGetFileInfoW)(LPCWSTR,DWORD,SHFILEINFOW*,UINT,UINT);
static  fnpSHGetFileInfoW pSHGetFileInfoW;
typedef UINT    (WINAPI *fnpDragQueryFileW)(HDROP, UINT, LPWSTR, UINT);
static  fnpDragQueryFileW pDragQueryFileW;
typedef BOOL    (WINAPI *fnpSHGetPathFromIDListW)(LPCITEMIDLIST, LPWSTR);
static  fnpSHGetPathFromIDListW pSHGetPathFromIDListW;
typedef BOOL    (WINAPI *fnpShellExecuteExW)(LPSHELLEXECUTEINFOW);
static  fnpShellExecuteExW pShellExecuteExW;
typedef HICON   (WINAPI *fnpSHFileOperationW)(LPSHFILEOPSTRUCTW);
static  fnpSHFileOperationW pSHFileOperationW;
typedef UINT    (WINAPI *fnpExtractIconExW)(LPCWSTR, INT,HICON *,HICON *, UINT);
static  fnpExtractIconExW pExtractIconExW;
typedef BOOL    (WINAPI *fnpSHGetNewLinkInfoW)(LPCWSTR, LPCWSTR, LPCWSTR, BOOL*, UINT);
static  fnpSHGetNewLinkInfoW pSHGetNewLinkInfoW;
typedef HRESULT (WINAPI *fnpSHDefExtractIconW)(LPCWSTR, int, UINT, HICON*, HICON*, UINT);
static  fnpSHDefExtractIconW pSHDefExtractIconW;
typedef HICON   (WINAPI *fnpExtractIconW)(HINSTANCE, LPCWSTR, UINT);
static  fnpExtractIconW pExtractIconW;
typedef BOOL    (WINAPI *fnpGetSaveFileNameW)(LPOPENFILENAMEW);
static  fnpGetSaveFileNameW pGetSaveFileNameW;
typedef DWORD   (WINAPI *fnpWNetRestoreConnectionW)(HWND, LPWSTR);
static  fnpWNetRestoreConnectionW pWNetRestoreConnectionW;
typedef DWORD   (WINAPI *fnpWNetGetLastErrorW)(LPDWORD, LPWSTR, DWORD, LPWSTR, DWORD);
static  fnpWNetGetLastErrorW pWNetGetLastErrorW;
typedef BOOL    (WINAPI *fnpPageSetupDlgW)(LPPAGESETUPDLGW);
static  fnpPageSetupDlgW pPageSetupDlgW;
typedef BOOL    (WINAPI *fnpPrintDlgW)(LPPRINTDLGW);
static  fnpPrintDlgW pPrintDlgW;
typedef BOOL    (WINAPI *fnpGetOpenFileNameW)(LPOPENFILENAMEW);
static  fnpGetOpenFileNameW pGetOpenFileNameW;
typedef DWORD   (WINAPI *fnpGetFileVersionInfoSizeW)(LPCWSTR,LPDWORD);
static  fnpGetFileVersionInfoSizeW pGetFileVersionInfoSizeW;
typedef BOOL    (WINAPI *fnpGetFileVersionInfoW)(LPCWSTR,DWORD,DWORD,LPVOID);
static  fnpGetFileVersionInfoW pGetFileVersionInfoW;
typedef WORD    (WINAPI *fnpVerQueryValueW)(LPVOID,LPCWSTR,LPVOID*,UINT*);
static  fnpVerQueryValueW pVerQueryValueW;
typedef BOOL    (WINAPI *fnpCOMCTL32_417)(HDC,INT,INT,UINT,const RECT*,LPCWSTR,UINT,const INT*);
static  fnpCOMCTL32_417 pCOMCTL32_417;
typedef HRESULT (WINAPI *fnpDllGetVersion)(DLLVERSIONINFO*);
static  fnpDllGetVersion pDllGetVersion;
typedef HRESULT (WINAPI *fnpCreateFormatEnumerator)(UINT,FORMATETC*,IEnumFORMATETC**);
static fnpCreateFormatEnumerator pCreateFormatEnumerator;
typedef HRESULT (WINAPI *fnpRegisterFormatEnumerator)(LPBC,IEnumFORMATETC*,DWORD);
static fnpRegisterFormatEnumerator pRegisterFormatEnumerator;

132 133 134 135
HRESULT WINAPI IUnknown_QueryService(IUnknown*,REFGUID,REFIID,LPVOID*);
HRESULT WINAPI SHInvokeCommand(HWND,IShellFolder*,LPCITEMIDLIST,BOOL);
HRESULT WINAPI CLSIDFromStringWrap(LPCWSTR,CLSID*);
BOOL    WINAPI SHAboutInfoW(LPWSTR,DWORD);
136

137
/*
138
 NOTES: Most functions exported by ordinal seem to be superflous.
139
 The reason for these functions to be there is to provide a wrapper
140
 for unicode functions to provide these functions on systems without
141
 unicode functions eg. win95/win98. Since we have such functions we just
142
 call these. If running Wine with native DLL's, some late bound calls may
143
 fail. However, it is better to implement the functions in the forward DLL
144
 and recommend the builtin rather than reimplementing the calls here!
145 146
*/

147
/*************************************************************************
148 149 150
 * SHLWAPI_DupSharedHandle
 *
 * Internal implemetation of SHLWAPI_11.
151
 */
152
static
153
HANDLE WINAPI SHLWAPI_DupSharedHandle(HANDLE hShared, DWORD dwDstProcId,
154 155
                                       DWORD dwSrcProcId, DWORD dwAccess,
                                       DWORD dwOptions)
156
{
157 158
  HANDLE hDst, hSrc;
  DWORD dwMyProcId = GetCurrentProcessId();
159
  HANDLE hRet = NULL;
160

161
  TRACE("(%p,%ld,%ld,%08lx,%08lx)\n", hShared, dwDstProcId, dwSrcProcId,
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
        dwAccess, dwOptions);

  /* Get dest process handle */
  if (dwDstProcId == dwMyProcId)
    hDst = GetCurrentProcess();
  else
    hDst = OpenProcess(PROCESS_DUP_HANDLE, 0, dwDstProcId);

  if (hDst)
  {
    /* Get src process handle */
    if (dwSrcProcId == dwMyProcId)
      hSrc = GetCurrentProcess();
    else
      hSrc = OpenProcess(PROCESS_DUP_HANDLE, 0, dwSrcProcId);

    if (hSrc)
    {
      /* Make handle available to dest process */
181
      if (!DuplicateHandle(hDst, hShared, hSrc, &hRet,
182
                           dwAccess, 0, dwOptions | DUPLICATE_SAME_ACCESS))
183
        hRet = NULL;
184 185 186 187 188 189 190 191 192

      if (dwSrcProcId != dwMyProcId)
        CloseHandle(hSrc);
    }

    if (dwDstProcId != dwMyProcId)
      CloseHandle(hDst);
  }

193
  TRACE("Returning handle %p\n", hRet);
194
  return hRet;
195 196 197
}

/*************************************************************************
198 199 200 201 202 203 204
 * @  [SHLWAPI.7]
 *
 * Create a block of sharable memory and initialise it with data.
 *
 * PARAMS
 * lpvData  [I] Pointer to data to write
 * dwSize   [I] Size of data
205
 * dwProcId [I] ID of process owning data
206 207 208 209 210 211 212 213 214 215 216 217
 *
 * RETURNS
 * Success: A shared memory handle
 * Failure: NULL
 *
 * NOTES
 * Ordinals 7-11 provide a set of calls to create shared memory between a
 * group of processes. The shared memory is treated opaquely in that its size
 * is not exposed to clients who map it. This is accomplished by storing
 * the size of the map as the first DWORD of mapped data, and then offsetting
 * the view pointer returned by this size.
 *
218
 */
219
HANDLE WINAPI SHAllocShared(LPCVOID lpvData, DWORD dwSize, DWORD dwProcId)
220 221 222
{
  HANDLE hMap;
  LPVOID pMapped;
223
  HANDLE hRet = NULL;
224

225
  TRACE("(%p,%ld,%ld)\n", lpvData, dwSize, dwProcId);
226 227 228 229 230 231 232 233 234 235 236 237 238 239

  /* Create file mapping of the correct length */
  hMap = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, FILE_MAP_READ, 0,
                            dwSize + sizeof(dwSize), NULL);
  if (!hMap)
    return hRet;

  /* Get a view in our process address space */
  pMapped = MapViewOfFile(hMap, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0);

  if (pMapped)
  {
    /* Write size of data, followed by the data, to the view */
    *((DWORD*)pMapped) = dwSize;
240
    if (lpvData)
Patrik Stridvall's avatar
Patrik Stridvall committed
241
      memcpy((char *) pMapped + sizeof(dwSize), lpvData, dwSize);
242 243 244

    /* Release view. All further views mapped will be opaque */
    UnmapViewOfFile(pMapped);
245
    hRet = SHLWAPI_DupSharedHandle(hMap, dwProcId,
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
                                   GetCurrentProcessId(), FILE_MAP_ALL_ACCESS,
                                   DUPLICATE_SAME_ACCESS);
  }

  CloseHandle(hMap);
  return hRet;
}

/*************************************************************************
 * @ [SHLWAPI.8]
 *
 * Get a pointer to a block of shared memory from a shared memory handle.
 *
 * PARAMS
 * hShared  [I] Shared memory handle
 * dwProcId [I] ID of process owning hShared
 *
 * RETURNS
 * Success: A pointer to the shared memory
 * Failure: NULL
 *
267
 */
268
PVOID WINAPI SHLockShared(HANDLE hShared, DWORD dwProcId)
269
{
270
  HANDLE hDup;
271 272
  LPVOID pMapped;

273
  TRACE("(%p %ld)\n", hShared, dwProcId);
274 275 276 277 278

  /* Get handle to shared memory for current process */
  hDup = SHLWAPI_DupSharedHandle(hShared, dwProcId, GetCurrentProcessId(),
                                 FILE_MAP_ALL_ACCESS, 0);
  /* Get View */
279
  pMapped = MapViewOfFile(hDup, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0);
280 281 282
  CloseHandle(hDup);

  if (pMapped)
Patrik Stridvall's avatar
Patrik Stridvall committed
283
    return (char *) pMapped + sizeof(DWORD); /* Hide size */
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
  return NULL;
}

/*************************************************************************
 * @ [SHLWAPI.9]
 *
 * Release a pointer to a block of shared memory.
 *
 * PARAMS
 * lpView [I] Shared memory pointer
 *
 * RETURNS
 * Success: TRUE
 * Failure: FALSE
 *
299
 */
300
BOOL WINAPI SHUnlockShared(LPVOID lpView)
301
{
302
  TRACE("(%p)\n", lpView);
Patrik Stridvall's avatar
Patrik Stridvall committed
303
  return UnmapViewOfFile((char *) lpView - sizeof(DWORD)); /* Include size */
304 305 306
}

/*************************************************************************
307 308 309 310 311 312 313 314 315 316 317 318
 * @ [SHLWAPI.10]
 *
 * Destroy a block of sharable memory.
 *
 * PARAMS
 * hShared  [I] Shared memory handle
 * dwProcId [I] ID of process owning hShared
 *
 * RETURNS
 * Success: TRUE
 * Failure: FALSE
 *
319
 */
320
BOOL WINAPI SHFreeShared(HANDLE hShared, DWORD dwProcId)
321
{
322
  HANDLE hClose;
323

324
  TRACE("(%p %ld)\n", hShared, dwProcId);
325 326 327 328 329

  /* Get a copy of the handle for our process, closing the source handle */
  hClose = SHLWAPI_DupSharedHandle(hShared, dwProcId, GetCurrentProcessId(),
                                   FILE_MAP_ALL_ACCESS,DUPLICATE_CLOSE_SOURCE);
  /* Close local copy */
330
  return CloseHandle(hClose);
331 332 333 334 335 336 337 338 339 340 341
}

/*************************************************************************
 * @   [SHLWAPI.11]
 *
 * Copy a sharable memory handle from one process to another.
 *
 * PARAMS
 * hShared     [I] Shared memory handle to duplicate
 * dwDstProcId [I] ID of the process wanting the duplicated handle
 * dwSrcProcId [I] ID of the process owning hShared
342 343
 * dwAccess    [I] Desired DuplicateHandle() access
 * dwOptions   [I] Desired DuplicateHandle() options
344 345 346 347 348 349
 *
 * RETURNS
 * Success: A handle suitable for use by the dwDstProcId process.
 * Failure: A NULL handle.
 *
 */
350
HANDLE WINAPI SHMapHandle(HANDLE hShared, DWORD dwDstProcId, DWORD dwSrcProcId,
351 352
                          DWORD dwAccess, DWORD dwOptions)
{
353
  HANDLE hRet;
354 355 356 357

  hRet = SHLWAPI_DupSharedHandle(hShared, dwDstProcId, dwSrcProcId,
                                 dwAccess, dwOptions);
  return hRet;
358 359 360 361
}

/*************************************************************************
 *      @	[SHLWAPI.13]
362 363 364 365 366 367 368 369 370 371 372 373 374 375
 *
 * Create and register a clipboard enumerator for a web browser.
 *
 * PARAMS
 *  lpBC      [I] Binding context
 *  lpUnknown [I] An object exposing the IWebBrowserApp interface
 *
 * RETURNS
 *  Success: S_OK.
 *  Failure: An HRESULT error code.
 *
 * NOTES
 *  The enumerator is stored as a property of the web browser. If it does not
 *  yet exist, it is created and set before being registered.
376
 */
377
HRESULT WINAPI RegisterDefaultAcceptHeaders(LPBC lpBC, IUnknown *lpUnknown)
378
{
379 380 381 382 383 384 385
  static const WCHAR szProperty[] = { '{','D','0','F','C','A','4','2','0',
      '-','D','3','F','5','-','1','1','C','F', '-','B','2','1','1','-','0',
      '0','A','A','0','0','4','A','E','8','3','7','}','\0' };
  IEnumFORMATETC* pIEnumFormatEtc = NULL;
  VARIANTARG var;
  HRESULT hRet;
  IWebBrowserApp* pBrowser = NULL;
386

387 388
  TRACE("(%p, %p)\n", lpBC, lpUnknown);

389
  /* Get An IWebBrowserApp interface from  lpUnknown */
390
  hRet = IUnknown_QueryService(lpUnknown, &IID_IWebBrowserApp, &IID_IWebBrowserApp, (PVOID)&pBrowser);
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479
  if (FAILED(hRet) || !pBrowser)
    return E_NOINTERFACE;

  V_VT(&var) = VT_EMPTY;

  /* The property we get is the browsers clipboard enumerator */
  hRet = IWebBrowserApp_GetProperty(pBrowser, (BSTR)szProperty, &var);
  if (FAILED(hRet))
    return hRet;

  if (V_VT(&var) == VT_EMPTY)
  {
    /* Iterate through accepted documents and RegisterClipBoardFormatA() them */
    char szKeyBuff[128], szValueBuff[128];
    DWORD dwKeySize, dwValueSize, dwRet = 0, dwCount = 0, dwNumValues, dwType;
    FORMATETC* formatList, *format;
    HKEY hDocs;

    TRACE("Registering formats and creating IEnumFORMATETC instance\n");

    if (!RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\Current"
                     "Version\\Internet Settings\\Accepted Documents", &hDocs))
      return E_FAIL;

    /* Get count of values in key */
    while (!dwRet)
    {
      dwKeySize = sizeof(szKeyBuff);
      dwRet = RegEnumValueA(hDocs,dwCount,szKeyBuff,&dwKeySize,0,&dwType,0,0);
      dwCount++;
    }

    dwNumValues = dwCount;

    /* Note: dwCount = number of items + 1; The extra item is the end node */
    format = formatList = HeapAlloc(GetProcessHeap(), 0, dwCount * sizeof(FORMATETC));
    if (!formatList)
      return E_OUTOFMEMORY;

    if (dwNumValues > 1)
    {
      dwRet = 0;
      dwCount = 0;

      dwNumValues--;

      /* Register clipboard formats for the values and populate format list */
      while(!dwRet && dwCount < dwNumValues)
      {
        dwKeySize = sizeof(szKeyBuff);
        dwValueSize = sizeof(szValueBuff);
        dwRet = RegEnumValueA(hDocs, dwCount, szKeyBuff, &dwKeySize, 0, &dwType,
                              (PBYTE)szValueBuff, &dwValueSize);
        if (!dwRet)
          return E_FAIL;

        format->cfFormat = RegisterClipboardFormatA(szValueBuff);
        format->ptd = NULL;
        format->dwAspect = 1;
        format->lindex = 4;
        format->tymed = -1;

        format++;
        dwCount++;
      }
    }

    /* Terminate the (maybe empty) list, last entry has a cfFormat of 0 */
    format->cfFormat = 0;
    format->ptd = NULL;
    format->dwAspect = 1;
    format->lindex = 4;
    format->tymed = -1;

    /* Create a clipboard enumerator */
    GET_FUNC(pCreateFormatEnumerator, urlmon, "CreateFormatEnumerator", E_FAIL);
    hRet = pCreateFormatEnumerator(dwNumValues, formatList, &pIEnumFormatEtc);

    if (FAILED(hRet) || !pIEnumFormatEtc)
      return hRet;

    /* Set our enumerator as the browsers property */
    V_VT(&var) = VT_UNKNOWN;
    V_UNKNOWN(&var) = (IUnknown*)pIEnumFormatEtc;

    hRet = IWebBrowserApp_PutProperty(pBrowser, (BSTR)szProperty, var);
    if (FAILED(hRet))
    {
       IEnumFORMATETC_Release(pIEnumFormatEtc);
480
       goto RegisterDefaultAcceptHeaders_Exit;
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513
    }
  }

  if (V_VT(&var) == VT_UNKNOWN)
  {
    /* Our variant is holding the clipboard enumerator */
    IUnknown* pIUnknown = V_UNKNOWN(&var);
    IEnumFORMATETC* pClone = NULL;

    TRACE("Retrieved IEnumFORMATETC property\n");

    /* Get an IEnumFormatEtc interface from the variants value */
    pIEnumFormatEtc = NULL;
    hRet = IUnknown_QueryInterface(pIUnknown, &IID_IEnumFORMATETC,
                                   (PVOID)&pIEnumFormatEtc);
    if (!hRet && pIEnumFormatEtc)
    {
      /* Clone and register the enumerator */
      hRet = IEnumFORMATETC_Clone(pIEnumFormatEtc, &pClone);
      if (!hRet && pClone)
      {
        GET_FUNC(pRegisterFormatEnumerator, urlmon, "RegisterFormatEnumerator", E_FAIL);
        pRegisterFormatEnumerator(lpBC, pClone, 0);

        IEnumFORMATETC_Release(pClone);
      }

      /* Release the IEnumFormatEtc interface */
      IEnumFORMATETC_Release(pIUnknown);
    }
    IUnknown_Release(V_UNKNOWN(&var));
  }

514
RegisterDefaultAcceptHeaders_Exit:
515 516
  IWebBrowserApp_Release(pBrowser);
  return hRet;
517 518 519
}

/*************************************************************************
520
 *      @	[SHLWAPI.15]
521
 *
522
 * Get Explorers "AcceptLanguage" setting.
523
 *
524 525 526
 * PARAMS
 *  langbuf [O] Destination for language string
 *  buflen  [I] Length of langbuf
527
 *          [0] Success: used length of langbuf
528 529 530 531 532
 *
 * RETURNS
 *  Success: S_OK.   langbuf is set to the language string found.
 *  Failure: E_FAIL, If any arguments are invalid, error occurred, or Explorer
 *           does not contain the setting.
533
 *           E_INVALIDARG, If the buffer is not big enough
534
 */
535
HRESULT WINAPI GetAcceptLanguagesW( LPWSTR langbuf, LPDWORD buflen)
536
{
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575
    static const WCHAR szkeyW[] = {
	'S','o','f','t','w','a','r','e','\\',
	'M','i','c','r','o','s','o','f','t','\\',
	'I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r','\\',
	'I','n','t','e','r','n','a','t','i','o','n','a','l',0};
    static const WCHAR valueW[] = {
	'A','c','c','e','p','t','L','a','n','g','u','a','g','e',0};
    static const WCHAR enusW[] = {'e','n','-','u','s',0};
    DWORD mystrlen, mytype;
    HKEY mykey;
    HRESULT retval;
    LCID mylcid;
    WCHAR *mystr;

    if(!langbuf || !buflen || !*buflen)
	return E_FAIL;

    mystrlen = (*buflen > 20) ? *buflen : 20 ;
    mystr = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * mystrlen);
    RegOpenKeyW(HKEY_CURRENT_USER, szkeyW, &mykey);
    if(RegQueryValueExW(mykey, valueW, 0, &mytype, (PBYTE)mystr, &mystrlen)) {
        /* Did not find value */
        mylcid = GetUserDefaultLCID();
        /* somehow the mylcid translates into "en-us"
         *  this is similar to "LOCALE_SABBREVLANGNAME"
         *  which could be gotten via GetLocaleInfo.
         *  The only problem is LOCALE_SABBREVLANGUAGE" is
         *  a 3 char string (first 2 are country code and third is
         *  letter for "sublanguage", which does not come close to
         *  "en-us"
         */
        lstrcpyW(mystr, enusW);
        mystrlen = lstrlenW(mystr);
    } else {
        /* handle returned string */
        FIXME("missing code\n");
    }
    memcpy( langbuf, mystr, min(*buflen,strlenW(mystr)+1)*sizeof(WCHAR) );

576 577
    if(*buflen > strlenW(mystr)) {
	*buflen = strlenW(mystr);
578 579 580 581 582 583 584 585 586
	retval = S_OK;
    } else {
	*buflen = 0;
	retval = E_INVALIDARG;
	SetLastError(ERROR_INSUFFICIENT_BUFFER);
    }
    RegCloseKey(mykey);
    HeapFree(GetProcessHeap(), 0, mystr);
    return retval;
587 588
}

589
/*************************************************************************
590
 *      @	[SHLWAPI.14]
591
 *
592
 * Ascii version of GetAcceptLanguagesW.
593
 */
594
HRESULT WINAPI GetAcceptLanguagesA( LPSTR langbuf, LPDWORD buflen)
595
{
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610
    WCHAR *langbufW;
    DWORD buflenW, convlen;
    HRESULT retval;

    if(!langbuf || !buflen || !*buflen) return E_FAIL;

    buflenW = *buflen;
    langbufW = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * buflenW);
    retval = GetAcceptLanguagesW(langbufW, &buflenW);

    /* FIXME: this is wrong, the string may not be null-terminated */
    convlen = WideCharToMultiByte(CP_ACP, 0, langbufW, -1, langbuf,
                                  *buflen, NULL, NULL);
    *buflen = buflenW ? convlen : 0;

611
    HeapFree(GetProcessHeap(), 0, langbufW);
612
    return retval;
613 614
}

615
/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
616
 *      @	[SHLWAPI.23]
617
 *
618 619 620
 * Convert a GUID to a string.
 *
 * PARAMS
Jon Griffiths's avatar
Jon Griffiths committed
621 622 623
 *  guid     [I] GUID to convert
 *  lpszDest [O] Destination for string
 *  cchMax   [I] Length of output buffer
624 625 626
 *
 * RETURNS
 *  The length of the string created.
627
 */
628
INT WINAPI SHStringFromGUIDA(REFGUID guid, LPSTR lpszDest, INT cchMax)
629
{
630 631 632 633 634 635 636 637 638 639 640
  char xguid[40];
  INT iLen;

  TRACE("(%s,%p,%d)\n", debugstr_guid(guid), lpszDest, cchMax);

  sprintf(xguid, "{%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
          guid->Data1, guid->Data2, guid->Data3,
          guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
          guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);

  iLen = strlen(xguid) + 1;
641

642 643 644 645
  if (iLen > cchMax)
    return 0;
  memcpy(lpszDest, xguid, iLen);
  return iLen;
646 647 648
}

/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
649
 *      @	[SHLWAPI.24]
650
 *
Jacek Caban's avatar
Jacek Caban committed
651 652 653 654 655 656 657 658 659
 * Convert a GUID to a string.
 *
 * PARAMS
 *  guid [I] GUID to convert
 *  str  [O] Destination for string
 *  cmax [I] Length of output buffer
 *
 * RETURNS
 *  The length of the string created.
660
 */
661
INT WINAPI SHStringFromGUIDW(REFGUID guid, LPWSTR lpszDest, INT cchMax)
662
{
Jacek Caban's avatar
Jacek Caban committed
663 664 665 666 667 668 669
  WCHAR xguid[40];
  INT iLen;
  static const WCHAR wszFormat[] = {'{','%','0','8','l','X','-','%','0','4','X','-','%','0','4','X','-',
      '%','0','2','X','%','0','2','X','-','%','0','2','X','%','0','2','X','%','0','2','X','%','0','2',
      'X','%','0','2','X','%','0','2','X','}',0};

  TRACE("(%s,%p,%d)\n", debugstr_guid(guid), lpszDest, cchMax);
Jon Griffiths's avatar
Jon Griffiths committed
670

Jacek Caban's avatar
Jacek Caban committed
671 672 673 674 675 676 677 678 679
  sprintfW(xguid, wszFormat, guid->Data1, guid->Data2, guid->Data3,
          guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
          guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);

  iLen = strlenW(xguid) + 1;

  if (iLen > cchMax)
    return 0;
  memcpy(lpszDest, xguid, iLen*sizeof(WCHAR));
680
  return iLen;
681
}
682

683
/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
684
 *      @	[SHLWAPI.25]
685
 *
686 687 688 689 690 691 692 693
 * Determine if a Unicode character is alphabetic.
 *
 * PARAMS
 *  wc [I] Character to check.
 *
 * RETURNS
 *  TRUE, if wc is alphabetic,
 *  FALSE otherwise.
694
 */
695
BOOL WINAPI IsCharAlphaWrapW(WCHAR wc)
696
{
Guy Albertelli's avatar
Guy Albertelli committed
697
    return (get_char_typeW(wc) & C1_ALPHA) != 0;
698 699
}

700
/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
701
 *      @	[SHLWAPI.26]
702
 *
703 704 705 706 707 708 709 710
 * Determine if a Unicode character is upper-case.
 *
 * PARAMS
 *  wc [I] Character to check.
 *
 * RETURNS
 *  TRUE, if wc is upper-case,
 *  FALSE otherwise.
711
 */
712
BOOL WINAPI IsCharUpperWrapW(WCHAR wc)
713 714 715 716 717
{
    return (get_char_typeW(wc) & C1_UPPER) != 0;
}

/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
718
 *      @	[SHLWAPI.27]
719
 *
720 721 722 723 724 725 726 727
 * Determine if a Unicode character is lower-case.
 *
 * PARAMS
 *  wc [I] Character to check.
 *
 * RETURNS
 *  TRUE, if wc is lower-case,
 *  FALSE otherwise.
728
 */
729
BOOL WINAPI IsCharLowerWrapW(WCHAR wc)
730 731 732 733 734
{
    return (get_char_typeW(wc) & C1_LOWER) != 0;
}

/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
735
 *      @	[SHLWAPI.28]
736
 *
737 738 739 740 741 742 743 744
 * Determine if a Unicode character is alphabetic or a digit.
 *
 * PARAMS
 *  wc [I] Character to check.
 *
 * RETURNS
 *  TRUE, if wc is alphabetic or a digit,
 *  FALSE otherwise.
745
 */
746
BOOL WINAPI IsCharAlphaNumericWrapW(WCHAR wc)
747 748 749 750
{
    return (get_char_typeW(wc) & (C1_ALPHA|C1_DIGIT)) != 0;
}

751
/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
752
 *      @	[SHLWAPI.29]
753
 *
754 755 756 757 758 759 760 761
 * Determine if a Unicode character is a space.
 *
 * PARAMS
 *  wc [I] Character to check.
 *
 * RETURNS
 *  TRUE, if wc is a space,
 *  FALSE otherwise.
762
 */
763
BOOL WINAPI IsCharSpaceW(WCHAR wc)
764 765 766 767
{
    return (get_char_typeW(wc) & C1_SPACE) != 0;
}

768
/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
769
 *      @	[SHLWAPI.30]
770
 *
771 772 773 774 775 776 777 778 779
 * Determine if a Unicode character is a blank.
 *
 * PARAMS
 *  wc [I] Character to check.
 *
 * RETURNS
 *  TRUE, if wc is a blank,
 *  FALSE otherwise.
 *
780
 */
781
BOOL WINAPI IsCharBlankW(WCHAR wc)
782
{
783 784 785 786
    return (get_char_typeW(wc) & C1_BLANK) != 0;
}

/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
787
 *      @	[SHLWAPI.31]
788
 *
789 790 791 792 793 794 795 796
 * Determine if a Unicode character is punctuation.
 *
 * PARAMS
 *  wc [I] Character to check.
 *
 * RETURNS
 *  TRUE, if wc is punctuation,
 *  FALSE otherwise.
797
 */
798
BOOL WINAPI IsCharPunctW(WCHAR wc)
799 800
{
    return (get_char_typeW(wc) & C1_PUNCT) != 0;
801
}
802

803
/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
804
 *      @	[SHLWAPI.32]
805
 *
806 807 808 809 810 811 812 813
 * Determine if a Unicode character is a control character.
 *
 * PARAMS
 *  wc [I] Character to check.
 *
 * RETURNS
 *  TRUE, if wc is a control character,
 *  FALSE otherwise.
814
 */
815
BOOL WINAPI IsCharCntrlW(WCHAR wc)
816
{
817
    return (get_char_typeW(wc) & C1_CNTRL) != 0;
818 819
}

820
/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
821
 *      @	[SHLWAPI.33]
822
 *
823 824 825 826 827 828 829 830
 * Determine if a Unicode character is a digit.
 *
 * PARAMS
 *  wc [I] Character to check.
 *
 * RETURNS
 *  TRUE, if wc is a digit,
 *  FALSE otherwise.
831
 */
832
BOOL WINAPI IsCharDigitW(WCHAR wc)
833
{
Guy Albertelli's avatar
Guy Albertelli committed
834
    return (get_char_typeW(wc) & C1_DIGIT) != 0;
835 836
}

837
/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
838
 *      @	[SHLWAPI.34]
839
 *
840 841 842 843 844 845 846 847
 * Determine if a Unicode character is a hex digit.
 *
 * PARAMS
 *  wc [I] Character to check.
 *
 * RETURNS
 *  TRUE, if wc is a hex digit,
 *  FALSE otherwise.
848
 */
849
BOOL WINAPI IsCharXDigitW(WCHAR wc)
850 851 852 853
{
    return (get_char_typeW(wc) & C1_XDIGIT) != 0;
}

854
/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
855
 *      @	[SHLWAPI.35]
856 857
 *
 */
858
BOOL WINAPI GetStringType3ExW(LPWSTR lpszStr, DWORD dwLen, LPVOID p3)
859
{
860
    FIXME("(%s,0x%08lx,%p): stub\n", debugstr_w(lpszStr), dwLen, p3);
861 862 863
    return TRUE;
}

864
/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
865
 *      @	[SHLWAPI.36]
866
 *
867 868 869 870 871 872 873 874 875 876 877
 * Insert a bitmap menu item at the bottom of a menu.
 *
 * PARAMS
 *  hMenu [I] Menu to insert into
 *  flags [I] Flags for insertion
 *  id    [I] Menu ID of the item
 *  str   [I] Menu text for the item
 *
 * RETURNS
 *  Success: TRUE,  the item is inserted into the menu
 *  Failure: FALSE, if any parameter is invalid
878
 */
879
BOOL WINAPI AppendMenuWrapW(HMENU hMenu, UINT flags, UINT id, LPCWSTR str)
880
{
881
    TRACE("(%p,0x%08x,0x%08x,%s)\n",hMenu, flags, id, debugstr_w(str));
882
    return InsertMenuW(hMenu, -1, flags | MF_BITMAP, id, str);
883 884
}

885
/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
886
 *      @	[SHLWAPI.74]
887 888
 *
 * Get the text from a given dialog item.
889 890 891 892 893 894 895 896 897 898
 *
 * PARAMS
 *  hWnd     [I] Handle of dialog
 *  nItem    [I] Index of item
 *  lpsDest  [O] Buffer for receiving window text
 *  nDestLen [I] Length of buffer.
 *
 * RETURNS
 *  Success: The length of the returned text.
 *  Failure: 0.
899
 */
900
INT WINAPI GetDlgItemTextWrapW(HWND hWnd, INT nItem, LPWSTR lpsDest,INT nDestLen)
901 902 903 904 905 906 907
{
  HWND hItem = GetDlgItem(hWnd, nItem);

  if (hItem)
    return GetWindowTextW(hItem, lpsDest, nDestLen);
  if (nDestLen)
    *lpsDest = (WCHAR)'\0';
908
  return 0;
909
}
910

911 912 913
/*************************************************************************
 *      @   [SHLWAPI.138]
 *
914 915 916 917 918 919 920 921 922 923
 * Set the text of a given dialog item.
 *
 * PARAMS
 *  hWnd     [I] Handle of dialog
 *  iItem    [I] Index of item
 *  lpszText [O] Text to set
 *
 * RETURNS
 *  Success: TRUE.  The text of the dialog is set to lpszText.
 *  Failure: FALSE, Otherwise.
924
 */
925
BOOL WINAPI SetDlgItemTextWrapW(HWND hWnd, INT iItem, LPCWSTR lpszText)
926 927 928 929 930 931 932
{
    HWND hWndItem = GetDlgItem(hWnd, iItem);
    if (hWndItem)
        return SetWindowTextW(hWndItem, lpszText);
    return FALSE;
}

933
/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
934
 *      @	[SHLWAPI.151]
935 936 937 938 939 940 941 942 943 944 945
 *
 * Compare two Ascii strings up to a given length.
 *
 * PARAMS
 *  lpszSrc [I] Source string
 *  lpszCmp [I] String to compare to lpszSrc
 *  len     [I] Maximum length
 *
 * RETURNS
 *  A number greater than, less than or equal to 0 depending on whether
 *  lpszSrc is greater than, less than or equal to lpszCmp.
946
 */
947
DWORD WINAPI StrCmpNCA(LPCSTR lpszSrc, LPCSTR lpszCmp, INT len)
948
{
949
    return strncmp(lpszSrc, lpszCmp, len);
950 951
}

952
/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
953
 *      @	[SHLWAPI.152]
954
 *
955
 * Unicode version of StrCmpNCA.
956
 */
957
DWORD WINAPI StrCmpNCW(LPCWSTR lpszSrc, LPCWSTR lpszCmp, INT len)
958
{
959
    return strncmpW(lpszSrc, lpszCmp, len);
960 961
}

962
/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
963
 *      @	[SHLWAPI.153]
964 965 966 967 968 969 970 971 972 973 974
 *
 * Compare two Ascii strings up to a given length, ignoring case.
 *
 * PARAMS
 *  lpszSrc [I] Source string
 *  lpszCmp [I] String to compare to lpszSrc
 *  len     [I] Maximum length
 *
 * RETURNS
 *  A number greater than, less than or equal to 0 depending on whether
 *  lpszSrc is greater than, less than or equal to lpszCmp.
975
 */
976
DWORD WINAPI StrCmpNICA(LPCSTR lpszSrc, LPCSTR lpszCmp, DWORD len)
977
{
978
    return strncasecmp(lpszSrc, lpszCmp, len);
979 980 981 982 983
}

/*************************************************************************
 *      @	[SHLWAPI.154]
 *
984
 * Unicode version of StrCmpNICA.
985
 */
986
DWORD WINAPI StrCmpNICW(LPCWSTR lpszSrc, LPCWSTR lpszCmp, DWORD len)
987
{
988
    return strncmpiW(lpszSrc, lpszCmp, len);
989 990
}

991 992 993
/*************************************************************************
 *      @	[SHLWAPI.155]
 *
994 995 996 997 998 999 1000 1001 1002
 * Compare two Ascii strings.
 *
 * PARAMS
 *  lpszSrc [I] Source string
 *  lpszCmp [I] String to compare to lpszSrc
 *
 * RETURNS
 *  A number greater than, less than or equal to 0 depending on whether
 *  lpszSrc is greater than, less than or equal to lpszCmp.
1003
 */
1004
DWORD WINAPI StrCmpCA(LPCSTR lpszSrc, LPCSTR lpszCmp)
1005
{
1006
    return strcmp(lpszSrc, lpszCmp);
1007 1008
}

1009
/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
1010
 *      @	[SHLWAPI.156]
1011
 *
1012
 * Unicode version of StrCmpCA.
1013
 */
1014
DWORD WINAPI StrCmpCW(LPCWSTR lpszSrc, LPCWSTR lpszCmp)
1015
{
1016
    return strcmpW(lpszSrc, lpszCmp);
1017 1018
}

1019 1020 1021
/*************************************************************************
 *      @	[SHLWAPI.157]
 *
1022 1023 1024 1025 1026 1027 1028 1029 1030
 * Compare two Ascii strings, ignoring case.
 *
 * PARAMS
 *  lpszSrc [I] Source string
 *  lpszCmp [I] String to compare to lpszSrc
 *
 * RETURNS
 *  A number greater than, less than or equal to 0 depending on whether
 *  lpszSrc is greater than, less than or equal to lpszCmp.
1031
 */
1032
DWORD WINAPI StrCmpICA(LPCSTR lpszSrc, LPCSTR lpszCmp)
1033
{
1034
    return strcasecmp(lpszSrc, lpszCmp);
1035
}
1036

1037 1038 1039
/*************************************************************************
 *      @	[SHLWAPI.158]
 *
1040
 * Unicode version of StrCmpICA.
1041
 */
1042
DWORD WINAPI StrCmpICW(LPCWSTR lpszSrc, LPCWSTR lpszCmp)
1043 1044 1045 1046 1047
{
    return strcmpiW(lpszSrc, lpszCmp);
}

/*************************************************************************
1048
 *      @	[SHLWAPI.160]
1049 1050 1051 1052 1053 1054 1055 1056 1057 1058
 *
 * Get an identification string for the OS and explorer.
 *
 * PARAMS
 *  lpszDest  [O] Destination for Id string
 *  dwDestLen [I] Length of lpszDest
 *
 * RETURNS
 *  TRUE,  If the string was created successfully
 *  FALSE, Otherwise
1059
 */
1060
BOOL WINAPI SHAboutInfoA(LPSTR lpszDest, DWORD dwDestLen)
1061
{
1062 1063
  WCHAR buff[2084];

1064
  TRACE("(%p,%ld)\n", lpszDest, dwDestLen);
1065

1066
  if (lpszDest && SHAboutInfoW(buff, dwDestLen))
1067 1068 1069 1070 1071 1072 1073 1074
  {
    WideCharToMultiByte(CP_ACP, 0, buff, -1, lpszDest, dwDestLen, NULL, NULL);
    return TRUE;
  }
  return FALSE;
}

/*************************************************************************
1075
 *      @	[SHLWAPI.161]
1076
 *
1077
 * Unicode version of SHAboutInfoA.
1078
 */
1079
BOOL WINAPI SHAboutInfoW(LPWSTR lpszDest, DWORD dwDestLen)
1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109
{
  static const WCHAR szIEKey[] = { 'S','O','F','T','W','A','R','E','\\',
    'M','i','c','r','o','s','o','f','t','\\','I','n','t','e','r','n','e','t',
    ' ','E','x','p','l','o','r','e','r','\0' };
  static const WCHAR szWinNtKey[] = { 'S','O','F','T','W','A','R','E','\\',
    'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s',' ',
    'N','T','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\0' };
  static const WCHAR szWinKey[] = { 'S','O','F','T','W','A','R','E','\\',
    'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
    'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\0' };
  static const WCHAR szRegKey[] = { 'S','O','F','T','W','A','R','E','\\',
    'M','i','c','r','o','s','o','f','t','\\','I','n','t','e','r','n','e','t',
    ' ','E','x','p','l','o','r','e','r','\\',
    'R','e','g','i','s','t','r','a','t','i','o','n','\0' };
  static const WCHAR szVersion[] = { 'V','e','r','s','i','o','n','\0' };
  static const WCHAR szCustomized[] = { 'C','u','s','t','o','m','i','z','e','d',
    'V','e','r','s','i','o','n','\0' };
  static const WCHAR szOwner[] = { 'R','e','g','i','s','t','e','r','e','d',
    'O','w','n','e','r','\0' };
  static const WCHAR szOrg[] = { 'R','e','g','i','s','t','e','r','e','d',
    'O','r','g','a','n','i','z','a','t','i','o','n','\0' };
  static const WCHAR szProduct[] = { 'P','r','o','d','u','c','t','I','d','\0' };
  static const WCHAR szUpdate[] = { 'I','E','A','K',
    'U','p','d','a','t','e','U','r','l','\0' };
  static const WCHAR szHelp[] = { 'I','E','A','K',
    'H','e','l','p','S','t','r','i','n','g','\0' };
  WCHAR buff[2084];
  HKEY hReg;
  DWORD dwType, dwLen;

1110
  TRACE("(%p,%ld)\n", lpszDest, dwDestLen);
1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172

  if (!lpszDest)
    return FALSE;

  *lpszDest = '\0';

  /* Try the NT key first, followed by 95/98 key */
  if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, szWinNtKey, 0, KEY_READ, &hReg) &&
      RegOpenKeyExW(HKEY_LOCAL_MACHINE, szWinKey, 0, KEY_READ, &hReg))
    return FALSE;

  /* OS Version */
  buff[0] = '\0';
  dwLen = 30;
  if (!SHGetValueW(HKEY_LOCAL_MACHINE, szIEKey, szVersion, &dwType, buff, &dwLen))
  {
    DWORD dwStrLen = strlenW(buff);
    dwLen = 30 - dwStrLen;
    SHGetValueW(HKEY_LOCAL_MACHINE, szIEKey,
                szCustomized, &dwType, buff+dwStrLen, &dwLen);
  }
  StrCatBuffW(lpszDest, buff, dwDestLen);

  /* ~Registered Owner */
  buff[0] = '~';
  dwLen = 256;
  if (SHGetValueW(hReg, szOwner, 0, &dwType, buff+1, &dwLen))
    buff[1] = '\0';
  StrCatBuffW(lpszDest, buff, dwDestLen);

  /* ~Registered Organization */
  dwLen = 256;
  if (SHGetValueW(hReg, szOrg, 0, &dwType, buff+1, &dwLen))
    buff[1] = '\0';
  StrCatBuffW(lpszDest, buff, dwDestLen);

  /* FIXME: Not sure where this number comes from  */
  buff[0] = '~';
  buff[1] = '0';
  buff[2] = '\0';
  StrCatBuffW(lpszDest, buff, dwDestLen);

  /* ~Product Id */
  dwLen = 256;
  if (SHGetValueW(HKEY_LOCAL_MACHINE, szRegKey, szProduct, &dwType, buff+1, &dwLen))
    buff[1] = '\0';
  StrCatBuffW(lpszDest, buff, dwDestLen);

  /* ~IE Update Url */
  dwLen = 2048;
  if(SHGetValueW(HKEY_LOCAL_MACHINE, szWinKey, szUpdate, &dwType, buff+1, &dwLen))
    buff[1] = '\0';
  StrCatBuffW(lpszDest, buff, dwDestLen);

  /* ~IE Help String */
  dwLen = 256;
  if(SHGetValueW(hReg, szHelp, 0, &dwType, buff+1, &dwLen))
    buff[1] = '\0';
  StrCatBuffW(lpszDest, buff, dwDestLen);

  RegCloseKey(hReg);
  return TRUE;
1173 1174
}

1175
/*************************************************************************
1176 1177
 *      @	[SHLWAPI.163]
 *
1178
 * Call IOleCommandTarget_QueryStatus() on an object.
1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190
 *
 * PARAMS
 *  lpUnknown     [I] Object supporting the IOleCommandTarget interface
 *  pguidCmdGroup [I] GUID for the command group
 *  cCmds         [I]
 *  prgCmds       [O] Commands
 *  pCmdText      [O] Command text
 *
 * RETURNS
 *  Success: S_OK.
 *  Failure: E_FAIL, if lpUnknown is NULL.
 *           E_NOINTERFACE, if lpUnknown does not support IOleCommandTarget.
1191
 *           Otherwise, an error code from IOleCommandTarget_QueryStatus().
Juergen Schmied's avatar
Juergen Schmied committed
1192
 */
1193
HRESULT WINAPI IUnknown_QueryStatus(IUnknown* lpUnknown, REFGUID pguidCmdGroup,
1194
                           ULONG cCmds, OLECMD *prgCmds, OLECMDTEXT* pCmdText)
Juergen Schmied's avatar
Juergen Schmied committed
1195
{
1196 1197 1198 1199 1200 1201 1202
  HRESULT hRet = E_FAIL;

  TRACE("(%p,%p,%ld,%p,%p)\n",lpUnknown, pguidCmdGroup, cCmds, prgCmds, pCmdText);

  if (lpUnknown)
  {
    IOleCommandTarget* lpOle;
Juergen Schmied's avatar
Juergen Schmied committed
1203

1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215
    hRet = IUnknown_QueryInterface(lpUnknown, &IID_IOleCommandTarget,
                                   (void**)&lpOle);

    if (SUCCEEDED(hRet) && lpOle)
    {
      hRet = IOleCommandTarget_QueryStatus(lpOle, pguidCmdGroup, cCmds,
                                           prgCmds, pCmdText);
      IOleCommandTarget_Release(lpOle);
    }
  }
  return hRet;
}
Juergen Schmied's avatar
Juergen Schmied committed
1216 1217

/*************************************************************************
1218 1219
 *      @		[SHLWAPI.164]
 *
1220
 * Call IOleCommandTarget_Exec() on an object.
1221 1222 1223 1224 1225 1226 1227 1228 1229
 *
 * PARAMS
 *  lpUnknown     [I] Object supporting the IOleCommandTarget interface
 *  pguidCmdGroup [I] GUID for the command group
 *
 * RETURNS
 *  Success: S_OK.
 *  Failure: E_FAIL, if lpUnknown is NULL.
 *           E_NOINTERFACE, if lpUnknown does not support IOleCommandTarget.
1230
 *           Otherwise, an error code from IOleCommandTarget_Exec().
1231
 */
1232
HRESULT WINAPI IUnknown_Exec(IUnknown* lpUnknown, REFGUID pguidCmdGroup,
1233 1234
                           DWORD nCmdID, DWORD nCmdexecopt, VARIANT* pvaIn,
                           VARIANT* pvaOut)
1235
{
1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254
  HRESULT hRet = E_FAIL;

  TRACE("(%p,%p,%ld,%ld,%p,%p)\n",lpUnknown, pguidCmdGroup, nCmdID,
        nCmdexecopt, pvaIn, pvaOut);

  if (lpUnknown)
  {
    IOleCommandTarget* lpOle;

    hRet = IUnknown_QueryInterface(lpUnknown, &IID_IOleCommandTarget,
                                   (void**)&lpOle);
    if (SUCCEEDED(hRet) && lpOle)
    {
      hRet = IOleCommandTarget_Exec(lpOle, pguidCmdGroup, nCmdID,
                                    nCmdexecopt, pvaIn, pvaOut);
      IOleCommandTarget_Release(lpOle);
    }
  }
  return hRet;
1255 1256
}

1257
/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
1258
 *      @	[SHLWAPI.165]
1259
 *
1260 1261 1262
 * Retrieve, modify, and re-set a value from a window.
 *
 * PARAMS
1263
 *  hWnd   [I] Window to get value from
1264 1265 1266 1267 1268 1269 1270 1271 1272 1273
 *  offset [I] Offset of value
 *  wMask  [I] Mask for uiFlags
 *  wFlags [I] Bits to set in window value
 *
 * RETURNS
 *  The new value as it was set, or 0 if any parameter is invalid.
 *
 * NOTES
 *  Any bits set in uiMask are cleared from the value, then any bits set in
 *  uiFlags are set in the value.
1274
 */
1275
LONG WINAPI SHSetWindowBits(HWND hwnd, INT offset, UINT wMask, UINT wFlags)
1276 1277
{
  LONG ret = GetWindowLongA(hwnd, offset);
1278
  LONG newFlags = (wFlags & wMask) | (ret & ~wFlags);
1279 1280 1281 1282

  if (newFlags != ret)
    ret = SetWindowLongA(hwnd, offset, newFlags);
  return ret;
1283 1284 1285
}

/*************************************************************************
1286 1287
 *      @	[SHLWAPI.167]
 *
1288
 * Change a window's parent.
1289 1290 1291 1292 1293 1294
 *
 * PARAMS
 *  hWnd       [I] Window to change parent of
 *  hWndParent [I] New parent window
 *
 * RETURNS
1295
 *  The old parent of hWnd.
1296 1297 1298
 *
 * NOTES
 *  If hWndParent is NULL (desktop), the window style is changed to WS_POPUP.
1299
 *  If hWndParent is NOT NULL then we set the WS_CHILD style.
Juergen Schmied's avatar
Juergen Schmied committed
1300
 */
1301
HWND WINAPI SHSetParentHwnd(HWND hWnd, HWND hWndParent)
Juergen Schmied's avatar
Juergen Schmied committed
1302
{
1303 1304 1305 1306 1307 1308
  TRACE("%p, %p\n", hWnd, hWndParent);

  if(GetParent(hWnd) == hWndParent)
    return 0;

  if(hWndParent)
1309
    SHSetWindowBits(hWnd, GWL_STYLE, WS_CHILD, WS_CHILD);
1310
  else
1311
    SHSetWindowBits(hWnd, GWL_STYLE, WS_POPUP, WS_POPUP);
1312 1313

  return SetParent(hWnd, hWndParent);
Juergen Schmied's avatar
Juergen Schmied committed
1314 1315
}

1316 1317 1318
/*************************************************************************
 *      @       [SHLWAPI.168]
 *
1319
 * Locate and advise a connection point in an IConnectionPointContainer object.
1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335
 *
 * PARAMS
 *  lpUnkSink   [I] Sink for the connection point advise call
 *  riid        [I] REFIID of connection point to advise
 *  bAdviseOnly [I] TRUE = Advise only, FALSE = Unadvise first
 *  lpUnknown   [I] Object supporting the IConnectionPointContainer interface
 *  lpCookie    [O] Pointer to connection point cookie
 *  lppCP       [O] Destination for the IConnectionPoint found
 *
 * RETURNS
 *  Success: S_OK. If lppCP is non-NULL, it is filled with the IConnectionPoint
 *           that was advised. The caller is responsable for releasing it.
 *  Failure: E_FAIL, if any arguments are invalid.
 *           E_NOINTERFACE, if lpUnknown isn't an IConnectionPointContainer,
 *           Or an HRESULT error code if any call fails.
 */
1336
HRESULT WINAPI ConnectToConnectionPoint(IUnknown* lpUnkSink, REFIID riid, BOOL bAdviseOnly,
1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375
                           IUnknown* lpUnknown, LPDWORD lpCookie,
                           IConnectionPoint **lppCP)
{
  HRESULT hRet;
  IConnectionPointContainer* lpContainer;
  IConnectionPoint *lpCP;

  if(!lpUnknown || (bAdviseOnly && !lpUnkSink))
    return E_FAIL;

  if(lppCP)
    *lppCP = NULL;

  hRet = IUnknown_QueryInterface(lpUnknown, &IID_IConnectionPointContainer,
                                 (void**)&lpContainer);
  if (SUCCEEDED(hRet))
  {
    hRet = IConnectionPointContainer_FindConnectionPoint(lpContainer, riid, &lpCP);

    if (SUCCEEDED(hRet))
    {
      if(!bAdviseOnly)
        hRet = IConnectionPoint_Unadvise(lpCP, *lpCookie);
      hRet = IConnectionPoint_Advise(lpCP, lpUnkSink, lpCookie);

      if (FAILED(hRet))
        *lpCookie = 0;

      if (lppCP && SUCCEEDED(hRet))
        *lppCP = lpCP; /* Caller keeps the interface */
      else
        IConnectionPoint_Release(lpCP); /* Release it */
    }

    IUnknown_Release(lpContainer);
  }
  return hRet;
}

Juergen Schmied's avatar
Juergen Schmied committed
1376
/*************************************************************************
1377
 *	@	[SHLWAPI.169]
1378
 *
1379 1380 1381 1382 1383 1384 1385
 * Release an interface.
 *
 * PARAMS
 *  lpUnknown [I] Object to release
 *
 * RETURNS
 *  Nothing.
1386
 */
1387
DWORD WINAPI IUnknown_AtomicRelease(IUnknown ** lpUnknown)
1388
{
1389 1390 1391
    IUnknown *temp;

    TRACE("(%p)\n",lpUnknown);
1392

1393 1394 1395 1396 1397 1398 1399
    if(!lpUnknown || !*((LPDWORD)lpUnknown)) return 0;
    temp = *lpUnknown;
    *lpUnknown = NULL;

    TRACE("doing Release\n");
    
    return IUnknown_Release(temp);
1400 1401
}

1402
/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
1403
 *      @	[SHLWAPI.170]
1404
 *
1405 1406 1407 1408 1409 1410 1411 1412
 * Skip '//' if present in a string.
 *
 * PARAMS
 *  lpszSrc [I] String to check for '//'
 *
 * RETURNS
 *  Success: The next character after the '//' or the string if not present
 *  Failure: NULL, if lpszStr is NULL.
1413
 */
1414
LPCSTR WINAPI PathSkipLeadingSlashesA(LPCSTR lpszSrc)
1415 1416 1417 1418 1419 1420
{
  if (lpszSrc && lpszSrc[0] == '/' && lpszSrc[1] == '/')
    lpszSrc += 2;
  return lpszSrc;
}

1421
/*************************************************************************
1422 1423
 *      @		[SHLWAPI.171]
 *
1424
 * Check if two interfaces come from the same object.
1425 1426
 *
 * PARAMS
1427 1428
 *   lpInt1 [I] Interface to check against lpInt2.
 *   lpInt2 [I] Interface to check against lpInt1.
1429 1430
 *
 * RETURNS
1431 1432
 *   TRUE, If the interfaces come from the same object.
 *   FALSE Otherwise.
Juergen Schmied's avatar
Juergen Schmied committed
1433
 */
1434
BOOL WINAPI SHIsSameObject(IUnknown* lpInt1, IUnknown* lpInt2)
Juergen Schmied's avatar
Juergen Schmied committed
1435
{
1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457
  LPVOID lpUnknown1, lpUnknown2;

  TRACE("%p %p\n", lpInt1, lpInt2);

  if (!lpInt1 || !lpInt2)
    return FALSE;

  if (lpInt1 == lpInt2)
    return TRUE;

  if (!SUCCEEDED(IUnknown_QueryInterface(lpInt1, &IID_IUnknown,
                                       (LPVOID *)&lpUnknown1)))
    return FALSE;

  if (!SUCCEEDED(IUnknown_QueryInterface(lpInt2, &IID_IUnknown,
                                       (LPVOID *)&lpUnknown2)))
    return FALSE;

  if (lpUnknown1 == lpUnknown2)
    return TRUE;
  
  return FALSE;
Juergen Schmied's avatar
Juergen Schmied committed
1458 1459 1460
}

/*************************************************************************
1461 1462
 *      @	[SHLWAPI.172]
 *
1463 1464 1465 1466 1467 1468 1469 1470 1471
 * Get the window handle of an object.
 *
 * PARAMS
 *  lpUnknown [I] Object to get the window handle of
 *  lphWnd    [O] Destination for window handle
 *
 * RETURNS
 *  Success: S_OK. lphWnd contains the objects window handle.
 *  Failure: An HRESULT error code.
1472
 *
1473 1474
 * NOTES
 *  lpUnknown is expected to support one of the following interfaces:
1475
 *  IOleWindow(), IInternetSecurityMgrSite(), or IShellView().
1476
 */
1477
HRESULT WINAPI IUnknown_GetWindow(IUnknown *lpUnknown, HWND *lphWnd)
1478
{
1479 1480 1481 1482 1483
  /* FIXME: Wine has no header for this object */
  static const GUID IID_IInternetSecurityMgrSite = { 0x79eac9ed,
    0xbaf9, 0x11ce, { 0x8c, 0x82, 0x00, 0xaa, 0x00, 0x4b, 0xa9, 0x0b }};
  IUnknown *lpOle;
  HRESULT hRet = E_FAIL;
1484

1485
  TRACE("(%p,%p)\n", lpUnknown, lphWnd);
1486

1487 1488
  if (!lpUnknown)
    return hRet;
Juergen Schmied's avatar
Juergen Schmied committed
1489

1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510
  hRet = IUnknown_QueryInterface(lpUnknown, &IID_IOleWindow, (void**)&lpOle);

  if (FAILED(hRet))
  {
    hRet = IUnknown_QueryInterface(lpUnknown,&IID_IShellView, (void**)&lpOle);

    if (FAILED(hRet))
    {
      hRet = IUnknown_QueryInterface(lpUnknown, &IID_IInternetSecurityMgrSite,
                                      (void**)&lpOle);
    }
  }

  if (SUCCEEDED(hRet))
  {
    /* Lazyness here - Since GetWindow() is the first method for the above 3
     * interfaces, we use the same call for them all.
     */
    hRet = IOleWindow_GetWindow((IOleWindow*)lpOle, lphWnd);
    IUnknown_Release(lpOle);
    if (lphWnd)
1511
      TRACE("Returning HWND=%p\n", *lphWnd);
1512 1513 1514
  }

  return hRet;
1515 1516
}

1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528
/*************************************************************************
 *      @	[SHLWAPI.173]
 *
 * Call a method on as as yet unidentified object.
 *
 * PARAMS
 *  pUnk [I] Object supporting the unidentified interface,
 *  arg  [I] Argument for the call on the object.
 *
 * RETURNS
 *  S_OK.
 */
1529
HRESULT WINAPI IUnknown_SetOwner(IUnknown *pUnk, ULONG arg)
1530 1531 1532 1533 1534 1535 1536 1537 1538
{
  static const GUID guid_173 = {
    0x5836fb00, 0x8187, 0x11cf, { 0xa1,0x2b,0x00,0xaa,0x00,0x4a,0xe8,0x37 }
  };
  IMalloc *pUnk2;

  TRACE("(%p,%ld)\n", pUnk, arg);

  /* Note: arg may not be a ULONG and pUnk2 is for sure not an IMalloc -
1539
   *       We use this interface as its vtable entry is compatible with the
1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551
   *       object in question.
   * FIXME: Find out what this object is and where it should be defined.
   */
  if (pUnk &&
      SUCCEEDED(IUnknown_QueryInterface(pUnk, &guid_173, (void**)&pUnk2)))
  {
    IMalloc_Alloc(pUnk2, arg); /* Faked call!! */
    IMalloc_Release(pUnk2);
  }
  return S_OK;
}

1552 1553 1554
/*************************************************************************
 *      @	[SHLWAPI.174]
 *
1555 1556 1557 1558 1559 1560 1561 1562
 * Call either IObjectWithSite_SetSite() or IPersistMoniker_GetClassID() on
 * an interface.
 *
 * RETURNS
 *  Success: S_OK.
 *  Failure: E_FAIL, if p1 is NULL.
 *           E_NOINTERFACE If p1 does not support the IPersist interface,
 *           Or an HRESULT error code.
1563
 */
1564
DWORD WINAPI IUnknown_SetSite(
1565 1566
        IUnknown *p1,     /* [in]   OLE object                          */
        LPVOID *p2)       /* [out]  ptr for call results */
1567 1568 1569 1570 1571 1572 1573
{
    DWORD ret, aa;

    if (!p1) return E_FAIL;

    /* see if SetSite interface exists for IObjectWithSite object */
    ret = IUnknown_QueryInterface((IUnknown *)p1, (REFIID)id1, (LPVOID *)&p1);
1574
    TRACE("first IU_QI ret=%08lx, p1=%p\n", ret, p1);
1575
    if (ret) {
1576 1577 1578

	/* see if GetClassId interface exists for IPersistMoniker object */
	ret = IUnknown_QueryInterface((IUnknown *)p1, (REFIID)id2, (LPVOID *)&aa);
1579
	TRACE("second IU_QI ret=%08lx, aa=%08lx\n", ret, aa);
1580 1581 1582 1583
	if (ret) return ret;

	/* fake a GetClassId call */
	ret = IOleWindow_GetWindow((IOleWindow *)aa, (HWND*)p2);
1584
	TRACE("second IU_QI doing 0x0c ret=%08lx, *p2=%08lx\n", ret,
1585 1586 1587 1588 1589 1590
	      *(LPDWORD)p2);
	IUnknown_Release((IUnknown *)aa);
    }
    else {
	/* fake a SetSite call */
	ret = IOleWindow_GetWindow((IOleWindow *)p1, (HWND*)p2);
1591
	TRACE("first IU_QI doing 0x0c ret=%08lx, *p2=%08lx\n", ret,
1592 1593 1594 1595 1596 1597
	      *(LPDWORD)p2);
	IUnknown_Release((IUnknown *)p1);
    }
    return ret;
}

1598 1599 1600
/*************************************************************************
 *      @	[SHLWAPI.175]
 *
1601
 * Call IPersist_GetClassID() on an object.
1602 1603 1604 1605 1606 1607 1608 1609 1610 1611
 *
 * PARAMS
 *  lpUnknown [I] Object supporting the IPersist interface
 *  lpClassId [O] Destination for Class Id
 *
 * RETURNS
 *  Success: S_OK. lpClassId contains the Class Id requested.
 *  Failure: E_FAIL, If lpUnknown is NULL,
 *           E_NOINTERFACE If lpUnknown does not support IPersist,
 *           Or an HRESULT error code.
1612
 */
1613
HRESULT WINAPI IUnknown_GetClassID(IUnknown *lpUnknown, CLSID* lpClassId)
1614
{
1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629
  IPersist* lpPersist;
  HRESULT hRet = E_FAIL;

  TRACE("(%p,%p)\n", lpUnknown, debugstr_guid(lpClassId));

  if (lpUnknown)
  {
    hRet = IUnknown_QueryInterface(lpUnknown,&IID_IPersist,(void**)&lpPersist);
    if (SUCCEEDED(hRet))
    {
      IPersist_GetClassID(lpPersist, lpClassId);
      IPersist_Release(lpPersist);
    }
  }
  return hRet;
1630
}
1631

1632
/*************************************************************************
1633 1634
 *      @	[SHLWAPI.176]
 *
1635 1636 1637 1638
 * Retrieve a Service Interface from an object.
 *
 * PARAMS
 *  lpUnknown [I] Object to get an IServiceProvider interface from
1639
 *  sid       [I] Service ID for IServiceProvider_QueryService() call
1640 1641
 *  riid      [I] Function requested for QueryService call
 *  lppOut    [O] Destination for the service interface pointer
1642
 *
1643 1644 1645 1646 1647 1648 1649
 * RETURNS
 *  Success: S_OK. lppOut contains an object providing the requested service
 *  Failure: An HRESULT error code
 *
 * NOTES
 *  lpUnknown is expected to support the IServiceProvider interface.
 */
1650
HRESULT WINAPI IUnknown_QueryService(IUnknown* lpUnknown, REFGUID sid, REFIID riid,
1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680
                           LPVOID *lppOut)
{
  IServiceProvider* pService = NULL;
  HRESULT hRet;

  if (!lppOut)
    return E_FAIL;

  *lppOut = NULL;

  if (!lpUnknown)
    return E_FAIL;

  /* Get an IServiceProvider interface from the object */
  hRet = IUnknown_QueryInterface(lpUnknown, &IID_IServiceProvider,
                                 (LPVOID*)&pService);

  if (!hRet && pService)
  {
    TRACE("QueryInterface returned (IServiceProvider*)%p\n", pService);

    /* Get a Service interface from the object */
    hRet = IServiceProvider_QueryService(pService, sid, riid, lppOut);

    TRACE("(IServiceProvider*)%p returned (IUnknown*)%p\n", pService, *lppOut);

    /* Release the IServiceProvider interface */
    IUnknown_Release(pService);
  }
  return hRet;
1681 1682
}

1683 1684 1685
/*************************************************************************
 *      @	[SHLWAPI.177]
 *
1686
 * Loads a popup menu.
1687 1688 1689 1690 1691 1692 1693 1694 1695
 *
 * PARAMS
 *  hInst  [I] Instance handle
 *  szName [I] Menu name
 *
 * RETURNS
 *  Success: TRUE.
 *  Failure: FALSE.
 */
1696
BOOL WINAPI SHLoadMenuPopup(HINSTANCE hInst, LPCWSTR szName)
1697 1698 1699 1700 1701 1702 1703 1704
{
  HMENU hMenu, hSubMenu;

  if ((hMenu = LoadMenuW(hInst, szName)))
  {
    if ((hSubMenu = GetSubMenu(hMenu, 0)))
      RemoveMenu(hMenu, 0, MF_BYPOSITION);

1705
    DestroyMenu(hMenu);
1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746
    return TRUE;
  }
  return FALSE;
}

typedef struct _enumWndData
{
  UINT   uiMsgId;
  WPARAM wParam;
  LPARAM lParam;
  LRESULT (WINAPI *pfnPost)(HWND,UINT,WPARAM,LPARAM);
} enumWndData;

/* Callback for SHLWAPI_178 */
static BOOL CALLBACK SHLWAPI_EnumChildProc(HWND hWnd, LPARAM lParam)
{
  enumWndData *data = (enumWndData *)lParam;

  TRACE("(%p,%p)\n", hWnd, data);
  data->pfnPost(hWnd, data->uiMsgId, data->wParam, data->lParam);
  return TRUE;
}

/*************************************************************************
 * @  [SHLWAPI.178]
 *
 * Send or post a message to every child of a window.
 *
 * PARAMS
 *  hWnd    [I] Window whose children will get the messages
 *  uiMsgId [I] Message Id
 *  wParam  [I] WPARAM of message
 *  lParam  [I] LPARAM of message
 *  bSend   [I] TRUE = Use SendMessageA(), FALSE = Use PostMessageA()
 *
 * RETURNS
 *  Nothing.
 *
 * NOTES
 *  The appropriate ASCII or Unicode function is called for the window.
 */
1747
void WINAPI SHPropagateMessage(HWND hWnd, UINT uiMsgId, WPARAM wParam, LPARAM lParam, BOOL bSend)
1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767
{
  enumWndData data;

  TRACE("(%p,%u,%d,%ld,%d)\n", hWnd, uiMsgId, wParam, lParam, bSend);

  if(hWnd)
  {
    data.uiMsgId = uiMsgId;
    data.wParam  = wParam;
    data.lParam  = lParam;

    if (bSend)
      data.pfnPost = IsWindowUnicode(hWnd) ? (void*)SendMessageW : (void*)SendMessageA;
    else
      data.pfnPost = IsWindowUnicode(hWnd) ? (void*)PostMessageW : (void*)PostMessageA;

    EnumChildWindows(hWnd, SHLWAPI_EnumChildProc, (LPARAM)&data);
  }
}

1768 1769 1770
/*************************************************************************
 *      @	[SHLWAPI.180]
 *
1771 1772 1773 1774 1775 1776 1777 1778
 * Remove all sub-menus from a menu.
 *
 * PARAMS
 *  hMenu [I] Menu to remove sub-menus from
 *
 * RETURNS
 *  Success: 0.  All sub-menus under hMenu are removed
 *  Failure: -1, if any parameter is invalid
1779
 */
1780
DWORD WINAPI SHRemoveAllSubMenus(HMENU hMenu)
1781 1782 1783 1784 1785 1786
{
  int iItemCount = GetMenuItemCount(hMenu) - 1;
  while (iItemCount >= 0)
  {
    HMENU hSubMenu = GetSubMenu(hMenu, iItemCount);
    if (hSubMenu)
1787
      RemoveMenu(hMenu, iItemCount, MF_BYPOSITION);
1788 1789 1790 1791 1792
    iItemCount--;
  }
  return iItemCount;
}

1793
/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
1794
 *      @	[SHLWAPI.181]
1795
 *
1796 1797 1798 1799 1800 1801 1802 1803
 * Enable or disable a menu item.
 *
 * PARAMS
 *  hMenu   [I] Menu holding menu item
 *  uID     [I] ID of menu item to enable/disable
 *  bEnable [I] Whether to enable (TRUE) or disable (FALSE) the item.
 *
 * RETURNS
1804
 *  The return code from EnableMenuItem.
1805
 */
1806
UINT WINAPI SHEnableMenuItem(HMENU hMenu, UINT wItemID, BOOL bEnable)
1807 1808 1809 1810
{
  return EnableMenuItem(hMenu, wItemID, bEnable ? MF_ENABLED : MF_GRAYED);
}

1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823
/*************************************************************************
 * @	[SHLWAPI.182]
 *
 * Check or uncheck a menu item.
 *
 * PARAMS
 *  hMenu  [I] Menu holding menu item
 *  uID    [I] ID of menu item to check/uncheck
 *  bCheck [I] Whether to check (TRUE) or uncheck (FALSE) the item.
 *
 * RETURNS
 *  The return code from CheckMenuItem.
 */
1824
DWORD WINAPI SHCheckMenuItem(HMENU hMenu, UINT uID, BOOL bCheck)
1825
{
1826
  return CheckMenuItem(hMenu, uID, bCheck ? MF_CHECKED : MF_UNCHECKED);
1827 1828
}

1829
/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
1830
 *      @	[SHLWAPI.183]
1831 1832
 *
 * Register a window class if it isn't already.
1833 1834 1835 1836 1837 1838
 *
 * PARAMS
 *  lpWndClass [I] Window class to register
 *
 * RETURNS
 *  The result of the RegisterClassA call.
1839
 */
1840
DWORD WINAPI SHRegisterClassA(WNDCLASSA *wndclass)
1841 1842 1843 1844 1845 1846 1847
{
  WNDCLASSA wca;
  if (GetClassInfoA(wndclass->hInstance, wndclass->lpszClassName, &wca))
    return TRUE;
  return (DWORD)RegisterClassA(wndclass);
}

1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871
/*************************************************************************
 *      @	[SHLWAPI.186]
 */
BOOL WINAPI SHSimulateDrop(IDropTarget *pDrop, IDataObject *pDataObj,
                           DWORD grfKeyState, PPOINTL lpPt, DWORD* pdwEffect)
{
  DWORD dwEffect = DROPEFFECT_LINK | DROPEFFECT_MOVE | DROPEFFECT_COPY;
  POINTL pt = { 0, 0 };

  if (!lpPt)
    lpPt = &pt;

  if (!pdwEffect)
    pdwEffect = &dwEffect;

  IDropTarget_DragEnter(pDrop, pDataObj, grfKeyState, *lpPt, pdwEffect);

  if (*pdwEffect)
    return IDropTarget_Drop(pDrop, pDataObj, grfKeyState, *lpPt, pdwEffect);

  IDropTarget_DragLeave(pDrop);
  return TRUE;
}

1872 1873 1874
/*************************************************************************
 *      @	[SHLWAPI.187]
 *
1875
 * Call IPersistPropertyBag_Load() on an object.
1876 1877 1878 1879 1880 1881 1882 1883 1884
 *
 * PARAMS
 *  lpUnknown [I] Object supporting the IPersistPropertyBag interface
 *  lpPropBag [O] Destination for loaded IPropertyBag
 *
 * RETURNS
 *  Success: S_OK.
 *  Failure: An HRESULT error code, or E_FAIL if lpUnknown is NULL.
 */
1885
DWORD WINAPI SHLoadFromPropertyBag(IUnknown *lpUnknown, IPropertyBag* lpPropBag)
1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904
{
  IPersistPropertyBag* lpPPBag;
  HRESULT hRet = E_FAIL;

  TRACE("(%p,%p)\n", lpUnknown, lpPropBag);

  if (lpUnknown)
  {
    hRet = IUnknown_QueryInterface(lpUnknown, &IID_IPersistPropertyBag,
                                   (void**)&lpPPBag);
    if (SUCCEEDED(hRet) && lpPPBag)
    {
      hRet = IPersistPropertyBag_Load(lpPPBag, lpPropBag, NULL);
      IPersistPropertyBag_Release(lpPPBag);
    }
  }
  return hRet;
}

Juergen Schmied's avatar
Juergen Schmied committed
1905
/*************************************************************************
1906 1907 1908 1909 1910 1911 1912
 * @  [SHLWAPI.189]
 *
 * Call IOleControlSite_GetExtendedControl() on an object.
 *
 * PARAMS
 *  lpUnknown [I] Object supporting the IOleControlSite interface
 *  lppDisp   [O] Destination for resulting IDispatch.
1913
 *
1914 1915 1916
 * RETURNS
 *  Success: S_OK.
 *  Failure: An HRESULT error code, or E_FAIL if lpUnknown is NULL.
Juergen Schmied's avatar
Juergen Schmied committed
1917
 */
1918
DWORD WINAPI IUnknown_OnFocusOCS(IUnknown *lpUnknown, IDispatch** lppDisp)
Juergen Schmied's avatar
Juergen Schmied committed
1919
{
1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948
  IOleControlSite* lpCSite;
  HRESULT hRet = E_FAIL;

  TRACE("(%p,%p)\n", lpUnknown, lppDisp);
  if (lpUnknown)
  {
    hRet = IUnknown_QueryInterface(lpUnknown, &IID_IOleControlSite,
                                   (void**)&lpCSite);
    if (SUCCEEDED(hRet) && lpCSite)
    {
      hRet = IOleControlSite_GetExtendedControl(lpCSite, lppDisp);
      IOleControlSite_Release(lpCSite);
    }
  }
  return hRet;
}

/*************************************************************************
 * @    [SHLWAPI.192]
 *
 * Get a sub-menu from a menu item.
 *
 * PARAMS
 *  hMenu [I] Menu to get sub-menu from
 *  uID   [I] ID of menu item containing sub-menu
 *
 * RETURNS
 *  The sub-menu of the item, or a NULL handle if any parameters are invalid.
 */
1949
HMENU WINAPI SHGetMenuFromID(HMENU hMenu, UINT uID)
1950 1951 1952 1953 1954 1955 1956 1957 1958
{
  MENUITEMINFOA mi;

  TRACE("(%p,%uld)\n", hMenu, uID);

  mi.cbSize = sizeof(MENUITEMINFOA);
  mi.fMask = MIIM_SUBMENU;

  if (!GetMenuItemInfoA(hMenu, uID, 0, &mi))
1959
    return NULL;
1960 1961

  return mi.hSubMenu;
Juergen Schmied's avatar
Juergen Schmied committed
1962 1963
}

1964
/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
1965
 *      @	[SHLWAPI.193]
1966 1967 1968 1969 1970 1971 1972 1973
 *
 * Get the color depth of the primary display.
 *
 * PARAMS
 *  None.
 *
 * RETURNS
 *  The color depth of the primary display.
1974
 */
1975
DWORD WINAPI SHGetCurColorRes()
1976
{
1977 1978
    HDC hdc;
    DWORD ret;
1979

1980
    TRACE("()\n");
1981

1982 1983 1984 1985
    hdc = GetDC(0);
    ret = GetDeviceCaps(hdc, BITSPIXEL) * GetDeviceCaps(hdc, PLANES);
    ReleaseDC(0, hdc);
    return ret;
1986 1987
}

1988 1989 1990 1991 1992 1993 1994 1995 1996 1997
/*************************************************************************
 *      @	[SHLWAPI.194]
 *
 * Wait for a message to arrive, with a timeout.
 *
 * PARAMS
 *  hand      [I] Handle to query
 *  dwTimeout [I] Timeout in ticks or INFINITE to never timeout
 *
 * RETURNS
1998 1999 2000
 *  STATUS_TIMEOUT if no message is received before dwTimeout ticks passes.
 *  Otherwise returns the value from MsgWaitForMultipleObjectsEx when a
 *  message is available.
2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022
 */
DWORD WINAPI SHWaitForSendMessageThread(HANDLE hand, DWORD dwTimeout)
{
  DWORD dwEndTicks = GetTickCount() + dwTimeout;
  DWORD dwRet;

  while ((dwRet = MsgWaitForMultipleObjectsEx(1, &hand, dwTimeout, QS_SENDMESSAGE, 0)) == 1)
  {
    MSG msg;

    PeekMessageW(&msg, NULL, 0, 0, PM_NOREMOVE);

    if (dwTimeout != INFINITE)
    {
        if ((int)(dwTimeout = dwEndTicks - GetTickCount()) <= 0)
            return WAIT_TIMEOUT;
    }
  }

  return dwRet;
}

2023 2024 2025 2026
/*************************************************************************
 *      @       [SHLWAPI.197]
 *
 * Blank out a region of text by drawing the background only.
2027 2028 2029 2030 2031 2032 2033 2034
 *
 * PARAMS
 *  hDC   [I] Device context to draw in
 *  pRect [I] Area to draw in
 *  cRef  [I] Color to draw in
 *
 * RETURNS
 *  Nothing.
2035
 */
2036
DWORD WINAPI SHFillRectClr(HDC hDC, LPCRECT pRect, COLORREF cRef)
2037 2038 2039 2040 2041 2042 2043
{
    COLORREF cOldColor = SetBkColor(hDC, cRef);
    ExtTextOutA(hDC, 0, 0, ETO_OPAQUE, pRect, 0, 0, 0);
    SetBkColor(hDC, cOldColor);
    return 0;
}

2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080
/*************************************************************************
 *      @	[SHLWAPI.198]
 *
 * Return the value asociated with a key in a map.
 *
 * PARAMS
 *  lpKeys   [I] A list of keys of length iLen
 *  lpValues [I] A list of values associated with lpKeys, of length iLen
 *  iLen     [I] Length of both lpKeys and lpValues
 *  iKey     [I] The key value to look up in lpKeys
 *
 * RETURNS
 *  The value in lpValues associated with iKey, or -1 if iKey is not
 *  found in lpKeys.
 *
 * NOTES
 *  - If two elements in the map share the same key, this function returns
 *    the value closest to the start of the map
 *  - The native version of this function crashes if lpKeys or lpValues is NULL.
 */
int WINAPI SHSearchMapInt(const int *lpKeys, const int *lpValues, int iLen, int iKey)
{
  if (lpKeys && lpValues)
  {
    int i = 0;

    while (i < iLen)
    {
      if (lpKeys[i] == iKey)
        return lpValues[i]; /* Found */
      i++;
    }
  }
  return -1; /* Not found */
}


2081 2082 2083
/*************************************************************************
 *      @	[SHLWAPI.199]
 *
2084
 * Copy an interface pointer
2085 2086 2087 2088 2089 2090 2091
 *
 * PARAMS
 *   lppDest   [O] Destination for copy
 *   lpUnknown [I] Source for copy
 *
 * RETURNS
 *  Nothing.
2092
 */
2093
VOID WINAPI IUnknown_Set(IUnknown **lppDest, IUnknown *lpUnknown)
2094 2095 2096 2097
{
  TRACE("(%p,%p)\n", lppDest, lpUnknown);

  if (lppDest)
2098
    IUnknown_AtomicRelease(lppDest); /* Release existing interface */
2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111

  if (lpUnknown)
  {
    /* Copy */
    IUnknown_AddRef(lpUnknown);
    *lppDest = lpUnknown;
  }
}

/*************************************************************************
 *      @	[SHLWAPI.201]
 *
 */
2112
HRESULT WINAPI MayExecForward(IUnknown* lpUnknown, INT iUnk, REFGUID pguidCmdGroup,
2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124
                           DWORD nCmdID, DWORD nCmdexecopt, VARIANT* pvaIn,
                           VARIANT* pvaOut)
{
  FIXME("(%p,%d,%p,%ld,%ld,%p,%p) - stub!\n", lpUnknown, iUnk, pguidCmdGroup,
        nCmdID, nCmdexecopt, pvaIn, pvaOut);
  return DRAGDROP_E_NOTREGISTERED;
}

/*************************************************************************
 *      @	[SHLWAPI.202]
 *
 */
2125
HRESULT WINAPI IsQSForward(REFGUID pguidCmdGroup,ULONG cCmds, OLECMD *prgCmds)
2126 2127 2128 2129 2130
{
  FIXME("(%p,%ld,%p) - stub!\n", pguidCmdGroup, cCmds, prgCmds);
  return DRAGDROP_E_NOTREGISTERED;
}

2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143
/*************************************************************************
 * @	[SHLWAPI.204]
 *
 * Determine if a window is not a child of another window.
 *
 * PARAMS
 * hParent [I] Suspected parent window
 * hChild  [I] Suspected child window
 *
 * RETURNS
 * TRUE:  If hChild is a child window of hParent
 * FALSE: If hChild is not a child window of hParent, or they are equal
 */
2144
BOOL WINAPI SHIsChildOrSelf(HWND hParent, HWND hChild)
2145
{
2146
  TRACE("(%p,%p)\n", hParent, hChild);
2147 2148 2149 2150 2151 2152 2153 2154

  if (!hParent || !hChild)
    return TRUE;
  else if(hParent == hChild)
    return FALSE;
  return !IsChild(hParent, hChild);
}

2155 2156 2157
/*************************************************************************
 *      @	[SHLWAPI.208]
 *
2158
 * Some sort of memory management process.
2159
 */
2160
DWORD WINAPI FDSA_Initialize(
2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171
	DWORD    a,
	DWORD    b,
	LPVOID   c,
	LPVOID   d,
	DWORD    e)
{
    FIXME("(0x%08lx 0x%08lx %p %p 0x%08lx) stub\n",
	  a, b, c, d, e);
    return 1;
}

2172 2173 2174
/*************************************************************************
 *      @	[SHLWAPI.209]
 *
2175
 * Some sort of memory management process.
2176
 */
2177
DWORD WINAPI FDSA_Destroy(
2178 2179 2180 2181 2182 2183 2184
	LPVOID   a)
{
    FIXME("(%p) stub\n",
	  a);
    return 1;
}

2185 2186 2187
/*************************************************************************
 *      @	[SHLWAPI.210]
 *
2188
 * Some sort of memory management process.
2189
 */
2190
DWORD WINAPI FDSA_InsertItem(
2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202
	LPVOID   a,
	DWORD    b,
	LPVOID   c)
{
    FIXME("(%p 0x%08lx %p) stub\n",
	  a, b, c);
    return 0;
}

/*************************************************************************
 *      @	[SHLWAPI.211]
 */
2203
DWORD WINAPI FDSA_DeleteItem(
2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216
	LPVOID   a,
	DWORD    b)
{
    FIXME("(%p 0x%08lx) stub\n",
	  a, b);
    return 1;
}

typedef struct {
    REFIID   refid;
    DWORD    indx;
} IFACE_INDEX_TBL;

2217 2218 2219 2220 2221 2222 2223 2224 2225
/*************************************************************************
 *      @	[SHLWAPI.219]
 *
 * Call IUnknown_QueryInterface() on a table of objects.
 *
 * RETURNS
 *  Success: S_OK.
 *  Failure: E_POINTER or E_NOINTERFACE.
 */
2226
HRESULT WINAPI QISearch(
2227 2228 2229 2230
	LPVOID w,           /* [in]   Table of interfaces */
	IFACE_INDEX_TBL *x, /* [in]   Array of REFIIDs and indexes into the table */
	REFIID riid,        /* [in]   REFIID to get interface for */
	LPVOID *ppv)          /* [out]  Destination for interface pointer */
2231 2232 2233 2234 2235
{
	HRESULT ret;
	IUnknown *a_vtbl;
	IFACE_INDEX_TBL *xmove;

2236 2237
	TRACE("(%p %p %s %p)\n", w,x,debugstr_guid(riid),ppv);
	if (ppv) {
2238 2239
	    xmove = x;
	    while (xmove->refid) {
2240
		TRACE("trying (indx %ld) %s\n", xmove->indx, debugstr_guid(xmove->refid));
2241 2242 2243
		if (IsEqualIID(riid, xmove->refid)) {
		    a_vtbl = (IUnknown*)(xmove->indx + (LPBYTE)w);
		    TRACE("matched, returning (%p)\n", a_vtbl);
2244
		    *ppv = (LPVOID)a_vtbl;
2245 2246 2247 2248 2249 2250 2251 2252 2253
		    IUnknown_AddRef(a_vtbl);
		    return S_OK;
		}
		xmove++;
	    }

	    if (IsEqualIID(riid, &IID_IUnknown)) {
		a_vtbl = (IUnknown*)(x->indx + (LPBYTE)w);
		TRACE("returning first for IUnknown (%p)\n", a_vtbl);
2254
		*ppv = (LPVOID)a_vtbl;
2255 2256 2257
		IUnknown_AddRef(a_vtbl);
		return S_OK;
	    }
2258
	    *ppv = 0;
2259 2260 2261
	    ret = E_NOINTERFACE;
	} else
	    ret = E_POINTER;
2262 2263

	TRACE("-- 0x%08lx\n", ret);
2264
	return ret;
2265 2266
}

2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277
/*************************************************************************
 *      @	[SHLWAPI.221]
 *
 * Remove the "PropDlgFont" property from a window.
 *
 * PARAMS
 *  hWnd [I] Window to remove the property from
 *
 * RETURNS
 *  A handle to the removed property, or NULL if it did not exist.
 */
2278
HANDLE WINAPI SHRemoveDefaultDialogFont(HWND hWnd)
2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293
{
  HANDLE hProp;

  TRACE("(%p)\n", hWnd);

  hProp = GetPropA(hWnd, "PropDlgFont");

  if(hProp)
  {
    DeleteObject(hProp);
    hProp = RemovePropA(hWnd, "PropDlgFont");
  }
  return hProp;
}

2294 2295
/*************************************************************************
 *      @	[SHLWAPI.236]
2296 2297 2298 2299 2300 2301 2302 2303 2304
 *
 * Load the in-process server of a given GUID.
 *
 * PARAMS
 *  refiid [I] GUID of the server to load.
 *
 * RETURNS
 *  Success: A handle to the loaded server dll.
 *  Failure: A NULL handle.
2305
 */
2306
HMODULE WINAPI SHPinDllOfCLSID(REFIID refiid)
2307 2308 2309 2310 2311 2312
{
    HKEY newkey;
    DWORD type, count;
    CHAR value[MAX_PATH], string[MAX_PATH];

    strcpy(string, "CLSID\\");
2313
    SHStringFromGUIDA(refiid, string + 6, sizeof(string)/sizeof(char) - 6);
2314 2315 2316 2317
    strcat(string, "\\InProcServer32");

    count = MAX_PATH;
    RegOpenKeyExA(HKEY_CLASSES_ROOT, string, 0, 1, &newkey);
2318
    RegQueryValueExA(newkey, 0, 0, &type, (PBYTE)value, &count);
2319 2320 2321 2322
    RegCloseKey(newkey);
    return LoadLibraryExA(value, 0, 0);
}

2323
/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
2324
 *      @	[SHLWAPI.237]
2325
 *
2326
 * Unicode version of SHLWAPI_183.
2327
 */
2328
DWORD WINAPI SHRegisterClassW(WNDCLASSW * lpWndClass)
2329 2330
{
	WNDCLASSW WndClass;
2331

2332
	TRACE("(%p %s)\n",lpWndClass->hInstance, debugstr_w(lpWndClass->lpszClassName));
2333

2334 2335 2336 2337 2338
	if (GetClassInfoW(lpWndClass->hInstance, lpWndClass->lpszClassName, &WndClass))
		return TRUE;
	return RegisterClassW(lpWndClass);
}

2339
/*************************************************************************
2340
 *      @	[SHLWAPI.238]
2341 2342 2343 2344 2345 2346 2347 2348 2349 2350
 *
 * Unregister a list of classes.
 *
 * PARAMS
 *  hInst      [I] Application instance that registered the classes
 *  lppClasses [I] List of class names
 *  iCount     [I] Number of names in lppClasses
 *
 * RETURNS
 *  Nothing.
2351
 */
2352
void WINAPI SHUnregisterClassesA(HINSTANCE hInst, LPCSTR *lppClasses, INT iCount)
2353
{
2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367
  WNDCLASSA WndClass;

  TRACE("(%p,%p,%d)\n", hInst, lppClasses, iCount);

  while (iCount > 0)
  {
    if (GetClassInfoA(hInst, *lppClasses, &WndClass))
      UnregisterClassA(*lppClasses, hInst);
    lppClasses++;
    iCount--;
  }
}

/*************************************************************************
2368
 *      @	[SHLWAPI.239]
2369
 *
2370
 * Unicode version of SHUnregisterClassesA.
2371
 */
2372
void WINAPI SHUnregisterClassesW(HINSTANCE hInst, LPCWSTR *lppClasses, INT iCount)
2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384
{
  WNDCLASSW WndClass;

  TRACE("(%p,%p,%d)\n", hInst, lppClasses, iCount);

  while (iCount > 0)
  {
    if (GetClassInfoW(hInst, *lppClasses, &WndClass))
      UnregisterClassW(*lppClasses, hInst);
    lppClasses++;
    iCount--;
  }
2385 2386
}

2387
/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
2388
 *      @	[SHLWAPI.240]
2389
 *
2390
 * Call The correct (Ascii/Unicode) default window procedure for a window.
2391 2392
 *
 * PARAMS
2393
 *  hWnd     [I] Window to call the default procedure for
2394 2395 2396 2397 2398
 *  uMessage [I] Message ID
 *  wParam   [I] WPARAM of message
 *  lParam   [I] LPARAM of message
 *
 * RETURNS
2399
 *  The result of calling DefWindowProcA() or DefWindowProcW().
2400
 */
2401
LRESULT CALLBACK SHDefWindowProc(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
2402 2403 2404 2405
{
	if (IsWindowUnicode(hWnd))
		return DefWindowProcW(hWnd, uMessage, wParam, lParam);
	return DefWindowProcA(hWnd, uMessage, wParam, lParam);
2406 2407
}

2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424
/*************************************************************************
 *      @	[SHLWAPI.257]
 *
 * Create a worker window using CreateWindowExA().
 *
 * PARAMS
 *  wndProc    [I] Window procedure
 *  hWndParent [I] Parent window
 *  dwExStyle  [I] Extra style flags
 *  dwStyle    [I] Style flags
 *  hMenu      [I] Window menu
 *  z          [I] Unknown
 *
 * RETURNS
 *  Success: The window handle of the newly created window.
 *  Failure: 0.
 */
2425
HWND WINAPI SHCreateWorkerWindowA(LONG wndProc, HWND hWndParent, DWORD dwExStyle,
2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440
                        DWORD dwStyle, HMENU hMenu, LONG z)
{
  static const char* szClass = "WorkerA";
  WNDCLASSA wc;
  HWND hWnd;

  TRACE("(0x%08lx,%p,0x%08lx,0x%08lx,%p,0x%08lx)\n",
         wndProc, hWndParent, dwExStyle, dwStyle, hMenu, z);

  /* Create Window class */
  wc.style         = 0;
  wc.lpfnWndProc   = DefWindowProcA;
  wc.cbClsExtra    = 0;
  wc.cbWndExtra    = 4;
  wc.hInstance     = shlwapi_hInstance;
2441 2442
  wc.hIcon         = NULL;
  wc.hCursor       = LoadCursorA(NULL, (LPSTR)IDC_ARROW);
2443 2444 2445 2446
  wc.hbrBackground = (HBRUSH)COLOR_BTNSHADOW;
  wc.lpszMenuName  = NULL;
  wc.lpszClassName = szClass;

2447
  SHRegisterClassA(&wc); /* Register class */
2448 2449 2450 2451 2452 2453 2454 2455 2456 2457

  /* FIXME: Set extra bits in dwExStyle */

  hWnd = CreateWindowExA(dwExStyle, szClass, 0, dwStyle, 0, 0, 0, 0,
                         hWndParent, hMenu, shlwapi_hInstance, 0);
  if (hWnd)
  {
    SetWindowLongA(hWnd, DWL_MSGRESULT, z);

    if (wndProc)
2458
      SetWindowLongPtrA(hWnd, GWLP_WNDPROC, wndProc);
2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471
  }
  return hWnd;
}

typedef struct tagPOLICYDATA
{
  DWORD policy;        /* flags value passed to SHRestricted */
  LPCWSTR appstr;      /* application str such as "Explorer" */
  LPCWSTR keystr;      /* name of the actual registry key / policy */
} POLICYDATA, *LPPOLICYDATA;

#define SHELL_NO_POLICY 0xffffffff

2472
/* default shell policy registry key */
2473
static const WCHAR strRegistryPolicyW[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o',
2474 2475 2476 2477
                                      's','o','f','t','\\','W','i','n','d','o','w','s','\\',
                                      'C','u','r','r','e','n','t','V','e','r','s','i','o','n',
                                      '\\','P','o','l','i','c','i','e','s',0};

2478
/*************************************************************************
2479 2480 2481 2482 2483 2484 2485 2486
 * @                          [SHLWAPI.271]
 *
 * Retrieve a policy value from the registry.
 *
 * PARAMS
 *  lpSubKey   [I]   registry key name
 *  lpSubName  [I]   subname of registry key
 *  lpValue    [I]   value name of registry value
2487
 *
2488 2489
 * RETURNS
 *  the value associated with the registry key or 0 if not found
2490
 */
2491
DWORD WINAPI SHGetRestriction(LPCWSTR lpSubKey, LPCWSTR lpSubName, LPCWSTR lpValue)
2492
{
2493
	DWORD retval, datsize = sizeof(retval);
2494 2495 2496
	HKEY hKey;

	if (!lpSubKey)
2497
	  lpSubKey = strRegistryPolicyW;
2498

2499 2500 2501 2502 2503 2504 2505 2506
	retval = RegOpenKeyW(HKEY_LOCAL_MACHINE, lpSubKey, &hKey);
    if (retval != ERROR_SUCCESS)
	  retval = RegOpenKeyW(HKEY_CURRENT_USER, lpSubKey, &hKey);
	if (retval != ERROR_SUCCESS)
	  return 0;

	SHGetValueW(hKey, lpSubName, lpValue, NULL, (LPBYTE)&retval, &datsize);
	RegCloseKey(hKey);
2507
	return retval;
2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529
}

/*************************************************************************
 * @                         [SHLWAPI.266]
 *
 * Helper function to retrieve the possibly cached value for a specific policy
 *
 * PARAMS
 *  policy     [I]   The policy to look for
 *  initial    [I]   Main registry key to open, if NULL use default
 *  polTable   [I]   Table of known policies, 0 terminated
 *  polArr     [I]   Cache array of policy values
 *
 * RETURNS
 *  The retrieved policy value or 0 if not successful
 *
 * NOTES
 *  This function is used by the native SHRestricted function to search for the
 *  policy and cache it once retrieved. The current Wine implementation uses a
 *  different POLICYDATA structure and implements a similar algorithme adapted to
 *  that structure.
 */
2530
DWORD WINAPI SHRestrictionLookup(
2531
	DWORD policy,
2532
	LPCWSTR initial,
2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548
	LPPOLICYDATA polTable,
	LPDWORD polArr)
{
	TRACE("(0x%08lx %s %p %p)\n", policy, debugstr_w(initial), polTable, polArr);

	if (!polTable || !polArr)
	  return 0;

	for (;polTable->policy; polTable++, polArr++)
	{
	  if (policy == polTable->policy)
	  {
	    /* we have a known policy */

	    /* check if this policy has been cached */
		if (*polArr == SHELL_NO_POLICY)
2549
	      *polArr = SHGetRestriction(initial, polTable->appstr, polTable->keystr);
2550 2551 2552 2553 2554 2555
	    return *polArr;
	  }
	}
	/* we don't know this policy, return 0 */
	TRACE("unknown policy: (%08lx)\n", policy);
	return 0;
2556 2557 2558
}

/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
2559
 *      @	[SHLWAPI.267]
2560
 *
2561 2562 2563 2564 2565 2566 2567
 * Get an interface from an object.
 *
 * RETURNS
 *  Success: S_OK. ppv contains the requested interface.
 *  Failure: An HRESULT error code.
 *
 * NOTES
2568 2569 2570 2571
 *   This QueryInterface asks the inner object for a interface. In case
 *   of aggregation this request would be forwarded by the inner to the
 *   outer object. This function asks the inner object directly for the
 *   interface circumventing the forwarding to the outer object.
2572
 */
2573
HRESULT WINAPI SHWeakQueryInterface(
2574 2575 2576 2577
	IUnknown * pUnk,   /* [in] Outer object */
	IUnknown * pInner, /* [in] Inner object */
	IID * riid, /* [in] Interface GUID to query for */
	LPVOID* ppv) /* [out] Destination for queried interface */
2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588
{
	HRESULT hret = E_NOINTERFACE;
	TRACE("(pUnk=%p pInner=%p\n\tIID:  %s %p)\n",pUnk,pInner,debugstr_guid(riid), ppv);

	*ppv = NULL;
	if(pUnk && pInner) {
	    hret = IUnknown_QueryInterface(pInner, riid, (LPVOID*)ppv);
	    if (SUCCEEDED(hret)) IUnknown_Release(pUnk);
	}
	TRACE("-- 0x%08lx\n", hret);
	return hret;
2589 2590 2591
}

/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
2592
 *      @	[SHLWAPI.268]
2593 2594 2595 2596 2597 2598 2599 2600 2601
 *
 * Move a reference from one interface to another.
 *
 * PARAMS
 *   lpDest     [O] Destination to receive the reference
 *   lppUnknown [O] Source to give up the reference to lpDest
 *
 * RETURNS
 *  Nothing.
2602
 */
2603
VOID WINAPI SHWeakReleaseInterface(IUnknown *lpDest, IUnknown **lppUnknown)
2604
{
2605
  TRACE("(%p,%p)\n", lpDest, lppUnknown);
2606

2607 2608 2609 2610
  if (*lppUnknown)
  {
    /* Copy Reference*/
    IUnknown_AddRef(lpDest);
2611
    IUnknown_AtomicRelease(lppUnknown); /* Release existing interface */
2612
  }
2613 2614
}

2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627
/*************************************************************************
 *      @	[SHLWAPI.269]
 *
 * Convert an ASCII string of a CLSID into a CLSID.
 *
 * PARAMS
 *  idstr [I] String representing a CLSID in registry format
 *  id    [O] Destination for the converted CLSID
 *
 * RETURNS
 *  Success: TRUE. id contains the converted CLSID.
 *  Failure: FALSE.
 */
2628
BOOL WINAPI GUIDFromStringA(LPCSTR idstr, CLSID *id)
2629 2630 2631
{
  WCHAR wClsid[40];
  MultiByteToWideChar(CP_ACP, 0, idstr, -1, wClsid, sizeof(wClsid)/sizeof(WCHAR));
2632
  return SUCCEEDED(CLSIDFromStringWrap(wClsid, id));
2633 2634 2635 2636 2637
}

/*************************************************************************
 *      @	[SHLWAPI.270]
 *
2638
 * Unicode version of GUIDFromStringA.
2639
 */
2640
BOOL WINAPI GUIDFromStringW(LPCWSTR idstr, CLSID *id)
2641
{
2642
  return SUCCEEDED(CLSIDFromStringWrap(idstr, id));
2643 2644
}

2645
/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
2646
 *      @	[SHLWAPI.276]
2647
 *
2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658
 * Determine if the browser is integrated into the shell, and set a registry
 * key accordingly.
 *
 * PARAMS
 *  None.
 *
 * RETURNS
 *  1, If the browser is not integrated.
 *  2, If the browser is integrated.
 *
 * NOTES
2659
 *  The key "HKLM\Software\Microsoft\Internet Explorer\IntegratedBrowser" is
2660 2661
 *  either set to TRUE, or removed depending on whether the browser is deemed
 *  to be integrated.
2662
 */
2663
DWORD WINAPI WhichPlatform()
2664
{
2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676
  static LPCSTR szIntegratedBrowser = "IntegratedBrowser";
  static DWORD dwState = 0;
  HKEY hKey;
  DWORD dwRet, dwData, dwSize;

  if (dwState)
    return dwState;

  /* If shell32 exports DllGetVersion(), the browser is integrated */
  GET_FUNC(pDllGetVersion, shell32, "DllGetVersion", 1);
  dwState = pDllGetVersion ? 2 : 1;

2677
  /* Set or delete the key accordingly */
2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700
  dwRet = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
                        "Software\\Microsoft\\Internet Explorer", 0,
                         KEY_ALL_ACCESS, &hKey);
  if (!dwRet)
  {
    dwRet = RegQueryValueExA(hKey, szIntegratedBrowser, 0, 0,
                             (LPBYTE)&dwData, &dwSize);

    if (!dwRet && dwState == 1)
    {
      /* Value exists but browser is not integrated */
      RegDeleteValueA(hKey, szIntegratedBrowser);
    }
    else if (dwRet && dwState == 2)
    {
      /* Browser is integrated but value does not exist */
      dwData = TRUE;
      RegSetValueExA(hKey, szIntegratedBrowser, 0, REG_DWORD,
                     (LPBYTE)&dwData, sizeof(dwData));
    }
    RegCloseKey(hKey);
  }
  return dwState;
2701 2702 2703
}

/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
2704
 *      @	[SHLWAPI.278]
2705
 *
2706
 * Unicode version of SHCreateWorkerWindowA.
2707
 */
2708
HWND WINAPI SHCreateWorkerWindowW(LONG wndProc, HWND hWndParent, DWORD dwExStyle,
2709
                        DWORD dwStyle, HMENU hMenu, LONG z)
2710
{
2711 2712 2713
  static const WCHAR szClass[] = { 'W', 'o', 'r', 'k', 'e', 'r', 'W', '\0' };
  WNDCLASSW wc;
  HWND hWnd;
2714

2715 2716
  TRACE("(0x%08lx,%p,0x%08lx,0x%08lx,%p,0x%08lx)\n",
         wndProc, hWndParent, dwExStyle, dwStyle, hMenu, z);
2717

2718 2719
  /* If our OS is natively ASCII, use the ASCII version */
  if (!(GetVersion() & 0x80000000))  /* NT */
2720
    return SHCreateWorkerWindowA(wndProc, hWndParent, dwExStyle, dwStyle, hMenu, z);
2721

2722 2723 2724 2725 2726 2727
  /* Create Window class */
  wc.style         = 0;
  wc.lpfnWndProc   = DefWindowProcW;
  wc.cbClsExtra    = 0;
  wc.cbWndExtra    = 4;
  wc.hInstance     = shlwapi_hInstance;
2728
  wc.hIcon         = NULL;
Jacek Caban's avatar
Jacek Caban committed
2729
  wc.hCursor       = LoadCursorW(NULL, (LPWSTR)IDC_ARROW);
2730 2731 2732 2733
  wc.hbrBackground = (HBRUSH)COLOR_BTNSHADOW;
  wc.lpszMenuName  = NULL;
  wc.lpszClassName = szClass;

2734
  SHRegisterClassW(&wc); /* Register class */
2735 2736 2737 2738 2739 2740 2741

  /* FIXME: Set extra bits in dwExStyle */

  hWnd = CreateWindowExW(dwExStyle, szClass, 0, dwStyle, 0, 0, 0, 0,
                         hWndParent, hMenu, shlwapi_hInstance, 0);
  if (hWnd)
  {
Jacek Caban's avatar
Jacek Caban committed
2742
    SetWindowLongW(hWnd, DWL_MSGRESULT, z);
2743 2744

    if (wndProc)
Jacek Caban's avatar
Jacek Caban committed
2745
      SetWindowLongPtrW(hWnd, GWLP_WNDPROC, wndProc);
2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763
  }
  return hWnd;
}

/*************************************************************************
 *      @	[SHLWAPI.279]
 *
 * Get and show a context menu from a shell folder.
 *
 * PARAMS
 *  hWnd           [I] Window displaying the shell folder
 *  lpFolder       [I] IShellFolder interface
 *  lpApidl        [I] Id for the particular folder desired
 *
 * RETURNS
 *  Success: S_OK.
 *  Failure: An HRESULT error code indicating the error.
 */
2764
HRESULT WINAPI SHInvokeDefaultCommand(HWND hWnd, IShellFolder* lpFolder, LPCITEMIDLIST lpApidl)
2765
{
2766
  return SHInvokeCommand(hWnd, lpFolder, lpApidl, FALSE);
2767 2768
}

Juergen Schmied's avatar
Juergen Schmied committed
2769
/*************************************************************************
2770 2771 2772
 *      @	[SHLWAPI.281]
 *
 * _SHPackDispParamsV
Juergen Schmied's avatar
Juergen Schmied committed
2773
 */
2774
HRESULT WINAPI SHPackDispParamsV(LPVOID w, LPVOID x, LPVOID y, LPVOID z)
Juergen Schmied's avatar
Juergen Schmied committed
2775 2776 2777 2778 2779
{
	FIXME("%p %p %p %p\n",w,x,y,z);
	return E_FAIL;
}

2780 2781 2782
/*************************************************************************
 *      @       [SHLWAPI.282]
 *
2783
 * This function seems to be a forward to SHPackDispParamsV (whatever THAT
2784 2785
 * function does...).
 */
2786
HRESULT WINAPI SHPackDispParams(LPVOID w, LPVOID x, LPVOID y, LPVOID z)
2787 2788 2789 2790 2791
{
  FIXME("%p %p %p %p\n", w, x, y, z);
  return E_FAIL;
}

Juergen Schmied's avatar
Juergen Schmied committed
2792
/*************************************************************************
2793 2794 2795
 *      @	[SHLWAPI.284]
 *
 * _IConnectionPoint_SimpleInvoke
Juergen Schmied's avatar
Juergen Schmied committed
2796
 */
2797
DWORD WINAPI IConnectionPoint_SimpleInvoke(
Juergen Schmied's avatar
Juergen Schmied committed
2798 2799 2800 2801
	LPVOID x,
	LPVOID y,
	LPVOID z)
{
2802
        FIXME("(%p %p %p) stub\n",x,y,z);
Juergen Schmied's avatar
Juergen Schmied committed
2803 2804 2805 2806
	return 0;
}

/*************************************************************************
2807
 *      @	[SHLWAPI.285]
2808 2809 2810 2811 2812 2813
 *
 * Notify an IConnectionPoint object of changes.
 *
 * PARAMS
 *  lpCP   [I] Object to notify
 *  dispID [I]
2814
 *
2815 2816 2817 2818
 * RETURNS
 *  Success: S_OK.
 *  Failure: E_NOINTERFACE, if lpCP is NULL or does not support the
 *           IConnectionPoint interface.
Juergen Schmied's avatar
Juergen Schmied committed
2819
 */
2820
HRESULT WINAPI IConnectionPoint_OnChanged(IConnectionPoint* lpCP, DISPID dispID)
Juergen Schmied's avatar
Juergen Schmied committed
2821
{
2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854
  IEnumConnections *lpEnum;
  HRESULT hRet = E_NOINTERFACE;

  TRACE("(%p,0x%8lX)\n", lpCP, dispID);

  /* Get an enumerator for the connections */
  if (lpCP)
    hRet = IConnectionPoint_EnumConnections(lpCP, &lpEnum);

  if (SUCCEEDED(hRet))
  {
    IPropertyNotifySink *lpSink;
    CONNECTDATA connData;
    ULONG ulFetched;

    /* Call OnChanged() for every notify sink in the connection point */
    while (IEnumConnections_Next(lpEnum, 1, &connData, &ulFetched) == S_OK)
    {
      if (SUCCEEDED(IUnknown_QueryInterface(connData.pUnk, &IID_IPropertyNotifySink, (void**)&lpSink)) &&
          lpSink)
      {
        IPropertyNotifySink_OnChanged(lpSink, dispID);
        IPropertyNotifySink_Release(lpSink);
      }
      IUnknown_Release(connData.pUnk);
    }

    IEnumConnections_Release(lpEnum);
  }
  return hRet;
}

/*************************************************************************
2855
 *      @	[SHLWAPI.287]
2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867
 *
 * Notify an IConnectionPointContainer object of changes.
 *
 * PARAMS
 *  lpUnknown [I] Object to notify
 *  dispID    [I]
 *
 * RETURNS
 *  Success: S_OK.
 *  Failure: E_NOINTERFACE, if lpUnknown is NULL or does not support the
 *           IConnectionPointContainer interface.
 */
2868
HRESULT WINAPI IUnknown_CPContainerOnChanged(IUnknown *lpUnknown, DISPID dispID)
2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884
{
  IConnectionPointContainer* lpCPC = NULL;
  HRESULT hRet = E_NOINTERFACE;

  TRACE("(%p,0x%8lX)\n", lpUnknown, dispID);

  if (lpUnknown)
    hRet = IUnknown_QueryInterface(lpUnknown, &IID_IConnectionPointContainer, (void**)&lpCPC);

  if (SUCCEEDED(hRet))
  {
    IConnectionPoint* lpCP;

    hRet = IConnectionPointContainer_FindConnectionPoint(lpCPC, &IID_IPropertyNotifySink, &lpCP);
    IConnectionPointContainer_Release(lpCPC);

2885
    hRet = IConnectionPoint_OnChanged(lpCP, dispID);
2886 2887 2888
    IConnectionPoint_Release(lpCP);
  }
  return hRet;
Juergen Schmied's avatar
Juergen Schmied committed
2889 2890
}

2891
/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
2892
 *      @	[SHLWAPI.289]
2893
 *
2894
 * See PlaySoundW.
2895
 */
2896
BOOL WINAPI PlaySoundWrapW(LPCWSTR pszSound, HMODULE hmod, DWORD fdwSound)
2897
{
2898 2899
  GET_FUNC(pPlaySoundW, winmm, "PlaySoundW", FALSE);
  return pPlaySoundW(pszSound, hmod, fdwSound);
2900 2901
}

2902
/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
2903
 *      @	[SHLWAPI.294]
2904
 */
2905
BOOL WINAPI SHGetIniStringW(LPSTR str1, LPSTR str2, LPSTR pStr, DWORD some_len,  LPCSTR lpStr2)
2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921
{
    /*
     * str1:		"I"	"I"	pushl esp+0x20
     * str2:		"U"	"I"	pushl 0x77c93810
     * (is "I" and "U" "integer" and "unsigned" ??)
     *
     * pStr:		""	""	pushl eax
     * some_len:	0x824	0x104	pushl 0x824
     * lpStr2:		"%l"	"%l"	pushl esp+0xc
     *
     * shlwapi. StrCpyNW(lpStr2, irrelevant_var, 0x104);
     * LocalAlloc(0x00, some_len) -> irrelevant_var
     * LocalAlloc(0x40, irrelevant_len) -> pStr
     * shlwapi.294(str1, str2, pStr, some_len, lpStr2);
     * shlwapi.PathRemoveBlanksW(pStr);
     */
2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936
    FIXME("('%s', '%s', '%s', %08lx, '%s'): stub!\n", str1, str2, pStr, some_len, lpStr2);
    return TRUE;
}

/*************************************************************************
 *      @	[SHLWAPI.295]
 *
 * Called by ICQ2000b install via SHDOCVW:
 * str1: "InternetShortcut"
 * x: some unknown pointer
 * str2: "http://free.aol.com/tryaolfree/index.adp?139269"
 * str3: "C:\\WINDOWS\\Desktop.new2\\Free AOL & Unlimited Internet.url"
 *
 * In short: this one maybe creates a desktop link :-)
 */
2937
BOOL WINAPI SHSetIniStringW(LPWSTR str1, LPVOID x, LPWSTR str2, LPWSTR str3)
2938 2939
{
    FIXME("('%s', %p, '%s', '%s'), stub.\n", debugstr_w(str1), x, debugstr_w(str2), debugstr_w(str3));
2940 2941 2942
    return TRUE;
}

2943 2944 2945
/*************************************************************************
 *      @	[SHLWAPI.299]
 *
2946
 * See COMCTL32_417.
2947
 */
2948
BOOL WINAPI ExtTextOutWrapW(HDC hdc, INT x, INT y, UINT flags, const RECT *lprect,
2949 2950 2951 2952 2953 2954
                         LPCWSTR str, UINT count, const INT *lpDx)
{
    GET_FUNC(pCOMCTL32_417, comctl32, (LPCSTR)417, FALSE);
    return pCOMCTL32_417(hdc, x, y, flags, lprect, str, count, lpDx);
}

2955
/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
2956
 *      @	[SHLWAPI.313]
2957
 *
2958
 * See SHGetFileInfoW.
2959
 */
2960
DWORD WINAPI SHGetFileInfoWrapW(LPCWSTR path, DWORD dwFileAttributes,
2961 2962
                         SHFILEINFOW *psfi, UINT sizeofpsfi, UINT flags)
{
2963 2964
  GET_FUNC(pSHGetFileInfoW, shell32, "SHGetFileInfoW", 0);
  return pSHGetFileInfoW(path, dwFileAttributes, psfi, sizeofpsfi, flags);
2965 2966 2967
}

/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
2968
 *      @	[SHLWAPI.318]
2969
 *
2970
 * See DragQueryFileW.
2971
 */
2972
UINT WINAPI DragQueryFileWrapW(HDROP hDrop, UINT lFile, LPWSTR lpszFile, UINT lLength)
2973
{
2974 2975
  GET_FUNC(pDragQueryFileW, shell32, "DragQueryFileW", 0);
  return pDragQueryFileW(hDrop, lFile, lpszFile, lLength);
2976 2977 2978
}

/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
2979
 *      @	[SHLWAPI.333]
2980
 *
2981
 * See SHBrowseForFolderW.
2982
 */
2983
LPITEMIDLIST WINAPI SHBrowseForFolderWrapW(LPBROWSEINFOW lpBi)
2984
{
2985 2986
  GET_FUNC(pSHBrowseForFolderW, shell32, "SHBrowseForFolderW", NULL);
  return pSHBrowseForFolderW(lpBi);
2987 2988 2989
}

/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
2990
 *      @	[SHLWAPI.334]
2991
 *
2992
 * See SHGetPathFromIDListW.
2993
 */
2994
BOOL WINAPI SHGetPathFromIDListWrapW(LPCITEMIDLIST pidl,LPWSTR pszPath)
2995
{
2996 2997
  GET_FUNC(pSHGetPathFromIDListW, shell32, "SHGetPathFromIDListW", 0);
  return pSHGetPathFromIDListW(pidl, pszPath);
2998 2999 3000
}

/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
3001
 *      @	[SHLWAPI.335]
3002
 *
3003
 * See ShellExecuteExW.
3004
 */
3005
BOOL WINAPI ShellExecuteExWrapW(LPSHELLEXECUTEINFOW lpExecInfo)
3006
{
3007 3008
  GET_FUNC(pShellExecuteExW, shell32, "ShellExecuteExW", FALSE);
  return pShellExecuteExW(lpExecInfo);
3009 3010 3011
}

/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
3012
 *      @	[SHLWAPI.336]
3013
 *
3014
 * See SHFileOperationW.
3015
 */
3016
HICON WINAPI SHFileOperationWrapW(LPSHFILEOPSTRUCTW lpFileOp)
3017
{
3018 3019
  GET_FUNC(pSHFileOperationW, shell32, "SHFileOperationW", 0);
  return pSHFileOperationW(lpFileOp);
3020 3021 3022
}

/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
3023
 *      @	[SHLWAPI.337]
3024
 *
3025
 * See ExtractIconExW.
3026
 */
3027
UINT WINAPI ExtractIconExWrapW(LPCWSTR lpszFile, INT nIconIndex, HICON *phiconLarge,
3028 3029
                         HICON *phiconSmall, UINT nIcons)
{
3030
  GET_FUNC(pExtractIconExW, shell32, "ExtractIconExW", 0);
3031
  return pExtractIconExW(lpszFile, nIconIndex, phiconLarge, phiconSmall, nIcons);
3032 3033
}

3034
/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
3035
 *      @	[SHLWAPI.342]
3036 3037
 *
 */
3038
LONG WINAPI SHInterlockedCompareExchange( PLONG dest, LONG xchg, LONG compare)
3039
{
3040
        return InterlockedCompareExchange(dest, xchg, compare);
3041 3042
}

3043 3044 3045
/*************************************************************************
 *      @	[SHLWAPI.350]
 *
3046
 * See GetFileVersionInfoSizeW.
3047
 */
3048
DWORD WINAPI GetFileVersionInfoSizeWrapW(
3049 3050 3051 3052 3053
	LPWSTR x,
	LPVOID y)
{
        DWORD ret;

3054 3055
	GET_FUNC(pGetFileVersionInfoSizeW, version, "GetFileVersionInfoSizeW", 0);
	ret = pGetFileVersionInfoSizeW(x, y);
3056 3057 3058 3059 3060 3061
	return 0x208 + ret;
}

/*************************************************************************
 *      @	[SHLWAPI.351]
 *
3062
 * See GetFileVersionInfoW.
3063
 */
3064
BOOL  WINAPI GetFileVersionInfoWrapW(
3065 3066
	LPWSTR w,   /* [in] path to dll */
	DWORD  x,   /* [in] parm 2 to GetFileVersionInfoA */
3067 3068
	DWORD  y,   /* [in] return value from SHLWAPI_350() - assume length */
	LPVOID z)   /* [in/out] buffer (+0x208 sent to GetFileVersionInfoA()) */
3069
{
3070
    GET_FUNC(pGetFileVersionInfoW, version, "GetFileVersionInfoW", 0);
3071
    return pGetFileVersionInfoW(w, x, y-0x208, (char*)z+0x208);
3072 3073 3074 3075 3076
}

/*************************************************************************
 *      @	[SHLWAPI.352]
 *
3077
 * See VerQueryValueW.
3078
 */
3079
WORD WINAPI VerQueryValueWrapW(
3080 3081 3082 3083
	LPVOID w,   /* [in] Buffer from SHLWAPI_351() */
	LPWSTR x,   /* [in]   Value to retrieve - converted and passed to VerQueryValueA() as #2 */
	LPVOID y,   /* [out]  Ver buffer - passed to VerQueryValueA as #3 */
	UINT*  z)   /* [in]   Ver length - passed to VerQueryValueA as #4 */
3084
{
3085
    GET_FUNC(pVerQueryValueW, version, "VerQueryValueW", 0);
3086
    return pVerQueryValueW((char*)w+0x208, x, y, z);
3087 3088
}

3089 3090 3091 3092 3093
#define IsIface(type) SUCCEEDED((hRet = IUnknown_QueryInterface(lpUnknown, &IID_##type, (void**)&lpObj)))
#define IShellBrowser_EnableModeless IShellBrowser_EnableModelessSB
#define EnableModeless(type) type##_EnableModeless((type*)lpObj, bModeless)

/*************************************************************************
3094
 *      @	[SHLWAPI.355]
3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110
 *
 * Change the modality of a shell object.
 *
 * PARAMS
 *  lpUnknown [I] Object to make modeless
 *  bModeless [I] TRUE=Make modeless, FALSE=Make modal
 *
 * RETURNS
 *  Success: S_OK. The modality lpUnknown is changed.
 *  Failure: An HRESULT error code indicating the error.
 *
 * NOTES
 *  lpUnknown must support the IOleInPlaceFrame interface, the
 *  IInternetSecurityMgrSite interface, the IShellBrowser interface
 *  or the IDocHostUIHandler interface, or this call fails.
 */
3111
HRESULT WINAPI IUnknown_EnableModeless(IUnknown *lpUnknown, BOOL bModeless)
3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138
{
  IUnknown *lpObj;
  HRESULT hRet;

  TRACE("(%p,%d)\n", lpUnknown, bModeless);

  if (!lpUnknown)
    return E_FAIL;

  if (IsIface(IOleInPlaceFrame))
    EnableModeless(IOleInPlaceFrame);
  else if (IsIface(IShellBrowser))
    EnableModeless(IShellBrowser);
#if 0
  /* FIXME: Wine has no headers for these objects yet */
  else if (IsIface(IInternetSecurityMgrSite))
    EnableModeless(IInternetSecurityMgrSite);
  else if (IsIface(IDocHostUIHandler))
    EnableModeless(IDocHostUIHandler);
#endif
  else
    return hRet;

  IUnknown_Release(lpObj);
  return S_OK;
}

3139
/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
3140
 *      @	[SHLWAPI.357]
3141
 *
3142
 * See SHGetNewLinkInfoW.
3143
 */
3144
BOOL WINAPI SHGetNewLinkInfoWrapW(LPCWSTR pszLinkTo, LPCWSTR pszDir, LPWSTR pszName,
3145 3146
                        BOOL *pfMustCopy, UINT uFlags)
{
3147 3148
  GET_FUNC(pSHGetNewLinkInfoW, shell32, "SHGetNewLinkInfoW", FALSE);
  return pSHGetNewLinkInfoW(pszLinkTo, pszDir, pszName, pfMustCopy, uFlags);
3149 3150 3151
}

/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
3152
 *      @	[SHLWAPI.358]
3153
 *
3154
 * See SHDefExtractIconW.
3155
 */
3156
UINT WINAPI SHDefExtractIconWrapW(LPCWSTR pszIconFile, int iIndex, UINT uFlags, HICON* phiconLarge,
3157
                         HICON* phiconSmall, UINT nIconSize)
3158
{
3159
  GET_FUNC(pSHDefExtractIconW, shell32, "SHDefExtractIconW", 0);
3160
  return pSHDefExtractIconW(pszIconFile, iIndex, uFlags, phiconLarge, phiconSmall, nIconSize);
3161 3162
}

3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178
/*************************************************************************
 *      @	[SHLWAPI.363]
 *
 * Get and show a context menu from a shell folder.
 *
 * PARAMS
 *  hWnd           [I] Window displaying the shell folder
 *  lpFolder       [I] IShellFolder interface
 *  lpApidl        [I] Id for the particular folder desired
 *  bInvokeDefault [I] Whether to invoke the default menu item
 *
 * RETURNS
 *  Success: S_OK. If bInvokeDefault is TRUE, the default menu action was
 *           executed.
 *  Failure: An HRESULT error code indicating the error.
 */
3179
HRESULT WINAPI SHInvokeCommand(HWND hWnd, IShellFolder* lpFolder, LPCITEMIDLIST lpApidl, BOOL bInvokeDefault)
3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227
{
  IContextMenu *iContext;
  HRESULT hRet = E_FAIL;

  TRACE("(%p,%p,%p,%d)\n", hWnd, lpFolder, lpApidl, bInvokeDefault);

  if (!lpFolder)
    return hRet;

  /* Get the context menu from the shell folder */
  hRet = IShellFolder_GetUIObjectOf(lpFolder, hWnd, 1, &lpApidl,
                                    &IID_IContextMenu, 0, (void**)&iContext);
  if (SUCCEEDED(hRet))
  {
    HMENU hMenu;
    if ((hMenu = CreatePopupMenu()))
    {
      HRESULT hQuery;
      DWORD dwDefaultId = 0;

      /* Add the context menu entries to the popup */
      hQuery = IContextMenu_QueryContextMenu(iContext, hMenu, 0, 1, 0x7FFF,
                                             bInvokeDefault ? CMF_NORMAL : CMF_DEFAULTONLY);

      if (SUCCEEDED(hQuery))
      {
        if (bInvokeDefault &&
            (dwDefaultId = GetMenuDefaultItem(hMenu, 0, 0)) != 0xFFFFFFFF)
        {
          CMINVOKECOMMANDINFO cmIci;
          /* Invoke the default item */
          memset(&cmIci,0,sizeof(cmIci));
          cmIci.cbSize = sizeof(cmIci);
          cmIci.fMask = CMIC_MASK_ASYNCOK;
          cmIci.hwnd = hWnd;
          cmIci.lpVerb = MAKEINTRESOURCEA(dwDefaultId);
          cmIci.nShow = SW_SCROLLCHILDREN;

          hRet = IContextMenu_InvokeCommand(iContext, &cmIci);
        }
      }
      DestroyMenu(hMenu);
    }
    IContextMenu_Release(iContext);
  }
  return hRet;
}

3228
/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
3229
 *      @	[SHLWAPI.370]
3230
 *
3231
 * See ExtractIconW.
3232
 */
3233
HICON WINAPI ExtractIconWrapW(HINSTANCE hInstance, LPCWSTR lpszExeFileName,
3234 3235
                         UINT nIconIndex)
{
3236
  GET_FUNC(pExtractIconW, shell32, "ExtractIconW", NULL);
3237
  return pExtractIconW(hInstance, lpszExeFileName, nIconIndex);
3238 3239 3240
}

/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
3241
 *      @	[SHLWAPI.376]
3242
 */
3243
LANGID WINAPI MLGetUILanguage()
3244
{
3245 3246 3247 3248 3249
    FIXME("() stub\n");
    /* FIXME: This should be a forward in the .spec file to the win2k function
     * kernel32.GetUserDefaultUILanguage, however that function isn't there yet.
     */
    return GetUserDefaultLangID();
3250
}
3251 3252

/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
3253
 *      @	[SHLWAPI.377]
3254
 *
3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265
 * Load a library from the directory of a particular process.
 *
 * PARAMS
 *  new_mod   [I] Library name
 *  inst_hwnd [I] Module whose directory is to be used
 *  dwFlags   [I] Flags controlling the load
 *
 * RETURNS
 *  Success: A handle to the loaded module
 *  Failure: A NULL handle.
 */
3266
HMODULE WINAPI MLLoadLibraryA(LPCSTR new_mod, HMODULE inst_hwnd, DWORD dwFlags)
3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285
{
  /* FIXME: Native appears to do DPA_Create and a DPA_InsertPtr for
   *        each call here.
   * FIXME: Native shows calls to:
   *  SHRegGetUSValue for "Software\Microsoft\Internet Explorer\International"
   *                      CheckVersion
   *  RegOpenKeyExA for "HKLM\Software\Microsoft\Internet Explorer"
   *  RegQueryValueExA for "LPKInstalled"
   *  RegCloseKey
   *  RegOpenKeyExA for "HKCU\Software\Microsoft\Internet Explorer\International"
   *  RegQueryValueExA for "ResourceLocale"
   *  RegCloseKey
   *  RegOpenKeyExA for "HKLM\Software\Microsoft\Active Setup\Installed Components\{guid}"
   *  RegQueryValueExA for "Locale"
   *  RegCloseKey
   *  and then tests the Locale ("en" for me).
   *     code below
   *  after the code then a DPA_Create (first time) and DPA_InsertPtr are done.
   */
3286 3287
    CHAR mod_path[2*MAX_PATH];
    LPSTR ptr;
3288
    DWORD len;
3289

3290
    FIXME("(%s,%p,0x%08lx) semi-stub!\n", debugstr_a(new_mod), inst_hwnd, dwFlags);
3291 3292 3293
    len = GetModuleFileNameA(inst_hwnd, mod_path, sizeof(mod_path));
    if (!len || len >= sizeof(mod_path)) return NULL;

3294 3295 3296 3297
    ptr = strrchr(mod_path, '\\');
    if (ptr) {
	strcpy(ptr+1, new_mod);
	TRACE("loading %s\n", debugstr_a(mod_path));
3298
	return LoadLibraryA(mod_path);
3299
    }
3300
    return NULL;
3301 3302 3303
}

/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
3304
 *      @	[SHLWAPI.378]
3305
 *
3306
 * Unicode version of MLLoadLibraryA.
3307
 */
3308
HMODULE WINAPI MLLoadLibraryW(LPCWSTR new_mod, HMODULE inst_hwnd, DWORD dwFlags)
3309 3310 3311
{
    WCHAR mod_path[2*MAX_PATH];
    LPWSTR ptr;
3312
    DWORD len;
3313

3314
    FIXME("(%s,%p,0x%08lx) semi-stub!\n", debugstr_w(new_mod), inst_hwnd, dwFlags);
3315 3316 3317
    len = GetModuleFileNameW(inst_hwnd, mod_path, sizeof(mod_path) / sizeof(WCHAR));
    if (!len || len >= sizeof(mod_path) / sizeof(WCHAR)) return NULL;

3318 3319 3320 3321
    ptr = strrchrW(mod_path, '\\');
    if (ptr) {
	strcpyW(ptr+1, new_mod);
	TRACE("loading %s\n", debugstr_w(mod_path));
3322
	return LoadLibraryW(mod_path);
3323
    }
3324
    return NULL;
3325 3326
}

3327
/*************************************************************************
3328
 * ColorAdjustLuma      [SHLWAPI.@]
3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358
 *
 * Adjust the luminosity of a color
 *
 * PARAMS
 *  cRGB         [I] RGB value to convert
 *  dwLuma       [I] Luma adjustment
 *  bUnknown     [I] Unknown
 *
 * RETURNS
 *  The adjusted RGB color.
 */
COLORREF WINAPI ColorAdjustLuma(COLORREF cRGB, int dwLuma, BOOL bUnknown)
{
  TRACE("(0x%8lx,%d,%d)\n", cRGB, dwLuma, bUnknown);

  if (dwLuma)
  {
    WORD wH, wL, wS;

    ColorRGBToHLS(cRGB, &wH, &wL, &wS);

    FIXME("Ignoring luma adjustment\n");

    /* FIXME: The ajdustment is not linear */

    cRGB = ColorHLSToRGB(wH, wL, wS);
  }
  return cRGB;
}

3359
/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
3360
 *      @	[SHLWAPI.389]
3361
 *
3362
 * See GetSaveFileNameW.
3363
 */
3364
BOOL WINAPI GetSaveFileNameWrapW(LPOPENFILENAMEW ofn)
3365
{
3366 3367
  GET_FUNC(pGetSaveFileNameW, comdlg32, "GetSaveFileNameW", FALSE);
  return pGetSaveFileNameW(ofn);
3368 3369 3370
}

/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
3371
 *      @	[SHLWAPI.390]
3372
 *
3373
 * See WNetRestoreConnectionW.
3374
 */
3375
DWORD WINAPI WNetRestoreConnectionWrapW(HWND hwndOwner, LPWSTR lpszDevice)
3376
{
3377
  GET_FUNC(pWNetRestoreConnectionW, mpr, "WNetRestoreConnectionW", 0);
3378
  return pWNetRestoreConnectionW(hwndOwner, lpszDevice);
3379 3380 3381
}

/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
3382
 *      @	[SHLWAPI.391]
3383
 *
3384
 * See WNetGetLastErrorW.
3385
 */
3386
DWORD WINAPI WNetGetLastErrorWrapW(LPDWORD lpError, LPWSTR lpErrorBuf, DWORD nErrorBufSize,
3387
                         LPWSTR lpNameBuf, DWORD nNameBufSize)
3388
{
3389
  GET_FUNC(pWNetGetLastErrorW, mpr, "WNetGetLastErrorW", 0);
3390
  return pWNetGetLastErrorW(lpError, lpErrorBuf, nErrorBufSize, lpNameBuf, nNameBufSize);
3391 3392 3393
}

/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
3394
 *      @	[SHLWAPI.401]
3395
 *
3396
 * See PageSetupDlgW.
3397
 */
3398
BOOL WINAPI PageSetupDlgWrapW(LPPAGESETUPDLGW pagedlg)
3399
{
3400 3401
  GET_FUNC(pPageSetupDlgW, comdlg32, "PageSetupDlgW", FALSE);
  return pPageSetupDlgW(pagedlg);
3402 3403 3404
}

/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
3405
 *      @	[SHLWAPI.402]
3406
 *
3407
 * See PrintDlgW.
3408
 */
3409
BOOL WINAPI PrintDlgWrapW(LPPRINTDLGW printdlg)
3410
{
3411 3412
  GET_FUNC(pPrintDlgW, comdlg32, "PrintDlgW", FALSE);
  return pPrintDlgW(printdlg);
3413 3414 3415
}

/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
3416
 *      @	[SHLWAPI.403]
3417
 *
3418
 * See GetOpenFileNameW.
3419
 */
3420
BOOL WINAPI GetOpenFileNameWrapW(LPOPENFILENAMEW ofn)
3421
{
3422 3423
  GET_FUNC(pGetOpenFileNameW, comdlg32, "GetOpenFileNameW", FALSE);
  return pGetOpenFileNameW(ofn);
3424 3425 3426
}

/* INTERNAL: Map from HLS color space to RGB */
3427
static WORD WINAPI ConvertHue(int wHue, WORD wMid1, WORD wMid2)
3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444
{
  wHue = wHue > 240 ? wHue - 240 : wHue < 0 ? wHue + 240 : wHue;

  if (wHue > 160)
    return wMid1;
  else if (wHue > 120)
    wHue = 160 - wHue;
  else if (wHue > 40)
    return wMid2;

  return ((wHue * (wMid2 - wMid1) + 20) / 40) + wMid1;
}

/* Convert to RGB and scale into RGB range (0..255) */
#define GET_RGB(h) (ConvertHue(h, wMid1, wMid2) * 255 + 120) / 240

/*************************************************************************
3445
 *      ColorHLSToRGB	[SHLWAPI.@]
3446
 *
3447 3448 3449 3450 3451 3452 3453 3454 3455
 * Convert from hls color space into an rgb COLORREF.
 *
 * PARAMS
 *  wHue        [I] Hue amount
 *  wLuminosity [I] Luminosity amount
 *  wSaturation [I] Saturation amount
 *
 * RETURNS
 *  A COLORREF representing the converted color.
3456 3457
 *
 * NOTES
3458
 *  Input hls values are constrained to the range (0..240).
3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485
 */
COLORREF WINAPI ColorHLSToRGB(WORD wHue, WORD wLuminosity, WORD wSaturation)
{
  WORD wRed;

  if (wSaturation)
  {
    WORD wGreen, wBlue, wMid1, wMid2;

    if (wLuminosity > 120)
      wMid2 = wSaturation + wLuminosity - (wSaturation * wLuminosity + 120) / 240;
    else
      wMid2 = ((wSaturation + 240) * wLuminosity + 120) / 240;

    wMid1 = wLuminosity * 2 - wMid2;

    wRed   = GET_RGB(wHue + 80);
    wGreen = GET_RGB(wHue);
    wBlue  = GET_RGB(wHue - 80);

    return RGB(wRed, wGreen, wBlue);
  }

  wRed = wLuminosity * 255 / 240;
  return RGB(wRed, wRed, wRed);
}

3486 3487 3488
/*************************************************************************
 *      @	[SHLWAPI.413]
 *
3489 3490 3491 3492 3493 3494 3495 3496
 * Get the current docking status of the system.
 *
 * PARAMS
 *  dwFlags [I] DOCKINFO_ flags from "winbase.h", unused
 *
 * RETURNS
 *  One of DOCKINFO_UNDOCKED, DOCKINFO_UNDOCKED, or 0 if the system is not
 *  a notebook.
3497
 */
3498
DWORD WINAPI SHGetMachineInfo(DWORD dwFlags)
3499
{
3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512
  HW_PROFILE_INFOA hwInfo;

  TRACE("(0x%08lx)\n", dwFlags);

  GetCurrentHwProfileA(&hwInfo);
  switch (hwInfo.dwDockInfo & (DOCKINFO_DOCKED|DOCKINFO_UNDOCKED))
  {
  case DOCKINFO_DOCKED:
  case DOCKINFO_UNDOCKED:
    return hwInfo.dwDockInfo & (DOCKINFO_DOCKED|DOCKINFO_UNDOCKED);
  default:
    return 0;
  }
3513 3514
}

3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528
/*************************************************************************
 *      @	[SHLWAPI.418]
 *
 * Function seems to do FreeLibrary plus other things.
 *
 * FIXME native shows the following calls:
 *   RtlEnterCriticalSection
 *   LocalFree
 *   GetProcAddress(Comctl32??, 150L)
 *   DPA_DeletePtr
 *   RtlLeaveCriticalSection
 *  followed by the FreeLibrary.
 *  The above code may be related to .377 above.
 */
3529
BOOL WINAPI MLFreeLibrary(HMODULE hModule)
3530
{
3531 3532
	FIXME("(%p) semi-stub\n", hModule);
	return FreeLibrary(hModule);
3533 3534
}

3535 3536 3537 3538 3539 3540 3541 3542
/*************************************************************************
 *      @	[SHLWAPI.419]
 */
BOOL WINAPI SHFlushSFCacheWrap(void) {
  FIXME(": stub\n");
  return TRUE;
}

Juan Lang's avatar
Juan Lang committed
3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553
/*************************************************************************
 *      @      [SHLWAPI.429]
 * FIXME I have no idea what this function does or what its arguments are.
 */
BOOL WINAPI MLIsMLHInstance(HINSTANCE hInst)
{
       FIXME("(%p) stub\n", hInst);
       return FALSE;
}


3554 3555 3556
/*************************************************************************
 *      @	[SHLWAPI.430]
 */
3557
DWORD WINAPI MLSetMLHInstance(HINSTANCE hInst, HANDLE hHeap)
3558
{
3559
	FIXME("(%p,%p) stub\n", hInst, hHeap);
3560 3561 3562
	return E_FAIL;   /* This is what is used if shlwapi not loaded */
}

3563
/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
3564
 *      @	[SHLWAPI.431]
3565
 */
3566
DWORD WINAPI MLClearMLHInstance(DWORD x)
3567 3568 3569 3570 3571
{
	FIXME("(0x%08lx)stub\n", x);
	return 0xabba1247;
}

3572 3573 3574
/*************************************************************************
 *      @	[SHLWAPI.436]
 *
3575 3576 3577 3578 3579 3580 3581 3582 3583 3584
 * Convert an Unicode string CLSID into a CLSID.
 *
 * PARAMS
 *  idstr      [I]   string containing a CLSID in text form
 *  id         [O]   CLSID extracted from the string
 *
 * RETURNS
 *  S_OK on success or E_INVALIDARG on failure
 *
 * NOTES
3585
 *  This is really CLSIDFromString() which is exported by ole32.dll,
3586 3587
 *  however the native shlwapi.dll does *not* import ole32. Nor does
 *  ole32.dll import this ordinal from shlwapi. Therefore we must conclude
3588
 *  that MS duplicated the code for CLSIDFromString(), and yes they did, only
3589
 *  it returns an E_INVALIDARG error code on failure.
3590 3591
 *  This is a duplicate (with changes for Unicode) of CLSIDFromString16()
 *  in "dlls/ole32/compobj.c".
3592
 */
3593
HRESULT WINAPI CLSIDFromStringWrap(LPCWSTR idstr, CLSID *id)
3594
{
3595 3596 3597 3598
	LPCWSTR s = idstr;
	BYTE *p;
	INT i;
	WCHAR table[256];
3599

3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622
	if (!s) {
	  memset(id, 0, sizeof(CLSID));
	  return S_OK;
	}
	else {  /* validate the CLSID string */

	  if (strlenW(s) != 38)
	    return E_INVALIDARG;

	  if ((s[0]!=L'{') || (s[9]!=L'-') || (s[14]!=L'-') || (s[19]!=L'-') || (s[24]!=L'-') || (s[37]!=L'}'))
	    return E_INVALIDARG;

	  for (i=1; i<37; i++)
	  {
	    if ((i == 9)||(i == 14)||(i == 19)||(i == 24))
	      continue;
	    if (!(((s[i] >= L'0') && (s[i] <= L'9'))  ||
	        ((s[i] >= L'a') && (s[i] <= L'f'))  ||
	        ((s[i] >= L'A') && (s[i] <= L'F')))
	       )
	      return E_INVALIDARG;
	  }
	}
3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677

    TRACE("%s -> %p\n", debugstr_w(s), id);

  /* quick lookup table */
    memset(table, 0, 256*sizeof(WCHAR));

    for (i = 0; i < 10; i++) {
	table['0' + i] = i;
    }
    for (i = 0; i < 6; i++) {
	table['A' + i] = i+10;
	table['a' + i] = i+10;
    }

    /* in form {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} */

    p = (BYTE *) id;

    s++;	/* skip leading brace  */
    for (i = 0; i < 4; i++) {
	p[3 - i] = table[*s]<<4 | table[*(s+1)];
	s += 2;
    }
    p += 4;
    s++;	/* skip - */

    for (i = 0; i < 2; i++) {
	p[1-i] = table[*s]<<4 | table[*(s+1)];
	s += 2;
    }
    p += 2;
    s++;	/* skip - */

    for (i = 0; i < 2; i++) {
	p[1-i] = table[*s]<<4 | table[*(s+1)];
	s += 2;
    }
    p += 2;
    s++;	/* skip - */

    /* these are just sequential bytes */
    for (i = 0; i < 2; i++) {
	*p++ = table[*s]<<4 | table[*(s+1)];
	s += 2;
    }
    s++;	/* skip - */

    for (i = 0; i < 6; i++) {
	*p++ = table[*s]<<4 | table[*(s+1)];
	s += 2;
    }

    return S_OK;
}

3678
/*************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
3679
 *      @	[SHLWAPI.437]
3680
 *
3681 3682 3683 3684 3685 3686 3687 3688
 * Determine if the OS supports a given feature.
 *
 * PARAMS
 *  dwFeature [I] Feature requested (undocumented)
 *
 * RETURNS
 *  TRUE  If the feature is available.
 *  FALSE If the feature is not available.
3689
 */
Jacek Caban's avatar
Jacek Caban committed
3690
BOOL WINAPI IsOS(DWORD feature)
3691
{
Jacek Caban's avatar
Jacek Caban committed
3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801
    OSVERSIONINFOA osvi;
    DWORD platform, majorv, minorv;

    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
    if(!GetVersionExA(&osvi))  {
        ERR("GetVersionEx failed");
        return FALSE;
    }

    majorv = osvi.dwMajorVersion;
    minorv = osvi.dwMinorVersion;
    platform = osvi.dwPlatformId;

#define ISOS_RETURN(x) \
    TRACE("(0x%lx) ret=%d\n",feature,(x)); \
    return (x);

    switch(feature)  {
    case OS_WIN32SORGREATER:
        ISOS_RETURN(platform == VER_PLATFORM_WIN32s
                 || platform == VER_PLATFORM_WIN32_WINDOWS)
    case OS_NT:
        ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT)
    case OS_WIN95ORGREATER:
        ISOS_RETURN(platform == VER_PLATFORM_WIN32_WINDOWS)
    case OS_NT4ORGREATER:
        ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT && majorv >= 4)
    case OS_WIN2000ORGREATER_ALT:
    case OS_WIN2000ORGREATER:
        ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT && majorv >= 5)
    case OS_WIN98ORGREATER:
        ISOS_RETURN(platform == VER_PLATFORM_WIN32_WINDOWS && minorv >= 10)
    case OS_WIN98_GOLD:
        ISOS_RETURN(platform == VER_PLATFORM_WIN32_WINDOWS && minorv == 10)
    case OS_WIN2000PRO:
        ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT && majorv >= 5)
    case OS_WIN2000SERVER:
        ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT && (minorv == 0 || minorv == 1))
    case OS_WIN2000ADVSERVER:
        ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT && (minorv == 0 || minorv == 1))
    case OS_WIN2000DATACENTER:
        ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT && (minorv == 0 || minorv == 1))
    case OS_WIN2000TERMINAL:
        ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT && (minorv == 0 || minorv == 1))
    case OS_EMBEDDED:
        FIXME("(OS_EMBEDDED) What should we return here?\n");
        return FALSE;
    case OS_TERMINALCLIENT:
        FIXME("(OS_TERMINALCLIENT) What should we return here?\n");
        return FALSE;
    case OS_TERMINALREMOTEADMIN:
        FIXME("(OS_TERMINALREMOTEADMIN) What should we return here?\n");
        return FALSE;
    case OS_WIN95_GOLD:
        ISOS_RETURN(platform == VER_PLATFORM_WIN32_WINDOWS && minorv == 0)
    case OS_MEORGREATER:
        ISOS_RETURN(platform == VER_PLATFORM_WIN32_WINDOWS && minorv >= 90)
    case OS_XPORGREATER:
        ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT && majorv >= 5 && minorv >= 1)
    case OS_HOME:
        ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT && majorv >= 5 && minorv >= 1)
    case OS_PROFESSIONAL:
        ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT) 
    case OS_DATACENTER:
        ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT)
    case OS_ADVSERVER:
        ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT && majorv >= 5)
    case OS_SERVER:
        ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT)
    case OS_TERMINALSERVER:
        ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT)
    case OS_PERSONALTERMINALSERVER:
        ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT && minorv >= 1 && majorv >= 5)
    case OS_FASTUSERSWITCHING:
        FIXME("(OS_FASTUSERSWITCHING) What should we return here?\n");
        return TRUE;
    case OS_WELCOMELOGONUI:
        FIXME("(OS_WELCOMELOGONUI) What should we return here?\n");
        return FALSE;
    case OS_DOMAINMEMBER:
        FIXME("(OS_DOMAINMEMBER) What should we return here?\n");
        return TRUE;
    case OS_ANYSERVER:
        ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT)
    case OS_WOW6432:
        FIXME("(OS_WOW6432) Should we check this?\n");
        return FALSE;
    case OS_WEBSERVER:
        ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT)
    case OS_SMALLBUSINESSSERVER:
        ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT)
    case OS_TABLETPC:
        FIXME("(OS_TABLEPC) What should we return here?\n");
        return FALSE;
    case OS_SERVERADMINUI:
        FIXME("(OS_SERVERADMINUI) What should we return here?\n");
        return FALSE;
    case OS_MEDIACENTER:
        FIXME("(OS_MEDIACENTER) What should we return here?\n");
        return FALSE;
    case OS_APPLIANCE:
        FIXME("(OS_APPLIANCE) What should we return here?\n");
        return FALSE;
    }

#undef ISOS_RETURN

    WARN("(0x%lx) unknown parameter\n",feature);

    return FALSE;
3802 3803 3804
}

/*************************************************************************
3805
 *      ColorRGBToHLS	[SHLWAPI.@]
3806
 *
3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817
 * Convert an rgb COLORREF into the hls color space.
 *
 * PARAMS
 *  cRGB         [I] Source rgb value
 *  pwHue        [O] Destination for converted hue
 *  pwLuminance  [O] Destination for converted luminance
 *  pwSaturation [O] Destination for converted saturation
 *
 * RETURNS
 *  Nothing. pwHue, pwLuminance and pwSaturation are set to the converted
 *  values.
3818 3819
 *
 * NOTES
3820 3821
 *  Output HLS values are constrained to the range (0..240).
 *  For Achromatic conversions, Hue is set to 160.
3822
 */
3823 3824
VOID WINAPI ColorRGBToHLS(COLORREF cRGB, LPWORD pwHue,
			  LPWORD pwLuminance, LPWORD pwSaturation)
3825
{
3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879
  int wR, wG, wB, wMax, wMin, wHue, wLuminosity, wSaturation;

  TRACE("(%08lx,%p,%p,%p)\n", cRGB, pwHue, pwLuminance, pwSaturation);

  wR = GetRValue(cRGB);
  wG = GetGValue(cRGB);
  wB = GetBValue(cRGB);

  wMax = max(wR, max(wG, wB));
  wMin = min(wR, min(wG, wB));

  /* Luminosity */
  wLuminosity = ((wMax + wMin) * 240 + 255) / 510;

  if (wMax == wMin)
  {
    /* Achromatic case */
    wSaturation = 0;
    /* Hue is now unrepresentable, but this is what native returns... */
    wHue = 160;
  }
  else
  {
    /* Chromatic case */
    int wDelta = wMax - wMin, wRNorm, wGNorm, wBNorm;

    /* Saturation */
    if (wLuminosity <= 120)
      wSaturation = ((wMax + wMin)/2 + wDelta * 240) / (wMax + wMin);
    else
      wSaturation = ((510 - wMax - wMin)/2 + wDelta * 240) / (510 - wMax - wMin);

    /* Hue */
    wRNorm = (wDelta/2 + wMax * 40 - wR * 40) / wDelta;
    wGNorm = (wDelta/2 + wMax * 40 - wG * 40) / wDelta;
    wBNorm = (wDelta/2 + wMax * 40 - wB * 40) / wDelta;

    if (wR == wMax)
      wHue = wBNorm - wGNorm;
    else if (wG == wMax)
      wHue = 80 + wRNorm - wBNorm;
    else
      wHue = 160 + wGNorm - wRNorm;
    if (wHue < 0)
      wHue += 240;
    else if (wHue > 240)
      wHue -= 240;
  }
  if (pwHue)
    *pwHue = wHue;
  if (pwLuminance)
    *pwLuminance = wLuminosity;
  if (pwSaturation)
    *pwSaturation = wSaturation;
3880 3881
}

3882 3883 3884 3885 3886 3887 3888 3889 3890
/*************************************************************************
 *      SHCreateShellPalette	[SHLWAPI.@]
 */
HPALETTE WINAPI SHCreateShellPalette(HDC hdc)
{
	FIXME("stub\n");
	return CreateHalftonePalette(hdc);
}

3891
/*************************************************************************
3892
 *	SHGetInverseCMAP (SHLWAPI.@)
3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911
 *
 * Get an inverse color map table.
 *
 * PARAMS
 *  lpCmap  [O] Destination for color map
 *  dwSize  [I] Size of memory pointed to by lpCmap
 *
 * RETURNS
 *  Success: S_OK.
 *  Failure: E_POINTER,    If lpCmap is invalid.
 *           E_INVALIDARG, If dwFlags is invalid
 *           E_OUTOFMEMORY, If there is no memory available
 *
 * NOTES
 *  dwSize may only be CMAP_PTR_SIZE (4) or CMAP_SIZE (8192).
 *  If dwSize = CMAP_PTR_SIZE, *lpCmap is set to the address of this DLL's
 *  internal CMap.
 *  If dwSize = CMAP_SIZE, lpCmap is filled with a copy of the data from
 *  this DLL's internal CMap.
3912
 */
3913
HRESULT WINAPI SHGetInverseCMAP(LPDWORD dest, DWORD dwSize)
3914
{
3915
    if (dwSize == 4) {
3916
	FIXME(" - returning bogus address for SHGetInverseCMAP\n");
3917
	*dest = (DWORD)0xabba1249;
3918
	return 0;
3919
    }
3920
    FIXME("(%p, %#lx) stub\n", dest, dwSize);
3921
    return 0;
3922 3923
}

3924 3925
/*************************************************************************
 *      SHIsLowMemoryMachine	[SHLWAPI.@]
3926 3927 3928 3929 3930 3931 3932 3933 3934
 *
 * Determine if the current computer has low memory.
 *
 * PARAMS
 *  x [I] FIXME
 *
 * RETURNS
 *  TRUE if the users machine has 16 Megabytes of memory or less,
 *  FALSE otherwise.
3935
 */
3936
BOOL WINAPI SHIsLowMemoryMachine (DWORD x)
3937
{
3938 3939
  FIXME("(0x%08lx) stub\n", x);
  return FALSE;
3940
}
3941 3942 3943

/*************************************************************************
 *      GetMenuPosFromID	[SHLWAPI.@]
3944 3945 3946 3947 3948 3949 3950 3951 3952 3953
 *
 * Return the position of a menu item from its Id.
 *
 * PARAMS
 *   hMenu [I] Menu containing the item
 *   wID   [I] Id of the menu item
 *
 * RETURNS
 *  Success: The index of the menu item in hMenu.
 *  Failure: -1, If the item is not found.
3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968
 */
INT WINAPI GetMenuPosFromID(HMENU hMenu, UINT wID)
{
 MENUITEMINFOA mi;
 INT nCount = GetMenuItemCount(hMenu), nIter = 0;

 while (nIter < nCount)
 {
   mi.wID = 0;
   if (!GetMenuItemInfoA(hMenu, nIter, TRUE, &mi) && mi.wID == wID)
     return nIter;
   nIter++;
 }
 return -1;
}
3969

3970 3971 3972 3973 3974 3975 3976 3977 3978 3979
/*************************************************************************
 *      @	[SHLWAPI.179]
 *
 * Same as SHLWAPI.GetMenuPosFromID
 */
DWORD WINAPI SHMenuIndexFromID(HMENU hMenu, UINT uID)
{
    return GetMenuPosFromID(hMenu, uID);
}

3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997

/*************************************************************************
 *      @	[SHLWAPI.448]
 */
VOID WINAPI FixSlashesAndColonW(LPWSTR lpwstr)
{
    while (*lpwstr)
    {
        if (*lpwstr == '/')
            *lpwstr = '\\';
        lpwstr++;
    }
}


/*************************************************************************
 *      @	[SHLWAPI.461]
 */
3998
DWORD WINAPI SHGetAppCompatFlags(DWORD Unknown)
3999 4000 4001 4002 4003 4004
{
  FIXME("stub\n");
  return 0;
}


4005 4006 4007 4008 4009 4010 4011 4012 4013
/*************************************************************************
 *      @	[SHLWAPI.549]
 */
HRESULT WINAPI SHCoCreateInstanceAC(REFCLSID rclsid, LPUNKNOWN pUnkOuter,
                                    DWORD dwClsContext, REFIID iid, LPVOID *ppv)
{
    return CoCreateInstance(rclsid, pUnkOuter, dwClsContext, iid, ppv);
}

4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029
/*************************************************************************
 * SHSkipJunction	[SHLWAPI.@]
 *
 * Determine if a bind context can be bound to an object
 *
 * PARAMS
 *  pbc    [I] Bind context to check
 *  pclsid [I] CLSID of object to be bound to
 *
 * RETURNS
 *  TRUE: If it is safe to bind
 *  FALSE: If pbc is invalid or binding would not be safe
 *
 */
BOOL WINAPI SHSkipJunction(IBindCtx *pbc, const CLSID *pclsid)
{
4030
  static const WCHAR szSkipBinding[] = { 'S','k','i','p',' ',
4031 4032 4033 4034 4035 4036 4037
    'B','i','n','d','i','n','g',' ','C','L','S','I','D','\0' };
  BOOL bRet = FALSE;

  if (pbc)
  {
    IUnknown* lpUnk;

4038
    if (SUCCEEDED(IBindCtx_GetObjectParam(pbc, (LPOLESTR)szSkipBinding, &lpUnk)))
4039 4040 4041
    {
      CLSID clsid;

4042
      if (SUCCEEDED(IUnknown_GetClassID(lpUnk, &clsid)) &&
4043 4044 4045 4046 4047 4048 4049 4050
          IsEqualGUID(pclsid, &clsid))
        bRet = TRUE;

      IUnknown_Release(lpUnk);
    }
  }
  return bRet;
}
4051

4052 4053 4054
/***********************************************************************
 *		SHGetShellKey (SHLWAPI.@)
 */
4055 4056 4057 4058 4059 4060
DWORD WINAPI SHGetShellKey(DWORD a, DWORD b, DWORD c)
{
    FIXME("(%lx, %lx, %lx): stub\n", a, b, c);
    return 0x50;
}

4061 4062 4063
/***********************************************************************
 *		SHQueueUserWorkItem (SHLWAPI.@)
 */
4064 4065 4066 4067 4068 4069
HRESULT WINAPI SHQueueUserWorkItem(DWORD a, DWORD b, DWORD c, DWORD d, DWORD e, DWORD f, DWORD g)
{
    FIXME("(%lx, %lx, %lx, %lx, %lx, %lx, %lx): stub\n", a, b, c, d, e, f, g);
    return E_FAIL;
}

4070 4071 4072
/***********************************************************************
 *		IUnknown_OnFocusChangeIS (SHLWAPI.@)
 */
4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085
DWORD WINAPI IUnknown_OnFocusChangeIS(IUnknown * pUnk, IUnknown * pFocusObject, BOOL bChange)
{
    FIXME("(%p, %p, %s)\n", pUnk, pFocusObject, bChange ? "TRUE" : "FALSE");

/*
    IInputObjectSite * pIOS = NULL;
    if (SUCCEEDED(IUnknown_QueryInterface(pUnk, &IID_IInputObjectSite, (void **)&pIOS))
        IInputObjectSite_OnFocusChangeIS(pIOS, pFocusObject, bChange);
*/

    return 0;
}

4086 4087 4088
/***********************************************************************
 *		SHGetValueW (SHLWAPI.@)
 */
4089 4090 4091 4092 4093
HRESULT WINAPI SKGetValueW(DWORD a, LPWSTR b, LPWSTR c, DWORD d, DWORD e, DWORD f)
{
    FIXME("(%lx, %s, %s, %lx, %lx, %lx): stub\n", a, debugstr_w(b), debugstr_w(c), d, e, f);
    return E_FAIL;
}
4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121

typedef HRESULT (WINAPI *DllGetVersion_func)(DLLVERSIONINFO *);

/***********************************************************************
 *              GetUIVersion (SHLWAPI.452)
 */
DWORD WINAPI GetUIVersion(void)
{
    static DWORD version;

    if (!version)
    {
        DllGetVersion_func pDllGetVersion;
        HMODULE dll = LoadLibraryA("shell32.dll");
        if (!dll) return 0;

        pDllGetVersion = (DllGetVersion_func)GetProcAddress(dll, "DllGetVersion");
        if (pDllGetVersion)
        {
            DLLVERSIONINFO dvi;
            dvi.cbSize = sizeof(DLLVERSIONINFO);
            if (pDllGetVersion(&dvi) == S_OK) version = dvi.dwMajorVersion;
        }
        FreeLibrary( dll );
        if (!version) version = 3;  /* old shell dlls don't have DllGetVersion */
    }
    return version;
}