ReactOS 0.4.16-dev-340-g0540c21
ordinal.c
Go to the documentation of this file.
1/*
2 * SHLWAPI ordinal functions
3 *
4 * Copyright 1997 Marcus Meissner
5 * 1998 Jürgen Schmied
6 * 2001-2003 Jon Griffiths
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 */
22
23#include "config.h"
24#include "wine/port.h"
25
26#include <stdarg.h>
27#include <stdio.h>
28#include <string.h>
29
30#define COBJMACROS
31
32#include "windef.h"
33#include "winbase.h"
34#include "winnls.h"
35#include "winreg.h"
36#include "wingdi.h"
37#include "winuser.h"
38#include "winver.h"
39#include "winnetwk.h"
40#include "mmsystem.h"
41#include "objbase.h"
42#include "exdisp.h"
43#include "shdeprecated.h"
44#include "shlobj.h"
45#include "shlwapi.h"
46#include "shellapi.h"
47#include "commdlg.h"
48#include "mlang.h"
49#include "mshtmhst.h"
50#ifdef __REACTOS__
51 #include <shlwapi_undoc.h>
52#endif
53#include "wine/unicode.h"
54#include "wine/debug.h"
55
56
58
59/* DLL handles for late bound calls */
62
64#ifdef __REACTOS__
66#else
68#endif
70
71/*
72 NOTES: Most functions exported by ordinal seem to be superfluous.
73 The reason for these functions to be there is to provide a wrapper
74 for unicode functions to provide these functions on systems without
75 unicode functions eg. win95/win98. Since we have such functions we just
76 call these. If running Wine with native DLLs, some late bound calls may
77 fail. However, it is better to implement the functions in the forward DLL
78 and recommend the builtin rather than reimplementing the calls here!
79*/
80
81/*************************************************************************
82 * @ [SHLWAPI.11]
83 *
84 * Copy a sharable memory handle from one process to another.
85 *
86 * PARAMS
87 * hShared [I] Shared memory handle to duplicate
88 * dwSrcProcId [I] ID of the process owning hShared
89 * dwDstProcId [I] ID of the process wanting the duplicated handle
90 * dwAccess [I] Desired DuplicateHandle() access
91 * dwOptions [I] Desired DuplicateHandle() options
92 *
93 * RETURNS
94 * Success: A handle suitable for use by the dwDstProcId process.
95 * Failure: A NULL handle.
96 *
97 */
98HANDLE WINAPI SHMapHandle(HANDLE hShared, DWORD dwSrcProcId, DWORD dwDstProcId,
99 DWORD dwAccess, DWORD dwOptions)
100{
101 HANDLE hDst, hSrc;
102 DWORD dwMyProcId = GetCurrentProcessId();
103 HANDLE hRet = NULL;
104
105 TRACE("(%p,%d,%d,%08x,%08x)\n", hShared, dwDstProcId, dwSrcProcId,
106 dwAccess, dwOptions);
107
108 if (!hShared)
109 {
110 TRACE("Returning handle NULL\n");
111 return NULL;
112 }
113
114 /* Get dest process handle */
115 if (dwDstProcId == dwMyProcId)
116 hDst = GetCurrentProcess();
117 else
118 hDst = OpenProcess(PROCESS_DUP_HANDLE, 0, dwDstProcId);
119
120 if (hDst)
121 {
122 /* Get src process handle */
123 if (dwSrcProcId == dwMyProcId)
124 hSrc = GetCurrentProcess();
125 else
126 hSrc = OpenProcess(PROCESS_DUP_HANDLE, 0, dwSrcProcId);
127
128 if (hSrc)
129 {
130 /* Make handle available to dest process */
131 if (!DuplicateHandle(hSrc, hShared, hDst, &hRet,
132 dwAccess, 0, dwOptions | DUPLICATE_SAME_ACCESS))
133 hRet = NULL;
134
135 if (dwSrcProcId != dwMyProcId)
136 CloseHandle(hSrc);
137 }
138
139 if (dwDstProcId != dwMyProcId)
140 CloseHandle(hDst);
141 }
142
143 TRACE("Returning handle %p\n", hRet);
144 return hRet;
145}
146
147/*************************************************************************
148 * @ [SHLWAPI.7]
149 *
150 * Create a block of sharable memory and initialise it with data.
151 *
152 * PARAMS
153 * lpvData [I] Pointer to data to write
154 * dwSize [I] Size of data
155 * dwProcId [I] ID of process owning data
156 *
157 * RETURNS
158 * Success: A shared memory handle
159 * Failure: NULL
160 *
161 * NOTES
162 * Ordinals 7-11 provide a set of calls to create shared memory between a
163 * group of processes. The shared memory is treated opaquely in that its size
164 * is not exposed to clients who map it. This is accomplished by storing
165 * the size of the map as the first DWORD of mapped data, and then offsetting
166 * the view pointer returned by this size.
167 *
168 */
170{
171 HANDLE hMap;
172 LPVOID pMapped;
173 HANDLE hRet = NULL;
174
175 TRACE("(%p,%d,%d)\n", lpvData, dwSize, dwProcId);
176
177 /* Create file mapping of the correct length */
179 dwSize + sizeof(dwSize), NULL);
180 if (!hMap)
181 return hRet;
182
183 /* Get a view in our process address space */
184 pMapped = MapViewOfFile(hMap, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0);
185
186 if (pMapped)
187 {
188 /* Write size of data, followed by the data, to the view */
189 *((DWORD*)pMapped) = dwSize;
190 if (lpvData)
191 memcpy((char *) pMapped + sizeof(dwSize), lpvData, dwSize);
192
193 /* Release view. All further views mapped will be opaque */
194 UnmapViewOfFile(pMapped);
195 hRet = SHMapHandle(hMap, GetCurrentProcessId(), dwProcId,
197 }
198
199 CloseHandle(hMap);
200 return hRet;
201}
202
203#ifdef __REACTOS__
204/*************************************************************************
205 * @ [SHLWAPI.510]
206 *
207 * Get a pointer to a block of shared memory from a shared memory handle,
208 * with specified access rights.
209 *
210 * PARAMS
211 * hShared [I] Shared memory handle
212 * dwProcId [I] ID of process owning hShared
213 * bWriteAccess [I] TRUE to get a writable block,
214 * FALSE to get a read-only block
215 *
216 * RETURNS
217 * Success: A pointer to the shared memory
218 * Failure: NULL
219 */
221SHLockSharedEx(HANDLE hShared, DWORD dwProcId, BOOL bWriteAccess)
222{
223 HANDLE hDup;
224 LPVOID pMapped;
225 DWORD dwAccess;
226
227 TRACE("(%p %d %d)\n", hShared, dwProcId, bWriteAccess);
228
229 /* Get handle to shared memory for current process */
230 hDup = SHMapHandle(hShared, dwProcId, GetCurrentProcessId(), FILE_MAP_ALL_ACCESS, 0);
231 if (hDup == NULL)
232 return NULL;
233
234 /* Get View */
235 dwAccess = (FILE_MAP_READ | (bWriteAccess ? FILE_MAP_WRITE : 0));
236 pMapped = MapViewOfFile(hDup, dwAccess, 0, 0, 0);
237 CloseHandle(hDup);
238
239 if (pMapped)
240 return (char *) pMapped + sizeof(DWORD); /* Hide size */
241 return NULL;
242}
243
244#endif
245/*************************************************************************
246 * @ [SHLWAPI.8]
247 *
248 * Get a pointer to a block of shared memory from a shared memory handle.
249 *
250 * PARAMS
251 * hShared [I] Shared memory handle
252 * dwProcId [I] ID of process owning hShared
253 *
254 * RETURNS
255 * Success: A pointer to the shared memory
256 * Failure: NULL
257 *
258 */
260{
261#ifdef __REACTOS__
262 return SHLockSharedEx(hShared, dwProcId, TRUE);
263#else
264 HANDLE hDup;
265 LPVOID pMapped;
266
267 TRACE("(%p %d)\n", hShared, dwProcId);
268
269 /* Get handle to shared memory for current process */
270 hDup = SHMapHandle(hShared, dwProcId, GetCurrentProcessId(), FILE_MAP_ALL_ACCESS, 0);
271
272 /* Get View */
273 pMapped = MapViewOfFile(hDup, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0);
274 CloseHandle(hDup);
275
276 if (pMapped)
277 return (char *) pMapped + sizeof(DWORD); /* Hide size */
278 return NULL;
279#endif
280}
281
282/*************************************************************************
283 * @ [SHLWAPI.9]
284 *
285 * Release a pointer to a block of shared memory.
286 *
287 * PARAMS
288 * lpView [I] Shared memory pointer
289 *
290 * RETURNS
291 * Success: TRUE
292 * Failure: FALSE
293 *
294 */
296{
297 TRACE("(%p)\n", lpView);
298 return UnmapViewOfFile((char *) lpView - sizeof(DWORD)); /* Include size */
299}
300
301/*************************************************************************
302 * @ [SHLWAPI.10]
303 *
304 * Destroy a block of sharable memory.
305 *
306 * PARAMS
307 * hShared [I] Shared memory handle
308 * dwProcId [I] ID of process owning hShared
309 *
310 * RETURNS
311 * Success: TRUE
312 * Failure: FALSE
313 *
314 */
316{
317 HANDLE hClose;
318
319 TRACE("(%p %d)\n", hShared, dwProcId);
320
321 if (!hShared)
322 return TRUE;
323
324 /* Get a copy of the handle for our process, closing the source handle */
325 hClose = SHMapHandle(hShared, dwProcId, GetCurrentProcessId(),
327 /* Close local copy */
328 return CloseHandle(hClose);
329}
330
331/*************************************************************************
332 * @ [SHLWAPI.13]
333 *
334 * Create and register a clipboard enumerator for a web browser.
335 *
336 * PARAMS
337 * lpBC [I] Binding context
338 * lpUnknown [I] An object exposing the IWebBrowserApp interface
339 *
340 * RETURNS
341 * Success: S_OK.
342 * Failure: An HRESULT error code.
343 *
344 * NOTES
345 * The enumerator is stored as a property of the web browser. If it does not
346 * yet exist, it is created and set before being registered.
347 */
349{
350 static const WCHAR szProperty[] = { '{','D','0','F','C','A','4','2','0',
351 '-','D','3','F','5','-','1','1','C','F', '-','B','2','1','1','-','0',
352 '0','A','A','0','0','4','A','E','8','3','7','}','\0' };
354 IEnumFORMATETC* pIEnumFormatEtc = NULL;
356 HRESULT hr;
357 IWebBrowserApp* pBrowser;
358
359 TRACE("(%p, %p)\n", lpBC, lpUnknown);
360
361 hr = IUnknown_QueryService(lpUnknown, &IID_IWebBrowserApp, &IID_IWebBrowserApp, (void**)&pBrowser);
362 if (FAILED(hr))
363 return hr;
364
365 V_VT(&var) = VT_EMPTY;
366
367 /* The property we get is the browsers clipboard enumerator */
368 property = SysAllocString(szProperty);
369 hr = IWebBrowserApp_GetProperty(pBrowser, property, &var);
371 if (FAILED(hr)) goto exit;
372
373 if (V_VT(&var) == VT_EMPTY)
374 {
375 /* Iterate through accepted documents and RegisterClipBoardFormatA() them */
376 char szKeyBuff[128], szValueBuff[128];
377 DWORD dwKeySize, dwValueSize, dwRet = 0, dwCount = 0, dwNumValues, dwType;
378 FORMATETC* formatList, *format;
379 HKEY hDocs;
380
381 TRACE("Registering formats and creating IEnumFORMATETC instance\n");
382
383 if (!RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\Current"
384 "Version\\Internet Settings\\Accepted Documents", &hDocs))
385 {
386 hr = E_FAIL;
387 goto exit;
388 }
389
390 /* Get count of values in key */
391 while (!dwRet)
392 {
393 dwKeySize = sizeof(szKeyBuff);
394 dwRet = RegEnumValueA(hDocs,dwCount,szKeyBuff,&dwKeySize,0,&dwType,0,0);
395 dwCount++;
396 }
397
398 dwNumValues = dwCount;
399
400 /* Note: dwCount = number of items + 1; The extra item is the end node */
401 format = formatList = HeapAlloc(GetProcessHeap(), 0, dwCount * sizeof(FORMATETC));
402 if (!formatList)
403 {
404 RegCloseKey(hDocs);
406 goto exit;
407 }
408
409 if (dwNumValues > 1)
410 {
411 dwRet = 0;
412 dwCount = 0;
413
414 dwNumValues--;
415
416 /* Register clipboard formats for the values and populate format list */
417 while(!dwRet && dwCount < dwNumValues)
418 {
419 dwKeySize = sizeof(szKeyBuff);
420 dwValueSize = sizeof(szValueBuff);
421 dwRet = RegEnumValueA(hDocs, dwCount, szKeyBuff, &dwKeySize, 0, &dwType,
422 (PBYTE)szValueBuff, &dwValueSize);
423 if (!dwRet)
424 {
425 HeapFree(GetProcessHeap(), 0, formatList);
426 RegCloseKey(hDocs);
427 hr = E_FAIL;
428 goto exit;
429 }
430
431 format->cfFormat = RegisterClipboardFormatA(szValueBuff);
432 format->ptd = NULL;
433 format->dwAspect = 1;
434 format->lindex = 4;
435 format->tymed = -1;
436
437 format++;
438 dwCount++;
439 }
440 }
441
442 RegCloseKey(hDocs);
443
444 /* Terminate the (maybe empty) list, last entry has a cfFormat of 0 */
445 format->cfFormat = 0;
446 format->ptd = NULL;
447 format->dwAspect = 1;
448 format->lindex = 4;
449 format->tymed = -1;
450
451 /* Create a clipboard enumerator */
452 hr = CreateFormatEnumerator(dwNumValues, formatList, &pIEnumFormatEtc);
453 HeapFree(GetProcessHeap(), 0, formatList);
454 if (FAILED(hr)) goto exit;
455
456 /* Set our enumerator as the browsers property */
457 V_VT(&var) = VT_UNKNOWN;
458 V_UNKNOWN(&var) = (IUnknown*)pIEnumFormatEtc;
459
460 property = SysAllocString(szProperty);
461 hr = IWebBrowserApp_PutProperty(pBrowser, property, var);
463 if (FAILED(hr))
464 {
465 IEnumFORMATETC_Release(pIEnumFormatEtc);
466 goto exit;
467 }
468 }
469
470 if (V_VT(&var) == VT_UNKNOWN)
471 {
472 /* Our variant is holding the clipboard enumerator */
473 IUnknown* pIUnknown = V_UNKNOWN(&var);
474 IEnumFORMATETC* pClone = NULL;
475
476 TRACE("Retrieved IEnumFORMATETC property\n");
477
478 /* Get an IEnumFormatEtc interface from the variants value */
479 pIEnumFormatEtc = NULL;
480 hr = IUnknown_QueryInterface(pIUnknown, &IID_IEnumFORMATETC, (void**)&pIEnumFormatEtc);
481 if (hr == S_OK && pIEnumFormatEtc)
482 {
483 /* Clone and register the enumerator */
484 hr = IEnumFORMATETC_Clone(pIEnumFormatEtc, &pClone);
485 if (hr == S_OK && pClone)
486 {
487 RegisterFormatEnumerator(lpBC, pClone, 0);
488
489 IEnumFORMATETC_Release(pClone);
490 }
491
492 IUnknown_Release(pIUnknown);
493 }
494 IUnknown_Release(V_UNKNOWN(&var));
495 }
496
497exit:
498 IWebBrowserApp_Release(pBrowser);
499 return hr;
500}
501
502/*************************************************************************
503 * @ [SHLWAPI.15]
504 *
505 * Get Explorers "AcceptLanguage" setting.
506 *
507 * PARAMS
508 * langbuf [O] Destination for language string
509 * buflen [I] Length of langbuf in characters
510 * [0] Success: used length of langbuf
511 *
512 * RETURNS
513 * Success: S_OK. langbuf is set to the language string found.
514 * Failure: E_FAIL, If any arguments are invalid, error occurred, or Explorer
515 * does not contain the setting.
516 * E_NOT_SUFFICIENT_BUFFER, If the buffer is not big enough
517 */
519{
520 static const WCHAR szkeyW[] = {
521 'S','o','f','t','w','a','r','e','\\',
522 'M','i','c','r','o','s','o','f','t','\\',
523 'I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r','\\',
524 'I','n','t','e','r','n','a','t','i','o','n','a','l',0};
525 static const WCHAR valueW[] = {
526 'A','c','c','e','p','t','L','a','n','g','u','a','g','e',0};
527 DWORD mystrlen, mytype;
528 DWORD len;
529 HKEY mykey;
530 LCID mylcid;
531 WCHAR *mystr;
532 LONG lres;
533
534 TRACE("(%p, %p) *%p: %d\n", langbuf, buflen, buflen, buflen ? *buflen : -1);
535
536 if(!langbuf || !buflen || !*buflen)
537 return E_FAIL;
538
539 mystrlen = (*buflen > 20) ? *buflen : 20 ;
540 len = mystrlen * sizeof(WCHAR);
541 mystr = HeapAlloc(GetProcessHeap(), 0, len);
542 mystr[0] = 0;
543 RegOpenKeyW(HKEY_CURRENT_USER, szkeyW, &mykey);
544 lres = RegQueryValueExW(mykey, valueW, 0, &mytype, (PBYTE)mystr, &len);
545 RegCloseKey(mykey);
546 len = lstrlenW(mystr);
547
548 if (!lres && (*buflen > len)) {
549 lstrcpyW(langbuf, mystr);
550 *buflen = len;
551 HeapFree(GetProcessHeap(), 0, mystr);
552 return S_OK;
553 }
554
555 /* Did not find a value in the registry or the user buffer is too small */
556 mylcid = GetUserDefaultLCID();
557 LcidToRfc1766W(mylcid, mystr, mystrlen);
558 len = lstrlenW(mystr);
559
560 memcpy( langbuf, mystr, min(*buflen, len+1)*sizeof(WCHAR) );
561 HeapFree(GetProcessHeap(), 0, mystr);
562
563 if (*buflen > len) {
564 *buflen = len;
565 return S_OK;
566 }
567
568 *buflen = 0;
570}
571
572/*************************************************************************
573 * @ [SHLWAPI.14]
574 *
575 * Ascii version of GetAcceptLanguagesW.
576 */
578{
579 WCHAR *langbufW;
580 DWORD buflenW, convlen;
581 HRESULT retval;
582
583 TRACE("(%p, %p) *%p: %d\n", langbuf, buflen, buflen, buflen ? *buflen : -1);
584
585 if(!langbuf || !buflen || !*buflen) return E_FAIL;
586
587 buflenW = *buflen;
588 langbufW = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * buflenW);
589 retval = GetAcceptLanguagesW(langbufW, &buflenW);
590
591 if (retval == S_OK)
592 {
593 convlen = WideCharToMultiByte(CP_ACP, 0, langbufW, -1, langbuf, *buflen, NULL, NULL);
594 convlen--; /* do not count the terminating 0 */
595 }
596 else /* copy partial string anyway */
597 {
598 convlen = WideCharToMultiByte(CP_ACP, 0, langbufW, *buflen, langbuf, *buflen, NULL, NULL);
599 if (convlen < *buflen)
600 {
601 langbuf[convlen] = 0;
602 convlen--; /* do not count the terminating 0 */
603 }
604 else
605 {
606 convlen = *buflen;
607 }
608 }
609 *buflen = buflenW ? convlen : 0;
610
611 HeapFree(GetProcessHeap(), 0, langbufW);
612 return retval;
613}
614
615/*************************************************************************
616 * @ [SHLWAPI.23]
617 *
618 * Convert a GUID to a string.
619 *
620 * PARAMS
621 * guid [I] GUID to convert
622 * lpszDest [O] Destination for string
623 * cchMax [I] Length of output buffer
624 *
625 * RETURNS
626 * The length of the string created.
627 */
629{
630 char xguid[40];
631 INT iLen;
632
633 TRACE("(%s,%p,%d)\n", debugstr_guid(guid), lpszDest, cchMax);
634
635 sprintf(xguid, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
636 guid->Data1, guid->Data2, guid->Data3,
637 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
638 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
639
640 iLen = strlen(xguid) + 1;
641
642 if (iLen > cchMax)
643 return 0;
644 memcpy(lpszDest, xguid, iLen);
645 return iLen;
646}
647
648/*************************************************************************
649 * @ [SHLWAPI.24]
650 *
651 * Convert a GUID to a string.
652 *
653 * PARAMS
654 * guid [I] GUID to convert
655 * str [O] Destination for string
656 * cmax [I] Length of output buffer
657 *
658 * RETURNS
659 * The length of the string created.
660 */
662{
663 WCHAR xguid[40];
664 INT iLen;
665 static const WCHAR wszFormat[] = {'{','%','0','8','l','X','-','%','0','4','X','-','%','0','4','X','-',
666 '%','0','2','X','%','0','2','X','-','%','0','2','X','%','0','2','X','%','0','2','X','%','0','2',
667 'X','%','0','2','X','%','0','2','X','}',0};
668
669 TRACE("(%s,%p,%d)\n", debugstr_guid(guid), lpszDest, cchMax);
670
671 sprintfW(xguid, wszFormat, guid->Data1, guid->Data2, guid->Data3,
672 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
673 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
674
675 iLen = strlenW(xguid) + 1;
676
677 if (iLen > cchMax)
678 return 0;
679 memcpy(lpszDest, xguid, iLen*sizeof(WCHAR));
680 return iLen;
681}
682
683/*************************************************************************
684 * @ [SHLWAPI.30]
685 *
686 * Determine if a Unicode character is a blank.
687 *
688 * PARAMS
689 * wc [I] Character to check.
690 *
691 * RETURNS
692 * TRUE, if wc is a blank,
693 * FALSE otherwise.
694 *
695 */
697{
698 WORD CharType;
699
700 return GetStringTypeW(CT_CTYPE1, &wc, 1, &CharType) && (CharType & C1_BLANK);
701}
702
703/*************************************************************************
704 * @ [SHLWAPI.31]
705 *
706 * Determine if a Unicode character is punctuation.
707 *
708 * PARAMS
709 * wc [I] Character to check.
710 *
711 * RETURNS
712 * TRUE, if wc is punctuation,
713 * FALSE otherwise.
714 */
716{
717 WORD CharType;
718
719 return GetStringTypeW(CT_CTYPE1, &wc, 1, &CharType) && (CharType & C1_PUNCT);
720}
721
722/*************************************************************************
723 * @ [SHLWAPI.32]
724 *
725 * Determine if a Unicode character is a control character.
726 *
727 * PARAMS
728 * wc [I] Character to check.
729 *
730 * RETURNS
731 * TRUE, if wc is a control character,
732 * FALSE otherwise.
733 */
735{
736 WORD CharType;
737
738 return GetStringTypeW(CT_CTYPE1, &wc, 1, &CharType) && (CharType & C1_CNTRL);
739}
740
741/*************************************************************************
742 * @ [SHLWAPI.33]
743 *
744 * Determine if a Unicode character is a digit.
745 *
746 * PARAMS
747 * wc [I] Character to check.
748 *
749 * RETURNS
750 * TRUE, if wc is a digit,
751 * FALSE otherwise.
752 */
754{
755 WORD CharType;
756
757 return GetStringTypeW(CT_CTYPE1, &wc, 1, &CharType) && (CharType & C1_DIGIT);
758}
759
760/*************************************************************************
761 * @ [SHLWAPI.34]
762 *
763 * Determine if a Unicode character is a hex digit.
764 *
765 * PARAMS
766 * wc [I] Character to check.
767 *
768 * RETURNS
769 * TRUE, if wc is a hex digit,
770 * FALSE otherwise.
771 */
773{
774 WORD CharType;
775
776 return GetStringTypeW(CT_CTYPE1, &wc, 1, &CharType) && (CharType & C1_XDIGIT);
777}
778
779/*************************************************************************
780 * @ [SHLWAPI.35]
781 *
782 */
784{
786}
787
788/*************************************************************************
789 * @ [SHLWAPI.151]
790 *
791 * Compare two Ascii strings up to a given length.
792 *
793 * PARAMS
794 * lpszSrc [I] Source string
795 * lpszCmp [I] String to compare to lpszSrc
796 * len [I] Maximum length
797 *
798 * RETURNS
799 * A number greater than, less than or equal to 0 depending on whether
800 * lpszSrc is greater than, less than or equal to lpszCmp.
801 */
803{
804 return StrCmpNA(lpszSrc, lpszCmp, len);
805}
806
807/*************************************************************************
808 * @ [SHLWAPI.152]
809 *
810 * Unicode version of StrCmpNCA.
811 */
813{
814 return StrCmpNW(lpszSrc, lpszCmp, len);
815}
816
817/*************************************************************************
818 * @ [SHLWAPI.153]
819 *
820 * Compare two Ascii strings up to a given length, ignoring case.
821 *
822 * PARAMS
823 * lpszSrc [I] Source string
824 * lpszCmp [I] String to compare to lpszSrc
825 * len [I] Maximum length
826 *
827 * RETURNS
828 * A number greater than, less than or equal to 0 depending on whether
829 * lpszSrc is greater than, less than or equal to lpszCmp.
830 */
832{
833 return StrCmpNIA(lpszSrc, lpszCmp, len);
834}
835
836/*************************************************************************
837 * @ [SHLWAPI.154]
838 *
839 * Unicode version of StrCmpNICA.
840 */
842{
843 return StrCmpNIW(lpszSrc, lpszCmp, len);
844}
845
846/*************************************************************************
847 * @ [SHLWAPI.155]
848 *
849 * Compare two Ascii strings.
850 *
851 * PARAMS
852 * lpszSrc [I] Source string
853 * lpszCmp [I] String to compare to lpszSrc
854 *
855 * RETURNS
856 * A number greater than, less than or equal to 0 depending on whether
857 * lpszSrc is greater than, less than or equal to lpszCmp.
858 */
860{
861 return lstrcmpA(lpszSrc, lpszCmp);
862}
863
864/*************************************************************************
865 * @ [SHLWAPI.156]
866 *
867 * Unicode version of StrCmpCA.
868 */
870{
871 return lstrcmpW(lpszSrc, lpszCmp);
872}
873
874/*************************************************************************
875 * @ [SHLWAPI.157]
876 *
877 * Compare two Ascii strings, ignoring case.
878 *
879 * PARAMS
880 * lpszSrc [I] Source string
881 * lpszCmp [I] String to compare to lpszSrc
882 *
883 * RETURNS
884 * A number greater than, less than or equal to 0 depending on whether
885 * lpszSrc is greater than, less than or equal to lpszCmp.
886 */
888{
889 return lstrcmpiA(lpszSrc, lpszCmp);
890}
891
892/*************************************************************************
893 * @ [SHLWAPI.158]
894 *
895 * Unicode version of StrCmpICA.
896 */
898{
899 return lstrcmpiW(lpszSrc, lpszCmp);
900}
901
902/*************************************************************************
903 * @ [SHLWAPI.160]
904 *
905 * Get an identification string for the OS and explorer.
906 *
907 * PARAMS
908 * lpszDest [O] Destination for Id string
909 * dwDestLen [I] Length of lpszDest
910 *
911 * RETURNS
912 * TRUE, If the string was created successfully
913 * FALSE, Otherwise
914 */
916{
917 WCHAR buff[2084];
918
919 TRACE("(%p,%d)\n", lpszDest, dwDestLen);
920
921 if (lpszDest && SHAboutInfoW(buff, dwDestLen))
922 {
923 WideCharToMultiByte(CP_ACP, 0, buff, -1, lpszDest, dwDestLen, NULL, NULL);
924 return TRUE;
925 }
926 return FALSE;
927}
928
929/*************************************************************************
930 * @ [SHLWAPI.161]
931 *
932 * Unicode version of SHAboutInfoA.
933 */
935{
936 static const WCHAR szIEKey[] = { 'S','O','F','T','W','A','R','E','\\',
937 'M','i','c','r','o','s','o','f','t','\\','I','n','t','e','r','n','e','t',
938 ' ','E','x','p','l','o','r','e','r','\0' };
939 static const WCHAR szWinNtKey[] = { 'S','O','F','T','W','A','R','E','\\',
940 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s',' ',
941 'N','T','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\0' };
942 static const WCHAR szWinKey[] = { 'S','O','F','T','W','A','R','E','\\',
943 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
944 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\0' };
945 static const WCHAR szRegKey[] = { 'S','O','F','T','W','A','R','E','\\',
946 'M','i','c','r','o','s','o','f','t','\\','I','n','t','e','r','n','e','t',
947 ' ','E','x','p','l','o','r','e','r','\\',
948 'R','e','g','i','s','t','r','a','t','i','o','n','\0' };
949 static const WCHAR szVersion[] = { 'V','e','r','s','i','o','n','\0' };
950 static const WCHAR szCustomized[] = { 'C','u','s','t','o','m','i','z','e','d',
951 'V','e','r','s','i','o','n','\0' };
952 static const WCHAR szOwner[] = { 'R','e','g','i','s','t','e','r','e','d',
953 'O','w','n','e','r','\0' };
954 static const WCHAR szOrg[] = { 'R','e','g','i','s','t','e','r','e','d',
955 'O','r','g','a','n','i','z','a','t','i','o','n','\0' };
956 static const WCHAR szProduct[] = { 'P','r','o','d','u','c','t','I','d','\0' };
957 static const WCHAR szUpdate[] = { 'I','E','A','K',
958 'U','p','d','a','t','e','U','r','l','\0' };
959 static const WCHAR szHelp[] = { 'I','E','A','K',
960 'H','e','l','p','S','t','r','i','n','g','\0' };
961 WCHAR buff[2084];
962 HKEY hReg;
963 DWORD dwType, dwLen;
964
965 TRACE("(%p,%d)\n", lpszDest, dwDestLen);
966
967 if (!lpszDest)
968 return FALSE;
969
970 *lpszDest = '\0';
971
972 /* Try the NT key first, followed by 95/98 key */
973 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, szWinNtKey, 0, KEY_READ, &hReg) &&
974 RegOpenKeyExW(HKEY_LOCAL_MACHINE, szWinKey, 0, KEY_READ, &hReg))
975 return FALSE;
976
977 /* OS Version */
978 buff[0] = '\0';
979 dwLen = 30;
980 if (!SHGetValueW(HKEY_LOCAL_MACHINE, szIEKey, szVersion, &dwType, buff, &dwLen))
981 {
982 DWORD dwStrLen = strlenW(buff);
983 dwLen = 30 - dwStrLen;
985 szCustomized, &dwType, buff+dwStrLen, &dwLen);
986 }
987 StrCatBuffW(lpszDest, buff, dwDestLen);
988
989 /* ~Registered Owner */
990 buff[0] = '~';
991 dwLen = 256;
992 if (SHGetValueW(hReg, szOwner, 0, &dwType, buff+1, &dwLen))
993 buff[1] = '\0';
994 StrCatBuffW(lpszDest, buff, dwDestLen);
995
996 /* ~Registered Organization */
997 dwLen = 256;
998 if (SHGetValueW(hReg, szOrg, 0, &dwType, buff+1, &dwLen))
999 buff[1] = '\0';
1000 StrCatBuffW(lpszDest, buff, dwDestLen);
1001
1002 /* FIXME: Not sure where this number comes from */
1003 buff[0] = '~';
1004 buff[1] = '0';
1005 buff[2] = '\0';
1006 StrCatBuffW(lpszDest, buff, dwDestLen);
1007
1008 /* ~Product Id */
1009 dwLen = 256;
1010 if (SHGetValueW(HKEY_LOCAL_MACHINE, szRegKey, szProduct, &dwType, buff+1, &dwLen))
1011 buff[1] = '\0';
1012 StrCatBuffW(lpszDest, buff, dwDestLen);
1013
1014 /* ~IE Update Url */
1015 dwLen = 2048;
1016 if(SHGetValueW(HKEY_LOCAL_MACHINE, szWinKey, szUpdate, &dwType, buff+1, &dwLen))
1017 buff[1] = '\0';
1018 StrCatBuffW(lpszDest, buff, dwDestLen);
1019
1020 /* ~IE Help String */
1021 dwLen = 256;
1022 if(SHGetValueW(hReg, szHelp, 0, &dwType, buff+1, &dwLen))
1023 buff[1] = '\0';
1024 StrCatBuffW(lpszDest, buff, dwDestLen);
1025
1026 RegCloseKey(hReg);
1027 return TRUE;
1028}
1029
1030/*************************************************************************
1031 * @ [SHLWAPI.163]
1032 *
1033 * Call IOleCommandTarget_QueryStatus() on an object.
1034 *
1035 * PARAMS
1036 * lpUnknown [I] Object supporting the IOleCommandTarget interface
1037 * pguidCmdGroup [I] GUID for the command group
1038 * cCmds [I]
1039 * prgCmds [O] Commands
1040 * pCmdText [O] Command text
1041 *
1042 * RETURNS
1043 * Success: S_OK.
1044 * Failure: E_FAIL, if lpUnknown is NULL.
1045 * E_NOINTERFACE, if lpUnknown does not support IOleCommandTarget.
1046 * Otherwise, an error code from IOleCommandTarget_QueryStatus().
1047 */
1049 ULONG cCmds, OLECMD *prgCmds, OLECMDTEXT* pCmdText)
1050{
1051 HRESULT hRet = E_FAIL;
1052
1053 TRACE("(%p,%p,%d,%p,%p)\n",lpUnknown, pguidCmdGroup, cCmds, prgCmds, pCmdText);
1054
1055 if (lpUnknown)
1056 {
1057 IOleCommandTarget* lpOle;
1058
1059 hRet = IUnknown_QueryInterface(lpUnknown, &IID_IOleCommandTarget,
1060 (void**)&lpOle);
1061
1062 if (SUCCEEDED(hRet) && lpOle)
1063 {
1064 hRet = IOleCommandTarget_QueryStatus(lpOle, pguidCmdGroup, cCmds,
1065 prgCmds, pCmdText);
1066 IOleCommandTarget_Release(lpOle);
1067 }
1068 }
1069 return hRet;
1070}
1071
1072/*************************************************************************
1073 * @ [SHLWAPI.164]
1074 *
1075 * Call IOleCommandTarget_Exec() on an object.
1076 *
1077 * PARAMS
1078 * lpUnknown [I] Object supporting the IOleCommandTarget interface
1079 * pguidCmdGroup [I] GUID for the command group
1080 *
1081 * RETURNS
1082 * Success: S_OK.
1083 * Failure: E_FAIL, if lpUnknown is NULL.
1084 * E_NOINTERFACE, if lpUnknown does not support IOleCommandTarget.
1085 * Otherwise, an error code from IOleCommandTarget_Exec().
1086 */
1087HRESULT WINAPI IUnknown_Exec(IUnknown* lpUnknown, REFGUID pguidCmdGroup,
1088 DWORD nCmdID, DWORD nCmdexecopt, VARIANT* pvaIn,
1089 VARIANT* pvaOut)
1090{
1091 HRESULT hRet = E_FAIL;
1092
1093 TRACE("(%p,%p,%d,%d,%p,%p)\n",lpUnknown, pguidCmdGroup, nCmdID,
1094 nCmdexecopt, pvaIn, pvaOut);
1095
1096 if (lpUnknown)
1097 {
1098 IOleCommandTarget* lpOle;
1099
1100 hRet = IUnknown_QueryInterface(lpUnknown, &IID_IOleCommandTarget,
1101 (void**)&lpOle);
1102 if (SUCCEEDED(hRet) && lpOle)
1103 {
1104 hRet = IOleCommandTarget_Exec(lpOle, pguidCmdGroup, nCmdID,
1105 nCmdexecopt, pvaIn, pvaOut);
1106 IOleCommandTarget_Release(lpOle);
1107 }
1108 }
1109 return hRet;
1110}
1111
1112/*************************************************************************
1113 * @ [SHLWAPI.165]
1114 *
1115 * Retrieve, modify, and re-set a value from a window.
1116 *
1117 * PARAMS
1118 * hWnd [I] Window to get value from
1119 * offset [I] Offset of value
1120 * mask [I] Mask for flags
1121 * flags [I] Bits to set in window value
1122 *
1123 * RETURNS
1124 * The new value as it was set, or 0 if any parameter is invalid.
1125 *
1126 * NOTES
1127 * Only bits specified in mask are affected - set if present in flags and
1128 * reset otherwise.
1129 */
1131{
1133 LONG new_flags = (flags & mask) | (ret & ~mask);
1134
1135 TRACE("%p %d %x %x\n", hwnd, offset, mask, flags);
1136
1137 if (new_flags != ret)
1138 ret = SetWindowLongW(hwnd, offset, new_flags);
1139 return ret;
1140}
1141
1142/*************************************************************************
1143 * @ [SHLWAPI.167]
1144 *
1145 * Change a window's parent.
1146 *
1147 * PARAMS
1148 * hWnd [I] Window to change parent of
1149 * hWndParent [I] New parent window
1150 *
1151 * RETURNS
1152 * The old parent of hWnd.
1153 *
1154 * NOTES
1155 * If hWndParent is NULL (desktop), the window style is changed to WS_POPUP.
1156 * If hWndParent is NOT NULL then we set the WS_CHILD style.
1157 */
1159{
1160 TRACE("%p, %p\n", hWnd, hWndParent);
1161
1162 if(GetParent(hWnd) == hWndParent)
1163 return NULL;
1164
1165 if(hWndParent)
1167 else
1169
1171}
1172
1173/*************************************************************************
1174 * @ [SHLWAPI.168]
1175 *
1176 * Locate and advise a connection point in an IConnectionPointContainer object.
1177 *
1178 * PARAMS
1179 * lpUnkSink [I] Sink for the connection point advise call
1180 * riid [I] REFIID of connection point to advise
1181 * fConnect [I] TRUE = Connection being establisted, FALSE = broken
1182 * lpUnknown [I] Object supporting the IConnectionPointContainer interface
1183 * lpCookie [O] Pointer to connection point cookie
1184 * lppCP [O] Destination for the IConnectionPoint found
1185 *
1186 * RETURNS
1187 * Success: S_OK. If lppCP is non-NULL, it is filled with the IConnectionPoint
1188 * that was advised. The caller is responsible for releasing it.
1189 * Failure: E_FAIL, if any arguments are invalid.
1190 * E_NOINTERFACE, if lpUnknown isn't an IConnectionPointContainer,
1191 * Or an HRESULT error code if any call fails.
1192 */
1194 IUnknown* lpUnknown, LPDWORD lpCookie,
1195 IConnectionPoint **lppCP)
1196{
1197 HRESULT hRet;
1198 IConnectionPointContainer* lpContainer;
1199 IConnectionPoint *lpCP;
1200
1201 if(!lpUnknown || (fConnect && !lpUnkSink))
1202 return E_FAIL;
1203
1204 if(lppCP)
1205 *lppCP = NULL;
1206
1207 hRet = IUnknown_QueryInterface(lpUnknown, &IID_IConnectionPointContainer,
1208 (void**)&lpContainer);
1209 if (SUCCEEDED(hRet))
1210 {
1211 hRet = IConnectionPointContainer_FindConnectionPoint(lpContainer, riid, &lpCP);
1212
1213 if (SUCCEEDED(hRet))
1214 {
1215 if(!fConnect)
1216 hRet = IConnectionPoint_Unadvise(lpCP, *lpCookie);
1217 else
1218 hRet = IConnectionPoint_Advise(lpCP, lpUnkSink, lpCookie);
1219
1220 if (FAILED(hRet))
1221 *lpCookie = 0;
1222
1223 if (lppCP && SUCCEEDED(hRet))
1224 *lppCP = lpCP; /* Caller keeps the interface */
1225 else
1226 IConnectionPoint_Release(lpCP); /* Release it */
1227 }
1228
1229 IConnectionPointContainer_Release(lpContainer);
1230 }
1231 return hRet;
1232}
1233
1234/*************************************************************************
1235 * @ [SHLWAPI.169]
1236 *
1237 * Release an interface and zero a supplied pointer.
1238 *
1239 * PARAMS
1240 * lpUnknown [I] Object to release
1241 *
1242 * RETURNS
1243 * Nothing.
1244 */
1246{
1247 TRACE("(%p)\n", lpUnknown);
1248
1249 if(!lpUnknown || !*lpUnknown) return;
1250
1251 TRACE("doing Release\n");
1252
1253 IUnknown_Release(*lpUnknown);
1254 *lpUnknown = NULL;
1255}
1256
1257/*************************************************************************
1258 * @ [SHLWAPI.170]
1259 *
1260 * Skip '//' if present in a string.
1261 *
1262 * PARAMS
1263 * lpszSrc [I] String to check for '//'
1264 *
1265 * RETURNS
1266 * Success: The next character after the '//' or the string if not present
1267 * Failure: NULL, if lpszStr is NULL.
1268 */
1270{
1271 if (lpszSrc && lpszSrc[0] == '/' && lpszSrc[1] == '/')
1272 lpszSrc += 2;
1273 return lpszSrc;
1274}
1275
1276/*************************************************************************
1277 * @ [SHLWAPI.171]
1278 *
1279 * Check if two interfaces come from the same object.
1280 *
1281 * PARAMS
1282 * lpInt1 [I] Interface to check against lpInt2.
1283 * lpInt2 [I] Interface to check against lpInt1.
1284 *
1285 * RETURNS
1286 * TRUE, If the interfaces come from the same object.
1287 * FALSE Otherwise.
1288 */
1290{
1291 IUnknown *lpUnknown1, *lpUnknown2;
1292 BOOL ret;
1293
1294 TRACE("(%p %p)\n", lpInt1, lpInt2);
1295
1296 if (!lpInt1 || !lpInt2)
1297 return FALSE;
1298
1299 if (lpInt1 == lpInt2)
1300 return TRUE;
1301
1302 if (IUnknown_QueryInterface(lpInt1, &IID_IUnknown, (void**)&lpUnknown1) != S_OK)
1303 return FALSE;
1304
1305 if (IUnknown_QueryInterface(lpInt2, &IID_IUnknown, (void**)&lpUnknown2) != S_OK)
1306 {
1307 IUnknown_Release(lpUnknown1);
1308 return FALSE;
1309 }
1310
1311 ret = lpUnknown1 == lpUnknown2;
1312
1313 IUnknown_Release(lpUnknown1);
1314 IUnknown_Release(lpUnknown2);
1315
1316 return ret;
1317}
1318
1319/*************************************************************************
1320 * @ [SHLWAPI.172]
1321 *
1322 * Get the window handle of an object.
1323 *
1324 * PARAMS
1325 * lpUnknown [I] Object to get the window handle of
1326 * lphWnd [O] Destination for window handle
1327 *
1328 * RETURNS
1329 * Success: S_OK. lphWnd contains the objects window handle.
1330 * Failure: An HRESULT error code.
1331 *
1332 * NOTES
1333 * lpUnknown is expected to support one of the following interfaces:
1334 * IOleWindow(), IInternetSecurityMgrSite(), or IShellView().
1335 */
1337{
1338 IUnknown *lpOle;
1339 HRESULT hRet = E_FAIL;
1340
1341 TRACE("(%p,%p)\n", lpUnknown, lphWnd);
1342
1343 if (!lpUnknown)
1344 return hRet;
1345
1346 hRet = IUnknown_QueryInterface(lpUnknown, &IID_IOleWindow, (void**)&lpOle);
1347
1348 if (FAILED(hRet))
1349 {
1350 hRet = IUnknown_QueryInterface(lpUnknown,&IID_IShellView, (void**)&lpOle);
1351
1352 if (FAILED(hRet))
1353 {
1354 hRet = IUnknown_QueryInterface(lpUnknown, &IID_IInternetSecurityMgrSite,
1355 (void**)&lpOle);
1356 }
1357 }
1358
1359 if (SUCCEEDED(hRet))
1360 {
1361 /* Laziness here - Since GetWindow() is the first method for the above 3
1362 * interfaces, we use the same call for them all.
1363 */
1364 hRet = IOleWindow_GetWindow((IOleWindow*)lpOle, lphWnd);
1365 IUnknown_Release(lpOle);
1366 if (lphWnd)
1367 TRACE("Returning HWND=%p\n", *lphWnd);
1368 }
1369
1370 return hRet;
1371}
1372
1373/*************************************************************************
1374 * @ [SHLWAPI.173]
1375 *
1376 * Call a SetOwner method of IShellService from specified object.
1377 *
1378 * PARAMS
1379 * iface [I] Object that supports IShellService
1380 * pUnk [I] Argument for the SetOwner call
1381 *
1382 * RETURNS
1383 * Corresponding return value from last call or E_FAIL for null input
1384 */
1386{
1387 IShellService *service;
1388 HRESULT hr;
1389
1390 TRACE("(%p, %p)\n", iface, pUnk);
1391
1392 if (!iface) return E_FAIL;
1393
1394 hr = IUnknown_QueryInterface(iface, &IID_IShellService, (void**)&service);
1395 if (hr == S_OK)
1396 {
1397 hr = IShellService_SetOwner(service, pUnk);
1398 IShellService_Release(service);
1399 }
1400
1401 return hr;
1402}
1403
1404/*************************************************************************
1405 * @ [SHLWAPI.174]
1406 *
1407 * Call either IObjectWithSite_SetSite() or IInternetSecurityManager_SetSecuritySite() on
1408 * an object.
1409 *
1410 */
1412 IUnknown *obj, /* [in] OLE object */
1413 IUnknown *site) /* [in] Site interface */
1414{
1415 HRESULT hr;
1416 IObjectWithSite *iobjwithsite;
1417 IInternetSecurityManager *isecmgr;
1418
1419 if (!obj) return E_FAIL;
1420
1421 hr = IUnknown_QueryInterface(obj, &IID_IObjectWithSite, (LPVOID *)&iobjwithsite);
1422 TRACE("IID_IObjectWithSite QI ret=%08x, %p\n", hr, iobjwithsite);
1423 if (SUCCEEDED(hr))
1424 {
1425 hr = IObjectWithSite_SetSite(iobjwithsite, site);
1426 TRACE("done IObjectWithSite_SetSite ret=%08x\n", hr);
1427 IObjectWithSite_Release(iobjwithsite);
1428 }
1429 else
1430 {
1431 hr = IUnknown_QueryInterface(obj, &IID_IInternetSecurityManager, (LPVOID *)&isecmgr);
1432 TRACE("IID_IInternetSecurityManager QI ret=%08x, %p\n", hr, isecmgr);
1433 if (FAILED(hr)) return hr;
1434
1435 hr = IInternetSecurityManager_SetSecuritySite(isecmgr, (IInternetSecurityMgrSite *)site);
1436 TRACE("done IInternetSecurityManager_SetSecuritySite ret=%08x\n", hr);
1437 IInternetSecurityManager_Release(isecmgr);
1438 }
1439 return hr;
1440}
1441
1442/*************************************************************************
1443 * @ [SHLWAPI.175]
1444 *
1445 * Call IPersist_GetClassID() on an object.
1446 *
1447 * PARAMS
1448 * lpUnknown [I] Object supporting the IPersist interface
1449 * clsid [O] Destination for Class Id
1450 *
1451 * RETURNS
1452 * Success: S_OK. lpClassId contains the Class Id requested.
1453 * Failure: E_FAIL, If lpUnknown is NULL,
1454 * E_NOINTERFACE If lpUnknown does not support IPersist,
1455 * Or an HRESULT error code.
1456 */
1458{
1459 IPersist *persist;
1460 HRESULT hr;
1461
1462 TRACE("(%p, %p)\n", lpUnknown, clsid);
1463
1464 if (!lpUnknown)
1465 {
1466 memset(clsid, 0, sizeof(*clsid));
1467 return E_FAIL;
1468 }
1469
1470 hr = IUnknown_QueryInterface(lpUnknown, &IID_IPersist, (void**)&persist);
1471 if (hr != S_OK)
1472 {
1473 hr = IUnknown_QueryInterface(lpUnknown, &IID_IPersistFolder, (void**)&persist);
1474 if (hr != S_OK)
1475 return hr;
1476 }
1477
1478 hr = IPersist_GetClassID(persist, clsid);
1479 IPersist_Release(persist);
1480 return hr;
1481}
1482
1483/*************************************************************************
1484 * @ [SHLWAPI.176]
1485 *
1486 * Retrieve a Service Interface from an object.
1487 *
1488 * PARAMS
1489 * lpUnknown [I] Object to get an IServiceProvider interface from
1490 * sid [I] Service ID for IServiceProvider_QueryService() call
1491 * riid [I] Function requested for QueryService call
1492 * lppOut [O] Destination for the service interface pointer
1493 *
1494 * RETURNS
1495 * Success: S_OK. lppOut contains an object providing the requested service
1496 * Failure: An HRESULT error code
1497 *
1498 * NOTES
1499 * lpUnknown is expected to support the IServiceProvider interface.
1500 */
1502 LPVOID *lppOut)
1503{
1504 IServiceProvider* pService = NULL;
1505 HRESULT hRet;
1506
1507 if (!lppOut)
1508 return E_FAIL;
1509
1510 *lppOut = NULL;
1511
1512 if (!lpUnknown)
1513 return E_FAIL;
1514
1515 hRet = IUnknown_QueryInterface(lpUnknown, &IID_IServiceProvider,
1516 (LPVOID*)&pService);
1517
1518 if (hRet == S_OK && pService)
1519 {
1520 TRACE("QueryInterface returned (IServiceProvider*)%p\n", pService);
1521
1522 /* Get a Service interface from the object */
1523 hRet = IServiceProvider_QueryService(pService, sid, riid, lppOut);
1524
1525 TRACE("(IServiceProvider*)%p returned (IUnknown*)%p\n", pService, *lppOut);
1526
1527 IServiceProvider_Release(pService);
1528 }
1529 return hRet;
1530}
1531
1532/*************************************************************************
1533 * @ [SHLWAPI.484]
1534 *
1535 * Calls IOleCommandTarget::Exec() for specified service object.
1536 *
1537 * PARAMS
1538 * lpUnknown [I] Object to get an IServiceProvider interface from
1539 * service [I] Service ID for IServiceProvider_QueryService() call
1540 * group [I] Group ID for IOleCommandTarget::Exec() call
1541 * cmdId [I] Command ID for IOleCommandTarget::Exec() call
1542 * cmdOpt [I] Options flags for command
1543 * pIn [I] Input arguments for command
1544 * pOut [O] Output arguments for command
1545 *
1546 * RETURNS
1547 * Success: S_OK. lppOut contains an object providing the requested service
1548 * Failure: An HRESULT error code
1549 *
1550 * NOTES
1551 * lpUnknown is expected to support the IServiceProvider interface.
1552 */
1554 const GUID *group, DWORD cmdId, DWORD cmdOpt, VARIANT *pIn, VARIANT *pOut)
1555{
1557 HRESULT hr;
1558
1559 TRACE("%p %s %s %d %08x %p %p\n", lpUnknown, debugstr_guid(service),
1560 debugstr_guid(group), cmdId, cmdOpt, pIn, pOut);
1561
1562 hr = IUnknown_QueryService(lpUnknown, service, &IID_IOleCommandTarget, (void**)&target);
1563 if (hr == S_OK)
1564 {
1565 hr = IOleCommandTarget_Exec(target, group, cmdId, cmdOpt, pIn, pOut);
1566 IOleCommandTarget_Release(target);
1567 }
1568
1569 TRACE("<-- hr=0x%08x\n", hr);
1570
1571 return hr;
1572}
1573
1574/*************************************************************************
1575 * @ [SHLWAPI.514]
1576 *
1577 * Calls IProfferService methods to proffer/revoke specified service.
1578 *
1579 * PARAMS
1580 * lpUnknown [I] Object to get an IServiceProvider interface from
1581 * service [I] Service ID for IProfferService::Proffer/Revoke calls
1582 * pService [I] Service to proffer. If NULL ::Revoke is called
1583 * pCookie [IO] Group ID for IOleCommandTarget::Exec() call
1584 *
1585 * RETURNS
1586 * Success: S_OK. IProffer method returns S_OK
1587 * Failure: An HRESULT error code
1588 *
1589 * NOTES
1590 * lpUnknown is expected to support the IServiceProvider interface.
1591 */
1593{
1594 IProfferService *proffer;
1595 HRESULT hr;
1596
1597 TRACE("%p %s %p %p\n", lpUnknown, debugstr_guid(service), pService, pCookie);
1598
1599 hr = IUnknown_QueryService(lpUnknown, &IID_IProfferService, &IID_IProfferService, (void**)&proffer);
1600 if (hr == S_OK)
1601 {
1602 if (pService)
1603 hr = IProfferService_ProfferService(proffer, service, pService, pCookie);
1604 else
1605 {
1606 hr = IProfferService_RevokeService(proffer, *pCookie);
1607 *pCookie = 0;
1608 }
1609
1610 IProfferService_Release(proffer);
1611 }
1612
1613 return hr;
1614}
1615
1616/*************************************************************************
1617 * @ [SHLWAPI.479]
1618 *
1619 * Call an object's UIActivateIO method.
1620 *
1621 * PARAMS
1622 * unknown [I] Object to call the UIActivateIO method on
1623 * activate [I] Parameter for UIActivateIO call
1624 * msg [I] Parameter for UIActivateIO call
1625 *
1626 * RETURNS
1627 * Success: Value of UI_ActivateIO call
1628 * Failure: An HRESULT error code
1629 *
1630 * NOTES
1631 * unknown is expected to support the IInputObject interface.
1632 */
1634{
1635 IInputObject* object = NULL;
1636 HRESULT ret;
1637
1638 if (!unknown)
1639 return E_FAIL;
1640
1641 /* Get an IInputObject interface from the object */
1642 ret = IUnknown_QueryInterface(unknown, &IID_IInputObject, (LPVOID*) &object);
1643
1644 if (ret == S_OK)
1645 {
1646 ret = IInputObject_UIActivateIO(object, activate, msg);
1647 IInputObject_Release(object);
1648 }
1649
1650 return ret;
1651}
1652
1653/*************************************************************************
1654 * @ [SHLWAPI.177]
1655 *
1656 * Loads a popup menu.
1657 *
1658 * PARAMS
1659 * hInst [I] Instance handle
1660 * szName [I] Menu name
1661 *
1662 * RETURNS
1663 * Success: TRUE.
1664 * Failure: FALSE.
1665 */
1667{
1668 HMENU hMenu;
1669
1670 TRACE("%p %s\n", hInst, debugstr_w(szName));
1671
1672 if ((hMenu = LoadMenuW(hInst, szName)))
1673 {
1674 if (GetSubMenu(hMenu, 0))
1675 RemoveMenu(hMenu, 0, MF_BYPOSITION);
1676
1677 DestroyMenu(hMenu);
1678 return TRUE;
1679 }
1680 return FALSE;
1681}
1682
1683typedef struct _enumWndData
1684{
1690
1691/* Callback for SHLWAPI_178 */
1693{
1695
1696 TRACE("(%p,%p)\n", hWnd, data);
1697 data->pfnPost(hWnd, data->uiMsgId, data->wParam, data->lParam);
1698 return TRUE;
1699}
1700
1701/*************************************************************************
1702 * @ [SHLWAPI.178]
1703 *
1704 * Send or post a message to every child of a window.
1705 *
1706 * PARAMS
1707 * hWnd [I] Window whose children will get the messages
1708 * uiMsgId [I] Message Id
1709 * wParam [I] WPARAM of message
1710 * lParam [I] LPARAM of message
1711 * bSend [I] TRUE = Use SendMessageA(), FALSE = Use PostMessageA()
1712 *
1713 * RETURNS
1714 * Nothing.
1715 *
1716 * NOTES
1717 * The appropriate ASCII or Unicode function is called for the window.
1718 */
1720{
1722
1723 TRACE("(%p,%u,%ld,%ld,%d)\n", hWnd, uiMsgId, wParam, lParam, bSend);
1724
1725 if(hWnd)
1726 {
1727 data.uiMsgId = uiMsgId;
1728 data.wParam = wParam;
1729 data.lParam = lParam;
1730
1731 if (bSend)
1732 data.pfnPost = IsWindowUnicode(hWnd) ? (void*)SendMessageW : (void*)SendMessageA;
1733 else
1734 data.pfnPost = IsWindowUnicode(hWnd) ? (void*)PostMessageW : (void*)PostMessageA;
1735
1737 }
1738}
1739
1740/*************************************************************************
1741 * @ [SHLWAPI.180]
1742 *
1743 * Remove all sub-menus from a menu.
1744 *
1745 * PARAMS
1746 * hMenu [I] Menu to remove sub-menus from
1747 *
1748 * RETURNS
1749 * Success: 0. All sub-menus under hMenu are removed
1750 * Failure: -1, if any parameter is invalid
1751 */
1753{
1754 int iItemCount = GetMenuItemCount(hMenu) - 1;
1755
1756 TRACE("%p\n", hMenu);
1757
1758 while (iItemCount >= 0)
1759 {
1760 HMENU hSubMenu = GetSubMenu(hMenu, iItemCount);
1761 if (hSubMenu)
1762 RemoveMenu(hMenu, iItemCount, MF_BYPOSITION);
1763 iItemCount--;
1764 }
1765 return iItemCount;
1766}
1767
1768/*************************************************************************
1769 * @ [SHLWAPI.181]
1770 *
1771 * Enable or disable a menu item.
1772 *
1773 * PARAMS
1774 * hMenu [I] Menu holding menu item
1775 * uID [I] ID of menu item to enable/disable
1776 * bEnable [I] Whether to enable (TRUE) or disable (FALSE) the item.
1777 *
1778 * RETURNS
1779 * The return code from EnableMenuItem.
1780 */
1782{
1783 TRACE("%p, %u, %d\n", hMenu, wItemID, bEnable);
1784 return EnableMenuItem(hMenu, wItemID, bEnable ? MF_ENABLED : MF_GRAYED);
1785}
1786
1787/*************************************************************************
1788 * @ [SHLWAPI.182]
1789 *
1790 * Check or uncheck a menu item.
1791 *
1792 * PARAMS
1793 * hMenu [I] Menu holding menu item
1794 * uID [I] ID of menu item to check/uncheck
1795 * bCheck [I] Whether to check (TRUE) or uncheck (FALSE) the item.
1796 *
1797 * RETURNS
1798 * The return code from CheckMenuItem.
1799 */
1801{
1802 TRACE("%p, %u, %d\n", hMenu, uID, bCheck);
1803 return CheckMenuItem(hMenu, uID, bCheck ? MF_CHECKED : MF_UNCHECKED);
1804}
1805
1806/*************************************************************************
1807 * @ [SHLWAPI.183]
1808 *
1809 * Register a window class if it isn't already.
1810 *
1811 * PARAMS
1812 * lpWndClass [I] Window class to register
1813 *
1814 * RETURNS
1815 * The result of the RegisterClassA call.
1816 */
1818{
1819 WNDCLASSA wca;
1820 if (GetClassInfoA(wndclass->hInstance, wndclass->lpszClassName, &wca))
1821 return TRUE;
1822 return (DWORD)RegisterClassA(wndclass);
1823}
1824
1825/*************************************************************************
1826 * @ [SHLWAPI.186]
1827 */
1829 DWORD grfKeyState, PPOINTL lpPt, DWORD* pdwEffect)
1830{
1831 DWORD dwEffect = DROPEFFECT_LINK | DROPEFFECT_MOVE | DROPEFFECT_COPY;
1832 POINTL pt = { 0, 0 };
1833
1834 TRACE("%p %p 0x%08x %p %p\n", pDrop, pDataObj, grfKeyState, lpPt, pdwEffect);
1835
1836 if (!lpPt)
1837 lpPt = &pt;
1838
1839 if (!pdwEffect)
1840 pdwEffect = &dwEffect;
1841
1842 IDropTarget_DragEnter(pDrop, pDataObj, grfKeyState, *lpPt, pdwEffect);
1843
1844 if (*pdwEffect != DROPEFFECT_NONE)
1845 return IDropTarget_Drop(pDrop, pDataObj, grfKeyState, *lpPt, pdwEffect);
1846
1847 IDropTarget_DragLeave(pDrop);
1848 return TRUE;
1849}
1850
1851/*************************************************************************
1852 * @ [SHLWAPI.187]
1853 *
1854 * Call IPersistPropertyBag_Load() on an object.
1855 *
1856 * PARAMS
1857 * lpUnknown [I] Object supporting the IPersistPropertyBag interface
1858 * lpPropBag [O] Destination for loaded IPropertyBag
1859 *
1860 * RETURNS
1861 * Success: S_OK.
1862 * Failure: An HRESULT error code, or E_FAIL if lpUnknown is NULL.
1863 */
1865{
1866 IPersistPropertyBag* lpPPBag;
1867 HRESULT hRet = E_FAIL;
1868
1869 TRACE("(%p,%p)\n", lpUnknown, lpPropBag);
1870
1871 if (lpUnknown)
1872 {
1873 hRet = IUnknown_QueryInterface(lpUnknown, &IID_IPersistPropertyBag,
1874 (void**)&lpPPBag);
1875 if (SUCCEEDED(hRet) && lpPPBag)
1876 {
1877 hRet = IPersistPropertyBag_Load(lpPPBag, lpPropBag, NULL);
1878 IPersistPropertyBag_Release(lpPPBag);
1879 }
1880 }
1881 return hRet;
1882}
1883
1884/*************************************************************************
1885 * @ [SHLWAPI.188]
1886 *
1887 * Call IOleControlSite_TranslateAccelerator() on an object.
1888 *
1889 * PARAMS
1890 * lpUnknown [I] Object supporting the IOleControlSite interface.
1891 * lpMsg [I] Key message to be processed.
1892 * dwModifiers [I] Flags containing the state of the modifier keys.
1893 *
1894 * RETURNS
1895 * Success: S_OK.
1896 * Failure: An HRESULT error code, or E_INVALIDARG if lpUnknown is NULL.
1897 */
1899{
1900 IOleControlSite* lpCSite = NULL;
1901 HRESULT hRet = E_INVALIDARG;
1902
1903 TRACE("(%p,%p,0x%08x)\n", lpUnknown, lpMsg, dwModifiers);
1904 if (lpUnknown)
1905 {
1906 hRet = IUnknown_QueryInterface(lpUnknown, &IID_IOleControlSite,
1907 (void**)&lpCSite);
1908 if (SUCCEEDED(hRet) && lpCSite)
1909 {
1910 hRet = IOleControlSite_TranslateAccelerator(lpCSite, lpMsg, dwModifiers);
1911 IOleControlSite_Release(lpCSite);
1912 }
1913 }
1914 return hRet;
1915}
1916
1917
1918/*************************************************************************
1919 * @ [SHLWAPI.189]
1920 *
1921 * Call IOleControlSite_OnFocus() on an object.
1922 *
1923 * PARAMS
1924 * lpUnknown [I] Object supporting the IOleControlSite interface.
1925 * fGotFocus [I] Whether focus was gained (TRUE) or lost (FALSE).
1926 *
1927 * RETURNS
1928 * Success: S_OK.
1929 * Failure: An HRESULT error code, or E_FAIL if lpUnknown is NULL.
1930 */
1932{
1933 IOleControlSite* lpCSite = NULL;
1934 HRESULT hRet = E_FAIL;
1935
1936 TRACE("(%p, %d)\n", lpUnknown, fGotFocus);
1937 if (lpUnknown)
1938 {
1939 hRet = IUnknown_QueryInterface(lpUnknown, &IID_IOleControlSite,
1940 (void**)&lpCSite);
1941 if (SUCCEEDED(hRet) && lpCSite)
1942 {
1943 hRet = IOleControlSite_OnFocus(lpCSite, fGotFocus);
1944 IOleControlSite_Release(lpCSite);
1945 }
1946 }
1947 return hRet;
1948}
1949
1950/*************************************************************************
1951 * @ [SHLWAPI.190]
1952 */
1954 PVOID lpArg2, PVOID lpArg3, PVOID lpArg4)
1955{
1956 /* FIXME: {D12F26B2-D90A-11D0-830D-00AA005B4383} - What object does this represent? */
1957 static const DWORD service_id[] = { 0xd12f26b2, 0x11d0d90a, 0xaa000d83, 0x83435b00 };
1958 /* FIXME: {D12F26B1-D90A-11D0-830D-00AA005B4383} - Also Unknown/undocumented */
1959 static const DWORD function_id[] = { 0xd12f26b1, 0x11d0d90a, 0xaa000d83, 0x83435b00 };
1960 HRESULT hRet = E_INVALIDARG;
1961 LPUNKNOWN lpUnkInner = NULL; /* FIXME: Real type is unknown */
1962
1963 TRACE("(%p,%p,%p,%p,%p)\n", lpUnknown, lpArg1, lpArg2, lpArg3, lpArg4);
1964
1965 if (lpUnknown && lpArg4)
1966 {
1967 hRet = IUnknown_QueryService(lpUnknown, (REFGUID)service_id,
1968 (REFGUID)function_id, (void**)&lpUnkInner);
1969
1970 if (SUCCEEDED(hRet) && lpUnkInner)
1971 {
1972 /* FIXME: The type of service object requested is unknown, however
1973 * testing shows that its first method is called with 4 parameters.
1974 * Fake this by using IParseDisplayName_ParseDisplayName since the
1975 * signature and position in the vtable matches our unknown object type.
1976 */
1977 hRet = IParseDisplayName_ParseDisplayName((LPPARSEDISPLAYNAME)lpUnkInner,
1978 lpArg1, lpArg2, lpArg3, lpArg4);
1979 IUnknown_Release(lpUnkInner);
1980 }
1981 }
1982 return hRet;
1983}
1984
1985/*************************************************************************
1986 * @ [SHLWAPI.192]
1987 *
1988 * Get a sub-menu from a menu item.
1989 *
1990 * PARAMS
1991 * hMenu [I] Menu to get sub-menu from
1992 * uID [I] ID of menu item containing sub-menu
1993 *
1994 * RETURNS
1995 * The sub-menu of the item, or a NULL handle if any parameters are invalid.
1996 */
1998{
2000
2001 TRACE("(%p,%u)\n", hMenu, uID);
2002
2003 mi.cbSize = sizeof(mi);
2004 mi.fMask = MIIM_SUBMENU;
2005
2006 if (!GetMenuItemInfoW(hMenu, uID, FALSE, &mi))
2007 return NULL;
2008
2009 return mi.hSubMenu;
2010}
2011
2012/*************************************************************************
2013 * @ [SHLWAPI.193]
2014 *
2015 * Get the color depth of the primary display.
2016 *
2017 * PARAMS
2018 * None.
2019 *
2020 * RETURNS
2021 * The color depth of the primary display.
2022 */
2024{
2025 HDC hdc;
2026 DWORD ret;
2027
2028 TRACE("()\n");
2029
2030 hdc = GetDC(0);
2032 ReleaseDC(0, hdc);
2033 return ret;
2034}
2035
2036/*************************************************************************
2037 * @ [SHLWAPI.194]
2038 *
2039 * Wait for a message to arrive, with a timeout.
2040 *
2041 * PARAMS
2042 * hand [I] Handle to query
2043 * dwTimeout [I] Timeout in ticks or INFINITE to never timeout
2044 *
2045 * RETURNS
2046 * STATUS_TIMEOUT if no message is received before dwTimeout ticks passes.
2047 * Otherwise returns the value from MsgWaitForMultipleObjectsEx when a
2048 * message is available.
2049 */
2051{
2052 DWORD dwEndTicks = GetTickCount() + dwTimeout;
2053 DWORD dwRet;
2054
2055 while ((dwRet = MsgWaitForMultipleObjectsEx(1, &hand, dwTimeout, QS_SENDMESSAGE, 0)) == 1)
2056 {
2057 MSG msg;
2058
2059 PeekMessageW(&msg, NULL, 0, 0, PM_NOREMOVE);
2060
2061 if (dwTimeout != INFINITE)
2062 {
2063 if ((int)(dwTimeout = dwEndTicks - GetTickCount()) <= 0)
2064 return WAIT_TIMEOUT;
2065 }
2066 }
2067
2068 return dwRet;
2069}
2070
2071/*************************************************************************
2072 * @ [SHLWAPI.195]
2073 *
2074 * Determine if a shell folder can be expanded.
2075 *
2076 * PARAMS
2077 * lpFolder [I] Parent folder containing the object to test.
2078 * pidl [I] Id of the object to test.
2079 *
2080 * RETURNS
2081 * Success: S_OK, if the object is expandable, S_FALSE otherwise.
2082 * Failure: E_INVALIDARG, if any argument is invalid.
2083 *
2084 * NOTES
2085 * If the object to be tested does not expose the IQueryInfo() interface it
2086 * will not be identified as an expandable folder.
2087 */
2089{
2090 HRESULT hRet = E_INVALIDARG;
2091 IQueryInfo *lpInfo;
2092
2093 if (lpFolder && pidl)
2094 {
2095 hRet = IShellFolder_GetUIObjectOf(lpFolder, NULL, 1, &pidl, &IID_IQueryInfo,
2096 NULL, (void**)&lpInfo);
2097 if (FAILED(hRet))
2098 hRet = S_FALSE; /* Doesn't expose IQueryInfo */
2099 else
2100 {
2101 DWORD dwFlags = 0;
2102
2103 /* MSDN states of IQueryInfo_GetInfoFlags() that "This method is not
2104 * currently used". Really? You wouldn't be holding out on me would you?
2105 */
2106 hRet = IQueryInfo_GetInfoFlags(lpInfo, &dwFlags);
2107
2108 if (SUCCEEDED(hRet))
2109 {
2110 /* 0x2 is an undocumented flag apparently indicating expandability */
2111 hRet = dwFlags & 0x2 ? S_OK : S_FALSE;
2112 }
2113
2114 IQueryInfo_Release(lpInfo);
2115 }
2116 }
2117 return hRet;
2118}
2119
2120/*************************************************************************
2121 * @ [SHLWAPI.197]
2122 *
2123 * Blank out a region of text by drawing the background only.
2124 *
2125 * PARAMS
2126 * hDC [I] Device context to draw in
2127 * pRect [I] Area to draw in
2128 * cRef [I] Color to draw in
2129 *
2130 * RETURNS
2131 * Nothing.
2132 */
2134{
2135 COLORREF cOldColor = SetBkColor(hDC, cRef);
2136 ExtTextOutA(hDC, 0, 0, ETO_OPAQUE, pRect, 0, 0, 0);
2137 SetBkColor(hDC, cOldColor);
2138 return 0;
2139}
2140
2141/*************************************************************************
2142 * @ [SHLWAPI.198]
2143 *
2144 * Return the value associated with a key in a map.
2145 *
2146 * PARAMS
2147 * lpKeys [I] A list of keys of length iLen
2148 * lpValues [I] A list of values associated with lpKeys, of length iLen
2149 * iLen [I] Length of both lpKeys and lpValues
2150 * iKey [I] The key value to look up in lpKeys
2151 *
2152 * RETURNS
2153 * The value in lpValues associated with iKey, or -1 if iKey is not
2154 * found in lpKeys.
2155 *
2156 * NOTES
2157 * - If two elements in the map share the same key, this function returns
2158 * the value closest to the start of the map
2159 * - The native version of this function crashes if lpKeys or lpValues is NULL.
2160 */
2161int WINAPI SHSearchMapInt(const int *lpKeys, const int *lpValues, int iLen, int iKey)
2162{
2163 if (lpKeys && lpValues)
2164 {
2165 int i = 0;
2166
2167 while (i < iLen)
2168 {
2169 if (lpKeys[i] == iKey)
2170 return lpValues[i]; /* Found */
2171 i++;
2172 }
2173 }
2174 return -1; /* Not found */
2175}
2176
2177
2178/*************************************************************************
2179 * @ [SHLWAPI.199]
2180 *
2181 * Copy an interface pointer
2182 *
2183 * PARAMS
2184 * lppDest [O] Destination for copy
2185 * lpUnknown [I] Source for copy
2186 *
2187 * RETURNS
2188 * Nothing.
2189 */
2191{
2192 TRACE("(%p,%p)\n", lppDest, lpUnknown);
2193
2194 IUnknown_AtomicRelease(lppDest);
2195
2196 if (lpUnknown)
2197 {
2198 IUnknown_AddRef(lpUnknown);
2199 *lppDest = lpUnknown;
2200 }
2201}
2202
2203/*************************************************************************
2204 * @ [SHLWAPI.200]
2205 *
2206 */
2208 REFGUID riidCmdGrp, ULONG cCmds,
2209 OLECMD *prgCmds, OLECMDTEXT* pCmdText)
2210{
2211 FIXME("(%p,%p,%p,%d,%p,%p) - stub\n",
2212 lpUnknown, lpReserved, riidCmdGrp, cCmds, prgCmds, pCmdText);
2213
2214 /* FIXME: Calls IsQSForward & IUnknown_QueryStatus */
2216}
2217
2218/*************************************************************************
2219 * @ [SHLWAPI.201]
2220 *
2221 */
2222HRESULT WINAPI MayExecForward(IUnknown* lpUnknown, INT iUnk, REFGUID pguidCmdGroup,
2223 DWORD nCmdID, DWORD nCmdexecopt, VARIANT* pvaIn,
2224 VARIANT* pvaOut)
2225{
2226 FIXME("(%p,%d,%p,%d,%d,%p,%p) - stub!\n", lpUnknown, iUnk, pguidCmdGroup,
2227 nCmdID, nCmdexecopt, pvaIn, pvaOut);
2229}
2230
2231/*************************************************************************
2232 * @ [SHLWAPI.202]
2233 *
2234 */
2235HRESULT WINAPI IsQSForward(REFGUID pguidCmdGroup,ULONG cCmds, OLECMD *prgCmds)
2236{
2237 FIXME("(%p,%d,%p) - stub!\n", pguidCmdGroup, cCmds, prgCmds);
2239}
2240
2241/*************************************************************************
2242 * @ [SHLWAPI.204]
2243 *
2244 * Determine if a window is not a child of another window.
2245 *
2246 * PARAMS
2247 * hParent [I] Suspected parent window
2248 * hChild [I] Suspected child window
2249 *
2250 * RETURNS
2251 * TRUE: If hChild is a child window of hParent
2252 * FALSE: If hChild is not a child window of hParent, or they are equal
2253 */
2255{
2256 TRACE("(%p,%p)\n", hParent, hChild);
2257
2258 if (!hParent || !hChild)
2259 return TRUE;
2260 else if(hParent == hChild)
2261 return FALSE;
2262 return !IsChild(hParent, hChild);
2263}
2264
2265/*************************************************************************
2266 * FDSA functions. Manage a dynamic array of fixed size memory blocks.
2267 */
2268
2269typedef struct
2270{
2271 DWORD num_items; /* Number of elements inserted */
2272 void *mem; /* Ptr to array */
2273 DWORD blocks_alloced; /* Number of elements allocated */
2274 BYTE inc; /* Number of elements to grow by when we need to expand */
2275 BYTE block_size; /* Size in bytes of an element */
2276 BYTE flags; /* Flags */
2277} FDSA_info;
2278
2279#define FDSA_FLAG_INTERNAL_ALLOC 0x01 /* When set we have allocated mem internally */
2280
2281/*************************************************************************
2282 * @ [SHLWAPI.208]
2283 *
2284 * Initialize an FDSA array.
2285 */
2287 DWORD init_blocks)
2288{
2289 TRACE("(0x%08x 0x%08x %p %p 0x%08x)\n", block_size, inc, info, mem, init_blocks);
2290
2291 if(inc == 0)
2292 inc = 1;
2293
2294 if(mem)
2295 memset(mem, 0, block_size * init_blocks);
2296
2297 info->num_items = 0;
2298 info->inc = inc;
2299 info->mem = mem;
2300 info->blocks_alloced = init_blocks;
2301 info->block_size = block_size;
2302 info->flags = 0;
2303
2304 return TRUE;
2305}
2306
2307/*************************************************************************
2308 * @ [SHLWAPI.209]
2309 *
2310 * Destroy an FDSA array
2311 */
2313{
2314 TRACE("(%p)\n", info);
2315
2316 if(info->flags & FDSA_FLAG_INTERNAL_ALLOC)
2317 {
2318 HeapFree(GetProcessHeap(), 0, info->mem);
2319 return FALSE;
2320 }
2321
2322 return TRUE;
2323}
2324
2325/*************************************************************************
2326 * @ [SHLWAPI.210]
2327 *
2328 * Insert element into an FDSA array
2329 */
2331{
2332 TRACE("(%p 0x%08x %p)\n", info, where, block);
2333 if(where > info->num_items)
2334 where = info->num_items;
2335
2336 if(info->num_items >= info->blocks_alloced)
2337 {
2338 DWORD size = (info->blocks_alloced + info->inc) * info->block_size;
2339 if(info->flags & 0x1)
2341 else
2342 {
2343 void *old_mem = info->mem;
2345 memcpy(info->mem, old_mem, info->blocks_alloced * info->block_size);
2346 }
2347 info->blocks_alloced += info->inc;
2348 info->flags |= 0x1;
2349 }
2350
2351 if(where < info->num_items)
2352 {
2353 memmove((char*)info->mem + (where + 1) * info->block_size,
2354 (char*)info->mem + where * info->block_size,
2355 (info->num_items - where) * info->block_size);
2356 }
2357 memcpy((char*)info->mem + where * info->block_size, block, info->block_size);
2358
2359 info->num_items++;
2360 return where;
2361}
2362
2363/*************************************************************************
2364 * @ [SHLWAPI.211]
2365 *
2366 * Delete an element from an FDSA array.
2367 */
2369{
2370 TRACE("(%p 0x%08x)\n", info, where);
2371
2372 if(where >= info->num_items)
2373 return FALSE;
2374
2375 if(where < info->num_items - 1)
2376 {
2377 memmove((char*)info->mem + where * info->block_size,
2378 (char*)info->mem + (where + 1) * info->block_size,
2379 (info->num_items - where - 1) * info->block_size);
2380 }
2381 memset((char*)info->mem + (info->num_items - 1) * info->block_size,
2382 0, info->block_size);
2383 info->num_items--;
2384 return TRUE;
2385}
2386
2387/*************************************************************************
2388 * @ [SHLWAPI.219]
2389 *
2390 * Call IUnknown_QueryInterface() on a table of objects.
2391 *
2392 * RETURNS
2393 * Success: S_OK.
2394 * Failure: E_POINTER or E_NOINTERFACE.
2395 */
2397 void *base, /* [in] Table of interfaces */
2398 const QITAB *table, /* [in] Array of REFIIDs and indexes into the table */
2399 REFIID riid, /* [in] REFIID to get interface for */
2400 void **ppv) /* [out] Destination for interface pointer */
2401{
2402 HRESULT ret;
2403 IUnknown *a_vtbl;
2404 const QITAB *xmove;
2405
2406 TRACE("(%p %p %s %p)\n", base, table, debugstr_guid(riid), ppv);
2407 if (ppv) {
2408 xmove = table;
2409 while (xmove->piid) {
2410 TRACE("trying (offset %d) %s\n", xmove->dwOffset, debugstr_guid(xmove->piid));
2411 if (IsEqualIID(riid, xmove->piid)) {
2412 a_vtbl = (IUnknown*)(xmove->dwOffset + (LPBYTE)base);
2413 TRACE("matched, returning (%p)\n", a_vtbl);
2414 *ppv = a_vtbl;
2415 IUnknown_AddRef(a_vtbl);
2416 return S_OK;
2417 }
2418 xmove++;
2419 }
2420
2421 if (IsEqualIID(riid, &IID_IUnknown)) {
2422 a_vtbl = (IUnknown*)(table->dwOffset + (LPBYTE)base);
2423 TRACE("returning first for IUnknown (%p)\n", a_vtbl);
2424 *ppv = a_vtbl;
2425 IUnknown_AddRef(a_vtbl);
2426 return S_OK;
2427 }
2428 *ppv = 0;
2430 } else
2431 ret = E_POINTER;
2432
2433 TRACE("-- 0x%08x\n", ret);
2434 return ret;
2435}
2436
2437/*************************************************************************
2438 * @ [SHLWAPI.220]
2439 *
2440 * Set the Font for a window and the "PropDlgFont" property of the parent window.
2441 *
2442 * PARAMS
2443 * hWnd [I] Parent Window to set the property
2444 * id [I] Index of child Window to set the Font
2445 *
2446 * RETURNS
2447#ifdef __REACTOS__
2448 * VOID
2449#else
2450 * Success: S_OK
2451#endif
2452 *
2453 */
2454#ifdef __REACTOS__
2456#else
2458#endif
2459{
2460#ifdef __REACTOS__
2461 HFONT hOldFont, hNewFont;
2462 LOGFONTW lfOldFont, lfNewFont;
2463 HWND hwndItem;
2464
2465 TRACE("(%p, %d)\n", hWnd, id);
2466
2467 hOldFont = (HFONT)SendMessageW(hWnd, WM_GETFONT, 0, 0);
2468 GetObjectW(hOldFont, sizeof(lfOldFont), &lfOldFont);
2469 SystemParametersInfoW(SPI_GETICONTITLELOGFONT, sizeof(lfNewFont), &lfNewFont, 0);
2470
2471 if (lfOldFont.lfCharSet == lfNewFont.lfCharSet)
2472 return;
2473
2474 hNewFont = GetPropW(hWnd, L"PropDlgFont");
2475 if (!hNewFont)
2476 {
2477 /* Create the icon-title font of the same height */
2478 lfNewFont.lfHeight = lfOldFont.lfHeight;
2479 hNewFont = CreateFontIndirectW(&lfNewFont);
2480
2481 /* If creating the font is failed, then keep the old font */
2482 if (!hNewFont)
2483 hNewFont = hOldFont;
2484
2485 /* Set "PropDlgFont" property if the font is changed */
2486 if (hOldFont != hNewFont)
2487 SetPropW(hWnd, L"PropDlgFont", hNewFont);
2488 }
2489
2490 hwndItem = GetDlgItem(hWnd, id);
2491 SendMessageW(hwndItem, WM_SETFONT, (WPARAM)hNewFont, 0);
2492#else
2493 FIXME("(%p, %d) stub\n", hWnd, id);
2494 return S_OK;
2495#endif
2496}
2497
2498/*************************************************************************
2499 * @ [SHLWAPI.221]
2500 *
2501 * Remove the "PropDlgFont" property from a window.
2502 *
2503 * PARAMS
2504 * hWnd [I] Window to remove the property from
2505 *
2506 * RETURNS
2507 * A handle to the removed property, or NULL if it did not exist.
2508 */
2510{
2511 HANDLE hProp;
2512
2513 TRACE("(%p)\n", hWnd);
2514
2515 hProp = GetPropA(hWnd, "PropDlgFont");
2516
2517 if(hProp)
2518 {
2519 DeleteObject(hProp);
2520 hProp = RemovePropA(hWnd, "PropDlgFont");
2521 }
2522 return hProp;
2523}
2524
2525/*************************************************************************
2526 * @ [SHLWAPI.236]
2527 *
2528 * Load the in-process server of a given GUID.
2529 *
2530 * PARAMS
2531 * refiid [I] GUID of the server to load.
2532 *
2533 * RETURNS
2534 * Success: A handle to the loaded server dll.
2535 * Failure: A NULL handle.
2536 */
2538{
2539 HKEY newkey;
2540 DWORD type, count;
2541 CHAR value[MAX_PATH], string[MAX_PATH];
2542
2543 strcpy(string, "CLSID\\");
2544 SHStringFromGUIDA(refiid, string + 6, sizeof(string)/sizeof(char) - 6);
2545 strcat(string, "\\InProcServer32");
2546
2547 count = MAX_PATH;
2548 RegOpenKeyExA(HKEY_CLASSES_ROOT, string, 0, 1, &newkey);
2549 RegQueryValueExA(newkey, 0, 0, &type, (PBYTE)value, &count);
2550 RegCloseKey(newkey);
2551 return LoadLibraryExA(value, 0, 0);
2552}
2553
2554/*************************************************************************
2555 * @ [SHLWAPI.237]
2556 *
2557 * Unicode version of SHLWAPI_183.
2558 */
2560{
2562
2563 TRACE("(%p %s)\n",lpWndClass->hInstance, debugstr_w(lpWndClass->lpszClassName));
2564
2565 if (GetClassInfoW(lpWndClass->hInstance, lpWndClass->lpszClassName, &WndClass))
2566 return TRUE;
2567 return RegisterClassW(lpWndClass);
2568}
2569
2570/*************************************************************************
2571 * @ [SHLWAPI.238]
2572 *
2573 * Unregister a list of classes.
2574 *
2575 * PARAMS
2576 * hInst [I] Application instance that registered the classes
2577 * lppClasses [I] List of class names
2578 * iCount [I] Number of names in lppClasses
2579 *
2580 * RETURNS
2581 * Nothing.
2582 */
2584{
2586
2587 TRACE("(%p,%p,%d)\n", hInst, lppClasses, iCount);
2588
2589 while (iCount > 0)
2590 {
2591 if (GetClassInfoA(hInst, *lppClasses, &WndClass))
2592 UnregisterClassA(*lppClasses, hInst);
2593 lppClasses++;
2594 iCount--;
2595 }
2596}
2597
2598/*************************************************************************
2599 * @ [SHLWAPI.239]
2600 *
2601 * Unicode version of SHUnregisterClassesA.
2602 */
2604{
2606
2607 TRACE("(%p,%p,%d)\n", hInst, lppClasses, iCount);
2608
2609 while (iCount > 0)
2610 {
2611 if (GetClassInfoW(hInst, *lppClasses, &WndClass))
2612 UnregisterClassW(*lppClasses, hInst);
2613 lppClasses++;
2614 iCount--;
2615 }
2616}
2617
2618/*************************************************************************
2619 * @ [SHLWAPI.240]
2620 *
2621 * Call The correct (Ascii/Unicode) default window procedure for a window.
2622 *
2623 * PARAMS
2624 * hWnd [I] Window to call the default procedure for
2625 * uMessage [I] Message ID
2626 * wParam [I] WPARAM of message
2627 * lParam [I] LPARAM of message
2628 *
2629 * RETURNS
2630 * The result of calling DefWindowProcA() or DefWindowProcW().
2631 */
2633{
2634 if (IsWindowUnicode(hWnd))
2635 return DefWindowProcW(hWnd, uMessage, wParam, lParam);
2636 return DefWindowProcA(hWnd, uMessage, wParam, lParam);
2637}
2638
2639/*************************************************************************
2640 * @ [SHLWAPI.256]
2641 */
2643{
2644 HRESULT hRet = E_INVALIDARG;
2645 LPOBJECTWITHSITE lpSite = NULL;
2646
2647 TRACE("(%p,%s,%p)\n", lpUnknown, debugstr_guid(iid), lppSite);
2648
2649 if (lpUnknown && iid && lppSite)
2650 {
2651 hRet = IUnknown_QueryInterface(lpUnknown, &IID_IObjectWithSite,
2652 (void**)&lpSite);
2653 if (SUCCEEDED(hRet) && lpSite)
2654 {
2655 hRet = IObjectWithSite_GetSite(lpSite, iid, lppSite);
2656 IObjectWithSite_Release(lpSite);
2657 }
2658 }
2659 return hRet;
2660}
2661
2662/*************************************************************************
2663 * @ [SHLWAPI.257]
2664 *
2665 * Create a worker window using CreateWindowExA().
2666 *
2667 * PARAMS
2668 * wndProc [I] Window procedure
2669 * hWndParent [I] Parent window
2670 * dwExStyle [I] Extra style flags
2671 * dwStyle [I] Style flags
2672 * hMenu [I] Window menu
2673 * wnd_extra [I] Window extra bytes value
2674 *
2675 * RETURNS
2676 * Success: The window handle of the newly created window.
2677 * Failure: 0.
2678 */
2680 DWORD dwStyle, HMENU hMenu, LONG_PTR wnd_extra)
2681{
2682 static const char szClass[] = "WorkerA";
2683 WNDCLASSA wc;
2684 HWND hWnd;
2685
2686 TRACE("(%p, %p, 0x%08x, 0x%08x, %p, 0x%08lx)\n",
2687 wndProc, hWndParent, dwExStyle, dwStyle, hMenu, wnd_extra);
2688
2689 /* Create Window class */
2690 wc.style = 0;
2692 wc.cbClsExtra = 0;
2693 wc.cbWndExtra = sizeof(LONG_PTR);
2695 wc.hIcon = NULL;
2697 wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
2698 wc.lpszMenuName = NULL;
2699 wc.lpszClassName = szClass;
2700
2701 SHRegisterClassA(&wc);
2702
2703 hWnd = CreateWindowExA(dwExStyle, szClass, 0, dwStyle, 0, 0, 0, 0,
2704 hWndParent, hMenu, shlwapi_hInstance, 0);
2705 if (hWnd)
2706 {
2707 SetWindowLongPtrW(hWnd, 0, wnd_extra);
2709 }
2710
2711 return hWnd;
2712}
2713
2714#ifndef __REACTOS__ /* The followings are defined in <shlwapi_undoc.h> */
2715typedef struct tagPOLICYDATA
2716{
2717 DWORD policy; /* flags value passed to SHRestricted */
2718 LPCWSTR appstr; /* application str such as "Explorer" */
2719 LPCWSTR keystr; /* name of the actual registry key / policy */
2721
2722#define SHELL_NO_POLICY 0xffffffff
2723
2724/* default shell policy registry key */
2725static const WCHAR strRegistryPolicyW[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o',
2726 's','o','f','t','\\','W','i','n','d','o','w','s','\\',
2727 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',
2728 '\\','P','o','l','i','c','i','e','s',0};
2729#endif /* ndef __REACTOS__ */
2730
2731/*************************************************************************
2732 * @ [SHLWAPI.271]
2733 *
2734 * Retrieve a policy value from the registry.
2735 *
2736 * PARAMS
2737 * lpSubKey [I] registry key name
2738 * lpSubName [I] subname of registry key
2739 * lpValue [I] value name of registry value
2740 *
2741 * RETURNS
2742 * the value associated with the registry key or 0 if not found
2743 */
2745{
2746#ifdef __REACTOS__
2748 DWORD dwSize, dwValue = 0;
2749
2750 TRACE("(%s, %s, %s)\n", debugstr_w(lpSubKey), debugstr_w(lpSubName), debugstr_w(lpValue));
2751
2752 if (!lpSubKey)
2753 lpSubKey = L"Software\\Microsoft\\Windows\\CurrentVersion\\Policies";
2754
2755 PathCombineW(szPath, lpSubKey, lpSubName);
2756
2757 dwSize = sizeof(dwValue);
2758 if (SHGetValueW(HKEY_LOCAL_MACHINE, szPath, lpValue, NULL, &dwValue, &dwSize) == ERROR_SUCCESS)
2759 return dwValue;
2760
2761 dwSize = sizeof(dwValue);
2762 SHGetValueW(HKEY_CURRENT_USER, szPath, lpValue, NULL, &dwValue, &dwSize);
2763 return dwValue;
2764#else
2765 DWORD retval, datsize = sizeof(retval);
2766 HKEY hKey;
2767
2768 if (!lpSubKey)
2769 lpSubKey = strRegistryPolicyW;
2770
2771 retval = RegOpenKeyW(HKEY_LOCAL_MACHINE, lpSubKey, &hKey);
2772 if (retval != ERROR_SUCCESS)
2773 retval = RegOpenKeyW(HKEY_CURRENT_USER, lpSubKey, &hKey);
2774 if (retval != ERROR_SUCCESS)
2775 return 0;
2776
2777 SHGetValueW(hKey, lpSubName, lpValue, NULL, &retval, &datsize);
2779 return retval;
2780#endif
2781}
2782
2783/*************************************************************************
2784 * @ [SHLWAPI.266]
2785 *
2786 * Helper function to retrieve the possibly cached value for a specific policy
2787 *
2788 * PARAMS
2789 * policy [I] The policy to look for
2790 * initial [I] Main registry key to open, if NULL use default
2791 * polTable [I] Table of known policies, 0 terminated
2792 * polArr [I] Cache array of policy values
2793 *
2794 * RETURNS
2795 * The retrieved policy value or 0 if not successful
2796 *
2797 * NOTES
2798 * This function is used by the native SHRestricted function to search for the
2799 * policy and cache it once retrieved. The current Wine implementation uses a
2800 * different POLICYDATA structure and implements a similar algorithm adapted to
2801 * that structure.
2802 */
2803#ifdef __REACTOS__
2807 _In_ LPCWSTR initial,
2808 _In_ const POLICYDATA *polTable,
2809 _Inout_ LPDWORD polArr)
2810#else
2812 DWORD policy,
2813 LPCWSTR initial,
2814 LPPOLICYDATA polTable,
2815 LPDWORD polArr)
2816#endif
2817{
2818 TRACE("(0x%08x %s %p %p)\n", policy, debugstr_w(initial), polTable, polArr);
2819
2820#ifndef __REACTOS__
2821 if (!polTable || !polArr)
2822 return 0;
2823#endif
2824
2825#ifndef __REACTOS__
2826 for (;polTable->appstr; polTable++, polArr++)
2827#else
2828 for (;polTable->policy; polTable++, polArr++)
2829#endif
2830 {
2831 if (policy == polTable->policy)
2832 {
2833 /* we have a known policy */
2834
2835 /* check if this policy has been cached */
2836 if (*polArr == SHELL_NO_POLICY)
2837 *polArr = SHGetRestriction(initial, polTable->appstr, polTable->keystr);
2838 return *polArr;
2839 }
2840 }
2841 /* we don't know this policy, return 0 */
2842 TRACE("unknown policy: (%08x)\n", policy);
2843 return 0;
2844}
2845
2846/*************************************************************************
2847 * @ [SHLWAPI.267]
2848 *
2849 * Get an interface from an object.
2850 *
2851 * RETURNS
2852 * Success: S_OK. ppv contains the requested interface.
2853 * Failure: An HRESULT error code.
2854 *
2855 * NOTES
2856 * This QueryInterface asks the inner object for an interface. In case
2857 * of aggregation this request would be forwarded by the inner to the
2858 * outer object. This function asks the inner object directly for the
2859 * interface circumventing the forwarding to the outer object.
2860 */
2862 IUnknown * pUnk, /* [in] Outer object */
2863 IUnknown * pInner, /* [in] Inner object */
2864 IID * riid, /* [in] Interface GUID to query for */
2865 LPVOID* ppv) /* [out] Destination for queried interface */
2866{
2867 HRESULT hret = E_NOINTERFACE;
2868 TRACE("(pUnk=%p pInner=%p\n\tIID: %s %p)\n",pUnk,pInner,debugstr_guid(riid), ppv);
2869
2870 *ppv = NULL;
2871 if(pUnk && pInner) {
2872 hret = IUnknown_QueryInterface(pInner, riid, ppv);
2873 if (SUCCEEDED(hret)) IUnknown_Release(pUnk);
2874 }
2875 TRACE("-- 0x%08x\n", hret);
2876 return hret;
2877}
2878
2879/*************************************************************************
2880 * @ [SHLWAPI.268]
2881 *
2882 * Move a reference from one interface to another.
2883 *
2884 * PARAMS
2885 * lpDest [O] Destination to receive the reference
2886 * lppUnknown [O] Source to give up the reference to lpDest
2887 *
2888 * RETURNS
2889 * Nothing.
2890 */
2892{
2893 TRACE("(%p,%p)\n", lpDest, lppUnknown);
2894
2895 if (*lppUnknown)
2896 {
2897 /* Copy Reference*/
2898 IUnknown_AddRef(lpDest);
2899 IUnknown_AtomicRelease(lppUnknown); /* Release existing interface */
2900 }
2901}
2902
2903/*************************************************************************
2904 * @ [SHLWAPI.269]
2905 *
2906 * Convert an ASCII string of a CLSID into a CLSID.
2907 *
2908 * PARAMS
2909 * idstr [I] String representing a CLSID in registry format
2910 * id [O] Destination for the converted CLSID
2911 *
2912 * RETURNS
2913 * Success: TRUE. id contains the converted CLSID.
2914 * Failure: FALSE.
2915 */
2917{
2918 WCHAR wClsid[40];
2919 MultiByteToWideChar(CP_ACP, 0, idstr, -1, wClsid, sizeof(wClsid)/sizeof(WCHAR));
2920 return SUCCEEDED(CLSIDFromString(wClsid, id));
2921}
2922
2923/*************************************************************************
2924 * @ [SHLWAPI.270]
2925 *
2926 * Unicode version of GUIDFromStringA.
2927 */
2929{
2930 return SUCCEEDED(CLSIDFromString((LPCOLESTR)idstr, id));
2931}
2932
2933/*************************************************************************
2934 * @ [SHLWAPI.276]
2935 *
2936 * Determine if the browser is integrated into the shell, and set a registry
2937 * key accordingly.
2938 *
2939 * PARAMS
2940 * None.
2941 *
2942 * RETURNS
2943 * 1, If the browser is not integrated.
2944 * 2, If the browser is integrated.
2945 *
2946 * NOTES
2947 * The key "HKLM\Software\Microsoft\Internet Explorer\IntegratedBrowser" is
2948 * either set to TRUE, or removed depending on whether the browser is deemed
2949 * to be integrated.
2950 */
2952{
2953 static const char szIntegratedBrowser[] = "IntegratedBrowser";
2954 static DWORD dwState = 0;
2955 HKEY hKey;
2956 DWORD dwRet, dwData, dwSize;
2957 HMODULE hshell32;
2958
2959 if (dwState)
2960 return dwState;
2961
2962 /* If shell32 exports DllGetVersion(), the browser is integrated */
2963 dwState = 1;
2964 hshell32 = LoadLibraryA("shell32.dll");
2965 if (hshell32)
2966 {
2967 FARPROC pDllGetVersion;
2968 pDllGetVersion = GetProcAddress(hshell32, "DllGetVersion");
2969 dwState = pDllGetVersion ? 2 : 1;
2970 FreeLibrary(hshell32);
2971 }
2972
2973 /* Set or delete the key accordingly */
2975 "Software\\Microsoft\\Internet Explorer", 0,
2977 if (!dwRet)
2978 {
2979 dwRet = RegQueryValueExA(hKey, szIntegratedBrowser, 0, 0,
2980 (LPBYTE)&dwData, &dwSize);
2981
2982 if (!dwRet && dwState == 1)
2983 {
2984 /* Value exists but browser is not integrated */
2985 RegDeleteValueA(hKey, szIntegratedBrowser);
2986 }
2987 else if (dwRet && dwState == 2)
2988 {
2989 /* Browser is integrated but value does not exist */
2990 dwData = TRUE;
2991 RegSetValueExA(hKey, szIntegratedBrowser, 0, REG_DWORD,
2992 (LPBYTE)&dwData, sizeof(dwData));
2993 }
2995 }
2996 return dwState;
2997}
2998
2999/*************************************************************************
3000 * @ [SHLWAPI.278]
3001 *
3002 * Unicode version of SHCreateWorkerWindowA.
3003 */
3005 DWORD dwStyle, HMENU hMenu, LONG_PTR wnd_extra)
3006{
3007 static const WCHAR szClass[] = { 'W', 'o', 'r', 'k', 'e', 'r', 'W', 0 };
3008 WNDCLASSW wc;
3009 HWND hWnd;
3010
3011 TRACE("(%p, %p, 0x%08x, 0x%08x, %p, 0x%08lx)\n",
3012 wndProc, hWndParent, dwExStyle, dwStyle, hMenu, wnd_extra);
3013
3014 /* If our OS is natively ANSI, use the ANSI version */
3015 if (GetVersion() & 0x80000000) /* not NT */
3016 {
3017 TRACE("fallback to ANSI, ver 0x%08x\n", GetVersion());
3018 return SHCreateWorkerWindowA(wndProc, hWndParent, dwExStyle, dwStyle, hMenu, wnd_extra);
3019 }
3020
3021 /* Create Window class */
3022 wc.style = 0;
3024 wc.cbClsExtra = 0;
3025 wc.cbWndExtra = sizeof(LONG_PTR);
3027 wc.hIcon = NULL;
3029 wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
3030 wc.lpszMenuName = NULL;
3031 wc.lpszClassName = szClass;
3032
3033 SHRegisterClassW(&wc);
3034
3035 hWnd = CreateWindowExW(dwExStyle, szClass, 0, dwStyle, 0, 0, 0, 0,
3036 hWndParent, hMenu, shlwapi_hInstance, 0);
3037 if (hWnd)
3038 {
3039 SetWindowLongPtrW(hWnd, 0, wnd_extra);
3041 }
3042
3043 return hWnd;
3044}
3045
3046/*************************************************************************
3047 * @ [SHLWAPI.279]
3048 *
3049 * Get and show a context menu from a shell folder.
3050 *
3051 * PARAMS
3052 * hWnd [I] Window displaying the shell folder
3053 * lpFolder [I] IShellFolder interface
3054 * lpApidl [I] Id for the particular folder desired
3055 *
3056 * RETURNS
3057 * Success: S_OK.
3058 * Failure: An HRESULT error code indicating the error.
3059 */
3061{
3062 TRACE("%p %p %p\n", hWnd, lpFolder, lpApidl);
3063#ifdef __REACTOS__
3064 return SHInvokeCommand(hWnd, lpFolder, lpApidl, NULL);
3065#else
3066 return SHInvokeCommand(hWnd, lpFolder, lpApidl, 0);
3067#endif
3068}
3069
3070/*************************************************************************
3071 * @ [SHLWAPI.281]
3072 *
3073 * _SHPackDispParamsV
3074 */
3076{
3077 VARIANTARG *iter;
3078
3079 TRACE("(%p %p %u ...)\n", params, args, cnt);
3080
3081 params->rgvarg = args;
3082 params->rgdispidNamedArgs = NULL;
3083 params->cArgs = cnt;
3084 params->cNamedArgs = 0;
3085
3086 iter = args+cnt;
3087
3088 while(iter-- > args) {
3089 V_VT(iter) = va_arg(valist, enum VARENUM);
3090
3091 TRACE("vt=%d\n", V_VT(iter));
3092
3093 if(V_VT(iter) & VT_BYREF) {
3094 V_BYREF(iter) = va_arg(valist, LPVOID);
3095 } else {
3096 switch(V_VT(iter)) {
3097 case VT_I4:
3098 V_I4(iter) = va_arg(valist, LONG);
3099 break;
3100 case VT_BSTR:
3101 V_BSTR(iter) = va_arg(valist, BSTR);
3102 break;
3103 case VT_DISPATCH:
3104 V_DISPATCH(iter) = va_arg(valist, IDispatch*);
3105 break;
3106 case VT_BOOL:
3107 V_BOOL(iter) = va_arg(valist, int);
3108 break;
3109 case VT_UNKNOWN:
3110 V_UNKNOWN(iter) = va_arg(valist, IUnknown*);
3111 break;
3112 default:
3113 V_VT(iter) = VT_I4;
3114 V_I4(iter) = va_arg(valist, LONG);
3115 }
3116 }
3117 }
3118
3119 return S_OK;
3120}
3121
3122/*************************************************************************
3123 * @ [SHLWAPI.282]
3124 *
3125 * SHPackDispParams
3126 */
3128{
3130 HRESULT hres;
3131
3132 __ms_va_start(valist, cnt);
3135 return hres;
3136}
3137
3138/*************************************************************************
3139 * SHLWAPI_InvokeByIID
3140 *
3141 * This helper function calls IDispatch::Invoke for each sink
3142 * which implements given iid or IDispatch.
3143 *
3144 */
3146 IConnectionPoint* iCP,
3147 REFIID iid,
3148 DISPID dispId,
3149 DISPPARAMS* dispParams)
3150{
3151 IEnumConnections *enumerator;
3152 CONNECTDATA rgcd;
3153 static DISPPARAMS empty = {NULL, NULL, 0, 0};
3154 DISPPARAMS* params = dispParams;
3155
3156 HRESULT result = IConnectionPoint_EnumConnections(iCP, &enumerator);
3157 if (FAILED(result))
3158 return result;
3159
3160 /* Invoke is never happening with an NULL dispParams */
3161 if (!params)
3162 params = &empty;
3163
3164 while(IEnumConnections_Next(enumerator, 1, &rgcd, NULL)==S_OK)
3165 {
3166 IDispatch *dispIface;
3167 if ((iid && SUCCEEDED(IUnknown_QueryInterface(rgcd.pUnk, iid, (LPVOID*)&dispIface))) ||
3168 SUCCEEDED(IUnknown_QueryInterface(rgcd.pUnk, &IID_IDispatch, (LPVOID*)&dispIface)))
3169 {
3170 IDispatch_Invoke(dispIface, dispId, &IID_NULL, 0, DISPATCH_METHOD, params, NULL, NULL, NULL);
3171 IDispatch_Release(dispIface);
3172 }
3173 IUnknown_Release(rgcd.pUnk);
3174 }
3175
3176 IEnumConnections_Release(enumerator);
3177
3178 return S_OK;
3179}
3180
3181/*************************************************************************
3182 * IConnectionPoint_InvokeWithCancel [SHLWAPI.283]
3183 */
3185 DISPID dispId, DISPPARAMS* dispParams,
3186 DWORD unknown1, DWORD unknown2 )
3187{
3188 IID iid;
3190
3191 FIXME("(%p)->(0x%x %p %x %x) partial stub\n", iCP, dispId, dispParams, unknown1, unknown2);
3192
3193 result = IConnectionPoint_GetConnectionInterface(iCP, &iid);
3194 if (SUCCEEDED(result))
3195 result = SHLWAPI_InvokeByIID(iCP, &iid, dispId, dispParams);
3196 else
3197 result = SHLWAPI_InvokeByIID(iCP, NULL, dispId, dispParams);
3198
3199 return result;
3200}
3201
3202
3203/*************************************************************************
3204 * @ [SHLWAPI.284]
3205 *
3206 * IConnectionPoint_SimpleInvoke
3207 */
3209 IConnectionPoint* iCP,
3210 DISPID dispId,
3211 DISPPARAMS* dispParams)
3212{
3213 IID iid;
3215
3216 TRACE("(%p)->(0x%x %p)\n",iCP,dispId,dispParams);
3217
3218 result = IConnectionPoint_GetConnectionInterface(iCP, &iid);
3219 if (SUCCEEDED(result))
3220 result = SHLWAPI_InvokeByIID(iCP, &iid, dispId, dispParams);
3221 else
3222 result = SHLWAPI_InvokeByIID(iCP, NULL, dispId, dispParams);
3223
3224 return result;
3225}
3226
3227/*************************************************************************
3228 * @ [SHLWAPI.285]
3229 *
3230 * Notify an IConnectionPoint object of changes.
3231 *
3232 * PARAMS
3233 * lpCP [I] Object to notify
3234 * dispID [I]
3235 *
3236 * RETURNS
3237 * Success: S_OK.
3238 * Failure: E_NOINTERFACE, if lpCP is NULL or does not support the
3239 * IConnectionPoint interface.
3240 */
3242{
3243 IEnumConnections *lpEnum;
3244 HRESULT hRet = E_NOINTERFACE;
3245
3246 TRACE("(%p,0x%8X)\n", lpCP, dispID);
3247
3248 /* Get an enumerator for the connections */
3249 if (lpCP)
3250 hRet = IConnectionPoint_EnumConnections(lpCP, &lpEnum);
3251
3252 if (SUCCEEDED(hRet))
3253 {
3254 IPropertyNotifySink *lpSink;
3255 CONNECTDATA connData;
3256 ULONG ulFetched;
3257
3258 /* Call OnChanged() for every notify sink in the connection point */
3259 while (IEnumConnections_Next(lpEnum, 1, &connData, &ulFetched) == S_OK)
3260 {
3261 if (SUCCEEDED(IUnknown_QueryInterface(connData.pUnk, &IID_IPropertyNotifySink, (void**)&lpSink)) &&
3262 lpSink)
3263 {
3264 IPropertyNotifySink_OnChanged(lpSink, dispID);
3265 IPropertyNotifySink_Release(lpSink);
3266 }
3267 IUnknown_Release(connData.pUnk);
3268 }
3269
3270 IEnumConnections_Release(lpEnum);
3271 }
3272 return hRet;
3273}
3274
3275/*************************************************************************
3276 * @ [SHLWAPI.286]
3277 *
3278 * IUnknown_CPContainerInvokeParam
3279 */
3282 REFIID riid,
3283 DISPID dispId,
3285 DWORD cParams, ...)
3286{
3288 IConnectionPoint *iCP;
3290 DISPPARAMS dispParams = {buffer, NULL, cParams, 0};
3292
3293 if (!container)
3294 return E_NOINTERFACE;
3295
3296 result = IUnknown_QueryInterface(container, &IID_IConnectionPointContainer,(LPVOID*) &iCPC);
3297 if (FAILED(result))
3298 return result;
3299
3300 result = IConnectionPointContainer_FindConnectionPoint(iCPC, riid, &iCP);
3301 IConnectionPointContainer_Release(iCPC);
3302 if(FAILED(result))
3303 return result;
3304
3305 __ms_va_start(valist, cParams);
3306 SHPackDispParamsV(&dispParams, buffer, cParams, valist);
3308
3309 result = SHLWAPI_InvokeByIID(iCP, riid, dispId, &dispParams);
3310 IConnectionPoint_Release(iCP);
3311
3312 return result;
3313}
3314
3315/*************************************************************************
3316 * @ [SHLWAPI.287]
3317 *
3318 * Notify an IConnectionPointContainer object of changes.
3319 *
3320 * PARAMS
3321 * lpUnknown [I] Object to notify
3322 * dispID [I]
3323 *
3324 * RETURNS
3325 * Success: S_OK.
3326 * Failure: E_NOINTERFACE, if lpUnknown is NULL or does not support the
3327 * IConnectionPointContainer interface.
3328 */
3330{
3332 HRESULT hRet = E_NOINTERFACE;
3333
3334 TRACE("(%p,0x%8X)\n", lpUnknown, dispID);
3335
3336 if (lpUnknown)
3337 hRet = IUnknown_QueryInterface(lpUnknown, &IID_IConnectionPointContainer, (void**)&lpCPC);
3338
3339 if (SUCCEEDED(hRet))
3340 {
3341 IConnectionPoint* lpCP;
3342
3343 hRet = IConnectionPointContainer_FindConnectionPoint(lpCPC, &IID_IPropertyNotifySink, &lpCP);
3344 IConnectionPointContainer_Release(lpCPC);
3345
3346 hRet = IConnectionPoint_OnChanged(lpCP, dispID);
3347 IConnectionPoint_Release(lpCP);
3348 }
3349 return hRet;
3350}
3351
3352/*************************************************************************
3353 * @ [SHLWAPI.289]
3354 *
3355 * See PlaySoundW.
3356 */
3358{
3359 return PlaySoundW(pszSound, hmod, fdwSound);
3360}
3361
3362#ifndef __REACTOS__ /* See propbag.cpp */
3363/*************************************************************************
3364 * @ [SHLWAPI.294]
3365 *
3366 * Retrieve a key value from an INI file. See GetPrivateProfileString for
3367 * more information.
3368 *
3369 * PARAMS
3370 * appName [I] The section in the INI file that contains the key
3371 * keyName [I] The key to be retrieved
3372 * out [O] The buffer into which the key's value will be copied
3373 * outLen [I] The length of the `out' buffer
3374 * filename [I] The location of the INI file
3375 *
3376 * RETURNS
3377 * Length of string copied into `out'.
3378 */
3380 DWORD outLen, LPCWSTR filename)
3381{
3382 INT ret;
3383 WCHAR *buf;
3384
3385 TRACE("(%s,%s,%p,%08x,%s)\n", debugstr_w(appName), debugstr_w(keyName),
3386 out, outLen, debugstr_w(filename));
3387
3388 if(outLen == 0)
3389 return 0;
3390
3391 buf = HeapAlloc(GetProcessHeap(), 0, outLen * sizeof(WCHAR));
3392 if(!buf){
3393 *out = 0;
3394 return 0;
3395 }
3396
3397 ret = GetPrivateProfileStringW(appName, keyName, NULL, buf, outLen, filename);
3398 if(ret)
3399 strcpyW(out, buf);
3400 else
3401 *out = 0;
3402
3404
3405 return strlenW(out);
3406}
3407#endif
3408
3409#ifndef __REACTOS__ /* See propbag.cpp */
3410/*************************************************************************
3411 * @ [SHLWAPI.295]
3412 *
3413 * Set a key value in an INI file. See WritePrivateProfileString for
3414 * more information.
3415 *
3416 * PARAMS
3417 * appName [I] The section in the INI file that contains the key
3418 * keyName [I] The key to be set
3419 * str [O] The value of the key
3420 * filename [I] The location of the INI file
3421 *
3422 * RETURNS
3423 * Success: TRUE
3424 * Failure: FALSE
3425 */
3428{
3429 TRACE("(%s, %p, %s, %s)\n", debugstr_w(appName), keyName, debugstr_w(str),
3431
3433}
3434#endif
3435
3436/*************************************************************************
3437 * @ [SHLWAPI.313]
3438 *
3439 * See SHGetFileInfoW.
3440 */
3442 SHFILEINFOW *psfi, UINT sizeofpsfi, UINT flags)
3443{
3444 return SHGetFileInfoW(path, dwFileAttributes, psfi, sizeofpsfi, flags);
3445}
3446
3447/*************************************************************************
3448 * @ [SHLWAPI.318]
3449 *
3450 * See DragQueryFileW.
3451 */
3452UINT WINAPI DragQueryFileWrapW(HDROP hDrop, UINT lFile, LPWSTR lpszFile, UINT lLength)
3453{
3454 return DragQueryFileW(hDrop, lFile, lpszFile, lLength);
3455}
3456
3457/*************************************************************************
3458 * @ [SHLWAPI.333]
3459 *
3460 * See SHBrowseForFolderW.
3461 */
3463{
3464 return SHBrowseForFolderW(lpBi);
3465}
3466
3467/*************************************************************************
3468 * @ [SHLWAPI.334]
3469 *
3470 * See SHGetPathFromIDListW.
3471 */
3473{
3474 return SHGetPathFromIDListW(pidl, pszPath);
3475}
3476
3477/*************************************************************************
3478 * @ [SHLWAPI.335]
3479 *
3480 * See ShellExecuteExW.
3481 */
3483{
3484 return ShellExecuteExW(lpExecInfo);
3485}
3486
3487/*************************************************************************
3488 * @ [SHLWAPI.336]
3489 *
3490 * See SHFileOperationW.
3491 */
3493{
3494 return SHFileOperationW(lpFileOp);
3495}
3496
3497/*************************************************************************
3498 * @ [SHLWAPI.342]
3499 *
3500 */
3502{
3504}
3505
3506/*************************************************************************
3507 * @ [SHLWAPI.350]
3508 *
3509 * See GetFileVersionInfoSizeW.
3510 */
3512{
3514}
3515
3516/*************************************************************************
3517 * @ [SHLWAPI.351]
3518 *
3519 * See GetFileVersionInfoW.
3520 */
3523{
3525}
3526
3527/*************************************************************************
3528 * @ [SHLWAPI.352]
3529 *
3530 * See VerQueryValueW.
3531 */
3533 LPVOID *lplpBuffer, UINT *puLen )
3534{
3535 return VerQueryValueW( pBlock, lpSubBlock, lplpBuffer, puLen );
3536}
3537
3538#define IsIface(type) SUCCEEDED((hRet = IUnknown_QueryInterface(lpUnknown, &IID_##type, (void**)&lpObj)))
3539#define IShellBrowser_EnableModeless IShellBrowser_EnableModelessSB
3540#define EnableModeless(type) type##_EnableModeless((type*)lpObj, bModeless)
3541
3542/*************************************************************************
3543 * @ [SHLWAPI.355]
3544 *
3545 * Change the modality of a shell object.
3546 *
3547 * PARAMS
3548 * lpUnknown [I] Object to make modeless
3549 * bModeless [I] TRUE=Make modeless, FALSE=Make modal
3550 *
3551 * RETURNS
3552 * Success: S_OK. The modality lpUnknown is changed.
3553 * Failure: An HRESULT error code indicating the error.
3554 *
3555 * NOTES
3556 * lpUnknown must support the IOleInPlaceFrame interface, the
3557 * IInternetSecurityMgrSite interface, the IShellBrowser interface
3558 * the IDocHostUIHandler interface, or the IOleInPlaceActiveObject interface,
3559 * or this call will fail.
3560 */
3562{
3563 IUnknown *lpObj;
3564 HRESULT hRet;
3565
3566 TRACE("(%p,%d)\n", lpUnknown, bModeless);
3567
3568 if (!lpUnknown)
3569 return E_FAIL;
3570
3573 else if (IsIface(IOleInPlaceFrame))
3575 else if (IsIface(IShellBrowser))
3579 else if (IsIface(IDocHostUIHandler))
3581 else
3582 return hRet;
3583
3584 IUnknown_Release(lpObj);
3585 return S_OK;
3586}
3587
3588/*************************************************************************
3589 * @ [SHLWAPI.357]
3590 *
3591 * See SHGetNewLinkInfoW.
3592 */
3595{
3596 return SHGetNewLinkInfoW(pszLinkTo, pszDir, pszName, pfMustCopy, uFlags);
3597}
3598
3599/*************************************************************************
3600 * @ [SHLWAPI.358]
3601 *
3602 * See SHDefExtractIconW.
3603 */
3604UINT WINAPI SHDefExtractIconWrapW(LPCWSTR pszIconFile, int iIndex, UINT uFlags, HICON* phiconLarge,
3605 HICON* phiconSmall, UINT nIconSize)
3606{
3607 return SHDefExtractIconW(pszIconFile, iIndex, uFlags, phiconLarge, phiconSmall, nIconSize);
3608}
3609
3610/*************************************************************************
3611 * @ [SHLWAPI.363]
3612 *
3613 * Get and show a context menu from a shell folder.
3614 *
3615 * PARAMS
3616 * hWnd [I] Window displaying the shell folder
3617 * lpFolder [I] IShellFolder interface
3618 * lpApidl [I] Id for the particular folder desired
3619 * dwCommandId [I] The command ID to invoke (0=invoke default)
3620 *
3621 * RETURNS
3622 * Success: S_OK. If bInvokeDefault is TRUE, the default menu action was
3623 * executed.
3624 * Failure: An HRESULT error code indicating the error.
3625 */
3626#ifdef __REACTOS__
3629{
3630 return SHInvokeCommandWithFlagsAndSite(hWnd, NULL, lpFolder, lpApidl, 0, lpVerb);
3631}
3632#else
3634{
3635 IContextMenu *iContext;
3636 HRESULT hRet;
3637
3638 TRACE("(%p, %p, %p, %u)\n", hWnd, lpFolder, lpApidl, dwCommandId);
3639
3640 if (!lpFolder)
3641 return E_FAIL;
3642
3643 /* Get the context menu from the shell folder */
3644 hRet = IShellFolder_GetUIObjectOf(lpFolder, hWnd, 1, &lpApidl,
3645 &IID_IContextMenu, 0, (void**)&iContext);
3646 if (SUCCEEDED(hRet))
3647 {
3648 HMENU hMenu;
3649 if ((hMenu = CreatePopupMenu()))
3650 {
3651 HRESULT hQuery;
3652
3653 /* Add the context menu entries to the popup */
3654 hQuery = IContextMenu_QueryContextMenu(iContext, hMenu, 0, 1, 0x7FFF,
3655 dwCommandId ? CMF_NORMAL : CMF_DEFAULTONLY);
3656
3657 if (SUCCEEDED(hQuery))
3658 {
3659 if (!dwCommandId)
3660 dwCommandId = GetMenuDefaultItem(hMenu, 0, 0);
3661 if (dwCommandId != (UINT)-1)
3662 {
3663 CMINVOKECOMMANDINFO cmIci;
3664 /* Invoke the default item */
3665 memset(&cmIci,0,sizeof(cmIci));
3666 cmIci.cbSize = sizeof(cmIci);
3667 cmIci.fMask = CMIC_MASK_ASYNCOK;
3668 cmIci.hwnd = hWnd;
3669#ifdef __REACTOS__ /* r75561 */
3670 cmIci.lpVerb = MAKEINTRESOURCEA(dwCommandId - 1);
3671#else
3672 cmIci.lpVerb = MAKEINTRESOURCEA(dwCommandId);
3673#endif
3674 cmIci.nShow = SW_SHOWNORMAL;
3675
3676 hRet = IContextMenu_InvokeCommand(iContext, &cmIci);
3677 }
3678 }
3679 DestroyMenu(hMenu);
3680 }
3681 IContextMenu_Release(iContext);
3682 }
3683 return hRet;
3684}
3685#endif /* __REACTOS__ */
3686
3687/*************************************************************************
3688 * @ [SHLWAPI.370]
3689 *
3690 * See ExtractIconW.
3691 */
3693 UINT nIconIndex)
3694{
3695 return ExtractIconW(hInstance, lpszExeFileName, nIconIndex);
3696}
3697
3698/*************************************************************************
3699 * @ [SHLWAPI.377]
3700 *
3701 * Load a library from the directory of a particular process.
3702 *
3703 * PARAMS
3704 * new_mod [I] Library name
3705 * inst_hwnd [I] Module whose directory is to be used
3706 * dwCrossCodePage [I] Should be FALSE (currently ignored)
3707 *
3708 * RETURNS
3709 * Success: A handle to the loaded module
3710 * Failure: A NULL handle.
3711 */
3712HMODULE WINAPI MLLoadLibraryA(LPCSTR new_mod, HMODULE inst_hwnd, DWORD dwCrossCodePage)
3713{
3714 /* FIXME: Native appears to do DPA_Create and a DPA_InsertPtr for
3715 * each call here.
3716 * FIXME: Native shows calls to:
3717 * SHRegGetUSValue for "Software\Microsoft\Internet Explorer\International"
3718 * CheckVersion
3719 * RegOpenKeyExA for "HKLM\Software\Microsoft\Internet Explorer"
3720 * RegQueryValueExA for "LPKInstalled"
3721 * RegCloseKey
3722 * RegOpenKeyExA for "HKCU\Software\Microsoft\Internet Explorer\International"
3723 * RegQueryValueExA for "ResourceLocale"
3724 * RegCloseKey
3725 * RegOpenKeyExA for "HKLM\Software\Microsoft\Active Setup\Installed Components\{guid}"
3726 * RegQueryValueExA for "Locale"
3727 * RegCloseKey
3728 * and then tests the Locale ("en" for me).
3729 * code below
3730 * after the code then a DPA_Create (first time) and DPA_InsertPtr are done.
3731 */
3732 CHAR mod_path[2*MAX_PATH];
3733 LPSTR ptr;
3734 DWORD len;
3735
3736 FIXME("(%s,%p,%d) semi-stub!\n", debugstr_a(new_mod), inst_hwnd, dwCrossCodePage);
3737 len = GetModuleFileNameA(inst_hwnd, mod_path, sizeof(mod_path));
3738 if (!len || len >= sizeof(mod_path)) return NULL;
3739
3740 ptr = strrchr(mod_path, '\\');
3741 if (ptr) {
3742 strcpy(ptr+1, new_mod);
3743 TRACE("loading %s\n", debugstr_a(mod_path));
3744 return LoadLibraryA(mod_path);
3745 }
3746 return NULL;
3747}
3748
3749/*************************************************************************
3750 * @ [SHLWAPI.378]
3751 *
3752 * Unicode version of MLLoadLibraryA.
3753 */
3754HMODULE WINAPI MLLoadLibraryW(LPCWSTR new_mod, HMODULE inst_hwnd, DWORD dwCrossCodePage)
3755{
3756 WCHAR mod_path[2*MAX_PATH];
3757 LPWSTR ptr;
3758 DWORD len;
3759
3760 FIXME("(%s,%p,%d) semi-stub!\n", debugstr_w(new_mod), inst_hwnd, dwCrossCodePage);
3761 len = GetModuleFileNameW(inst_hwnd, mod_path, sizeof(mod_path) / sizeof(WCHAR));
3762 if (!len || len >= sizeof(mod_path) / sizeof(WCHAR)) return NULL;
3763
3764 ptr = strrchrW(mod_path, '\\');
3765 if (ptr) {
3766 strcpyW(ptr+1, new_mod);
3767 TRACE("loading %s\n", debugstr_w(mod_path));
3768 return LoadLibraryW(mod_path);
3769 }
3770 return NULL;
3771}
3772
3773/*************************************************************************
3774 * ColorAdjustLuma [SHLWAPI.@]
3775 *
3776 * Adjust the luminosity of a color
3777 *
3778 * PARAMS
3779 * cRGB [I] RGB value to convert
3780 * dwLuma [I] Luma adjustment
3781 * bUnknown [I] Unknown
3782 *
3783 * RETURNS
3784 * The adjusted RGB color.
3785 */
3786COLORREF WINAPI ColorAdjustLuma(COLORREF cRGB, int dwLuma, BOOL bUnknown)
3787{
3788 TRACE("(0x%8x,%d,%d)\n", cRGB, dwLuma, bUnknown);
3789
3790 if (dwLuma)
3791 {
3792 WORD wH, wL, wS;
3793
3794 ColorRGBToHLS(cRGB, &wH, &wL, &wS);
3795
3796 FIXME("Ignoring luma adjustment\n");
3797
3798 /* FIXME: The adjustment is not linear */
3799
3800 cRGB = ColorHLSToRGB(wH, wL, wS);
3801 }
3802 return cRGB;
3803}
3804
3805/*************************************************************************
3806 * @ [SHLWAPI.389]
3807 *
3808 * See GetSaveFileNameW.
3809 */
3811{
3812 return GetSaveFileNameW(ofn);
3813}
3814
3815/*************************************************************************
3816 * @ [SHLWAPI.390]
3817 *
3818 * See WNetRestoreConnectionW.
3819 */
3821{
3822 return WNetRestoreConnectionW(hwndOwner, lpszDevice);
3823}
3824
3825/*************************************************************************
3826 * @ [SHLWAPI.391]
3827 *
3828 * See WNetGetLastErrorW.
3829 */
3830DWORD WINAPI WNetGetLastErrorWrapW(LPDWORD lpError, LPWSTR lpErrorBuf, DWORD nErrorBufSize,
3831 LPWSTR lpNameBuf, DWORD nNameBufSize)
3832{
3833 return WNetGetLastErrorW(lpError, lpErrorBuf, nErrorBufSize, lpNameBuf, nNameBufSize);
3834}
3835
3836/*************************************************************************
3837 * @ [SHLWAPI.401]
3838 *
3839 * See PageSetupDlgW.
3840 */
3842{
3843 return PageSetupDlgW(pagedlg);
3844}
3845
3846/*************************************************************************
3847 * @ [SHLWAPI.402]
3848 *
3849 * See PrintDlgW.
3850 */
3852{
3853 return PrintDlgW(printdlg);
3854}
3855
3856/*************************************************************************
3857 * @ [SHLWAPI.403]
3858 *
3859 * See GetOpenFileNameW.
3860 */
3862{
3863 return GetOpenFileNameW(ofn);
3864}
3865
3866/*************************************************************************
3867 * @ [SHLWAPI.404]
3868 */
3870{
3871 /* Windows attempts to get an IPersist interface and, if that fails, an
3872 * IPersistFolder interface on the folder passed-in here. If one of those
3873 * interfaces is available, it then calls GetClassID on the folder... and
3874 * then calls IShellFolder_EnumObjects no matter what, even crashing if
3875 * lpFolder isn't actually an IShellFolder object. The purpose of getting
3876 * the ClassID is unknown, so we don't do it here.
3877 *
3878 * For discussion and detailed tests, see:
3879 * "shlwapi: Be less strict on which type of IShellFolder can be enumerated"
3880 * wine-devel mailing list, 3 Jun 2010
3881 */
3882
3883 return IShellFolder_EnumObjects(lpFolder, hwnd, flags, ppenum);
3884}
3885
3886/* INTERNAL: Map from HLS color space to RGB */
3887static WORD ConvertHue(int wHue, WORD wMid1, WORD wMid2)
3888{
3889 wHue = wHue > 240 ? wHue - 240 : wHue < 0 ? wHue + 240 : wHue;
3890
3891 if (wHue > 160)
3892 return wMid1;
3893 else if (wHue > 120)
3894 wHue = 160 - wHue;
3895 else if (wHue > 40)
3896 return wMid2;
3897
3898 return ((wHue * (wMid2 - wMid1) + 20) / 40) + wMid1;
3899}
3900
3901/* Convert to RGB and scale into RGB range (0..255) */
3902#define GET_RGB(h) (ConvertHue(h, wMid1, wMid2) * 255 + 120) / 240
3903
3904/*************************************************************************
3905 * ColorHLSToRGB [SHLWAPI.@]
3906 *
3907 * Convert from hls color space into an rgb COLORREF.
3908 *
3909 * PARAMS
3910 * wHue [I] Hue amount
3911 * wLuminosity [I] Luminosity amount
3912 * wSaturation [I] Saturation amount
3913 *
3914 * RETURNS
3915 * A COLORREF representing the converted color.
3916 *
3917 * NOTES
3918 * Input hls values are constrained to the range (0..240).
3919 */
3920COLORREF WINAPI ColorHLSToRGB(WORD wHue, WORD wLuminosity, WORD wSaturation)
3921{
3922 WORD wRed;
3923
3924 if (wSaturation)
3925 {
3926 WORD wGreen, wBlue, wMid1, wMid2;
3927
3928 if (wLuminosity > 120)
3929 wMid2 = wSaturation + wLuminosity - (wSaturation * wLuminosity + 120) / 240;
3930 else
3931 wMid2 = ((wSaturation + 240) * wLuminosity + 120) / 240;
3932
3933 wMid1 = wLuminosity * 2 - wMid2;
3934
3935 wRed = GET_RGB(wHue + 80);
3936 wGreen = GET_RGB(wHue);
3937 wBlue = GET_RGB(wHue - 80);
3938
3939 return RGB(wRed, wGreen, wBlue);
3940 }
3941
3942 wRed = wLuminosity * 255 / 240;
3943 return RGB(wRed, wRed, wRed);
3944}
3945
3946/*************************************************************************
3947 * @ [SHLWAPI.413]
3948 *
3949 * Get the current docking status of the system.
3950 *
3951 * PARAMS
3952 * dwFlags [I] DOCKINFO_ flags from "winbase.h", unused
3953 *
3954 * RETURNS
3955 * One of DOCKINFO_UNDOCKED, DOCKINFO_UNDOCKED, or 0 if the system is not
3956 * a notebook.
3957 */
3959{
3960 HW_PROFILE_INFOA hwInfo;
3961
3962 TRACE("(0x%08x)\n", dwFlags);
3963
3964 GetCurrentHwProfileA(&hwInfo);
3965 switch (hwInfo.dwDockInfo & (DOCKINFO_DOCKED|DOCKINFO_UNDOCKED))
3966 {
3967 case DOCKINFO_DOCKED:
3968 case DOCKINFO_UNDOCKED:
3970 default:
3971 return 0;
3972 }
3973}
3974
3975/*************************************************************************
3976 * @ [SHLWAPI.416]
3977 *
3978 */
3980{
3981
3982 FIXME("(%p, %s, 0x%x, %p, %d)\n", hwnd, debugstr_w(helpfile), flags1, ptr1, flags2);
3983 return 0;
3984}
3985
3986/*************************************************************************
3987 * @ [SHLWAPI.417]
3988 *
3989 */
3991{
3992
3993 FIXME("(%p, %s, 0x%x, %p, %d)\n", hwnd, debugstr_a(helpfile), flags1, ptr1, flags2);
3994 return 0;
3995}
3996
3997/*************************************************************************
3998 * @ [SHLWAPI.418]
3999 *
4000 * Function seems to do FreeLibrary plus other things.
4001 *
4002 * FIXME native shows the following calls:
4003 * RtlEnterCriticalSection
4004 * LocalFree
4005 * GetProcAddress(Comctl32??, 150L)
4006 * DPA_DeletePtr
4007 * RtlLeaveCriticalSection
4008 * followed by the FreeLibrary.
4009 * The above code may be related to .377 above.
4010 */
4012{
4013 FIXME("(%p) semi-stub\n", hModule);
4014 return FreeLibrary(hModule);
4015}
4016
4017/*************************************************************************
4018 * @ [SHLWAPI.419]
4019 */
4021 FIXME(": stub\n");
4022 return TRUE;
4023}
4024
4025/*************************************************************************
4026 * @ [SHLWAPI.429]
4027 * FIXME I have no idea what this function does or what its arguments are.
4028 */
4030{
4031 FIXME("(%p) stub\n", hInst);
4032 return FALSE;
4033}
4034
4035
4036/*************************************************************************
4037 * @ [SHLWAPI.430]
4038 */
4040{
4041 FIXME("(%p,%p) stub\n", hInst, hHeap);
4042 return E_FAIL; /* This is what is used if shlwapi not loaded */
4043}
4044
4045/*************************************************************************
4046 * @ [SHLWAPI.431]
4047 */
4049{
4050 FIXME("(0x%08x)stub\n", x);
4051 return 0xabba1247;
4052}
4053
4054/*************************************************************************
4055 * @ [SHLWAPI.432]
4056 *
4057 * See SHSendMessageBroadcastW
4058 *
4059 */
4061{
4063 SMTO_ABORTIFHUNG, 2000, NULL);
4064}
4065
4066/*************************************************************************
4067 * @ [SHLWAPI.433]
4068 *
4069 * A wrapper for sending Broadcast Messages to all top level Windows
4070 *
4071 */
4073{
4075 SMTO_ABORTIFHUNG, 2000, NULL);
4076}
4077
4078/*************************************************************************
4079 * @ [SHLWAPI.436]
4080 *
4081 * Convert a Unicode string CLSID into a CLSID.
4082 *
4083 * PARAMS
4084 * idstr [I] string containing a CLSID in text form
4085 * id [O] CLSID extracted from the string
4086 *
4087 * RETURNS
4088 * S_OK on success or E_INVALIDARG on failure
4089 */
4091{
4092 return CLSIDFromString((LPCOLESTR)idstr, id);
4093}
4094
4095/*************************************************************************
4096 * @ [SHLWAPI.437]
4097 *
4098 * Determine if the OS supports a given feature.
4099 *
4100 * PARAMS
4101 * dwFeature [I] Feature requested (undocumented)
4102 *
4103 * RETURNS
4104 * TRUE If the feature is available.
4105 * FALSE If the feature is not available.
4106 */
4108{
4110 DWORD platform, majorv, minorv;
4111
4113 if(!GetVersionExA(&osvi)) {
4114 ERR("GetVersionEx failed\n");
4115 return FALSE;
4116 }
4117
4118 majorv = osvi.dwMajorVersion;
4119 minorv = osvi.dwMinorVersion;
4121
4122#define ISOS_RETURN(x) \
4123 TRACE("(0x%x) ret=%d\n",feature,(x)); \
4124 return (x);
4125
4126 switch(feature) {
4127 case OS_WIN32SORGREATER:
4130 case OS_NT:
4132 case OS_WIN95ORGREATER:
4134 case OS_NT4ORGREATER:
4135 ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT && majorv >= 4)
4138 ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT && majorv >= 5)
4139 case OS_WIN98ORGREATER:
4141 case OS_WIN98_GOLD:
4143 case OS_WIN2000PRO:
4144 ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT && majorv >= 5)
4145 case OS_WIN2000SERVER:
4146 ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT && (minorv == 0 || minorv == 1))
4148 ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT && (minorv == 0 || minorv == 1))
4150 ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT && (minorv == 0 || minorv == 1))
4151 case OS_WIN2000TERMINAL:
4152 ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT && (minorv == 0 || minorv == 1))
4153 case OS_EMBEDDED:
4154 FIXME("(OS_EMBEDDED) What should we return here?\n");
4155 return FALSE;
4156 case OS_TERMINALCLIENT:
4157 FIXME("(OS_TERMINALCLIENT) What should we return here?\n");
4158 return FALSE;
4160 FIXME("(OS_TERMINALREMOTEADMIN) What should we return here?\n");
4161 return FALSE;
4162 case OS_WIN95_GOLD:
4164 case OS_MEORGREATER:
4166 case OS_XPORGREATER:
4167 ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT && majorv >= 5 && minorv >= 1)
4168 case OS_HOME:
4169 ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT && majorv >= 5 && minorv >= 1)
4170 case OS_PROFESSIONAL:
4172 case OS_DATACENTER:
4174 case OS_ADVSERVER:
4175 ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT && majorv >= 5)
4176 case OS_SERVER:
4178 case OS_TERMINALSERVER:
4181 ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT && minorv >= 1 && majorv >= 5)
4183 FIXME("(OS_FASTUSERSWITCHING) What should we return here?\n");
4184 return TRUE;
4185 case OS_WELCOMELOGONUI:
4186 FIXME("(OS_WELCOMELOGONUI) What should we return here?\n");
4187 return FALSE;
4188 case OS_DOMAINMEMBER:
4189 FIXME("(OS_DOMAINMEMBER) What should we return here?\n");
4190 return TRUE;
4191 case OS_ANYSERVER:
4193 case OS_WOW6432:
4194 {
4195 BOOL is_wow64;
4197 return is_wow64;
4198 }
4199 case OS_WEBSERVER:
4203 case OS_TABLETPC:
4204 FIXME("(OS_TABLETPC) What should we return here?\n");
4205 return FALSE;
4206 case OS_SERVERADMINUI:
4207 FIXME("(OS_SERVERADMINUI) What should we return here?\n");
4208 return FALSE;
4209 case OS_MEDIACENTER:
4210 FIXME("(OS_MEDIACENTER) What should we return here?\n");
4211 return FALSE;
4212 case OS_APPLIANCE:
4213 FIXME("(OS_APPLIANCE) What should we return here?\n");
4214 return FALSE;
4215 case 0x25: /*OS_VISTAORGREATER*/
4216 ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT && majorv >= 6)
4217 }
4218
4219#undef ISOS_RETURN
4220
4221 WARN("(0x%x) unknown parameter\n",feature);
4222
4223 return FALSE;
4224}
4225
4226#ifdef __REACTOS__
4227/*************************************************************************
4228 * @ [SHLWAPI.438]
4229 */
4231{
4232 WCHAR valueW[MAX_PATH], bufferW[MAX_PATH];
4233 DWORD dwSize = ARRAY_SIZE(bufferW) * sizeof(CHAR);
4234 HRESULT hr;
4235
4237 valueW[ARRAY_SIZE(valueW) - 1] = UNICODE_NULL; /* Avoid buffer overrun */
4238
4239 if (RegQueryValueExW(hkey, valueW, NULL, NULL, (LPBYTE)bufferW, &dwSize) != ERROR_SUCCESS)
4240 return E_FAIL;
4241
4242 hr = SHLoadIndirectString(bufferW, bufferW, ARRAY_SIZE(bufferW), NULL);
4243 if (FAILED(hr))
4244 return hr;
4245
4246 WideCharToMultiByte(CP_ACP, 0, bufferW, -1, buf, size, NULL, NULL);
4247 if (size > 0)
4248 buf[size - 1] = ANSI_NULL; /* Avoid buffer overrun */
4249 return S_OK;
4250}
4251#endif
4252
4253/*************************************************************************
4254 * @ [SHLWAPI.439]
4255 */
4257{
4258 DWORD type, sz = size * sizeof(WCHAR);
4259
4260 if(RegQueryValueExW(hkey, value, NULL, &type, (LPBYTE)buf, &sz) != ERROR_SUCCESS)
4261 return E_FAIL;
4262
4264}
4265
4266/*************************************************************************
4267 * @ [SHLWAPI.478]
4268 *
4269 * Call IInputObject_TranslateAcceleratorIO() on an object.
4270 *
4271 * PARAMS
4272 * lpUnknown [I] Object supporting the IInputObject interface.
4273 * lpMsg [I] Key message to be processed.
4274 *
4275 * RETURNS
4276 * Success: S_OK.
4277 * Failure: An HRESULT error code, or E_INVALIDARG if lpUnknown is NULL.
4278 */
4280{
4281 IInputObject* lpInput = NULL;
4282 HRESULT hRet = E_INVALIDARG;
4283
4284 TRACE("(%p,%p)\n", lpUnknown, lpMsg);
4285 if (lpUnknown)
4286 {
4287 hRet = IUnknown_QueryInterface(lpUnknown, &IID_IInputObject,
4288 (void**)&lpInput);
4289 if (SUCCEEDED(hRet) && lpInput)
4290 {
4291 hRet = IInputObject_TranslateAcceleratorIO(lpInput, lpMsg);
4292 IInputObject_Release(lpInput);
4293 }
4294 }
4295 return hRet;
4296}
4297
4298/*************************************************************************
4299 * @ [SHLWAPI.481]
4300 *
4301 * Call IInputObject_HasFocusIO() on an object.
4302 *
4303 * PARAMS
4304 * lpUnknown [I] Object supporting the IInputObject interface.
4305 *
4306 * RETURNS
4307 * Success: S_OK, if lpUnknown is an IInputObject object and has the focus,
4308 * or S_FALSE otherwise.
4309 * Failure: An HRESULT error code, or E_INVALIDARG if lpUnknown is NULL.
4310 */
4312{
4313 IInputObject* lpInput = NULL;
4314 HRESULT hRet = E_INVALIDARG;
4315
4316 TRACE("(%p)\n", lpUnknown);
4317 if (lpUnknown)
4318 {
4319 hRet = IUnknown_QueryInterface(lpUnknown, &IID_IInputObject,
4320 (void**)&lpInput);
4321 if (SUCCEEDED(hRet) && lpInput)
4322 {
4323 hRet = IInputObject_HasFocusIO(lpInput);
4324 IInputObject_Release(lpInput);
4325 }
4326 }
4327 return hRet;
4328}
4329
4330/*************************************************************************
4331 * ColorRGBToHLS [SHLWAPI.@]
4332 *
4333 * Convert an rgb COLORREF into the hls color space.
4334 *
4335 * PARAMS
4336 * cRGB [I] Source rgb value
4337 * pwHue [O] Destination for converted hue
4338 * pwLuminance [O] Destination for converted luminance
4339 * pwSaturation [O] Destination for converted saturation
4340 *
4341 * RETURNS
4342 * Nothing. pwHue, pwLuminance and pwSaturation are set to the converted
4343 * values.
4344 *
4345 * NOTES
4346 * Output HLS values are constrained to the range (0..240).
4347 * For Achromatic conversions, Hue is set to 160.
4348 */
4350 LPWORD pwLuminance, LPWORD pwSaturation)
4351{
4352 int wR, wG, wB, wMax, wMin, wHue, wLuminosity, wSaturation;
4353
4354 TRACE("(%08x,%p,%p,%p)\n", cRGB, pwHue, pwLuminance, pwSaturation);
4355
4356 wR = GetRValue(cRGB);
4357 wG = GetGValue(cRGB);
4358 wB = GetBValue(cRGB);
4359
4360 wMax = max(wR, max(wG, wB));
4361 wMin = min(wR, min(wG, wB));
4362
4363 /* Luminosity */
4364 wLuminosity = ((wMax + wMin) * 240 + 255) / 510;
4365
4366 if (wMax == wMin)
4367 {
4368 /* Achromatic case */
4369 wSaturation = 0;
4370 /* Hue is now unrepresentable, but this is what native returns... */
4371 wHue = 160;
4372 }
4373 else
4374 {
4375 /* Chromatic case */
4376 int wDelta = wMax - wMin, wRNorm, wGNorm, wBNorm;
4377
4378 /* Saturation */
4379 if (wLuminosity <= 120)
4380 wSaturation = ((wMax + wMin)/2 + wDelta * 240) / (wMax + wMin);
4381 else
4382 wSaturation = ((510 - wMax - wMin)/2 + wDelta * 240) / (510 - wMax - wMin);
4383
4384 /* Hue */
4385 wRNorm = (wDelta/2 + wMax * 40 - wR * 40) / wDelta;
4386 wGNorm = (wDelta/2 + wMax * 40 - wG * 40) / wDelta;
4387 wBNorm = (wDelta/2 + wMax * 40 - wB * 40) / wDelta;
4388
4389 if (wR == wMax)
4390 wHue = wBNorm - wGNorm;
4391 else if (wG == wMax)
4392 wHue = 80 + wRNorm - wBNorm;
4393 else
4394 wHue = 160 + wGNorm - wRNorm;
4395 if (wHue < 0)
4396 wHue += 240;
4397 else if (wHue > 240)
4398 wHue -= 240;
4399 }
4400 if (pwHue)
4401 *pwHue = wHue;
4402 if (pwLuminance)
4403 *pwLuminance = wLuminosity;
4404 if (pwSaturation)
4405 *pwSaturation = wSaturation;
4406}
4407
4408/*************************************************************************
4409 * SHCreateShellPalette [SHLWAPI.@]
4410 */
4412{
4413 FIXME("stub\n");
4414 return CreateHalftonePalette(hdc);
4415}
4416
4417/*************************************************************************
4418 * SHGetInverseCMAP (SHLWAPI.@)
4419 *
4420 * Get an inverse color map table.
4421 *
4422 * PARAMS
4423 * lpCmap [O] Destination for color map
4424 * dwSize [I] Size of memory pointed to by lpCmap
4425 *
4426 * RETURNS
4427 * Success: S_OK.
4428 * Failure: E_POINTER, If lpCmap is invalid.
4429 * E_INVALIDARG, If dwFlags is invalid
4430 * E_OUTOFMEMORY, If there is no memory available
4431 *
4432 * NOTES
4433 * dwSize may only be CMAP_PTR_SIZE (4) or CMAP_SIZE (8192).
4434 * If dwSize = CMAP_PTR_SIZE, *lpCmap is set to the address of this DLL's
4435 * internal CMap.
4436 * If dwSize = CMAP_SIZE, lpCmap is filled with a copy of the data from
4437 * this DLL's internal CMap.
4438 */
4440{
4441 if (dwSize == 4) {
4442 FIXME(" - returning bogus address for SHGetInverseCMAP\n");
4443 *dest = (DWORD)0xabba1249;
4444 return 0;
4445 }
4446 FIXME("(%p, %#x) stub\n", dest, dwSize);
4447 return 0;
4448}
4449
4450/*************************************************************************
4451 * SHIsLowMemoryMachine [SHLWAPI.@]
4452 *
4453 * Determine if the current computer has low memory.
4454 *
4455 * PARAMS
4456 * dwType [I] Zero.
4457 *
4458 * RETURNS
4459 * TRUE if the users machine has 16 Megabytes of memory or less,
4460 * FALSE otherwise.
4461 */
4463{
4464#ifdef __REACTOS__
4466 static int is_low = -1;
4467 TRACE("(0x%08x)\n", dwType);
4468 if (dwType == 0 && is_low == -1)
4469 {
4471 is_low = (status.dwTotalPhys <= 0x1000000);
4472 }
4473 return is_low;
4474#else
4475 FIXME("(0x%08x) stub\n", dwType);
4476 return FALSE;
4477#endif
4478}
4479
4480/*************************************************************************
4481 * GetMenuPosFromID [SHLWAPI.@]
4482 *
4483 * Return the position of a menu item from its Id.
4484 *
4485 * PARAMS
4486 * hMenu [I] Menu containing the item
4487 * wID [I] Id of the menu item
4488 *
4489 * RETURNS
4490 * Success: The index of the menu item in hMenu.
4491 * Failure: -1, If the item is not found.
4492 */
4494{
4496 INT nCount = GetMenuItemCount(hMenu), nIter = 0;
4497
4498 TRACE("%p %u\n", hMenu, wID);
4499
4500 while (nIter < nCount)
4501 {
4502 mi.cbSize = sizeof(mi);
4503 mi.fMask = MIIM_ID;
4504 if (GetMenuItemInfoW(hMenu, nIter, TRUE, &mi) && mi.wID == wID)
4505 {
4506 TRACE("ret %d\n", nIter);
4507 return nIter;
4508 }
4509 nIter++;
4510 }
4511
4512 return -1;
4513}
4514
4515/*************************************************************************
4516 * @ [SHLWAPI.179]
4517 *
4518 * Same as SHLWAPI.GetMenuPosFromID
4519 */
4521{
4522 TRACE("%p %u\n", hMenu, uID);
4523 return GetMenuPosFromID(hMenu, uID);
4524}
4525
4526
4527/*************************************************************************
4528 * @ [SHLWAPI.448]
4529 */
4531{
4532 while (*lpwstr)
4533 {
4534 if (*lpwstr == '/')
4535 *lpwstr = '\\';
4536 lpwstr++;
4537 }
4538}
4539
4540
4541/*************************************************************************
4542 * @ [SHLWAPI.461]
4543 */
4545{
4546 FIXME("(0x%08x) stub\n", dwUnknown);
4547 return 0;
4548}
4549
4550
4551/*************************************************************************
4552 * @ [SHLWAPI.549]
4553 */
4555 DWORD dwClsContext, REFIID iid, LPVOID *ppv)
4556{
4557 return CoCreateInstance(rclsid, pUnkOuter, dwClsContext, iid, ppv);
4558}
4559
4560/*************************************************************************
4561 * SHSkipJunction [SHLWAPI.@]
4562 *
4563 * Determine if a bind context can be bound to an object
4564 *
4565 * PARAMS
4566 * pbc [I] Bind context to check
4567 * pclsid [I] CLSID of object to be bound to
4568 *
4569 * RETURNS
4570 * TRUE: If it is safe to bind
4571 * FALSE: If pbc is invalid or binding would not be safe
4572 *
4573 */
4575{
4576 static WCHAR szSkipBinding[] = { 'S','k','i','p',' ',
4577 'B','i','n','d','i','n','g',' ','C','L','S','I','D','\0' };
4578 BOOL bRet = FALSE;
4579
4580 if (pbc)
4581 {
4582 IUnknown* lpUnk;
4583
4584 if (SUCCEEDED(IBindCtx_GetObjectParam(pbc, szSkipBinding, &lpUnk)))
4585 {
4586 CLSID clsid;
4587
4588 if (SUCCEEDED(IUnknown_GetClassID(lpUnk, &clsid)) &&
4589 IsEqualGUID(pclsid, &clsid))
4590 bRet = TRUE;
4591
4592 IUnknown_Release(lpUnk);
4593 }
4594 }
4595 return bRet;
4596}
4597
4598/***********************************************************************
4599 * SHGetShellKey (SHLWAPI.491)
4600 */
4602{
4603#ifndef __REACTOS__
4604 enum _shellkey_flags {
4605 SHKEY_Root_HKCU = 0x1,
4606 SHKEY_Root_HKLM = 0x2,
4607 SHKEY_Key_Explorer = 0x00,
4608 SHKEY_Key_Shell = 0x10,
4609 SHKEY_Key_ShellNoRoam = 0x20,
4610 SHKEY_Key_Classes = 0x30,
4611 SHKEY_Subkey_Default = 0x0000,
4613 SHKEY_Subkey_Handlers = 0x2000,
4615 SHKEY_Subkey_Volatile = 0x4000,
4616 SHKEY_Subkey_MUICache = 0x5000,
4617 SHKEY_Subkey_FileExts = 0x6000
4618 };
4619#endif
4620
4621 static const WCHAR explorerW[] = {'S','o','f','t','w','a','r','e','\\',
4622 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
4623 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
4624 'E','x','p','l','o','r','e','r','\\'};
4625 static const WCHAR shellW[] = {'S','o','f','t','w','a','r','e','\\',
4626 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
4627 'S','h','e','l','l','\\'};
4628 static const WCHAR shell_no_roamW[] = {'S','o','f','t','w','a','r','e','\\',
4629 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
4630 'S','h','e','l','l','N','o','R','o','a','m','\\'};
4631 static const WCHAR classesW[] = {'S','o','f','t','w','a','r','e','\\',
4632 'C','l','a','s','s','e','s','\\'};
4633
4634 static const WCHAR localized_resource_nameW[] = {'L','o','c','a','l','i','z','e','d',
4635 'R','e','s','o','u','r','c','e','N','a','m','e','\\'};
4636 static const WCHAR handlersW[] = {'H','a','n','d','l','e','r','s','\\'};
4637 static const WCHAR associationsW[] = {'A','s','s','o','c','i','a','t','i','o','n','s','\\'};
4638 static const WCHAR volatileW[] = {'V','o','l','a','t','i','l','e','\\'};
4639 static const WCHAR mui_cacheW[] = {'M','U','I','C','a','c','h','e','\\'};
4640 static const WCHAR file_extsW[] = {'F','i','l','e','E','x','t','s','\\'};
4641
4642 WCHAR *path;
4643 const WCHAR *key, *subkey;
4644 int size_key, size_subkey, size_user;
4645 HKEY hkey = NULL;
4646
4647 TRACE("(0x%08x, %s, %d)\n", flags, debugstr_w(sub_key), create);
4648
4649 /* For compatibility with Vista+ */
4650 if(flags == 0x1ffff)
4651 flags = 0x21;
4652
4653 switch(flags&0xff0) {
4654 case SHKEY_Key_Explorer:
4655 key = explorerW;
4656 size_key = sizeof(explorerW);
4657 break;
4658 case SHKEY_Key_Shell:
4659 key = shellW;
4660 size_key = sizeof(shellW);
4661 break;
4663 key = shell_no_roamW;
4664 size_key = sizeof(shell_no_roamW);
4665 break;
4666 case SHKEY_Key_Classes:
4667 key = classesW;
4668 size_key = sizeof(classesW);
4669 break;
4670 default:
4671 FIXME("unsupported flags (0x%08x)\n", flags);
4672 return NULL;
4673 }
4674
4675 switch(flags&0xff000) {
4677 subkey = NULL;
4678 size_subkey = 0;
4679 break;
4681 subkey = localized_resource_nameW;
4682 size_subkey = sizeof(localized_resource_nameW);
4683 break;
4685 subkey = handlersW;
4686 size_subkey = sizeof(handlersW);
4687 break;
4689 subkey = associationsW;
4690 size_subkey = sizeof(associationsW);
4691 break;
4693 subkey = volatileW;
4694 size_subkey = sizeof(volatileW);
4695 break;
4697 subkey = mui_cacheW;
4698 size_subkey = sizeof(mui_cacheW);
4699 break;
4701 subkey = file_extsW;
4702 size_subkey = sizeof(file_extsW);
4703 break;
4704 default:
4705 FIXME("unsupported flags (0x%08x)\n", flags);
4706 return NULL;
4707 }
4708
4709 if(sub_key)
4710 size_user = lstrlenW(sub_key)*sizeof(WCHAR);
4711 else
4712 size_user = 0;
4713
4714 path = HeapAlloc(GetProcessHeap(), 0, size_key+size_subkey+size_user+sizeof(WCHAR));
4715 if(!path) {
4716 ERR("Out of memory\n");
4717 return NULL;
4718 }
4719
4720 memcpy(path, key, size_key);
4721 if(subkey)
4722 memcpy(path+size_key/sizeof(WCHAR), subkey,