61e8804d50b48c2214cb4b2e113a1e231d24601a
[reactos.git] / dll / win32 / shlwapi / ordinal.c
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 "precomp.h"
24
25 #include <stdio.h>
26
27 #include <winver.h>
28 #include <winnetwk.h>
29 #include <mmsystem.h>
30 #include <shdeprecated.h>
31 #include <shellapi.h>
32 #include <commdlg.h>
33 #include <mlang.h>
34 #include <mshtmhst.h>
35
36 /* DLL handles for late bound calls */
37 extern HINSTANCE shlwapi_hInstance;
38 extern DWORD SHLWAPI_ThreadRef_index;
39
40 HRESULT WINAPI IUnknown_QueryService(IUnknown*,REFGUID,REFIID,LPVOID*);
41 HRESULT WINAPI SHInvokeCommand(HWND,IShellFolder*,LPCITEMIDLIST,DWORD);
42 BOOL WINAPI SHAboutInfoW(LPWSTR,DWORD);
43
44 /*
45 NOTES: Most functions exported by ordinal seem to be superfluous.
46 The reason for these functions to be there is to provide a wrapper
47 for unicode functions to provide these functions on systems without
48 unicode functions eg. win95/win98. Since we have such functions we just
49 call these. If running Wine with native DLLs, some late bound calls may
50 fail. However, it is better to implement the functions in the forward DLL
51 and recommend the builtin rather than reimplementing the calls here!
52 */
53
54 /*************************************************************************
55 * @ [SHLWAPI.11]
56 *
57 * Copy a sharable memory handle from one process to another.
58 *
59 * PARAMS
60 * hShared [I] Shared memory handle to duplicate
61 * dwSrcProcId [I] ID of the process owning hShared
62 * dwDstProcId [I] ID of the process wanting the duplicated handle
63 * dwAccess [I] Desired DuplicateHandle() access
64 * dwOptions [I] Desired DuplicateHandle() options
65 *
66 * RETURNS
67 * Success: A handle suitable for use by the dwDstProcId process.
68 * Failure: A NULL handle.
69 *
70 */
71 HANDLE WINAPI SHMapHandle(HANDLE hShared, DWORD dwSrcProcId, DWORD dwDstProcId,
72 DWORD dwAccess, DWORD dwOptions)
73 {
74 HANDLE hDst, hSrc;
75 DWORD dwMyProcId = GetCurrentProcessId();
76 HANDLE hRet = NULL;
77
78 TRACE("(%p,%d,%d,%08x,%08x)\n", hShared, dwDstProcId, dwSrcProcId,
79 dwAccess, dwOptions);
80
81 /* Get dest process handle */
82 if (dwDstProcId == dwMyProcId)
83 hDst = GetCurrentProcess();
84 else
85 hDst = OpenProcess(PROCESS_DUP_HANDLE, 0, dwDstProcId);
86
87 if (hDst)
88 {
89 /* Get src process handle */
90 if (dwSrcProcId == dwMyProcId)
91 hSrc = GetCurrentProcess();
92 else
93 hSrc = OpenProcess(PROCESS_DUP_HANDLE, 0, dwSrcProcId);
94
95 if (hSrc)
96 {
97 /* Make handle available to dest process */
98 if (!DuplicateHandle(hSrc, hShared, hDst, &hRet,
99 dwAccess, 0, dwOptions | DUPLICATE_SAME_ACCESS))
100 hRet = NULL;
101
102 if (dwSrcProcId != dwMyProcId)
103 CloseHandle(hSrc);
104 }
105
106 if (dwDstProcId != dwMyProcId)
107 CloseHandle(hDst);
108 }
109
110 TRACE("Returning handle %p\n", hRet);
111 return hRet;
112 }
113
114 /*************************************************************************
115 * @ [SHLWAPI.7]
116 *
117 * Create a block of sharable memory and initialise it with data.
118 *
119 * PARAMS
120 * lpvData [I] Pointer to data to write
121 * dwSize [I] Size of data
122 * dwProcId [I] ID of process owning data
123 *
124 * RETURNS
125 * Success: A shared memory handle
126 * Failure: NULL
127 *
128 * NOTES
129 * Ordinals 7-11 provide a set of calls to create shared memory between a
130 * group of processes. The shared memory is treated opaquely in that its size
131 * is not exposed to clients who map it. This is accomplished by storing
132 * the size of the map as the first DWORD of mapped data, and then offsetting
133 * the view pointer returned by this size.
134 *
135 */
136 HANDLE WINAPI SHAllocShared(LPCVOID lpvData, DWORD dwSize, DWORD dwProcId)
137 {
138 HANDLE hMap;
139 LPVOID pMapped;
140 HANDLE hRet = NULL;
141
142 TRACE("(%p,%d,%d)\n", lpvData, dwSize, dwProcId);
143
144 /* Create file mapping of the correct length */
145 hMap = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, FILE_MAP_READ, 0,
146 dwSize + sizeof(dwSize), NULL);
147 if (!hMap)
148 return hRet;
149
150 /* Get a view in our process address space */
151 pMapped = MapViewOfFile(hMap, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0);
152
153 if (pMapped)
154 {
155 /* Write size of data, followed by the data, to the view */
156 *((DWORD*)pMapped) = dwSize;
157 if (lpvData)
158 memcpy((char *) pMapped + sizeof(dwSize), lpvData, dwSize);
159
160 /* Release view. All further views mapped will be opaque */
161 UnmapViewOfFile(pMapped);
162 hRet = SHMapHandle(hMap, GetCurrentProcessId(), dwProcId,
163 FILE_MAP_ALL_ACCESS, DUPLICATE_SAME_ACCESS);
164 }
165
166 CloseHandle(hMap);
167 return hRet;
168 }
169
170 /*************************************************************************
171 * @ [SHLWAPI.8]
172 *
173 * Get a pointer to a block of shared memory from a shared memory handle.
174 *
175 * PARAMS
176 * hShared [I] Shared memory handle
177 * dwProcId [I] ID of process owning hShared
178 *
179 * RETURNS
180 * Success: A pointer to the shared memory
181 * Failure: NULL
182 *
183 */
184 PVOID WINAPI SHLockShared(HANDLE hShared, DWORD dwProcId)
185 {
186 HANDLE hDup;
187 LPVOID pMapped;
188
189 TRACE("(%p %d)\n", hShared, dwProcId);
190
191 /* Get handle to shared memory for current process */
192 hDup = SHMapHandle(hShared, dwProcId, GetCurrentProcessId(), FILE_MAP_ALL_ACCESS, 0);
193
194 /* Get View */
195 pMapped = MapViewOfFile(hDup, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0);
196 CloseHandle(hDup);
197
198 if (pMapped)
199 return (char *) pMapped + sizeof(DWORD); /* Hide size */
200 return NULL;
201 }
202
203 /*************************************************************************
204 * @ [SHLWAPI.9]
205 *
206 * Release a pointer to a block of shared memory.
207 *
208 * PARAMS
209 * lpView [I] Shared memory pointer
210 *
211 * RETURNS
212 * Success: TRUE
213 * Failure: FALSE
214 *
215 */
216 BOOL WINAPI SHUnlockShared(LPVOID lpView)
217 {
218 TRACE("(%p)\n", lpView);
219 return UnmapViewOfFile((char *) lpView - sizeof(DWORD)); /* Include size */
220 }
221
222 /*************************************************************************
223 * @ [SHLWAPI.10]
224 *
225 * Destroy a block of sharable memory.
226 *
227 * PARAMS
228 * hShared [I] Shared memory handle
229 * dwProcId [I] ID of process owning hShared
230 *
231 * RETURNS
232 * Success: TRUE
233 * Failure: FALSE
234 *
235 */
236 BOOL WINAPI SHFreeShared(HANDLE hShared, DWORD dwProcId)
237 {
238 HANDLE hClose;
239
240 TRACE("(%p %d)\n", hShared, dwProcId);
241
242 if (!hShared)
243 return TRUE;
244
245 /* Get a copy of the handle for our process, closing the source handle */
246 hClose = SHMapHandle(hShared, dwProcId, GetCurrentProcessId(),
247 FILE_MAP_ALL_ACCESS,DUPLICATE_CLOSE_SOURCE);
248 /* Close local copy */
249 return CloseHandle(hClose);
250 }
251
252 /*************************************************************************
253 * @ [SHLWAPI.13]
254 *
255 * Create and register a clipboard enumerator for a web browser.
256 *
257 * PARAMS
258 * lpBC [I] Binding context
259 * lpUnknown [I] An object exposing the IWebBrowserApp interface
260 *
261 * RETURNS
262 * Success: S_OK.
263 * Failure: An HRESULT error code.
264 *
265 * NOTES
266 * The enumerator is stored as a property of the web browser. If it does not
267 * yet exist, it is created and set before being registered.
268 */
269 HRESULT WINAPI RegisterDefaultAcceptHeaders(LPBC lpBC, IUnknown *lpUnknown)
270 {
271 static const WCHAR szProperty[] = { '{','D','0','F','C','A','4','2','0',
272 '-','D','3','F','5','-','1','1','C','F', '-','B','2','1','1','-','0',
273 '0','A','A','0','0','4','A','E','8','3','7','}','\0' };
274 BSTR property;
275 IEnumFORMATETC* pIEnumFormatEtc = NULL;
276 VARIANTARG var;
277 HRESULT hr;
278 IWebBrowserApp* pBrowser;
279
280 TRACE("(%p, %p)\n", lpBC, lpUnknown);
281
282 hr = IUnknown_QueryService(lpUnknown, &IID_IWebBrowserApp, &IID_IWebBrowserApp, (void**)&pBrowser);
283 if (FAILED(hr))
284 return hr;
285
286 V_VT(&var) = VT_EMPTY;
287
288 /* The property we get is the browsers clipboard enumerator */
289 property = SysAllocString(szProperty);
290 hr = IWebBrowserApp_GetProperty(pBrowser, property, &var);
291 SysFreeString(property);
292 if (FAILED(hr)) goto exit;
293
294 if (V_VT(&var) == VT_EMPTY)
295 {
296 /* Iterate through accepted documents and RegisterClipBoardFormatA() them */
297 char szKeyBuff[128], szValueBuff[128];
298 DWORD dwKeySize, dwValueSize, dwRet = 0, dwCount = 0, dwNumValues, dwType;
299 FORMATETC* formatList, *format;
300 HKEY hDocs;
301
302 TRACE("Registering formats and creating IEnumFORMATETC instance\n");
303
304 if (!RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\Current"
305 "Version\\Internet Settings\\Accepted Documents", &hDocs))
306 {
307 hr = E_FAIL;
308 goto exit;
309 }
310
311 /* Get count of values in key */
312 while (!dwRet)
313 {
314 dwKeySize = sizeof(szKeyBuff);
315 dwRet = RegEnumValueA(hDocs,dwCount,szKeyBuff,&dwKeySize,0,&dwType,0,0);
316 dwCount++;
317 }
318
319 dwNumValues = dwCount;
320
321 /* Note: dwCount = number of items + 1; The extra item is the end node */
322 format = formatList = HeapAlloc(GetProcessHeap(), 0, dwCount * sizeof(FORMATETC));
323 if (!formatList)
324 {
325 RegCloseKey(hDocs);
326 hr = E_OUTOFMEMORY;
327 goto exit;
328 }
329
330 if (dwNumValues > 1)
331 {
332 dwRet = 0;
333 dwCount = 0;
334
335 dwNumValues--;
336
337 /* Register clipboard formats for the values and populate format list */
338 while(!dwRet && dwCount < dwNumValues)
339 {
340 dwKeySize = sizeof(szKeyBuff);
341 dwValueSize = sizeof(szValueBuff);
342 dwRet = RegEnumValueA(hDocs, dwCount, szKeyBuff, &dwKeySize, 0, &dwType,
343 (PBYTE)szValueBuff, &dwValueSize);
344 if (!dwRet)
345 {
346 HeapFree(GetProcessHeap(), 0, formatList);
347 RegCloseKey(hDocs);
348 hr = E_FAIL;
349 goto exit;
350 }
351
352 format->cfFormat = RegisterClipboardFormatA(szValueBuff);
353 format->ptd = NULL;
354 format->dwAspect = 1;
355 format->lindex = 4;
356 format->tymed = -1;
357
358 format++;
359 dwCount++;
360 }
361 }
362
363 RegCloseKey(hDocs);
364
365 /* Terminate the (maybe empty) list, last entry has a cfFormat of 0 */
366 format->cfFormat = 0;
367 format->ptd = NULL;
368 format->dwAspect = 1;
369 format->lindex = 4;
370 format->tymed = -1;
371
372 /* Create a clipboard enumerator */
373 hr = CreateFormatEnumerator(dwNumValues, formatList, &pIEnumFormatEtc);
374 HeapFree(GetProcessHeap(), 0, formatList);
375 if (FAILED(hr)) goto exit;
376
377 /* Set our enumerator as the browsers property */
378 V_VT(&var) = VT_UNKNOWN;
379 V_UNKNOWN(&var) = (IUnknown*)pIEnumFormatEtc;
380
381 property = SysAllocString(szProperty);
382 hr = IWebBrowserApp_PutProperty(pBrowser, property, var);
383 SysFreeString(property);
384 if (FAILED(hr))
385 {
386 IEnumFORMATETC_Release(pIEnumFormatEtc);
387 goto exit;
388 }
389 }
390
391 if (V_VT(&var) == VT_UNKNOWN)
392 {
393 /* Our variant is holding the clipboard enumerator */
394 IUnknown* pIUnknown = V_UNKNOWN(&var);
395 IEnumFORMATETC* pClone = NULL;
396
397 TRACE("Retrieved IEnumFORMATETC property\n");
398
399 /* Get an IEnumFormatEtc interface from the variants value */
400 pIEnumFormatEtc = NULL;
401 hr = IUnknown_QueryInterface(pIUnknown, &IID_IEnumFORMATETC, (void**)&pIEnumFormatEtc);
402 if (hr == S_OK && pIEnumFormatEtc)
403 {
404 /* Clone and register the enumerator */
405 hr = IEnumFORMATETC_Clone(pIEnumFormatEtc, &pClone);
406 if (hr == S_OK && pClone)
407 {
408 RegisterFormatEnumerator(lpBC, pClone, 0);
409
410 IEnumFORMATETC_Release(pClone);
411 }
412
413 IUnknown_Release(pIUnknown);
414 }
415 IUnknown_Release(V_UNKNOWN(&var));
416 }
417
418 exit:
419 IWebBrowserApp_Release(pBrowser);
420 return hr;
421 }
422
423 /*************************************************************************
424 * @ [SHLWAPI.15]
425 *
426 * Get Explorers "AcceptLanguage" setting.
427 *
428 * PARAMS
429 * langbuf [O] Destination for language string
430 * buflen [I] Length of langbuf in characters
431 * [0] Success: used length of langbuf
432 *
433 * RETURNS
434 * Success: S_OK. langbuf is set to the language string found.
435 * Failure: E_FAIL, If any arguments are invalid, error occurred, or Explorer
436 * does not contain the setting.
437 * E_NOT_SUFFICIENT_BUFFER, If the buffer is not big enough
438 */
439 HRESULT WINAPI GetAcceptLanguagesW( LPWSTR langbuf, LPDWORD buflen)
440 {
441 static const WCHAR szkeyW[] = {
442 'S','o','f','t','w','a','r','e','\\',
443 'M','i','c','r','o','s','o','f','t','\\',
444 'I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r','\\',
445 'I','n','t','e','r','n','a','t','i','o','n','a','l',0};
446 static const WCHAR valueW[] = {
447 'A','c','c','e','p','t','L','a','n','g','u','a','g','e',0};
448 DWORD mystrlen, mytype;
449 DWORD len;
450 HKEY mykey;
451 LCID mylcid;
452 WCHAR *mystr;
453 LONG lres;
454
455 TRACE("(%p, %p) *%p: %d\n", langbuf, buflen, buflen, buflen ? *buflen : -1);
456
457 if(!langbuf || !buflen || !*buflen)
458 return E_FAIL;
459
460 mystrlen = (*buflen > 20) ? *buflen : 20 ;
461 len = mystrlen * sizeof(WCHAR);
462 mystr = HeapAlloc(GetProcessHeap(), 0, len);
463 mystr[0] = 0;
464 RegOpenKeyW(HKEY_CURRENT_USER, szkeyW, &mykey);
465 lres = RegQueryValueExW(mykey, valueW, 0, &mytype, (PBYTE)mystr, &len);
466 RegCloseKey(mykey);
467 len = lstrlenW(mystr);
468
469 if (!lres && (*buflen > len)) {
470 lstrcpyW(langbuf, mystr);
471 *buflen = len;
472 HeapFree(GetProcessHeap(), 0, mystr);
473 return S_OK;
474 }
475
476 /* Did not find a value in the registry or the user buffer is too small */
477 mylcid = GetUserDefaultLCID();
478 LcidToRfc1766W(mylcid, mystr, mystrlen);
479 len = lstrlenW(mystr);
480
481 memcpy( langbuf, mystr, min(*buflen, len+1)*sizeof(WCHAR) );
482 HeapFree(GetProcessHeap(), 0, mystr);
483
484 if (*buflen > len) {
485 *buflen = len;
486 return S_OK;
487 }
488
489 *buflen = 0;
490 return E_NOT_SUFFICIENT_BUFFER;
491 }
492
493 /*************************************************************************
494 * @ [SHLWAPI.14]
495 *
496 * Ascii version of GetAcceptLanguagesW.
497 */
498 HRESULT WINAPI GetAcceptLanguagesA( LPSTR langbuf, LPDWORD buflen)
499 {
500 WCHAR *langbufW;
501 DWORD buflenW, convlen;
502 HRESULT retval;
503
504 TRACE("(%p, %p) *%p: %d\n", langbuf, buflen, buflen, buflen ? *buflen : -1);
505
506 if(!langbuf || !buflen || !*buflen) return E_FAIL;
507
508 buflenW = *buflen;
509 langbufW = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * buflenW);
510 retval = GetAcceptLanguagesW(langbufW, &buflenW);
511
512 if (retval == S_OK)
513 {
514 convlen = WideCharToMultiByte(CP_ACP, 0, langbufW, -1, langbuf, *buflen, NULL, NULL);
515 convlen--; /* do not count the terminating 0 */
516 }
517 else /* copy partial string anyway */
518 {
519 convlen = WideCharToMultiByte(CP_ACP, 0, langbufW, *buflen, langbuf, *buflen, NULL, NULL);
520 if (convlen < *buflen)
521 {
522 langbuf[convlen] = 0;
523 convlen--; /* do not count the terminating 0 */
524 }
525 else
526 {
527 convlen = *buflen;
528 }
529 }
530 *buflen = buflenW ? convlen : 0;
531
532 HeapFree(GetProcessHeap(), 0, langbufW);
533 return retval;
534 }
535
536 /*************************************************************************
537 * @ [SHLWAPI.23]
538 *
539 * Convert a GUID to a string.
540 *
541 * PARAMS
542 * guid [I] GUID to convert
543 * lpszDest [O] Destination for string
544 * cchMax [I] Length of output buffer
545 *
546 * RETURNS
547 * The length of the string created.
548 */
549 INT WINAPI SHStringFromGUIDA(REFGUID guid, LPSTR lpszDest, INT cchMax)
550 {
551 char xguid[40];
552 INT iLen;
553
554 TRACE("(%s,%p,%d)\n", debugstr_guid(guid), lpszDest, cchMax);
555
556 sprintf(xguid, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
557 guid->Data1, guid->Data2, guid->Data3,
558 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
559 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
560
561 iLen = strlen(xguid) + 1;
562
563 if (iLen > cchMax)
564 return 0;
565 memcpy(lpszDest, xguid, iLen);
566 return iLen;
567 }
568
569 /*************************************************************************
570 * @ [SHLWAPI.24]
571 *
572 * Convert a GUID to a string.
573 *
574 * PARAMS
575 * guid [I] GUID to convert
576 * str [O] Destination for string
577 * cmax [I] Length of output buffer
578 *
579 * RETURNS
580 * The length of the string created.
581 */
582 INT WINAPI SHStringFromGUIDW(REFGUID guid, LPWSTR lpszDest, INT cchMax)
583 {
584 WCHAR xguid[40];
585 INT iLen;
586 static const WCHAR wszFormat[] = {'{','%','0','8','l','X','-','%','0','4','X','-','%','0','4','X','-',
587 '%','0','2','X','%','0','2','X','-','%','0','2','X','%','0','2','X','%','0','2','X','%','0','2',
588 'X','%','0','2','X','%','0','2','X','}',0};
589
590 TRACE("(%s,%p,%d)\n", debugstr_guid(guid), lpszDest, cchMax);
591
592 sprintfW(xguid, wszFormat, guid->Data1, guid->Data2, guid->Data3,
593 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
594 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
595
596 iLen = strlenW(xguid) + 1;
597
598 if (iLen > cchMax)
599 return 0;
600 memcpy(lpszDest, xguid, iLen*sizeof(WCHAR));
601 return iLen;
602 }
603
604 /*************************************************************************
605 * @ [SHLWAPI.30]
606 *
607 * Determine if a Unicode character is a blank.
608 *
609 * PARAMS
610 * wc [I] Character to check.
611 *
612 * RETURNS
613 * TRUE, if wc is a blank,
614 * FALSE otherwise.
615 *
616 */
617 BOOL WINAPI IsCharBlankW(WCHAR wc)
618 {
619 WORD CharType;
620
621 return GetStringTypeW(CT_CTYPE1, &wc, 1, &CharType) && (CharType & C1_BLANK);
622 }
623
624 /*************************************************************************
625 * @ [SHLWAPI.31]
626 *
627 * Determine if a Unicode character is punctuation.
628 *
629 * PARAMS
630 * wc [I] Character to check.
631 *
632 * RETURNS
633 * TRUE, if wc is punctuation,
634 * FALSE otherwise.
635 */
636 BOOL WINAPI IsCharPunctW(WCHAR wc)
637 {
638 WORD CharType;
639
640 return GetStringTypeW(CT_CTYPE1, &wc, 1, &CharType) && (CharType & C1_PUNCT);
641 }
642
643 /*************************************************************************
644 * @ [SHLWAPI.32]
645 *
646 * Determine if a Unicode character is a control character.
647 *
648 * PARAMS
649 * wc [I] Character to check.
650 *
651 * RETURNS
652 * TRUE, if wc is a control character,
653 * FALSE otherwise.
654 */
655 BOOL WINAPI IsCharCntrlW(WCHAR wc)
656 {
657 WORD CharType;
658
659 return GetStringTypeW(CT_CTYPE1, &wc, 1, &CharType) && (CharType & C1_CNTRL);
660 }
661
662 /*************************************************************************
663 * @ [SHLWAPI.33]
664 *
665 * Determine if a Unicode character is a digit.
666 *
667 * PARAMS
668 * wc [I] Character to check.
669 *
670 * RETURNS
671 * TRUE, if wc is a digit,
672 * FALSE otherwise.
673 */
674 BOOL WINAPI IsCharDigitW(WCHAR wc)
675 {
676 WORD CharType;
677
678 return GetStringTypeW(CT_CTYPE1, &wc, 1, &CharType) && (CharType & C1_DIGIT);
679 }
680
681 /*************************************************************************
682 * @ [SHLWAPI.34]
683 *
684 * Determine if a Unicode character is a hex digit.
685 *
686 * PARAMS
687 * wc [I] Character to check.
688 *
689 * RETURNS
690 * TRUE, if wc is a hex digit,
691 * FALSE otherwise.
692 */
693 BOOL WINAPI IsCharXDigitW(WCHAR wc)
694 {
695 WORD CharType;
696
697 return GetStringTypeW(CT_CTYPE1, &wc, 1, &CharType) && (CharType & C1_XDIGIT);
698 }
699
700 /*************************************************************************
701 * @ [SHLWAPI.35]
702 *
703 */
704 BOOL WINAPI GetStringType3ExW(LPWSTR src, INT count, LPWORD type)
705 {
706 return GetStringTypeW(CT_CTYPE3, src, count, type);
707 }
708
709 /*************************************************************************
710 * @ [SHLWAPI.151]
711 *
712 * Compare two Ascii strings up to a given length.
713 *
714 * PARAMS
715 * lpszSrc [I] Source string
716 * lpszCmp [I] String to compare to lpszSrc
717 * len [I] Maximum length
718 *
719 * RETURNS
720 * A number greater than, less than or equal to 0 depending on whether
721 * lpszSrc is greater than, less than or equal to lpszCmp.
722 */
723 DWORD WINAPI StrCmpNCA(LPCSTR lpszSrc, LPCSTR lpszCmp, INT len)
724 {
725 return StrCmpNA(lpszSrc, lpszCmp, len);
726 }
727
728 /*************************************************************************
729 * @ [SHLWAPI.152]
730 *
731 * Unicode version of StrCmpNCA.
732 */
733 DWORD WINAPI StrCmpNCW(LPCWSTR lpszSrc, LPCWSTR lpszCmp, INT len)
734 {
735 return StrCmpNW(lpszSrc, lpszCmp, len);
736 }
737
738 /*************************************************************************
739 * @ [SHLWAPI.153]
740 *
741 * Compare two Ascii strings up to a given length, ignoring case.
742 *
743 * PARAMS
744 * lpszSrc [I] Source string
745 * lpszCmp [I] String to compare to lpszSrc
746 * len [I] Maximum length
747 *
748 * RETURNS
749 * A number greater than, less than or equal to 0 depending on whether
750 * lpszSrc is greater than, less than or equal to lpszCmp.
751 */
752 DWORD WINAPI StrCmpNICA(LPCSTR lpszSrc, LPCSTR lpszCmp, DWORD len)
753 {
754 return StrCmpNIA(lpszSrc, lpszCmp, len);
755 }
756
757 /*************************************************************************
758 * @ [SHLWAPI.154]
759 *
760 * Unicode version of StrCmpNICA.
761 */
762 DWORD WINAPI StrCmpNICW(LPCWSTR lpszSrc, LPCWSTR lpszCmp, DWORD len)
763 {
764 return StrCmpNIW(lpszSrc, lpszCmp, len);
765 }
766
767 /*************************************************************************
768 * @ [SHLWAPI.155]
769 *
770 * Compare two Ascii strings.
771 *
772 * PARAMS
773 * lpszSrc [I] Source string
774 * lpszCmp [I] String to compare to lpszSrc
775 *
776 * RETURNS
777 * A number greater than, less than or equal to 0 depending on whether
778 * lpszSrc is greater than, less than or equal to lpszCmp.
779 */
780 DWORD WINAPI StrCmpCA(LPCSTR lpszSrc, LPCSTR lpszCmp)
781 {
782 return lstrcmpA(lpszSrc, lpszCmp);
783 }
784
785 /*************************************************************************
786 * @ [SHLWAPI.156]
787 *
788 * Unicode version of StrCmpCA.
789 */
790 DWORD WINAPI StrCmpCW(LPCWSTR lpszSrc, LPCWSTR lpszCmp)
791 {
792 return lstrcmpW(lpszSrc, lpszCmp);
793 }
794
795 /*************************************************************************
796 * @ [SHLWAPI.157]
797 *
798 * Compare two Ascii strings, ignoring case.
799 *
800 * PARAMS
801 * lpszSrc [I] Source string
802 * lpszCmp [I] String to compare to lpszSrc
803 *
804 * RETURNS
805 * A number greater than, less than or equal to 0 depending on whether
806 * lpszSrc is greater than, less than or equal to lpszCmp.
807 */
808 DWORD WINAPI StrCmpICA(LPCSTR lpszSrc, LPCSTR lpszCmp)
809 {
810 return lstrcmpiA(lpszSrc, lpszCmp);
811 }
812
813 /*************************************************************************
814 * @ [SHLWAPI.158]
815 *
816 * Unicode version of StrCmpICA.
817 */
818 DWORD WINAPI StrCmpICW(LPCWSTR lpszSrc, LPCWSTR lpszCmp)
819 {
820 return lstrcmpiW(lpszSrc, lpszCmp);
821 }
822
823 /*************************************************************************
824 * @ [SHLWAPI.160]
825 *
826 * Get an identification string for the OS and explorer.
827 *
828 * PARAMS
829 * lpszDest [O] Destination for Id string
830 * dwDestLen [I] Length of lpszDest
831 *
832 * RETURNS
833 * TRUE, If the string was created successfully
834 * FALSE, Otherwise
835 */
836 BOOL WINAPI SHAboutInfoA(LPSTR lpszDest, DWORD dwDestLen)
837 {
838 WCHAR buff[2084];
839
840 TRACE("(%p,%d)\n", lpszDest, dwDestLen);
841
842 if (lpszDest && SHAboutInfoW(buff, dwDestLen))
843 {
844 WideCharToMultiByte(CP_ACP, 0, buff, -1, lpszDest, dwDestLen, NULL, NULL);
845 return TRUE;
846 }
847 return FALSE;
848 }
849
850 /*************************************************************************
851 * @ [SHLWAPI.161]
852 *
853 * Unicode version of SHAboutInfoA.
854 */
855 BOOL WINAPI SHAboutInfoW(LPWSTR lpszDest, DWORD dwDestLen)
856 {
857 static const WCHAR szIEKey[] = { 'S','O','F','T','W','A','R','E','\\',
858 'M','i','c','r','o','s','o','f','t','\\','I','n','t','e','r','n','e','t',
859 ' ','E','x','p','l','o','r','e','r','\0' };
860 static const WCHAR szWinNtKey[] = { 'S','O','F','T','W','A','R','E','\\',
861 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s',' ',
862 'N','T','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\0' };
863 static const WCHAR szWinKey[] = { 'S','O','F','T','W','A','R','E','\\',
864 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
865 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\0' };
866 static const WCHAR szRegKey[] = { 'S','O','F','T','W','A','R','E','\\',
867 'M','i','c','r','o','s','o','f','t','\\','I','n','t','e','r','n','e','t',
868 ' ','E','x','p','l','o','r','e','r','\\',
869 'R','e','g','i','s','t','r','a','t','i','o','n','\0' };
870 static const WCHAR szVersion[] = { 'V','e','r','s','i','o','n','\0' };
871 static const WCHAR szCustomized[] = { 'C','u','s','t','o','m','i','z','e','d',
872 'V','e','r','s','i','o','n','\0' };
873 static const WCHAR szOwner[] = { 'R','e','g','i','s','t','e','r','e','d',
874 'O','w','n','e','r','\0' };
875 static const WCHAR szOrg[] = { 'R','e','g','i','s','t','e','r','e','d',
876 'O','r','g','a','n','i','z','a','t','i','o','n','\0' };
877 static const WCHAR szProduct[] = { 'P','r','o','d','u','c','t','I','d','\0' };
878 static const WCHAR szUpdate[] = { 'I','E','A','K',
879 'U','p','d','a','t','e','U','r','l','\0' };
880 static const WCHAR szHelp[] = { 'I','E','A','K',
881 'H','e','l','p','S','t','r','i','n','g','\0' };
882 WCHAR buff[2084];
883 HKEY hReg;
884 DWORD dwType, dwLen;
885
886 TRACE("(%p,%d)\n", lpszDest, dwDestLen);
887
888 if (!lpszDest)
889 return FALSE;
890
891 *lpszDest = '\0';
892
893 /* Try the NT key first, followed by 95/98 key */
894 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, szWinNtKey, 0, KEY_READ, &hReg) &&
895 RegOpenKeyExW(HKEY_LOCAL_MACHINE, szWinKey, 0, KEY_READ, &hReg))
896 return FALSE;
897
898 /* OS Version */
899 buff[0] = '\0';
900 dwLen = 30;
901 if (!SHGetValueW(HKEY_LOCAL_MACHINE, szIEKey, szVersion, &dwType, buff, &dwLen))
902 {
903 DWORD dwStrLen = strlenW(buff);
904 dwLen = 30 - dwStrLen;
905 SHGetValueW(HKEY_LOCAL_MACHINE, szIEKey,
906 szCustomized, &dwType, buff+dwStrLen, &dwLen);
907 }
908 StrCatBuffW(lpszDest, buff, dwDestLen);
909
910 /* ~Registered Owner */
911 buff[0] = '~';
912 dwLen = 256;
913 if (SHGetValueW(hReg, szOwner, 0, &dwType, buff+1, &dwLen))
914 buff[1] = '\0';
915 StrCatBuffW(lpszDest, buff, dwDestLen);
916
917 /* ~Registered Organization */
918 dwLen = 256;
919 if (SHGetValueW(hReg, szOrg, 0, &dwType, buff+1, &dwLen))
920 buff[1] = '\0';
921 StrCatBuffW(lpszDest, buff, dwDestLen);
922
923 /* FIXME: Not sure where this number comes from */
924 buff[0] = '~';
925 buff[1] = '0';
926 buff[2] = '\0';
927 StrCatBuffW(lpszDest, buff, dwDestLen);
928
929 /* ~Product Id */
930 dwLen = 256;
931 if (SHGetValueW(HKEY_LOCAL_MACHINE, szRegKey, szProduct, &dwType, buff+1, &dwLen))
932 buff[1] = '\0';
933 StrCatBuffW(lpszDest, buff, dwDestLen);
934
935 /* ~IE Update Url */
936 dwLen = 2048;
937 if(SHGetValueW(HKEY_LOCAL_MACHINE, szWinKey, szUpdate, &dwType, buff+1, &dwLen))
938 buff[1] = '\0';
939 StrCatBuffW(lpszDest, buff, dwDestLen);
940
941 /* ~IE Help String */
942 dwLen = 256;
943 if(SHGetValueW(hReg, szHelp, 0, &dwType, buff+1, &dwLen))
944 buff[1] = '\0';
945 StrCatBuffW(lpszDest, buff, dwDestLen);
946
947 RegCloseKey(hReg);
948 return TRUE;
949 }
950
951 /*************************************************************************
952 * @ [SHLWAPI.163]
953 *
954 * Call IOleCommandTarget_QueryStatus() on an object.
955 *
956 * PARAMS
957 * lpUnknown [I] Object supporting the IOleCommandTarget interface
958 * pguidCmdGroup [I] GUID for the command group
959 * cCmds [I]
960 * prgCmds [O] Commands
961 * pCmdText [O] Command text
962 *
963 * RETURNS
964 * Success: S_OK.
965 * Failure: E_FAIL, if lpUnknown is NULL.
966 * E_NOINTERFACE, if lpUnknown does not support IOleCommandTarget.
967 * Otherwise, an error code from IOleCommandTarget_QueryStatus().
968 */
969 HRESULT WINAPI IUnknown_QueryStatus(IUnknown* lpUnknown, REFGUID pguidCmdGroup,
970 ULONG cCmds, OLECMD *prgCmds, OLECMDTEXT* pCmdText)
971 {
972 HRESULT hRet = E_FAIL;
973
974 TRACE("(%p,%p,%d,%p,%p)\n",lpUnknown, pguidCmdGroup, cCmds, prgCmds, pCmdText);
975
976 if (lpUnknown)
977 {
978 IOleCommandTarget* lpOle;
979
980 hRet = IUnknown_QueryInterface(lpUnknown, &IID_IOleCommandTarget,
981 (void**)&lpOle);
982
983 if (SUCCEEDED(hRet) && lpOle)
984 {
985 hRet = IOleCommandTarget_QueryStatus(lpOle, pguidCmdGroup, cCmds,
986 prgCmds, pCmdText);
987 IOleCommandTarget_Release(lpOle);
988 }
989 }
990 return hRet;
991 }
992
993 /*************************************************************************
994 * @ [SHLWAPI.164]
995 *
996 * Call IOleCommandTarget_Exec() on an object.
997 *
998 * PARAMS
999 * lpUnknown [I] Object supporting the IOleCommandTarget interface
1000 * pguidCmdGroup [I] GUID for the command group
1001 *
1002 * RETURNS
1003 * Success: S_OK.
1004 * Failure: E_FAIL, if lpUnknown is NULL.
1005 * E_NOINTERFACE, if lpUnknown does not support IOleCommandTarget.
1006 * Otherwise, an error code from IOleCommandTarget_Exec().
1007 */
1008 HRESULT WINAPI IUnknown_Exec(IUnknown* lpUnknown, REFGUID pguidCmdGroup,
1009 DWORD nCmdID, DWORD nCmdexecopt, VARIANT* pvaIn,
1010 VARIANT* pvaOut)
1011 {
1012 HRESULT hRet = E_FAIL;
1013
1014 TRACE("(%p,%p,%d,%d,%p,%p)\n",lpUnknown, pguidCmdGroup, nCmdID,
1015 nCmdexecopt, pvaIn, pvaOut);
1016
1017 if (lpUnknown)
1018 {
1019 IOleCommandTarget* lpOle;
1020
1021 hRet = IUnknown_QueryInterface(lpUnknown, &IID_IOleCommandTarget,
1022 (void**)&lpOle);
1023 if (SUCCEEDED(hRet) && lpOle)
1024 {
1025 hRet = IOleCommandTarget_Exec(lpOle, pguidCmdGroup, nCmdID,
1026 nCmdexecopt, pvaIn, pvaOut);
1027 IOleCommandTarget_Release(lpOle);
1028 }
1029 }
1030 return hRet;
1031 }
1032
1033 /*************************************************************************
1034 * @ [SHLWAPI.165]
1035 *
1036 * Retrieve, modify, and re-set a value from a window.
1037 *
1038 * PARAMS
1039 * hWnd [I] Window to get value from
1040 * offset [I] Offset of value
1041 * mask [I] Mask for flags
1042 * flags [I] Bits to set in window value
1043 *
1044 * RETURNS
1045 * The new value as it was set, or 0 if any parameter is invalid.
1046 *
1047 * NOTES
1048 * Only bits specified in mask are affected - set if present in flags and
1049 * reset otherwise.
1050 */
1051 LONG WINAPI SHSetWindowBits(HWND hwnd, INT offset, UINT mask, UINT flags)
1052 {
1053 LONG ret = GetWindowLongW(hwnd, offset);
1054 LONG new_flags = (flags & mask) | (ret & ~mask);
1055
1056 TRACE("%p %d %x %x\n", hwnd, offset, mask, flags);
1057
1058 if (new_flags != ret)
1059 ret = SetWindowLongW(hwnd, offset, new_flags);
1060 return ret;
1061 }
1062
1063 /*************************************************************************
1064 * @ [SHLWAPI.167]
1065 *
1066 * Change a window's parent.
1067 *
1068 * PARAMS
1069 * hWnd [I] Window to change parent of
1070 * hWndParent [I] New parent window
1071 *
1072 * RETURNS
1073 * The old parent of hWnd.
1074 *
1075 * NOTES
1076 * If hWndParent is NULL (desktop), the window style is changed to WS_POPUP.
1077 * If hWndParent is NOT NULL then we set the WS_CHILD style.
1078 */
1079 HWND WINAPI SHSetParentHwnd(HWND hWnd, HWND hWndParent)
1080 {
1081 TRACE("%p, %p\n", hWnd, hWndParent);
1082
1083 if(GetParent(hWnd) == hWndParent)
1084 return NULL;
1085
1086 if(hWndParent)
1087 SHSetWindowBits(hWnd, GWL_STYLE, WS_CHILD | WS_POPUP, WS_CHILD);
1088 else
1089 SHSetWindowBits(hWnd, GWL_STYLE, WS_CHILD | WS_POPUP, WS_POPUP);
1090
1091 return hWndParent ? SetParent(hWnd, hWndParent) : NULL;
1092 }
1093
1094 /*************************************************************************
1095 * @ [SHLWAPI.168]
1096 *
1097 * Locate and advise a connection point in an IConnectionPointContainer object.
1098 *
1099 * PARAMS
1100 * lpUnkSink [I] Sink for the connection point advise call
1101 * riid [I] REFIID of connection point to advise
1102 * fConnect [I] TRUE = Connection being establisted, FALSE = broken
1103 * lpUnknown [I] Object supporting the IConnectionPointContainer interface
1104 * lpCookie [O] Pointer to connection point cookie
1105 * lppCP [O] Destination for the IConnectionPoint found
1106 *
1107 * RETURNS
1108 * Success: S_OK. If lppCP is non-NULL, it is filled with the IConnectionPoint
1109 * that was advised. The caller is responsible for releasing it.
1110 * Failure: E_FAIL, if any arguments are invalid.
1111 * E_NOINTERFACE, if lpUnknown isn't an IConnectionPointContainer,
1112 * Or an HRESULT error code if any call fails.
1113 */
1114 HRESULT WINAPI ConnectToConnectionPoint(IUnknown* lpUnkSink, REFIID riid, BOOL fConnect,
1115 IUnknown* lpUnknown, LPDWORD lpCookie,
1116 IConnectionPoint **lppCP)
1117 {
1118 HRESULT hRet;
1119 IConnectionPointContainer* lpContainer;
1120 IConnectionPoint *lpCP;
1121
1122 if(!lpUnknown || (fConnect && !lpUnkSink))
1123 return E_FAIL;
1124
1125 if(lppCP)
1126 *lppCP = NULL;
1127
1128 hRet = IUnknown_QueryInterface(lpUnknown, &IID_IConnectionPointContainer,
1129 (void**)&lpContainer);
1130 if (SUCCEEDED(hRet))
1131 {
1132 hRet = IConnectionPointContainer_FindConnectionPoint(lpContainer, riid, &lpCP);
1133
1134 if (SUCCEEDED(hRet))
1135 {
1136 if(!fConnect)
1137 hRet = IConnectionPoint_Unadvise(lpCP, *lpCookie);
1138 else
1139 hRet = IConnectionPoint_Advise(lpCP, lpUnkSink, lpCookie);
1140
1141 if (FAILED(hRet))
1142 *lpCookie = 0;
1143
1144 if (lppCP && SUCCEEDED(hRet))
1145 *lppCP = lpCP; /* Caller keeps the interface */
1146 else
1147 IConnectionPoint_Release(lpCP); /* Release it */
1148 }
1149
1150 IConnectionPointContainer_Release(lpContainer);
1151 }
1152 return hRet;
1153 }
1154
1155 /*************************************************************************
1156 * @ [SHLWAPI.169]
1157 *
1158 * Release an interface and zero a supplied pointer.
1159 *
1160 * PARAMS
1161 * lpUnknown [I] Object to release
1162 *
1163 * RETURNS
1164 * Nothing.
1165 */
1166 void WINAPI IUnknown_AtomicRelease(IUnknown ** lpUnknown)
1167 {
1168 TRACE("(%p)\n", lpUnknown);
1169
1170 if(!lpUnknown || !*lpUnknown) return;
1171
1172 TRACE("doing Release\n");
1173
1174 IUnknown_Release(*lpUnknown);
1175 *lpUnknown = NULL;
1176 }
1177
1178 /*************************************************************************
1179 * @ [SHLWAPI.170]
1180 *
1181 * Skip '//' if present in a string.
1182 *
1183 * PARAMS
1184 * lpszSrc [I] String to check for '//'
1185 *
1186 * RETURNS
1187 * Success: The next character after the '//' or the string if not present
1188 * Failure: NULL, if lpszStr is NULL.
1189 */
1190 LPCSTR WINAPI PathSkipLeadingSlashesA(LPCSTR lpszSrc)
1191 {
1192 if (lpszSrc && lpszSrc[0] == '/' && lpszSrc[1] == '/')
1193 lpszSrc += 2;
1194 return lpszSrc;
1195 }
1196
1197 /*************************************************************************
1198 * @ [SHLWAPI.171]
1199 *
1200 * Check if two interfaces come from the same object.
1201 *
1202 * PARAMS
1203 * lpInt1 [I] Interface to check against lpInt2.
1204 * lpInt2 [I] Interface to check against lpInt1.
1205 *
1206 * RETURNS
1207 * TRUE, If the interfaces come from the same object.
1208 * FALSE Otherwise.
1209 */
1210 BOOL WINAPI SHIsSameObject(IUnknown* lpInt1, IUnknown* lpInt2)
1211 {
1212 IUnknown *lpUnknown1, *lpUnknown2;
1213 BOOL ret;
1214
1215 TRACE("(%p %p)\n", lpInt1, lpInt2);
1216
1217 if (!lpInt1 || !lpInt2)
1218 return FALSE;
1219
1220 if (lpInt1 == lpInt2)
1221 return TRUE;
1222
1223 if (IUnknown_QueryInterface(lpInt1, &IID_IUnknown, (void**)&lpUnknown1) != S_OK)
1224 return FALSE;
1225
1226 if (IUnknown_QueryInterface(lpInt2, &IID_IUnknown, (void**)&lpUnknown2) != S_OK)
1227 {
1228 IUnknown_Release(lpUnknown1);
1229 return FALSE;
1230 }
1231
1232 ret = lpUnknown1 == lpUnknown2;
1233
1234 IUnknown_Release(lpUnknown1);
1235 IUnknown_Release(lpUnknown2);
1236
1237 return ret;
1238 }
1239
1240 /*************************************************************************
1241 * @ [SHLWAPI.172]
1242 *
1243 * Get the window handle of an object.
1244 *
1245 * PARAMS
1246 * lpUnknown [I] Object to get the window handle of
1247 * lphWnd [O] Destination for window handle
1248 *
1249 * RETURNS
1250 * Success: S_OK. lphWnd contains the objects window handle.
1251 * Failure: An HRESULT error code.
1252 *
1253 * NOTES
1254 * lpUnknown is expected to support one of the following interfaces:
1255 * IOleWindow(), IInternetSecurityMgrSite(), or IShellView().
1256 */
1257 HRESULT WINAPI IUnknown_GetWindow(IUnknown *lpUnknown, HWND *lphWnd)
1258 {
1259 IUnknown *lpOle;
1260 HRESULT hRet = E_FAIL;
1261
1262 TRACE("(%p,%p)\n", lpUnknown, lphWnd);
1263
1264 if (!lpUnknown)
1265 return hRet;
1266
1267 hRet = IUnknown_QueryInterface(lpUnknown, &IID_IOleWindow, (void**)&lpOle);
1268
1269 if (FAILED(hRet))
1270 {
1271 hRet = IUnknown_QueryInterface(lpUnknown,&IID_IShellView, (void**)&lpOle);
1272
1273 if (FAILED(hRet))
1274 {
1275 hRet = IUnknown_QueryInterface(lpUnknown, &IID_IInternetSecurityMgrSite,
1276 (void**)&lpOle);
1277 }
1278 }
1279
1280 if (SUCCEEDED(hRet))
1281 {
1282 /* Laziness here - Since GetWindow() is the first method for the above 3
1283 * interfaces, we use the same call for them all.
1284 */
1285 hRet = IOleWindow_GetWindow((IOleWindow*)lpOle, lphWnd);
1286 IUnknown_Release(lpOle);
1287 if (lphWnd)
1288 TRACE("Returning HWND=%p\n", *lphWnd);
1289 }
1290
1291 return hRet;
1292 }
1293
1294 /*************************************************************************
1295 * @ [SHLWAPI.173]
1296 *
1297 * Call a SetOwner method of IShellService from specified object.
1298 *
1299 * PARAMS
1300 * iface [I] Object that supports IShellService
1301 * pUnk [I] Argument for the SetOwner call
1302 *
1303 * RETURNS
1304 * Corresponding return value from last call or E_FAIL for null input
1305 */
1306 HRESULT WINAPI IUnknown_SetOwner(IUnknown *iface, IUnknown *pUnk)
1307 {
1308 IShellService *service;
1309 HRESULT hr;
1310
1311 TRACE("(%p, %p)\n", iface, pUnk);
1312
1313 if (!iface) return E_FAIL;
1314
1315 hr = IUnknown_QueryInterface(iface, &IID_IShellService, (void**)&service);
1316 if (hr == S_OK)
1317 {
1318 hr = IShellService_SetOwner(service, pUnk);
1319 IShellService_Release(service);
1320 }
1321
1322 return hr;
1323 }
1324
1325 /*************************************************************************
1326 * @ [SHLWAPI.174]
1327 *
1328 * Call either IObjectWithSite_SetSite() or IInternetSecurityManager_SetSecuritySite() on
1329 * an object.
1330 *
1331 */
1332 HRESULT WINAPI IUnknown_SetSite(
1333 IUnknown *obj, /* [in] OLE object */
1334 IUnknown *site) /* [in] Site interface */
1335 {
1336 HRESULT hr;
1337 IObjectWithSite *iobjwithsite;
1338 IInternetSecurityManager *isecmgr;
1339
1340 if (!obj) return E_FAIL;
1341
1342 hr = IUnknown_QueryInterface(obj, &IID_IObjectWithSite, (LPVOID *)&iobjwithsite);
1343 TRACE("IID_IObjectWithSite QI ret=%08x, %p\n", hr, iobjwithsite);
1344 if (SUCCEEDED(hr))
1345 {
1346 hr = IObjectWithSite_SetSite(iobjwithsite, site);
1347 TRACE("done IObjectWithSite_SetSite ret=%08x\n", hr);
1348 IObjectWithSite_Release(iobjwithsite);
1349 }
1350 else
1351 {
1352 hr = IUnknown_QueryInterface(obj, &IID_IInternetSecurityManager, (LPVOID *)&isecmgr);
1353 TRACE("IID_IInternetSecurityManager QI ret=%08x, %p\n", hr, isecmgr);
1354 if (FAILED(hr)) return hr;
1355
1356 hr = IInternetSecurityManager_SetSecuritySite(isecmgr, (IInternetSecurityMgrSite *)site);
1357 TRACE("done IInternetSecurityManager_SetSecuritySite ret=%08x\n", hr);
1358 IInternetSecurityManager_Release(isecmgr);
1359 }
1360 return hr;
1361 }
1362
1363 /*************************************************************************
1364 * @ [SHLWAPI.175]
1365 *
1366 * Call IPersist_GetClassID() on an object.
1367 *
1368 * PARAMS
1369 * lpUnknown [I] Object supporting the IPersist interface
1370 * clsid [O] Destination for Class Id
1371 *
1372 * RETURNS
1373 * Success: S_OK. lpClassId contains the Class Id requested.
1374 * Failure: E_FAIL, If lpUnknown is NULL,
1375 * E_NOINTERFACE If lpUnknown does not support IPersist,
1376 * Or an HRESULT error code.
1377 */
1378 HRESULT WINAPI IUnknown_GetClassID(IUnknown *lpUnknown, CLSID *clsid)
1379 {
1380 IPersist *persist;
1381 HRESULT hr;
1382
1383 TRACE("(%p, %p)\n", lpUnknown, clsid);
1384
1385 if (!lpUnknown)
1386 {
1387 memset(clsid, 0, sizeof(*clsid));
1388 return E_FAIL;
1389 }
1390
1391 hr = IUnknown_QueryInterface(lpUnknown, &IID_IPersist, (void**)&persist);
1392 if (hr != S_OK)
1393 {
1394 hr = IUnknown_QueryInterface(lpUnknown, &IID_IPersistFolder, (void**)&persist);
1395 if (hr != S_OK)
1396 return hr;
1397 }
1398
1399 hr = IPersist_GetClassID(persist, clsid);
1400 IPersist_Release(persist);
1401 return hr;
1402 }
1403
1404 /*************************************************************************
1405 * @ [SHLWAPI.176]
1406 *
1407 * Retrieve a Service Interface from an object.
1408 *
1409 * PARAMS
1410 * lpUnknown [I] Object to get an IServiceProvider interface from
1411 * sid [I] Service ID for IServiceProvider_QueryService() call
1412 * riid [I] Function requested for QueryService call
1413 * lppOut [O] Destination for the service interface pointer
1414 *
1415 * RETURNS
1416 * Success: S_OK. lppOut contains an object providing the requested service
1417 * Failure: An HRESULT error code
1418 *
1419 * NOTES
1420 * lpUnknown is expected to support the IServiceProvider interface.
1421 */
1422 HRESULT WINAPI IUnknown_QueryService(IUnknown* lpUnknown, REFGUID sid, REFIID riid,
1423 LPVOID *lppOut)
1424 {
1425 IServiceProvider* pService = NULL;
1426 HRESULT hRet;
1427
1428 if (!lppOut)
1429 return E_FAIL;
1430
1431 *lppOut = NULL;
1432
1433 if (!lpUnknown)
1434 return E_FAIL;
1435
1436 hRet = IUnknown_QueryInterface(lpUnknown, &IID_IServiceProvider,
1437 (LPVOID*)&pService);
1438
1439 if (hRet == S_OK && pService)
1440 {
1441 TRACE("QueryInterface returned (IServiceProvider*)%p\n", pService);
1442
1443 /* Get a Service interface from the object */
1444 hRet = IServiceProvider_QueryService(pService, sid, riid, lppOut);
1445
1446 TRACE("(IServiceProvider*)%p returned (IUnknown*)%p\n", pService, *lppOut);
1447
1448 IServiceProvider_Release(pService);
1449 }
1450 return hRet;
1451 }
1452
1453 /*************************************************************************
1454 * @ [SHLWAPI.484]
1455 *
1456 * Calls IOleCommandTarget::Exec() for specified service object.
1457 *
1458 * PARAMS
1459 * lpUnknown [I] Object to get an IServiceProvider interface from
1460 * service [I] Service ID for IServiceProvider_QueryService() call
1461 * group [I] Group ID for IOleCommandTarget::Exec() call
1462 * cmdId [I] Command ID for IOleCommandTarget::Exec() call
1463 * cmdOpt [I] Options flags for command
1464 * pIn [I] Input arguments for command
1465 * pOut [O] Output arguments for command
1466 *
1467 * RETURNS
1468 * Success: S_OK. lppOut contains an object providing the requested service
1469 * Failure: An HRESULT error code
1470 *
1471 * NOTES
1472 * lpUnknown is expected to support the IServiceProvider interface.
1473 */
1474 HRESULT WINAPI IUnknown_QueryServiceExec(IUnknown *lpUnknown, REFIID service,
1475 const GUID *group, DWORD cmdId, DWORD cmdOpt, VARIANT *pIn, VARIANT *pOut)
1476 {
1477 IOleCommandTarget *target;
1478 HRESULT hr;
1479
1480 TRACE("%p %s %s %d %08x %p %p\n", lpUnknown, debugstr_guid(service),
1481 debugstr_guid(group), cmdId, cmdOpt, pIn, pOut);
1482
1483 hr = IUnknown_QueryService(lpUnknown, service, &IID_IOleCommandTarget, (void**)&target);
1484 if (hr == S_OK)
1485 {
1486 hr = IOleCommandTarget_Exec(target, group, cmdId, cmdOpt, pIn, pOut);
1487 IOleCommandTarget_Release(target);
1488 }
1489
1490 TRACE("<-- hr=0x%08x\n", hr);
1491
1492 return hr;
1493 }
1494
1495 /*************************************************************************
1496 * @ [SHLWAPI.514]
1497 *
1498 * Calls IProfferService methods to proffer/revoke specified service.
1499 *
1500 * PARAMS
1501 * lpUnknown [I] Object to get an IServiceProvider interface from
1502 * service [I] Service ID for IProfferService::Proffer/Revoke calls
1503 * pService [I] Service to proffer. If NULL ::Revoke is called
1504 * pCookie [IO] Group ID for IOleCommandTarget::Exec() call
1505 *
1506 * RETURNS
1507 * Success: S_OK. IProffer method returns S_OK
1508 * Failure: An HRESULT error code
1509 *
1510 * NOTES
1511 * lpUnknown is expected to support the IServiceProvider interface.
1512 */
1513 HRESULT WINAPI IUnknown_ProfferService(IUnknown *lpUnknown, REFGUID service, IServiceProvider *pService, DWORD *pCookie)
1514 {
1515 IProfferService *proffer;
1516 HRESULT hr;
1517
1518 TRACE("%p %s %p %p\n", lpUnknown, debugstr_guid(service), pService, pCookie);
1519
1520 hr = IUnknown_QueryService(lpUnknown, &IID_IProfferService, &IID_IProfferService, (void**)&proffer);
1521 if (hr == S_OK)
1522 {
1523 if (pService)
1524 hr = IProfferService_ProfferService(proffer, service, pService, pCookie);
1525 else
1526 {
1527 hr = IProfferService_RevokeService(proffer, *pCookie);
1528 *pCookie = 0;
1529 }
1530
1531 IProfferService_Release(proffer);
1532 }
1533
1534 return hr;
1535 }
1536
1537 /*************************************************************************
1538 * @ [SHLWAPI.479]
1539 *
1540 * Call an object's UIActivateIO method.
1541 *
1542 * PARAMS
1543 * unknown [I] Object to call the UIActivateIO method on
1544 * activate [I] Parameter for UIActivateIO call
1545 * msg [I] Parameter for UIActivateIO call
1546 *
1547 * RETURNS
1548 * Success: Value of UI_ActivateIO call
1549 * Failure: An HRESULT error code
1550 *
1551 * NOTES
1552 * unknown is expected to support the IInputObject interface.
1553 */
1554 HRESULT WINAPI IUnknown_UIActivateIO(IUnknown *unknown, BOOL activate, LPMSG msg)
1555 {
1556 IInputObject* object = NULL;
1557 HRESULT ret;
1558
1559 if (!unknown)
1560 return E_FAIL;
1561
1562 /* Get an IInputObject interface from the object */
1563 ret = IUnknown_QueryInterface(unknown, &IID_IInputObject, (LPVOID*) &object);
1564
1565 if (ret == S_OK)
1566 {
1567 ret = IInputObject_UIActivateIO(object, activate, msg);
1568 IInputObject_Release(object);
1569 }
1570
1571 return ret;
1572 }
1573
1574 /*************************************************************************
1575 * @ [SHLWAPI.177]
1576 *
1577 * Loads a popup menu.
1578 *
1579 * PARAMS
1580 * hInst [I] Instance handle
1581 * szName [I] Menu name
1582 *
1583 * RETURNS
1584 * Success: TRUE.
1585 * Failure: FALSE.
1586 */
1587 BOOL WINAPI SHLoadMenuPopup(HINSTANCE hInst, LPCWSTR szName)
1588 {
1589 HMENU hMenu;
1590
1591 TRACE("%p %s\n", hInst, debugstr_w(szName));
1592
1593 if ((hMenu = LoadMenuW(hInst, szName)))
1594 {
1595 if (GetSubMenu(hMenu, 0))
1596 RemoveMenu(hMenu, 0, MF_BYPOSITION);
1597
1598 DestroyMenu(hMenu);
1599 return TRUE;
1600 }
1601 return FALSE;
1602 }
1603
1604 typedef struct _enumWndData
1605 {
1606 UINT uiMsgId;
1607 WPARAM wParam;
1608 LPARAM lParam;
1609 LRESULT (WINAPI *pfnPost)(HWND,UINT,WPARAM,LPARAM);
1610 } enumWndData;
1611
1612 /* Callback for SHLWAPI_178 */
1613 static BOOL CALLBACK SHLWAPI_EnumChildProc(HWND hWnd, LPARAM lParam)
1614 {
1615 enumWndData *data = (enumWndData *)lParam;
1616
1617 TRACE("(%p,%p)\n", hWnd, data);
1618 data->pfnPost(hWnd, data->uiMsgId, data->wParam, data->lParam);
1619 return TRUE;
1620 }
1621
1622 /*************************************************************************
1623 * @ [SHLWAPI.178]
1624 *
1625 * Send or post a message to every child of a window.
1626 *
1627 * PARAMS
1628 * hWnd [I] Window whose children will get the messages
1629 * uiMsgId [I] Message Id
1630 * wParam [I] WPARAM of message
1631 * lParam [I] LPARAM of message
1632 * bSend [I] TRUE = Use SendMessageA(), FALSE = Use PostMessageA()
1633 *
1634 * RETURNS
1635 * Nothing.
1636 *
1637 * NOTES
1638 * The appropriate ASCII or Unicode function is called for the window.
1639 */
1640 void WINAPI SHPropagateMessage(HWND hWnd, UINT uiMsgId, WPARAM wParam, LPARAM lParam, BOOL bSend)
1641 {
1642 enumWndData data;
1643
1644 TRACE("(%p,%u,%ld,%ld,%d)\n", hWnd, uiMsgId, wParam, lParam, bSend);
1645
1646 if(hWnd)
1647 {
1648 data.uiMsgId = uiMsgId;
1649 data.wParam = wParam;
1650 data.lParam = lParam;
1651
1652 if (bSend)
1653 data.pfnPost = IsWindowUnicode(hWnd) ? (void*)SendMessageW : (void*)SendMessageA;
1654 else
1655 data.pfnPost = IsWindowUnicode(hWnd) ? (void*)PostMessageW : (void*)PostMessageA;
1656
1657 EnumChildWindows(hWnd, SHLWAPI_EnumChildProc, (LPARAM)&data);
1658 }
1659 }
1660
1661 /*************************************************************************
1662 * @ [SHLWAPI.180]
1663 *
1664 * Remove all sub-menus from a menu.
1665 *
1666 * PARAMS
1667 * hMenu [I] Menu to remove sub-menus from
1668 *
1669 * RETURNS
1670 * Success: 0. All sub-menus under hMenu are removed
1671 * Failure: -1, if any parameter is invalid
1672 */
1673 DWORD WINAPI SHRemoveAllSubMenus(HMENU hMenu)
1674 {
1675 int iItemCount = GetMenuItemCount(hMenu) - 1;
1676
1677 TRACE("%p\n", hMenu);
1678
1679 while (iItemCount >= 0)
1680 {
1681 HMENU hSubMenu = GetSubMenu(hMenu, iItemCount);
1682 if (hSubMenu)
1683 RemoveMenu(hMenu, iItemCount, MF_BYPOSITION);
1684 iItemCount--;
1685 }
1686 return iItemCount;
1687 }
1688
1689 /*************************************************************************
1690 * @ [SHLWAPI.181]
1691 *
1692 * Enable or disable a menu item.
1693 *
1694 * PARAMS
1695 * hMenu [I] Menu holding menu item
1696 * uID [I] ID of menu item to enable/disable
1697 * bEnable [I] Whether to enable (TRUE) or disable (FALSE) the item.
1698 *
1699 * RETURNS
1700 * The return code from EnableMenuItem.
1701 */
1702 UINT WINAPI SHEnableMenuItem(HMENU hMenu, UINT wItemID, BOOL bEnable)
1703 {
1704 TRACE("%p, %u, %d\n", hMenu, wItemID, bEnable);
1705 return EnableMenuItem(hMenu, wItemID, bEnable ? MF_ENABLED : MF_GRAYED);
1706 }
1707
1708 /*************************************************************************
1709 * @ [SHLWAPI.182]
1710 *
1711 * Check or uncheck a menu item.
1712 *
1713 * PARAMS
1714 * hMenu [I] Menu holding menu item
1715 * uID [I] ID of menu item to check/uncheck
1716 * bCheck [I] Whether to check (TRUE) or uncheck (FALSE) the item.
1717 *
1718 * RETURNS
1719 * The return code from CheckMenuItem.
1720 */
1721 DWORD WINAPI SHCheckMenuItem(HMENU hMenu, UINT uID, BOOL bCheck)
1722 {
1723 TRACE("%p, %u, %d\n", hMenu, uID, bCheck);
1724 return CheckMenuItem(hMenu, uID, bCheck ? MF_CHECKED : MF_UNCHECKED);
1725 }
1726
1727 /*************************************************************************
1728 * @ [SHLWAPI.183]
1729 *
1730 * Register a window class if it isn't already.
1731 *
1732 * PARAMS
1733 * lpWndClass [I] Window class to register
1734 *
1735 * RETURNS
1736 * The result of the RegisterClassA call.
1737 */
1738 DWORD WINAPI SHRegisterClassA(WNDCLASSA *wndclass)
1739 {
1740 WNDCLASSA wca;
1741 if (GetClassInfoA(wndclass->hInstance, wndclass->lpszClassName, &wca))
1742 return TRUE;
1743 return (DWORD)RegisterClassA(wndclass);
1744 }
1745
1746 /*************************************************************************
1747 * @ [SHLWAPI.186]
1748 */
1749 BOOL WINAPI SHSimulateDrop(IDropTarget *pDrop, IDataObject *pDataObj,
1750 DWORD grfKeyState, PPOINTL lpPt, DWORD* pdwEffect)
1751 {
1752 DWORD dwEffect = DROPEFFECT_LINK | DROPEFFECT_MOVE | DROPEFFECT_COPY;
1753 POINTL pt = { 0, 0 };
1754
1755 TRACE("%p %p 0x%08x %p %p\n", pDrop, pDataObj, grfKeyState, lpPt, pdwEffect);
1756
1757 if (!lpPt)
1758 lpPt = &pt;
1759
1760 if (!pdwEffect)
1761 pdwEffect = &dwEffect;
1762
1763 IDropTarget_DragEnter(pDrop, pDataObj, grfKeyState, *lpPt, pdwEffect);
1764
1765 if (*pdwEffect != DROPEFFECT_NONE)
1766 return IDropTarget_Drop(pDrop, pDataObj, grfKeyState, *lpPt, pdwEffect);
1767
1768 IDropTarget_DragLeave(pDrop);
1769 return TRUE;
1770 }
1771
1772 /*************************************************************************
1773 * @ [SHLWAPI.187]
1774 *
1775 * Call IPersistPropertyBag_Load() on an object.
1776 *
1777 * PARAMS
1778 * lpUnknown [I] Object supporting the IPersistPropertyBag interface
1779 * lpPropBag [O] Destination for loaded IPropertyBag
1780 *
1781 * RETURNS
1782 * Success: S_OK.
1783 * Failure: An HRESULT error code, or E_FAIL if lpUnknown is NULL.
1784 */
1785 DWORD WINAPI SHLoadFromPropertyBag(IUnknown *lpUnknown, IPropertyBag* lpPropBag)
1786 {
1787 IPersistPropertyBag* lpPPBag;
1788 HRESULT hRet = E_FAIL;
1789
1790 TRACE("(%p,%p)\n", lpUnknown, lpPropBag);
1791
1792 if (lpUnknown)
1793 {
1794 hRet = IUnknown_QueryInterface(lpUnknown, &IID_IPersistPropertyBag,
1795 (void**)&lpPPBag);
1796 if (SUCCEEDED(hRet) && lpPPBag)
1797 {
1798 hRet = IPersistPropertyBag_Load(lpPPBag, lpPropBag, NULL);
1799 IPersistPropertyBag_Release(lpPPBag);
1800 }
1801 }
1802 return hRet;
1803 }
1804
1805 /*************************************************************************
1806 * @ [SHLWAPI.188]
1807 *
1808 * Call IOleControlSite_TranslateAccelerator() on an object.
1809 *
1810 * PARAMS
1811 * lpUnknown [I] Object supporting the IOleControlSite interface.
1812 * lpMsg [I] Key message to be processed.
1813 * dwModifiers [I] Flags containing the state of the modifier keys.
1814 *
1815 * RETURNS
1816 * Success: S_OK.
1817 * Failure: An HRESULT error code, or E_INVALIDARG if lpUnknown is NULL.
1818 */
1819 HRESULT WINAPI IUnknown_TranslateAcceleratorOCS(IUnknown *lpUnknown, LPMSG lpMsg, DWORD dwModifiers)
1820 {
1821 IOleControlSite* lpCSite = NULL;
1822 HRESULT hRet = E_INVALIDARG;
1823
1824 TRACE("(%p,%p,0x%08x)\n", lpUnknown, lpMsg, dwModifiers);
1825 if (lpUnknown)
1826 {
1827 hRet = IUnknown_QueryInterface(lpUnknown, &IID_IOleControlSite,
1828 (void**)&lpCSite);
1829 if (SUCCEEDED(hRet) && lpCSite)
1830 {
1831 hRet = IOleControlSite_TranslateAccelerator(lpCSite, lpMsg, dwModifiers);
1832 IOleControlSite_Release(lpCSite);
1833 }
1834 }
1835 return hRet;
1836 }
1837
1838
1839 /*************************************************************************
1840 * @ [SHLWAPI.189]
1841 *
1842 * Call IOleControlSite_OnFocus() on an object.
1843 *
1844 * PARAMS
1845 * lpUnknown [I] Object supporting the IOleControlSite interface.
1846 * fGotFocus [I] Whether focus was gained (TRUE) or lost (FALSE).
1847 *
1848 * RETURNS
1849 * Success: S_OK.
1850 * Failure: An HRESULT error code, or E_FAIL if lpUnknown is NULL.
1851 */
1852 HRESULT WINAPI IUnknown_OnFocusOCS(IUnknown *lpUnknown, BOOL fGotFocus)
1853 {
1854 IOleControlSite* lpCSite = NULL;
1855 HRESULT hRet = E_FAIL;
1856
1857 TRACE("(%p, %d)\n", lpUnknown, fGotFocus);
1858 if (lpUnknown)
1859 {
1860 hRet = IUnknown_QueryInterface(lpUnknown, &IID_IOleControlSite,
1861 (void**)&lpCSite);
1862 if (SUCCEEDED(hRet) && lpCSite)
1863 {
1864 hRet = IOleControlSite_OnFocus(lpCSite, fGotFocus);
1865 IOleControlSite_Release(lpCSite);
1866 }
1867 }
1868 return hRet;
1869 }
1870
1871 /*************************************************************************
1872 * @ [SHLWAPI.190]
1873 */
1874 HRESULT WINAPI IUnknown_HandleIRestrict(LPUNKNOWN lpUnknown, PVOID lpArg1,
1875 PVOID lpArg2, PVOID lpArg3, PVOID lpArg4)
1876 {
1877 /* FIXME: {D12F26B2-D90A-11D0-830D-00AA005B4383} - What object does this represent? */
1878 static const DWORD service_id[] = { 0xd12f26b2, 0x11d0d90a, 0xaa000d83, 0x83435b00 };
1879 /* FIXME: {D12F26B1-D90A-11D0-830D-00AA005B4383} - Also Unknown/undocumented */
1880 static const DWORD function_id[] = { 0xd12f26b1, 0x11d0d90a, 0xaa000d83, 0x83435b00 };
1881 HRESULT hRet = E_INVALIDARG;
1882 LPUNKNOWN lpUnkInner = NULL; /* FIXME: Real type is unknown */
1883
1884 TRACE("(%p,%p,%p,%p,%p)\n", lpUnknown, lpArg1, lpArg2, lpArg3, lpArg4);
1885
1886 if (lpUnknown && lpArg4)
1887 {
1888 hRet = IUnknown_QueryService(lpUnknown, (REFGUID)service_id,
1889 (REFGUID)function_id, (void**)&lpUnkInner);
1890
1891 if (SUCCEEDED(hRet) && lpUnkInner)
1892 {
1893 /* FIXME: The type of service object requested is unknown, however
1894 * testing shows that its first method is called with 4 parameters.
1895 * Fake this by using IParseDisplayName_ParseDisplayName since the
1896 * signature and position in the vtable matches our unknown object type.
1897 */
1898 hRet = IParseDisplayName_ParseDisplayName((LPPARSEDISPLAYNAME)lpUnkInner,
1899 lpArg1, lpArg2, lpArg3, lpArg4);
1900 IUnknown_Release(lpUnkInner);
1901 }
1902 }
1903 return hRet;
1904 }
1905
1906 /*************************************************************************
1907 * @ [SHLWAPI.192]
1908 *
1909 * Get a sub-menu from a menu item.
1910 *
1911 * PARAMS
1912 * hMenu [I] Menu to get sub-menu from
1913 * uID [I] ID of menu item containing sub-menu
1914 *
1915 * RETURNS
1916 * The sub-menu of the item, or a NULL handle if any parameters are invalid.
1917 */
1918 HMENU WINAPI SHGetMenuFromID(HMENU hMenu, UINT uID)
1919 {
1920 MENUITEMINFOW mi;
1921
1922 TRACE("(%p,%u)\n", hMenu, uID);
1923
1924 mi.cbSize = sizeof(mi);
1925 mi.fMask = MIIM_SUBMENU;
1926
1927 if (!GetMenuItemInfoW(hMenu, uID, FALSE, &mi))
1928 return NULL;
1929
1930 return mi.hSubMenu;
1931 }
1932
1933 /*************************************************************************
1934 * @ [SHLWAPI.193]
1935 *
1936 * Get the color depth of the primary display.
1937 *
1938 * PARAMS
1939 * None.
1940 *
1941 * RETURNS
1942 * The color depth of the primary display.
1943 */
1944 DWORD WINAPI SHGetCurColorRes(void)
1945 {
1946 HDC hdc;
1947 DWORD ret;
1948
1949 TRACE("()\n");
1950
1951 hdc = GetDC(0);
1952 ret = GetDeviceCaps(hdc, BITSPIXEL) * GetDeviceCaps(hdc, PLANES);
1953 ReleaseDC(0, hdc);
1954 return ret;
1955 }
1956
1957 /*************************************************************************
1958 * @ [SHLWAPI.194]
1959 *
1960 * Wait for a message to arrive, with a timeout.
1961 *
1962 * PARAMS
1963 * hand [I] Handle to query
1964 * dwTimeout [I] Timeout in ticks or INFINITE to never timeout
1965 *
1966 * RETURNS
1967 * STATUS_TIMEOUT if no message is received before dwTimeout ticks passes.
1968 * Otherwise returns the value from MsgWaitForMultipleObjectsEx when a
1969 * message is available.
1970 */
1971 DWORD WINAPI SHWaitForSendMessageThread(HANDLE hand, DWORD dwTimeout)
1972 {
1973 DWORD dwEndTicks = GetTickCount() + dwTimeout;
1974 DWORD dwRet;
1975
1976 while ((dwRet = MsgWaitForMultipleObjectsEx(1, &hand, dwTimeout, QS_SENDMESSAGE, 0)) == 1)
1977 {
1978 MSG msg;
1979
1980 PeekMessageW(&msg, NULL, 0, 0, PM_NOREMOVE);
1981
1982 if (dwTimeout != INFINITE)
1983 {
1984 if ((int)(dwTimeout = dwEndTicks - GetTickCount()) <= 0)
1985 return WAIT_TIMEOUT;
1986 }
1987 }
1988
1989 return dwRet;
1990 }
1991
1992 /*************************************************************************
1993 * @ [SHLWAPI.195]
1994 *
1995 * Determine if a shell folder can be expanded.
1996 *
1997 * PARAMS
1998 * lpFolder [I] Parent folder containing the object to test.
1999 * pidl [I] Id of the object to test.
2000 *
2001 * RETURNS
2002 * Success: S_OK, if the object is expandable, S_FALSE otherwise.
2003 * Failure: E_INVALIDARG, if any argument is invalid.
2004 *
2005 * NOTES
2006 * If the object to be tested does not expose the IQueryInfo() interface it
2007 * will not be identified as an expandable folder.
2008 */
2009 HRESULT WINAPI SHIsExpandableFolder(LPSHELLFOLDER lpFolder, LPCITEMIDLIST pidl)
2010 {
2011 HRESULT hRet = E_INVALIDARG;
2012 IQueryInfo *lpInfo;
2013
2014 if (lpFolder && pidl)
2015 {
2016 hRet = IShellFolder_GetUIObjectOf(lpFolder, NULL, 1, &pidl, &IID_IQueryInfo,
2017 NULL, (void**)&lpInfo);
2018 if (FAILED(hRet))
2019 hRet = S_FALSE; /* Doesn't expose IQueryInfo */
2020 else
2021 {
2022 DWORD dwFlags = 0;
2023
2024 /* MSDN states of IQueryInfo_GetInfoFlags() that "This method is not
2025 * currently used". Really? You wouldn't be holding out on me would you?
2026 */
2027 hRet = IQueryInfo_GetInfoFlags(lpInfo, &dwFlags);
2028
2029 if (SUCCEEDED(hRet))
2030 {
2031 /* 0x2 is an undocumented flag apparently indicating expandability */
2032 hRet = dwFlags & 0x2 ? S_OK : S_FALSE;
2033 }
2034
2035 IQueryInfo_Release(lpInfo);
2036 }
2037 }
2038 return hRet;
2039 }
2040
2041 /*************************************************************************
2042 * @ [SHLWAPI.197]
2043 *
2044 * Blank out a region of text by drawing the background only.
2045 *
2046 * PARAMS
2047 * hDC [I] Device context to draw in
2048 * pRect [I] Area to draw in
2049 * cRef [I] Color to draw in
2050 *
2051 * RETURNS
2052 * Nothing.
2053 */
2054 DWORD WINAPI SHFillRectClr(HDC hDC, LPCRECT pRect, COLORREF cRef)
2055 {
2056 COLORREF cOldColor = SetBkColor(hDC, cRef);
2057 ExtTextOutA(hDC, 0, 0, ETO_OPAQUE, pRect, 0, 0, 0);
2058 SetBkColor(hDC, cOldColor);
2059 return 0;
2060 }
2061
2062 /*************************************************************************
2063 * @ [SHLWAPI.198]
2064 *
2065 * Return the value associated with a key in a map.
2066 *
2067 * PARAMS
2068 * lpKeys [I] A list of keys of length iLen
2069 * lpValues [I] A list of values associated with lpKeys, of length iLen
2070 * iLen [I] Length of both lpKeys and lpValues
2071 * iKey [I] The key value to look up in lpKeys
2072 *
2073 * RETURNS
2074 * The value in lpValues associated with iKey, or -1 if iKey is not
2075 * found in lpKeys.
2076 *
2077 * NOTES
2078 * - If two elements in the map share the same key, this function returns
2079 * the value closest to the start of the map
2080 * - The native version of this function crashes if lpKeys or lpValues is NULL.
2081 */
2082 int WINAPI SHSearchMapInt(const int *lpKeys, const int *lpValues, int iLen, int iKey)
2083 {
2084 if (lpKeys && lpValues)
2085 {
2086 int i = 0;
2087
2088 while (i < iLen)
2089 {
2090 if (lpKeys[i] == iKey)
2091 return lpValues[i]; /* Found */
2092 i++;
2093 }
2094 }
2095 return -1; /* Not found */
2096 }
2097
2098
2099 /*************************************************************************
2100 * @ [SHLWAPI.199]
2101 *
2102 * Copy an interface pointer
2103 *
2104 * PARAMS
2105 * lppDest [O] Destination for copy
2106 * lpUnknown [I] Source for copy
2107 *
2108 * RETURNS
2109 * Nothing.
2110 */
2111 VOID WINAPI IUnknown_Set(IUnknown **lppDest, IUnknown *lpUnknown)
2112 {
2113 TRACE("(%p,%p)\n", lppDest, lpUnknown);
2114
2115 IUnknown_AtomicRelease(lppDest);
2116
2117 if (lpUnknown)
2118 {
2119 IUnknown_AddRef(lpUnknown);
2120 *lppDest = lpUnknown;
2121 }
2122 }
2123
2124 /*************************************************************************
2125 * @ [SHLWAPI.200]
2126 *
2127 */
2128 HRESULT WINAPI MayQSForward(IUnknown* lpUnknown, PVOID lpReserved,
2129 REFGUID riidCmdGrp, ULONG cCmds,
2130 OLECMD *prgCmds, OLECMDTEXT* pCmdText)
2131 {
2132 FIXME("(%p,%p,%p,%d,%p,%p) - stub\n",
2133 lpUnknown, lpReserved, riidCmdGrp, cCmds, prgCmds, pCmdText);
2134
2135 /* FIXME: Calls IsQSForward & IUnknown_QueryStatus */
2136 return DRAGDROP_E_NOTREGISTERED;
2137 }
2138
2139 /*************************************************************************
2140 * @ [SHLWAPI.201]
2141 *
2142 */
2143 HRESULT WINAPI MayExecForward(IUnknown* lpUnknown, INT iUnk, REFGUID pguidCmdGroup,
2144 DWORD nCmdID, DWORD nCmdexecopt, VARIANT* pvaIn,
2145 VARIANT* pvaOut)
2146 {
2147 FIXME("(%p,%d,%p,%d,%d,%p,%p) - stub!\n", lpUnknown, iUnk, pguidCmdGroup,
2148 nCmdID, nCmdexecopt, pvaIn, pvaOut);
2149 return DRAGDROP_E_NOTREGISTERED;
2150 }
2151
2152 /*************************************************************************
2153 * @ [SHLWAPI.202]
2154 *
2155 */
2156 HRESULT WINAPI IsQSForward(REFGUID pguidCmdGroup,ULONG cCmds, OLECMD *prgCmds)
2157 {
2158 FIXME("(%p,%d,%p) - stub!\n", pguidCmdGroup, cCmds, prgCmds);
2159 return DRAGDROP_E_NOTREGISTERED;
2160 }
2161
2162 /*************************************************************************
2163 * @ [SHLWAPI.204]
2164 *
2165 * Determine if a window is not a child of another window.
2166 *
2167 * PARAMS
2168 * hParent [I] Suspected parent window
2169 * hChild [I] Suspected child window
2170 *
2171 * RETURNS
2172 * TRUE: If hChild is a child window of hParent
2173 * FALSE: If hChild is not a child window of hParent, or they are equal
2174 */
2175 BOOL WINAPI SHIsChildOrSelf(HWND hParent, HWND hChild)
2176 {
2177 TRACE("(%p,%p)\n", hParent, hChild);
2178
2179 if (!hParent || !hChild)
2180 return TRUE;
2181 else if(hParent == hChild)
2182 return FALSE;
2183 return !IsChild(hParent, hChild);
2184 }
2185
2186 /*************************************************************************
2187 * FDSA functions. Manage a dynamic array of fixed size memory blocks.
2188 */
2189
2190 typedef struct
2191 {
2192 DWORD num_items; /* Number of elements inserted */
2193 void *mem; /* Ptr to array */
2194 DWORD blocks_alloced; /* Number of elements allocated */
2195 BYTE inc; /* Number of elements to grow by when we need to expand */
2196 BYTE block_size; /* Size in bytes of an element */
2197 BYTE flags; /* Flags */
2198 } FDSA_info;
2199
2200 #define FDSA_FLAG_INTERNAL_ALLOC 0x01 /* When set we have allocated mem internally */
2201
2202 /*************************************************************************
2203 * @ [SHLWAPI.208]
2204 *
2205 * Initialize an FDSA array.
2206 */
2207 BOOL WINAPI FDSA_Initialize(DWORD block_size, DWORD inc, FDSA_info *info, void *mem,
2208 DWORD init_blocks)
2209 {
2210 TRACE("(0x%08x 0x%08x %p %p 0x%08x)\n", block_size, inc, info, mem, init_blocks);
2211
2212 if(inc == 0)
2213 inc = 1;
2214
2215 if(mem)
2216 memset(mem, 0, block_size * init_blocks);
2217
2218 info->num_items = 0;
2219 info->inc = inc;
2220 info->mem = mem;
2221 info->blocks_alloced = init_blocks;
2222 info->block_size = block_size;
2223 info->flags = 0;
2224
2225 return TRUE;
2226 }
2227
2228 /*************************************************************************
2229 * @ [SHLWAPI.209]
2230 *
2231 * Destroy an FDSA array
2232 */
2233 BOOL WINAPI FDSA_Destroy(FDSA_info *info)
2234 {
2235 TRACE("(%p)\n", info);
2236
2237 if(info->flags & FDSA_FLAG_INTERNAL_ALLOC)
2238 {
2239 HeapFree(GetProcessHeap(), 0, info->mem);
2240 return FALSE;
2241 }
2242
2243 return TRUE;
2244 }
2245
2246 /*************************************************************************
2247 * @ [SHLWAPI.210]
2248 *
2249 * Insert element into an FDSA array
2250 */
2251 DWORD WINAPI FDSA_InsertItem(FDSA_info *info, DWORD where, const void *block)
2252 {
2253 TRACE("(%p 0x%08x %p)\n", info, where, block);
2254 if(where > info->num_items)
2255 where = info->num_items;
2256
2257 if(info->num_items >= info->blocks_alloced)
2258 {
2259 DWORD size = (info->blocks_alloced + info->inc) * info->block_size;
2260 if(info->flags & 0x1)
2261 info->mem = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, info->mem, size);
2262 else
2263 {
2264 void *old_mem = info->mem;
2265 info->mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
2266 memcpy(info->mem, old_mem, info->blocks_alloced * info->block_size);
2267 }
2268 info->blocks_alloced += info->inc;
2269 info->flags |= 0x1;
2270 }
2271
2272 if(where < info->num_items)
2273 {
2274 memmove((char*)info->mem + (where + 1) * info->block_size,
2275 (char*)info->mem + where * info->block_size,
2276 (info->num_items - where) * info->block_size);
2277 }
2278 memcpy((char*)info->mem + where * info->block_size, block, info->block_size);
2279
2280 info->num_items++;
2281 return where;
2282 }
2283
2284 /*************************************************************************
2285 * @ [SHLWAPI.211]
2286 *
2287 * Delete an element from an FDSA array.
2288 */
2289 BOOL WINAPI FDSA_DeleteItem(FDSA_info *info, DWORD where)
2290 {
2291 TRACE("(%p 0x%08x)\n", info, where);
2292
2293 if(where >= info->num_items)
2294 return FALSE;
2295
2296 if(where < info->num_items - 1)
2297 {
2298 memmove((char*)info->mem + where * info->block_size,
2299 (char*)info->mem + (where + 1) * info->block_size,
2300 (info->num_items - where - 1) * info->block_size);
2301 }
2302 memset((char*)info->mem + (info->num_items - 1) * info->block_size,
2303 0, info->block_size);
2304 info->num_items--;
2305 return TRUE;
2306 }
2307
2308 /*************************************************************************
2309 * @ [SHLWAPI.219]
2310 *
2311 * Call IUnknown_QueryInterface() on a table of objects.
2312 *
2313 * RETURNS
2314 * Success: S_OK.
2315 * Failure: E_POINTER or E_NOINTERFACE.
2316 */
2317 HRESULT WINAPI QISearch(
2318 void *base, /* [in] Table of interfaces */
2319 const QITAB *table, /* [in] Array of REFIIDs and indexes into the table */
2320 REFIID riid, /* [in] REFIID to get interface for */
2321 void **ppv) /* [out] Destination for interface pointer */
2322 {
2323 HRESULT ret;
2324 IUnknown *a_vtbl;
2325 const QITAB *xmove;
2326
2327 TRACE("(%p %p %s %p)\n", base, table, debugstr_guid(riid), ppv);
2328 if (ppv) {
2329 xmove = table;
2330 while (xmove->piid) {
2331 TRACE("trying (offset %d) %s\n", xmove->dwOffset, debugstr_guid(xmove->piid));
2332 if (IsEqualIID(riid, xmove->piid)) {
2333 a_vtbl = (IUnknown*)(xmove->dwOffset + (LPBYTE)base);
2334 TRACE("matched, returning (%p)\n", a_vtbl);
2335 *ppv = a_vtbl;
2336 IUnknown_AddRef(a_vtbl);
2337 return S_OK;
2338 }
2339 xmove++;
2340 }
2341
2342 if (IsEqualIID(riid, &IID_IUnknown)) {
2343 a_vtbl = (IUnknown*)(table->dwOffset + (LPBYTE)base);
2344 TRACE("returning first for IUnknown (%p)\n", a_vtbl);
2345 *ppv = a_vtbl;
2346 IUnknown_AddRef(a_vtbl);
2347 return S_OK;
2348 }
2349 *ppv = 0;
2350 ret = E_NOINTERFACE;
2351 } else
2352 ret = E_POINTER;
2353
2354 TRACE("-- 0x%08x\n", ret);
2355 return ret;
2356 }
2357
2358 /*************************************************************************
2359 * @ [SHLWAPI.220]
2360 *
2361 * Set the Font for a window and the "PropDlgFont" property of the parent window.
2362 *
2363 * PARAMS
2364 * hWnd [I] Parent Window to set the property
2365 * id [I] Index of child Window to set the Font
2366 *
2367 * RETURNS
2368 * Success: S_OK
2369 *
2370 */
2371 HRESULT WINAPI SHSetDefaultDialogFont(HWND hWnd, INT id)
2372 {
2373 FIXME("(%p, %d) stub\n", hWnd, id);
2374 return S_OK;
2375 }
2376
2377 /*************************************************************************
2378 * @ [SHLWAPI.221]
2379 *
2380 * Remove the "PropDlgFont" property from a window.
2381 *
2382 * PARAMS
2383 * hWnd [I] Window to remove the property from
2384 *
2385 * RETURNS
2386 * A handle to the removed property, or NULL if it did not exist.
2387 */
2388 HANDLE WINAPI SHRemoveDefaultDialogFont(HWND hWnd)
2389 {
2390 HANDLE hProp;
2391
2392 TRACE("(%p)\n", hWnd);
2393
2394 hProp = GetPropA(hWnd, "PropDlgFont");
2395
2396 if(hProp)
2397 {
2398 DeleteObject(hProp);
2399 hProp = RemovePropA(hWnd, "PropDlgFont");
2400 }
2401 return hProp;
2402 }
2403
2404 /*************************************************************************
2405 * @ [SHLWAPI.236]
2406 *
2407 * Load the in-process server of a given GUID.
2408 *
2409 * PARAMS
2410 * refiid [I] GUID of the server to load.
2411 *
2412 * RETURNS
2413 * Success: A handle to the loaded server dll.
2414 * Failure: A NULL handle.
2415 */
2416 HMODULE WINAPI SHPinDllOfCLSID(REFIID refiid)
2417 {
2418 HKEY newkey;
2419 DWORD type, count;
2420 CHAR value[MAX_PATH], string[MAX_PATH];
2421
2422 strcpy(string, "CLSID\\");
2423 SHStringFromGUIDA(refiid, string + 6, sizeof(string)/sizeof(char) - 6);
2424 strcat(string, "\\InProcServer32");
2425
2426 count = MAX_PATH;
2427 RegOpenKeyExA(HKEY_CLASSES_ROOT, string, 0, 1, &newkey);
2428 RegQueryValueExA(newkey, 0, 0, &type, (PBYTE)value, &count);
2429 RegCloseKey(newkey);
2430 return LoadLibraryExA(value, 0, 0);
2431 }
2432
2433 /*************************************************************************
2434 * @ [SHLWAPI.237]
2435 *
2436 * Unicode version of SHLWAPI_183.
2437 */
2438 DWORD WINAPI SHRegisterClassW(WNDCLASSW * lpWndClass)
2439 {
2440 WNDCLASSW WndClass;
2441
2442 TRACE("(%p %s)\n",lpWndClass->hInstance, debugstr_w(lpWndClass->lpszClassName));
2443
2444 if (GetClassInfoW(lpWndClass->hInstance, lpWndClass->lpszClassName, &WndClass))
2445 return TRUE;
2446 return RegisterClassW(lpWndClass);
2447 }
2448
2449 /*************************************************************************
2450 * @ [SHLWAPI.238]
2451 *
2452 * Unregister a list of classes.
2453 *
2454 * PARAMS
2455 * hInst [I] Application instance that registered the classes
2456 * lppClasses [I] List of class names
2457 * iCount [I] Number of names in lppClasses
2458 *
2459 * RETURNS
2460 * Nothing.
2461 */
2462 void WINAPI SHUnregisterClassesA(HINSTANCE hInst, LPCSTR *lppClasses, INT iCount)
2463 {
2464 WNDCLASSA WndClass;
2465
2466 TRACE("(%p,%p,%d)\n", hInst, lppClasses, iCount);
2467
2468 while (iCount > 0)
2469 {
2470 if (GetClassInfoA(hInst, *lppClasses, &WndClass))
2471 UnregisterClassA(*lppClasses, hInst);
2472 lppClasses++;
2473 iCount--;
2474 }
2475 }
2476
2477 /*************************************************************************
2478 * @ [SHLWAPI.239]
2479 *
2480 * Unicode version of SHUnregisterClassesA.
2481 */
2482 void WINAPI SHUnregisterClassesW(HINSTANCE hInst, LPCWSTR *lppClasses, INT iCount)
2483 {
2484 WNDCLASSW WndClass;
2485
2486 TRACE("(%p,%p,%d)\n", hInst, lppClasses, iCount);
2487
2488 while (iCount > 0)
2489 {
2490 if (GetClassInfoW(hInst, *lppClasses, &WndClass))
2491 UnregisterClassW(*lppClasses, hInst);
2492 lppClasses++;
2493 iCount--;
2494 }
2495 }
2496
2497 /*************************************************************************
2498 * @ [SHLWAPI.240]
2499 *
2500 * Call The correct (Ascii/Unicode) default window procedure for a window.
2501 *
2502 * PARAMS
2503 * hWnd [I] Window to call the default procedure for
2504 * uMessage [I] Message ID
2505 * wParam [I] WPARAM of message
2506 * lParam [I] LPARAM of message
2507 *
2508 * RETURNS
2509 * The result of calling DefWindowProcA() or DefWindowProcW().
2510 */
2511 LRESULT CALLBACK SHDefWindowProc(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
2512 {
2513 if (IsWindowUnicode(hWnd))
2514 return DefWindowProcW(hWnd, uMessage, wParam, lParam);
2515 return DefWindowProcA(hWnd, uMessage, wParam, lParam);
2516 }
2517
2518 /*************************************************************************
2519 * @ [SHLWAPI.256]
2520 */
2521 HRESULT WINAPI IUnknown_GetSite(LPUNKNOWN lpUnknown, REFIID iid, PVOID *lppSite)
2522 {
2523 HRESULT hRet = E_INVALIDARG;
2524 LPOBJECTWITHSITE lpSite = NULL;
2525
2526 TRACE("(%p,%s,%p)\n", lpUnknown, debugstr_guid(iid), lppSite);
2527
2528 if (lpUnknown && iid && lppSite)
2529 {
2530 hRet = IUnknown_QueryInterface(lpUnknown, &IID_IObjectWithSite,
2531 (void**)&lpSite);
2532 if (SUCCEEDED(hRet) && lpSite)
2533 {
2534 hRet = IObjectWithSite_GetSite(lpSite, iid, lppSite);
2535 IObjectWithSite_Release(lpSite);
2536 }
2537 }
2538 return hRet;
2539 }
2540
2541 /*************************************************************************
2542 * @ [SHLWAPI.257]
2543 *
2544 * Create a worker window using CreateWindowExA().
2545 *
2546 * PARAMS
2547 * wndProc [I] Window procedure
2548 * hWndParent [I] Parent window
2549 * dwExStyle [I] Extra style flags
2550 * dwStyle [I] Style flags
2551 * hMenu [I] Window menu
2552 * wnd_extra [I] Window extra bytes value
2553 *
2554 * RETURNS
2555 * Success: The window handle of the newly created window.
2556 * Failure: 0.
2557 */
2558 HWND WINAPI SHCreateWorkerWindowA(WNDPROC wndProc, HWND hWndParent, DWORD dwExStyle,
2559 DWORD dwStyle, HMENU hMenu, LONG_PTR wnd_extra)
2560 {
2561 static const char szClass[] = "WorkerA";
2562 WNDCLASSA wc;
2563 HWND hWnd;
2564
2565 TRACE("(%p, %p, 0x%08x, 0x%08x, %p, 0x%08lx)\n",
2566 wndProc, hWndParent, dwExStyle, dwStyle, hMenu, wnd_extra);
2567
2568 /* Create Window class */
2569 wc.style = 0;
2570 wc.lpfnWndProc = DefWindowProcA;
2571 wc.cbClsExtra = 0;
2572 wc.cbWndExtra = sizeof(LONG_PTR);
2573 wc.hInstance = shlwapi_hInstance;
2574 wc.hIcon = NULL;
2575 wc.hCursor = LoadCursorA(NULL, (LPSTR)IDC_ARROW);
2576 wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
2577 wc.lpszMenuName = NULL;
2578 wc.lpszClassName = szClass;
2579
2580 SHRegisterClassA(&wc);
2581
2582 hWnd = CreateWindowExA(dwExStyle, szClass, 0, dwStyle, 0, 0, 0, 0,
2583 hWndParent, hMenu, shlwapi_hInstance, 0);
2584 if (hWnd)
2585 {
2586 SetWindowLongPtrW(hWnd, 0, wnd_extra);
2587 if (wndProc) SetWindowLongPtrA(hWnd, GWLP_WNDPROC, (LONG_PTR)wndProc);
2588 }
2589
2590 return hWnd;
2591 }
2592
2593 typedef struct tagPOLICYDATA
2594 {
2595 DWORD policy; /* flags value passed to SHRestricted */
2596 LPCWSTR appstr; /* application str such as "Explorer" */
2597 LPCWSTR keystr; /* name of the actual registry key / policy */
2598 } POLICYDATA, *LPPOLICYDATA;
2599
2600 #define SHELL_NO_POLICY 0xffffffff
2601
2602 /* default shell policy registry key */
2603 static const WCHAR strRegistryPolicyW[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o',
2604 's','o','f','t','\\','W','i','n','d','o','w','s','\\',
2605 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',
2606 '\\','P','o','l','i','c','i','e','s',0};
2607
2608 /*************************************************************************
2609 * @ [SHLWAPI.271]
2610 *
2611 * Retrieve a policy value from the registry.
2612 *
2613 * PARAMS
2614 * lpSubKey [I] registry key name
2615 * lpSubName [I] subname of registry key
2616 * lpValue [I] value name of registry value
2617 *
2618 * RETURNS
2619 * the value associated with the registry key or 0 if not found
2620 */
2621 DWORD WINAPI SHGetRestriction(LPCWSTR lpSubKey, LPCWSTR lpSubName, LPCWSTR lpValue)
2622 {
2623 DWORD retval, datsize = sizeof(retval);
2624 HKEY hKey;
2625
2626 if (!lpSubKey)
2627 lpSubKey = strRegistryPolicyW;
2628
2629 retval = RegOpenKeyW(HKEY_LOCAL_MACHINE, lpSubKey, &hKey);
2630 if (retval != ERROR_SUCCESS)
2631 retval = RegOpenKeyW(HKEY_CURRENT_USER, lpSubKey, &hKey);
2632 if (retval != ERROR_SUCCESS)
2633 return 0;
2634
2635 SHGetValueW(hKey, lpSubName, lpValue, NULL, &retval, &datsize);
2636 RegCloseKey(hKey);
2637 return retval;
2638 }
2639
2640 /*************************************************************************
2641 * @ [SHLWAPI.266]
2642 *
2643 * Helper function to retrieve the possibly cached value for a specific policy
2644 *
2645 * PARAMS
2646 * policy [I] The policy to look for
2647 * initial [I] Main registry key to open, if NULL use default
2648 * polTable [I] Table of known policies, 0 terminated
2649 * polArr [I] Cache array of policy values
2650 *
2651 * RETURNS
2652 * The retrieved policy value or 0 if not successful
2653 *
2654 * NOTES
2655 * This function is used by the native SHRestricted function to search for the
2656 * policy and cache it once retrieved. The current Wine implementation uses a
2657 * different POLICYDATA structure and implements a similar algorithm adapted to
2658 * that structure.
2659 */
2660 DWORD WINAPI SHRestrictionLookup(
2661 DWORD policy,
2662 LPCWSTR initial,
2663 LPPOLICYDATA polTable,
2664 LPDWORD polArr)
2665 {
2666 TRACE("(0x%08x %s %p %p)\n", policy, debugstr_w(initial), polTable, polArr);
2667
2668 if (!polTable || !polArr)
2669 return 0;
2670
2671 for (;polTable->policy; polTable++, polArr++)
2672 {
2673 if (policy == polTable->policy)
2674 {
2675 /* we have a known policy */
2676
2677 /* check if this policy has been cached */
2678 if (*polArr == SHELL_NO_POLICY)
2679 *polArr = SHGetRestriction(initial, polTable->appstr, polTable->keystr);
2680 return *polArr;
2681 }
2682 }
2683 /* we don't know this policy, return 0 */
2684 TRACE("unknown policy: (%08x)\n", policy);
2685 return 0;
2686 }
2687
2688 /*************************************************************************
2689 * @ [SHLWAPI.267]
2690 *
2691 * Get an interface from an object.
2692 *
2693 * RETURNS
2694 * Success: S_OK. ppv contains the requested interface.
2695 * Failure: An HRESULT error code.
2696 *
2697 * NOTES
2698 * This QueryInterface asks the inner object for an interface. In case
2699 * of aggregation this request would be forwarded by the inner to the
2700 * outer object. This function asks the inner object directly for the
2701 * interface circumventing the forwarding to the outer object.
2702 */
2703 HRESULT WINAPI SHWeakQueryInterface(
2704 IUnknown * pUnk, /* [in] Outer object */
2705 IUnknown * pInner, /* [in] Inner object */
2706 IID * riid, /* [in] Interface GUID to query for */
2707 LPVOID* ppv) /* [out] Destination for queried interface */
2708 {
2709 HRESULT hret = E_NOINTERFACE;
2710 TRACE("(pUnk=%p pInner=%p\n\tIID: %s %p)\n",pUnk,pInner,debugstr_guid(riid), ppv);
2711
2712 *ppv = NULL;
2713 if(pUnk && pInner) {
2714 hret = IUnknown_QueryInterface(pInner, riid, ppv);
2715 if (SUCCEEDED(hret)) IUnknown_Release(pUnk);
2716 }
2717 TRACE("-- 0x%08x\n", hret);
2718 return hret;
2719 }
2720
2721 /*************************************************************************
2722 * @ [SHLWAPI.268]
2723 *
2724 * Move a reference from one interface to another.
2725 *
2726 * PARAMS
2727 * lpDest [O] Destination to receive the reference
2728 * lppUnknown [O] Source to give up the reference to lpDest
2729 *
2730 * RETURNS
2731 * Nothing.
2732 */
2733 VOID WINAPI SHWeakReleaseInterface(IUnknown *lpDest, IUnknown **lppUnknown)
2734 {
2735 TRACE("(%p,%p)\n", lpDest, lppUnknown);
2736
2737 if (*lppUnknown)
2738 {
2739 /* Copy Reference*/
2740 IUnknown_AddRef(lpDest);
2741 IUnknown_AtomicRelease(lppUnknown); /* Release existing interface */
2742 }
2743 }
2744
2745 /*************************************************************************
2746 * @ [SHLWAPI.269]
2747 *
2748 * Convert an ASCII string of a CLSID into a CLSID.
2749 *
2750 * PARAMS
2751 * idstr [I] String representing a CLSID in registry format
2752 * id [O] Destination for the converted CLSID
2753 *
2754 * RETURNS
2755 * Success: TRUE. id contains the converted CLSID.
2756 * Failure: FALSE.
2757 */
2758 BOOL WINAPI GUIDFromStringA(LPCSTR idstr, CLSID *id)
2759 {
2760 WCHAR wClsid[40];
2761 MultiByteToWideChar(CP_ACP, 0, idstr, -1, wClsid, sizeof(wClsid)/sizeof(WCHAR));
2762 return SUCCEEDED(CLSIDFromString(wClsid, id));
2763 }
2764
2765 /*************************************************************************
2766 * @ [SHLWAPI.270]
2767 *
2768 * Unicode version of GUIDFromStringA.
2769 */
2770 BOOL WINAPI GUIDFromStringW(LPCWSTR idstr, CLSID *id)
2771 {
2772 return SUCCEEDED(CLSIDFromString((LPCOLESTR)idstr, id));
2773 }
2774
2775 /*************************************************************************
2776 * @ [SHLWAPI.276]
2777 *
2778 * Determine if the browser is integrated into the shell, and set a registry
2779 * key accordingly.
2780 *
2781 * PARAMS
2782 * None.
2783 *
2784 * RETURNS
2785 * 1, If the browser is not integrated.
2786 * 2, If the browser is integrated.
2787 *
2788 * NOTES
2789 * The key "HKLM\Software\Microsoft\Internet Explorer\IntegratedBrowser" is
2790 * either set to TRUE, or removed depending on whether the browser is deemed
2791 * to be integrated.
2792 */
2793 DWORD WINAPI WhichPlatform(void)
2794 {
2795 static const char szIntegratedBrowser[] = "IntegratedBrowser";
2796 static DWORD dwState = 0;
2797 HKEY hKey;
2798 DWORD dwRet, dwData, dwSize;
2799 HMODULE hshell32;
2800
2801 if (dwState)
2802 return dwState;
2803
2804 /* If shell32 exports DllGetVersion(), the browser is integrated */
2805 dwState = 1;
2806 hshell32 = LoadLibraryA("shell32.dll");
2807 if (hshell32)
2808 {
2809 FARPROC pDllGetVersion;
2810 pDllGetVersion = GetProcAddress(hshell32, "DllGetVersion");
2811 dwState = pDllGetVersion ? 2 : 1;
2812 FreeLibrary(hshell32);
2813 }
2814
2815 /* Set or delete the key accordingly */
2816 dwRet = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
2817 "Software\\Microsoft\\Internet Explorer", 0,
2818 KEY_ALL_ACCESS, &hKey);
2819 if (!dwRet)
2820 {
2821 dwRet = RegQueryValueExA(hKey, szIntegratedBrowser, 0, 0,
2822 (LPBYTE)&dwData, &dwSize);
2823
2824 if (!dwRet && dwState == 1)
2825 {
2826 /* Value exists but browser is not integrated */
2827 RegDeleteValueA(hKey, szIntegratedBrowser);
2828 }
2829 else if (dwRet && dwState == 2)
2830 {
2831 /* Browser is integrated but value does not exist */
2832 dwData = TRUE;
2833 RegSetValueExA(hKey, szIntegratedBrowser, 0, REG_DWORD,
2834 (LPBYTE)&dwData, sizeof(dwData));
2835 }
2836 RegCloseKey(hKey);
2837 }
2838 return dwState;
2839 }
2840
2841 /*************************************************************************
2842 * @ [SHLWAPI.278]
2843 *
2844 * Unicode version of SHCreateWorkerWindowA.
2845 */
2846 HWND WINAPI SHCreateWorkerWindowW(WNDPROC wndProc, HWND hWndParent, DWORD dwExStyle,
2847 DWORD dwStyle, HMENU hMenu, LONG_PTR wnd_extra)
2848 {
2849 static const WCHAR szClass[] = { 'W', 'o', 'r', 'k', 'e', 'r', 'W', 0 };
2850 WNDCLASSW wc;
2851 HWND hWnd;
2852
2853 TRACE("(%p, %p, 0x%08x, 0x%08x, %p, 0x%08lx)\n",
2854 wndProc, hWndParent, dwExStyle, dwStyle, hMenu, wnd_extra);
2855
2856 /* If our OS is natively ANSI, use the ANSI version */
2857 if (GetVersion() & 0x80000000) /* not NT */
2858 {
2859 TRACE("fallback to ANSI, ver 0x%08x\n", GetVersion());
2860 return SHCreateWorkerWindowA(wndProc, hWndParent, dwExStyle, dwStyle, hMenu, wnd_extra);
2861 }
2862
2863 /* Create Window class */
2864 wc.style = 0;
2865 wc.lpfnWndProc = DefWindowProcW;
2866 wc.cbClsExtra = 0;
2867 wc.cbWndExtra = sizeof(LONG_PTR);
2868 wc.hInstance = shlwapi_hInstance;
2869 wc.hIcon = NULL;
2870 wc.hCursor = LoadCursorW(NULL, (LPWSTR)IDC_ARROW);
2871 wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
2872 wc.lpszMenuName = NULL;
2873 wc.lpszClassName = szClass;
2874
2875 SHRegisterClassW(&wc);
2876
2877 hWnd = CreateWindowExW(dwExStyle, szClass, 0, dwStyle, 0, 0, 0, 0,
2878 hWndParent, hMenu, shlwapi_hInstance, 0);
2879 if (hWnd)
2880 {
2881 SetWindowLongPtrW(hWnd, 0, wnd_extra);
2882 if (wndProc) SetWindowLongPtrW(hWnd, GWLP_WNDPROC, (LONG_PTR)wndProc);
2883 }
2884
2885 return hWnd;
2886 }
2887
2888 /*************************************************************************
2889 * @ [SHLWAPI.279]
2890 *
2891 * Get and show a context menu from a shell folder.
2892 *
2893 * PARAMS
2894 * hWnd [I] Window displaying the shell folder
2895 * lpFolder [I] IShellFolder interface
2896 * lpApidl [I] Id for the particular folder desired
2897 *
2898 * RETURNS
2899 * Success: S_OK.
2900 * Failure: An HRESULT error code indicating the error.
2901 */
2902 HRESULT WINAPI SHInvokeDefaultCommand(HWND hWnd, IShellFolder* lpFolder, LPCITEMIDLIST lpApidl)
2903 {
2904 TRACE("%p %p %p\n", hWnd, lpFolder, lpApidl);
2905 return SHInvokeCommand(hWnd, lpFolder, lpApidl, 0);
2906 }
2907
2908 /*************************************************************************
2909 * @ [SHLWAPI.281]
2910 *
2911 * _SHPackDispParamsV
2912 */
2913 HRESULT WINAPI SHPackDispParamsV(DISPPARAMS *params, VARIANTARG *args, UINT cnt, __ms_va_list valist)
2914 {
2915 VARIANTARG *iter;
2916
2917 TRACE("(%p %p %u ...)\n", params, args, cnt);
2918
2919 params->rgvarg = args;
2920 params->rgdispidNamedArgs = NULL;
2921 params->cArgs = cnt;
2922 params->cNamedArgs = 0;
2923
2924 iter = args+cnt;
2925
2926 while(iter-- > args) {
2927 V_VT(iter) = va_arg(valist, enum VARENUM);
2928
2929 TRACE("vt=%d\n", V_VT(iter));
2930
2931 if(V_VT(iter) & VT_BYREF) {
2932 V_BYREF(iter) = va_arg(valist, LPVOID);
2933 } else {
2934 switch(V_VT(iter)) {
2935 case VT_I4:
2936 V_I4(iter) = va_arg(valist, LONG);
2937 break;
2938 case VT_BSTR:
2939 V_BSTR(iter) = va_arg(valist, BSTR);
2940 break;
2941 case VT_DISPATCH:
2942 V_DISPATCH(iter) = va_arg(valist, IDispatch*);
2943 break;
2944 case VT_BOOL:
2945 V_BOOL(iter) = va_arg(valist, int);
2946 break;
2947 case VT_UNKNOWN:
2948 V_UNKNOWN(iter) = va_arg(valist, IUnknown*);
2949 break;
2950 default:
2951 V_VT(iter) = VT_I4;
2952 V_I4(iter) = va_arg(valist, LONG);
2953 }
2954 }
2955 }
2956
2957 return S_OK;
2958 }
2959
2960 /*************************************************************************
2961 * @ [SHLWAPI.282]
2962 *
2963 * SHPackDispParams
2964 */
2965 HRESULT WINAPIV SHPackDispParams(DISPPARAMS *params, VARIANTARG *args, UINT cnt, ...)
2966 {
2967 __ms_va_list valist;
2968 HRESULT hres;
2969
2970 __ms_va_start(valist, cnt);
2971 hres = SHPackDispParamsV(params, args, cnt, valist);
2972 __ms_va_end(valist);
2973 return hres;
2974 }
2975
2976 /*************************************************************************
2977 * SHLWAPI_InvokeByIID
2978 *
2979 * This helper function calls IDispatch::Invoke for each sink
2980 * which implements given iid or IDispatch.
2981 *
2982 */
2983 static HRESULT SHLWAPI_InvokeByIID(
2984 IConnectionPoint* iCP,
2985 REFIID iid,
2986 DISPID dispId,
2987 DISPPARAMS* dispParams)
2988 {
2989 IEnumConnections *enumerator;
2990 CONNECTDATA rgcd;
2991 static DISPPARAMS empty = {NULL, NULL, 0, 0};
2992 DISPPARAMS* params = dispParams;
2993
2994 HRESULT result = IConnectionPoint_EnumConnections(iCP, &enumerator);
2995 if (FAILED(result))
2996 return result;
2997
2998 /* Invoke is never happening with an NULL dispParams */
2999 if (!params)
3000 params = &empty;
3001
3002 while(IEnumConnections_Next(enumerator, 1, &rgcd, NULL)==S_OK)
3003 {
3004 IDispatch *dispIface;
3005 if ((iid && SUCCEEDED(IUnknown_QueryInterface(rgcd.pUnk, iid, (LPVOID*)&dispIface))) ||
3006 SUCCEEDED(IUnknown_QueryInterface(rgcd.pUnk, &IID_IDispatch, (LPVOID*)&dispIface)))
3007 {
3008 IDispatch_Invoke(dispIface, dispId, &IID_NULL, 0, DISPATCH_METHOD, params, NULL, NULL, NULL);
3009 IDispatch_Release(dispIface);
3010 }
3011 IUnknown_Release(rgcd.pUnk);
3012 }
3013
3014 IEnumConnections_Release(enumerator);
3015
3016 return S_OK;
3017 }
3018
3019 /*************************************************************************
3020 * IConnectionPoint_InvokeWithCancel [SHLWAPI.283]
3021 */
3022 HRESULT WINAPI IConnectionPoint_InvokeWithCancel( IConnectionPoint* iCP,
3023 DISPID dispId, DISPPARAMS* dispParams,
3024 DWORD unknown1, DWORD unknown2 )
3025 {
3026 IID iid;
3027 HRESULT result;
3028
3029 FIXME("(%p)->(0x%x %p %x %x) partial stub\n", iCP, dispId, dispParams, unknown1, unknown2);
3030
3031 result = IConnectionPoint_GetConnectionInterface(iCP, &iid);
3032 if (SUCCEEDED(result))
3033 result = SHLWAPI_InvokeByIID(iCP, &iid, dispId, dispParams);
3034 else
3035 result = SHLWAPI_InvokeByIID(iCP, NULL, dispId, dispParams);
3036
3037 return result;
3038 }
3039
3040
3041 /*************************************************************************
3042 * @ [SHLWAPI.284]
3043 *
3044 * IConnectionPoint_SimpleInvoke
3045 */
3046 HRESULT WINAPI IConnectionPoint_SimpleInvoke(
3047 IConnectionPoint* iCP,
3048 DISPID dispId,
3049 DISPPARAMS* dispParams)
3050 {
3051 IID iid;
3052 HRESULT result;
3053
3054 TRACE("(%p)->(0x%x %p)\n",iCP,dispId,dispParams);
3055
3056 result = IConnectionPoint_GetConnectionInterface(iCP, &iid);
3057 if (SUCCEEDED(result))
3058 result = SHLWAPI_InvokeByIID(iCP, &iid, dispId, dispParams);
3059 else
3060 result = SHLWAPI_InvokeByIID(iCP, NULL, dispId, dispParams);
3061
3062 return result;
3063 }
3064
3065 /*************************************************************************
3066 * @ [SHLWAPI.285]
3067 *
3068 * Notify an IConnectionPoint object of changes.
3069 *
3070 * PARAMS
3071 * lpCP [I] Object to notify
3072 * dispID [I]
3073 *
3074 * RETURNS
3075 * Success: S_OK.
3076 * Failure: E_NOINTERFACE, if lpCP is NULL or does not support the
3077 * IConnectionPoint interface.
3078 */
3079 HRESULT WINAPI IConnectionPoint_OnChanged(IConnectionPoint* lpCP, DISPID dispID)
3080 {
3081 IEnumConnections *lpEnum;
3082 HRESULT hRet = E_NOINTERFACE;
3083
3084 TRACE("(%p,0x%8X)\n", lpCP, dispID);
3085
3086 /* Get an enumerator for the connections */
3087 if (lpCP)
3088 hRet = IConnectionPoint_EnumConnections(lpCP, &lpEnum);
3089
3090 if (SUCCEEDED(hRet))
3091 {
3092 IPropertyNotifySink *lpSink;
3093 CONNECTDATA connData;
3094 ULONG ulFetched;
3095
3096 /* Call OnChanged() for every notify sink in the connection point */
3097 while (IEnumConnections_Next(lpEnum, 1, &connData, &ulFetched) == S_OK)
3098 {
3099 if (SUCCEEDED(IUnknown_QueryInterface(connData.pUnk, &IID_IPropertyNotifySink, (void**)&lpSink)) &&
3100 lpSink)
3101 {
3102 IPropertyNotifySink_OnChanged(lpSink, dispID);
3103 IPropertyNotifySink_Release(lpSink);
3104 }
3105 IUnknown_Release(connData.pUnk);
3106 }
3107
3108 IEnumConnections_Release(lpEnum);
3109 }
3110 return hRet;
3111 }
3112
3113 /*************************************************************************
3114 * @ [SHLWAPI.286]
3115 *
3116 * IUnknown_CPContainerInvokeParam
3117 */
3118 HRESULT WINAPIV IUnknown_CPContainerInvokeParam(
3119 IUnknown *container,
3120 REFIID riid,
3121 DISPID dispId,
3122 VARIANTARG* buffer,
3123 DWORD cParams, ...)
3124 {
3125 HRESULT result;
3126 IConnectionPoint *iCP;
3127 IConnectionPointContainer *iCPC;
3128 DISPPARAMS dispParams = {buffer, NULL, cParams, 0};
3129 __ms_va_list valist;
3130
3131 if (!container)
3132 return E_NOINTERFACE;
3133
3134 result = IUnknown_QueryInterface(container, &IID_IConnectionPointContainer,(LPVOID*) &iCPC);
3135 if (FAILED(result))
3136 return result;
3137
3138 result = IConnectionPointContainer_FindConnectionPoint(iCPC, riid, &iCP);
3139 IConnectionPointContainer_Release(iCPC);
3140 if(FAILED(result))
3141 return result;
3142
3143 __ms_va_start(valist, cParams);
3144 SHPackDispParamsV(&dispParams, buffer, cParams, valist);
3145 __ms_va_end(valist);
3146
3147 result = SHLWAPI_InvokeByIID(iCP, riid, dispId, &dispParams);
3148 IConnectionPoint_Release(iCP);
3149
3150 return result;
3151 }
3152
3153 /*************************************************************************
3154 * @ [SHLWAPI.287]
3155 *
3156 * Notify an IConnectionPointContainer object of changes.
3157 *
3158 * PARAMS
3159 * lpUnknown [I] Object to notify
3160 * dispID [I]
3161 *
3162 * RETURNS
3163 * Success: S_OK.
3164 * Failure: E_NOINTERFACE, if lpUnknown is NULL or does not support the
3165 * IConnectionPointContainer interface.
3166 */
3167 HRESULT WINAPI IUnknown_CPContainerOnChanged(IUnknown *lpUnknown, DISPID dispID)
3168 {
3169 IConnectionPointContainer* lpCPC = NULL;
3170 HRESULT hRet = E_NOINTERFACE;
3171
3172 TRACE("(%p,0x%8X)\n", lpUnknown, dispID);
3173
3174 if (lpUnknown)
3175 hRet = IUnknown_QueryInterface(lpUnknown, &IID_IConnectionPointContainer, (void**)&lpCPC);
3176
3177 if (SUCCEEDED(hRet))
3178 {
3179 IConnectionPoint* lpCP;
3180
3181 hRet = IConnectionPointContainer_FindConnectionPoint(lpCPC, &IID_IPropertyNotifySink, &lpCP);
3182 IConnectionPointContainer_Release(lpCPC);
3183
3184 hRet = IConnectionPoint_OnChanged(lpCP, dispID);
3185 IConnectionPoint_Release(lpCP);
3186 }
3187 return hRet;
3188 }
3189
3190 /*************************************************************************
3191 * @ [SHLWAPI.289]
3192 *
3193 * See PlaySoundW.
3194 */
3195 BOOL WINAPI PlaySoundWrapW(LPCWSTR pszSound, HMODULE hmod, DWORD fdwSound)
3196 {
3197 return PlaySoundW(pszSound, hmod, fdwSound);
3198 }
3199
3200 /*************************************************************************
3201 * @ [SHLWAPI.294]
3202 *
3203 * Retrieve a key value from an INI file. See GetPrivateProfileString for
3204 * more information.
3205 *
3206 * PARAMS
3207 * appName [I] The section in the INI file that contains the key
3208 * keyName [I] The key to be retrieved
3209 * out [O] The buffer into which the key's value will be copied
3210 * outLen [I] The length of the `out' buffer
3211 * filename [I] The location of the INI file
3212 *
3213 * RETURNS
3214 * Length of string copied into `out'.
3215 */
3216 DWORD WINAPI SHGetIniStringW(LPCWSTR appName, LPCWSTR keyName, LPWSTR out,
3217 DWORD outLen, LPCWSTR filename)
3218 {
3219 INT ret;
3220 WCHAR *buf;
3221
3222 TRACE("(%s,%s,%p,%08x,%s)\n", debugstr_w(appName), debugstr_w(keyName),
3223 out, outLen, debugstr_w(filename));
3224
3225 if(outLen == 0)
3226 return 0;
3227
3228 buf = HeapAlloc(GetProcessHeap(), 0, outLen * sizeof(WCHAR));
3229 if(!buf){
3230 *out = 0;
3231 return 0;
3232 }
3233
3234 ret = GetPrivateProfileStringW(appName, keyName, NULL, buf, outLen, filename);
3235 if(ret)
3236 strcpyW(out, buf);
3237 else
3238 *out = 0;
3239
3240 HeapFree(GetProcessHeap(), 0, buf);
3241
3242 return strlenW(out);
3243 }
3244
3245 /*************************************************************************
3246 * @ [SHLWAPI.295]
3247 *
3248 * Set a key value in an INI file. See WritePrivateProfileString for
3249 * more information.
3250 *
3251 * PARAMS
3252 * appName [I] The section in the INI file that contains the key
3253 * keyName [I] The key to be set
3254 * str [O] The value of the key
3255 * filename [I] The location of the INI file
3256 *
3257 * RETURNS
3258 * Success: TRUE
3259 * Failure: FALSE
3260 */
3261 BOOL WINAPI SHSetIniStringW(LPCWSTR appName, LPCWSTR keyName, LPCWSTR str,
3262 LPCWSTR filename)
3263 {
3264 TRACE("(%s, %p, %s, %s)\n", debugstr_w(appName), keyName, debugstr_w(str),
3265 debugstr_w(filename));
3266
3267 return WritePrivateProfileStringW(appName, keyName, str, filename);
3268 }
3269
3270 /*************************************************************************
3271 * @ [SHLWAPI.313]
3272 *
3273 * See SHGetFileInfoW.
3274 */
3275 DWORD WINAPI SHGetFileInfoWrapW(LPCWSTR path, DWORD dwFileAttributes,
3276 SHFILEINFOW *psfi, UINT sizeofpsfi, UINT flags)
3277 {
3278 return SHGetFileInfoW(path, dwFileAttributes, psfi, sizeofpsfi, flags);
3279 }
3280
3281 /*************************************************************************
3282 * @ [SHLWAPI.318]
3283 *
3284 * See DragQueryFileW.
3285 */
3286 UINT WINAPI DragQueryFileWrapW(HDROP hDrop, UINT lFile, LPWSTR lpszFile, UINT lLength)
3287 {
3288 return DragQueryFileW(hDrop, lFile, lpszFile, lLength);
3289 }
3290
3291 /*************************************************************************
3292 * @ [SHLWAPI.333]
3293 *
3294 * See SHBrowseForFolderW.
3295 */
3296 LPITEMIDLIST WINAPI SHBrowseForFolderWrapW(LPBROWSEINFOW lpBi)
3297 {
3298 return SHBrowseForFolderW(lpBi);
3299 }
3300
3301 /*************************************************************************
3302 * @ [SHLWAPI.334]
3303 *
3304 * See SHGetPathFromIDListW.
3305 */
3306 BOOL WINAPI SHGetPathFromIDListWrapW(LPCITEMIDLIST pidl,LPWSTR pszPath)
3307 {
3308 return SHGetPathFromIDListW(pidl, pszPath);
3309 }
3310
3311 /*************************************************************************
3312 * @ [SHLWAPI.335]
3313 *
3314 * See ShellExecuteExW.
3315 */
3316 BOOL WINAPI ShellExecuteExWrapW(LPSHELLEXECUTEINFOW lpExecInfo)
3317 {
3318 return ShellExecuteExW(lpExecInfo);
3319 }
3320
3321 /*************************************************************************
3322 * @ [SHLWAPI.336]
3323 *
3324 * See SHFileOperationW.
3325 */
3326 INT WINAPI SHFileOperationWrapW(LPSHFILEOPSTRUCTW lpFileOp)
3327 {
3328 return SHFileOperationW(lpFileOp);
3329 }
3330
3331 /*************************************************************************
3332 * @ [SHLWAPI.342]
3333 *
3334 */
3335 PVOID WINAPI SHInterlockedCompareExchange( PVOID *dest, PVOID xchg, PVOID compare )
3336 {
3337 return InterlockedCompareExchangePointer( dest, xchg, compare );
3338 }
3339
3340 /*************************************************************************
3341 * @ [SHLWAPI.350]
3342 *
3343 * See GetFileVersionInfoSizeW.
3344 */
3345 DWORD WINAPI GetFileVersionInfoSizeWrapW( LPCWSTR filename, LPDWORD handle )
3346 {
3347 return GetFileVersionInfoSizeW( filename, handle );
3348 }
3349
3350 /*************************************************************************
3351 * @ [SHLWAPI.351]
3352 *
3353 * See GetFileVersionInfoW.
3354 */
3355 BOOL WINAPI GetFileVersionInfoWrapW( LPCWSTR filename, DWORD handle,
3356 DWORD datasize, LPVOID data )
3357 {
3358 return GetFileVersionInfoW( filename, handle, datasize, data );
3359 }
3360
3361 /*************************************************************************
3362 * @ [SHLWAPI.352]
3363 *
3364 * See VerQueryValueW.
3365 */
3366 WORD WINAPI VerQueryValueWrapW( LPVOID pBlock, LPCWSTR lpSubBlock,
3367 LPVOID *lplpBuffer, UINT *puLen )
3368 {
3369 return VerQueryValueW( pBlock, lpSubBlock, lplpBuffer, puLen );
3370 }
3371
3372 #define IsIface(type) SUCCEEDED((hRet = IUnknown_QueryInterface(lpUnknown, &IID_##type, (void**)&lpObj)))
3373 #define IShellBrowser_EnableModeless IShellBrowser_EnableModelessSB
3374 #define EnableModeless(type) type##_EnableModeless((type*)lpObj, bModeless)
3375
3376 /*************************************************************************
3377 * @ [SHLWAPI.355]
3378 *
3379 * Change the modality of a shell object.
3380 *
3381 * PARAMS
3382 * lpUnknown [I] Object to make modeless
3383 * bModeless [I] TRUE=Make modeless, FALSE=Make modal
3384 *
3385 * RETURNS
3386 * Success: S_OK. The modality lpUnknown is changed.
3387 * Failure: An HRESULT error code indicating the error.
3388 *
3389 * NOTES
3390 * lpUnknown must support the IOleInPlaceFrame interface, the
3391 * IInternetSecurityMgrSite interface, the IShellBrowser interface
3392 * the IDocHostUIHandler interface, or the IOleInPlaceActiveObject interface,
3393 * or this call will fail.
3394 */
3395 HRESULT WINAPI IUnknown_EnableModeless(IUnknown *lpUnknown, BOOL bModeless)
3396 {
3397 IUnknown *lpObj;
3398 HRESULT hRet;
3399
3400 TRACE("(%p,%d)\n", lpUnknown, bModeless);
3401
3402 if (!lpUnknown)
3403 return E_FAIL;
3404
3405 if (IsIface(IOleInPlaceActiveObject))
3406 EnableModeless(IOleInPlaceActiveObject);
3407 else if (IsIface(IOleInPlaceFrame))
3408 EnableModeless(IOleInPlaceFrame);
3409 else if (IsIface(IShellBrowser))
3410 EnableModeless(IShellBrowser);
3411 else if (IsIface(IInternetSecurityMgrSite))
3412 EnableModeless(IInternetSecurityMgrSite);
3413 else if (IsIface(IDocHostUIHandler))
3414 EnableModeless(IDocHostUIHandler);
3415 else
3416 return hRet;
3417
3418 IUnknown_Release(lpObj);
3419 return S_OK;
3420 }
3421
3422 /*************************************************************************
3423 * @ [SHLWAPI.357]
3424 *
3425 * See SHGetNewLinkInfoW.
3426 */
3427 BOOL WINAPI SHGetNewLinkInfoWrapW(LPCWSTR pszLinkTo, LPCWSTR pszDir, LPWSTR pszName,
3428 BOOL *pfMustCopy, UINT uFlags)
3429 {
3430 return SHGetNewLinkInfoW(pszLinkTo, pszDir, pszName, pfMustCopy, uFlags);
3431 }
3432
3433 /*************************************************************************
3434 * @ [SHLWAPI.358]
3435 *
3436 * See SHDefExtractIconW.
3437 */
3438 UINT WINAPI SHDefExtractIconWrapW(LPCWSTR pszIconFile, int iIndex, UINT uFlags, HICON* phiconLarge,
3439 HICON* phiconSmall, UINT nIconSize)
3440 {
3441 return SHDefExtractIconW(pszIconFile, iIndex, uFlags, phiconLarge, phiconSmall, nIconSize);
3442 }
3443
3444 /*************************************************************************
3445 * @ [SHLWAPI.363]
3446 *
3447 * Get and show a context menu from a shell folder.
3448 *
3449 * PARAMS
3450 * hWnd [I] Window displaying the shell folder
3451 * lpFolder [I] IShellFolder interface
3452 * lpApidl [I] Id for the particular folder desired
3453 * dwCommandId [I] The command ID to invoke (0=invoke default)
3454 *
3455 * RETURNS
3456 * Success: S_OK. If bInvokeDefault is TRUE, the default menu action was
3457 * executed.
3458 * Failure: An HRESULT error code indicating the error.
3459 */
3460 HRESULT WINAPI SHInvokeCommand(HWND hWnd, IShellFolder* lpFolder, LPCITEMIDLIST lpApidl, DWORD dwCommandId)
3461 {
3462 IContextMenu *iContext;
3463 HRESULT hRet;
3464
3465 TRACE("(%p, %p, %p, %u)\n", hWnd, lpFolder, lpApidl, dwCommandId);
3466
3467 if (!lpFolder)
3468 return E_FAIL;
3469
3470 /* Get the context menu from the shell folder */
3471 hRet = IShellFolder_GetUIObjectOf(lpFolder, hWnd, 1, &lpApidl,
3472 &IID_IContextMenu, 0, (void**)&iContext);
3473 if (SUCCEEDED(hRet))
3474 {
3475 HMENU hMenu;
3476 if ((hMenu = CreatePopupMenu()))
3477 {
3478 HRESULT hQuery;
3479
3480 /* Add the context menu entries to the popup */
3481 hQuery = IContextMenu_QueryContextMenu(iContext, hMenu, 0, 1, 0x7FFF,
3482 dwCommandId ? CMF_NORMAL : CMF_DEFAULTONLY);
3483
3484 if (SUCCEEDED(hQuery))
3485 {
3486 if (!dwCommandId)
3487 dwCommandId = GetMenuDefaultItem(hMenu, 0, 0);
3488 if (dwCommandId != (UINT)-1)
3489 {
3490 CMINVOKECOMMANDINFO cmIci;
3491 /* Invoke the default item */
3492 memset(&cmIci,0,sizeof(cmIci));
3493 cmIci.cbSize = sizeof(cmIci);
3494 cmIci.fMask = CMIC_MASK_ASYNCOK;
3495 cmIci.hwnd = hWnd;
3496 #ifdef __REACTOS__ /* r75561 */
3497 cmIci.lpVerb = MAKEINTRESOURCEA(dwCommandId - 1);
3498 #else
3499 cmIci.lpVerb = MAKEINTRESOURCEA(dwCommandId);
3500 #endif
3501 cmIci.nShow = SW_SHOWNORMAL;
3502
3503 hRet = IContextMenu_InvokeCommand(iContext, &cmIci);
3504 }
3505 }
3506 DestroyMenu(hMenu);
3507 }
3508 IContextMenu_Release(iContext);
3509 }
3510 return hRet;
3511 }
3512
3513 /*************************************************************************
3514 * @ [SHLWAPI.370]
3515 *
3516 * See ExtractIconW.
3517 */
3518 HICON WINAPI ExtractIconWrapW(HINSTANCE hInstance, LPCWSTR lpszExeFileName,
3519 UINT nIconIndex)
3520 {
3521 return ExtractIconW(hInstance, lpszExeFileName, nIconIndex);
3522 }
3523
3524 /*************************************************************************
3525 * @ [SHLWAPI.377]
3526 *
3527 * Load a library from the directory of a particular process.
3528 *
3529 * PARAMS
3530 * new_mod [I] Library name
3531 * inst_hwnd [I] Module whose directory is to be used
3532 * dwCrossCodePage [I] Should be FALSE (currently ignored)
3533 *
3534 * RETURNS
3535 * Success: A handle to the loaded module
3536 * Failure: A NULL handle.
3537 */
3538 HMODULE WINAPI MLLoadLibraryA(LPCSTR new_mod, HMODULE inst_hwnd, DWORD dwCrossCodePage)
3539 {
3540 /* FIXME: Native appears to do DPA_Create and a DPA_InsertPtr for
3541 * each call here.
3542 * FIXME: Native shows calls to:
3543 * SHRegGetUSValue for "Software\Microsoft\Internet Explorer\International"
3544 * CheckVersion
3545 * RegOpenKeyExA for "HKLM\Software\Microsoft\Internet Explorer"
3546 * RegQueryValueExA for "LPKInstalled"
3547 * RegCloseKey
3548 * RegOpenKeyExA for "HKCU\Software\Microsoft\Internet Explorer\International"
3549 * RegQueryValueExA for "ResourceLocale"
3550 * RegCloseKey
3551 * RegOpenKeyExA for "HKLM\Software\Microsoft\Active Setup\Installed Components\{guid}"
3552 * RegQueryValueExA for "Locale"
3553 * RegCloseKey
3554 * and then tests the Locale ("en" for me).
3555 * code below
3556 * after the code then a DPA_Create (first time) and DPA_InsertPtr are done.
3557 */
3558 CHAR mod_path[2*MAX_PATH];
3559 LPSTR ptr;
3560 DWORD len;
3561
3562 FIXME("(%s,%p,%d) semi-stub!\n", debugstr_a(new_mod), inst_hwnd, dwCrossCodePage);
3563 len = GetModuleFileNameA(inst_hwnd, mod_path, sizeof(mod_path));
3564 if (!len || len >= sizeof(mod_path)) return NULL;
3565
3566 ptr = strrchr(mod_path, '\\');
3567 if (ptr) {
3568 strcpy(ptr+1, new_mod);
3569 TRACE("loading %s\n", debugstr_a(mod_path));
3570 return LoadLibraryA(mod_path);
3571 }
3572 return NULL;
3573 }
3574
3575 /*************************************************************************
3576 * @ [SHLWAPI.378]
3577 *
3578 * Unicode version of MLLoadLibraryA.
3579 */
3580 HMODULE WINAPI MLLoadLibraryW(LPCWSTR new_mod, HMODULE inst_hwnd, DWORD dwCrossCodePage)
3581 {
3582 WCHAR mod_path[2*MAX_PATH];
3583 LPWSTR ptr;
3584 DWORD len;
3585
3586 FIXME("(%s,%p,%d) semi-stub!\n", debugstr_w(new_mod), inst_hwnd, dwCrossCodePage);
3587 len = GetModuleFileNameW(inst_hwnd, mod_path, sizeof(mod_path) / sizeof(WCHAR));
3588 if (!len || len >= sizeof(mod_path) / sizeof(WCHAR)) return NULL;
3589
3590 ptr = strrchrW(mod_path, '\\');
3591 if (ptr) {
3592 strcpyW(ptr+1, new_mod);
3593 TRACE("loading %s\n", debugstr_w(mod_path));
3594 return LoadLibraryW(mod_path);
3595 }
3596 return NULL;
3597 }
3598
3599 /*************************************************************************
3600 * ColorAdjustLuma [SHLWAPI.@]
3601 *
3602 * Adjust the luminosity of a color
3603 *
3604 * PARAMS
3605 * cRGB [I] RGB value to convert
3606 * dwLuma [I] Luma adjustment
3607 * bUnknown [I] Unknown
3608 *
3609 * RETURNS
3610 * The adjusted RGB color.
3611 */
3612 COLORREF WINAPI ColorAdjustLuma(COLORREF cRGB, int dwLuma, BOOL bUnknown)
3613 {
3614 TRACE("(0x%8x,%d,%d)\n", cRGB, dwLuma, bUnknown);
3615
3616 if (dwLuma)
3617 {
3618 WORD wH, wL, wS;
3619
3620 ColorRGBToHLS(cRGB, &wH, &wL, &wS);
3621
3622 FIXME("Ignoring luma adjustment\n");
3623
3624 /* FIXME: The adjustment is not linear */
3625
3626 cRGB = ColorHLSToRGB(wH, wL, wS);
3627 }
3628 return cRGB;
3629 }
3630
3631 /*************************************************************************
3632 * @ [SHLWAPI.389]
3633 *
3634 * See GetSaveFileNameW.
3635 */
3636 BOOL WINAPI GetSaveFileNameWrapW(LPOPENFILENAMEW ofn)
3637 {
3638 return GetSaveFileNameW(ofn);
3639 }
3640
3641 /*************************************************************************
3642 * @ [SHLWAPI.390]
3643 *
3644 * See WNetRestoreConnectionW.
3645 */
3646 DWORD WINAPI WNetRestoreConnectionWrapW(HWND hwndOwner, LPWSTR lpszDevice)
3647 {
3648 return WNetRestoreConnectionW(hwndOwner, lpszDevice);
3649 }
3650
3651 /*************************************************************************
3652 * @ [SHLWAPI.391]
3653 *
3654 * See WNetGetLastErrorW.
3655 */
3656 DWORD WINAPI WNetGetLastErrorWrapW(LPDWORD lpError, LPWSTR lpErrorBuf, DWORD nErrorBufSize,
3657 LPWSTR lpNameBuf, DWORD nNameBufSize)
3658 {
3659 return WNetGetLastErrorW(lpError, lpErrorBuf, nErrorBufSize, lpNameBuf, nNameBufSize);
3660 }
3661
3662 /*************************************************************************
3663 * @ [SHLWAPI.401]
3664 *
3665 * See PageSetupDlgW.
3666 */
3667 BOOL WINAPI PageSetupDlgWrapW(LPPAGESETUPDLGW pagedlg)
3668 {
3669 return PageSetupDlgW(pagedlg);
3670 }
3671
3672 /*************************************************************************
3673 * @ [SHLWAPI.402]
3674 *
3675 * See PrintDlgW.
3676 */
3677 BOOL WINAPI PrintDlgWrapW(LPPRINTDLGW printdlg)
3678 {
3679 return PrintDlgW(printdlg);
3680 }
3681
3682 /*************************************************************************
3683 * @ [SHLWAPI.403]
3684 *
3685 * See GetOpenFileNameW.
3686 */
3687 BOOL WINAPI GetOpenFileNameWrapW(LPOPENFILENAMEW ofn)
3688 {
3689 return GetOpenFileNameW(ofn);
3690 }
3691
3692 /*************************************************************************
3693 * @ [SHLWAPI.404]
3694 */
3695 HRESULT WINAPI SHIShellFolder_EnumObjects(LPSHELLFOLDER lpFolder, HWND hwnd, SHCONTF flags, IEnumIDList **ppenum)
3696 {
3697 /* Windows attempts to get an IPersist interface and, if that fails, an
3698 * IPersistFolder interface on the folder passed-in here. If one of those
3699 * interfaces is available, it then calls GetClassID on the folder... and
3700 * then calls IShellFolder_EnumObjects no matter what, even crashing if
3701 * lpFolder isn't actually an IShellFolder object. The purpose of getting
3702 * the ClassID is unknown, so we don't do it here.
3703 *
3704 * For discussion and detailed tests, see:
3705 * "shlwapi: Be less strict on which type of IShellFolder can be enumerated"
3706 * wine-devel mailing list, 3 Jun 2010
3707 */
3708
3709 return IShellFolder_EnumObjects(lpFolder, hwnd, flags, ppenum);
3710 }
3711
3712 /* INTERNAL: Map from HLS color space to RGB */
3713 static WORD ConvertHue(int wHue, WORD wMid1, WORD wMid2)
3714 {
3715 wHue = wHue > 240 ? wHue - 240 : wHue < 0 ? wHue + 240 : wHue;
3716
3717 if (wHue > 160)
3718 return wMid1;
3719 else if (wHue > 120)
3720 wHue = 160 - wHue;
3721 else if (wHue > 40)
3722 return wMid2;
3723
3724 return ((wHue * (wMid2 - wMid1) + 20) / 40) + wMid1;
3725 }
3726
3727 /* Convert to RGB and scale into RGB range (0..255) */
3728 #define GET_RGB(h) (ConvertHue(h, wMid1, wMid2) * 255 + 120) / 240
3729
3730 /*************************************************************************
3731 * ColorHLSToRGB [SHLWAPI.@]
3732 *
3733 * Convert from hls color space into an rgb COLORREF.
3734 *
3735 * PARAMS
3736 * wHue [I] Hue amount
3737 * wLuminosity [I] Luminosity amount
3738 * wSaturation [I] Saturation amount
3739 *
3740 * RETURNS
3741 * A COLORREF representing the converted color.
3742 *
3743 * NOTES
3744 * Input hls values are constrained to the range (0..240).
3745 */
3746 COLORREF WINAPI ColorHLSToRGB(WORD wHue, WORD wLuminosity, WORD wSaturation)
3747 {
3748 WORD wRed;
3749
3750 if (wSaturation)
3751 {
3752 WORD wGreen, wBlue, wMid1, wMid2;
3753
3754 if (wLuminosity > 120)
3755 wMid2 = wSaturation + wLuminosity - (wSaturation * wLuminosity + 120) / 240;
3756 else
3757 wMid2 = ((wSaturation + 240) * wLuminosity + 120) / 240;
3758
3759 wMid1 = wLuminosity * 2 - wMid2;
3760
3761 wRed = GET_RGB(wHue + 80);
3762 wGreen = GET_RGB(wHue);
3763 wBlue = GET_RGB(wHue - 80);
3764
3765 return RGB(wRed, wGreen, wBlue);
3766 }
3767
3768 wRed = wLuminosity * 255 / 240;
3769 return RGB(wRed, wRed, wRed);
3770 }
3771
3772 /*************************************************************************
3773 * @ [SHLWAPI.413]
3774 *
3775 * Get the current docking status of the system.
3776 *
3777 * PARAMS
3778 * dwFlags [I] DOCKINFO_ flags from "winbase.h", unused
3779 *
3780 * RETURNS
3781 * One of DOCKINFO_UNDOCKED, DOCKINFO_UNDOCKED, or 0 if the system is not
3782 * a notebook.
3783 */
3784 DWORD WINAPI SHGetMachineInfo(DWORD dwFlags)
3785 {
3786 HW_PROFILE_INFOA hwInfo;
3787
3788 TRACE("(0x%08x)\n", dwFlags);
3789
3790 GetCurrentHwProfileA(&hwInfo);
3791 switch (hwInfo.dwDockInfo & (DOCKINFO_DOCKED|DOCKINFO_UNDOCKED))
3792 {
3793 case DOCKINFO_DOCKED:
3794 case DOCKINFO_UNDOCKED:
3795 return hwInfo.dwDockInfo & (DOCKINFO_DOCKED|DOCKINFO_UNDOCKED);
3796 default:
3797 return 0;
3798 }
3799 }
3800
3801 /*************************************************************************
3802 * @ [SHLWAPI.416]
3803 *
3804 */
3805 DWORD WINAPI SHWinHelpOnDemandW(HWND hwnd, LPCWSTR helpfile, DWORD flags1, VOID *ptr1, DWORD flags2)
3806 {
3807
3808 FIXME("(%p, %s, 0x%x, %p, %d)\n", hwnd, debugstr_w(helpfile), flags1, ptr1, flags2);
3809 return 0;
3810 }
3811
3812 /*************************************************************************
3813 * @ [SHLWAPI.417]
3814 *
3815 */
3816 DWORD WINAPI SHWinHelpOnDemandA(HWND hwnd, LPCSTR helpfile, DWORD flags1, VOID *ptr1, DWORD flags2)
3817 {
3818
3819 FIXME("(%p, %s, 0x%x, %p, %d)\n", hwnd, debugstr_a(helpfile), flags1, ptr1, flags2);
3820 return 0;
3821 }
3822
3823 /*************************************************************************
3824 * @ [SHLWAPI.418]
3825 *
3826 * Function seems to do FreeLibrary plus other things.
3827 *
3828 * FIXME native shows the following calls:
3829 * RtlEnterCriticalSection
3830 * LocalFree
3831 * GetProcAddress(Comctl32??, 150L)
3832 * DPA_DeletePtr
3833 * RtlLeaveCriticalSection
3834 * followed by the FreeLibrary.
3835 * The above code may be related to .377 above.
3836 */
3837 BOOL WINAPI MLFreeLibrary(HMODULE hModule)
3838 {
3839 FIXME("(%p) semi-stub\n", hModule);
3840 return FreeLibrary(hModule);
3841 }
3842
3843 /*************************************************************************
3844 * @ [SHLWAPI.419]
3845 */
3846 BOOL WINAPI SHFlushSFCacheWrap(void) {
3847 FIXME(": stub\n");
3848 return TRUE;
3849 }
3850
3851 /*************************************************************************
3852 * @ [SHLWAPI.429]
3853 * FIXME I have no idea what this function does or what its arguments are.
3854 */
3855 BOOL WINAPI MLIsMLHInstance(HINSTANCE hInst)
3856 {
3857 FIXME("(%p) stub\n", hInst);
3858 return FALSE;
3859 }
3860
3861
3862 /*************************************************************************
3863 * @ [SHLWAPI.430]
3864 */
3865 DWORD WINAPI MLSetMLHInstance(HINSTANCE hInst, HANDLE hHeap)
3866 {
3867 FIXME("(%p,%p) stub\n", hInst, hHeap);
3868 return E_FAIL; /* This is what is used if shlwapi not loaded */
3869 }
3870
3871 /*************************************************************************
3872 * @ [SHLWAPI.431]
3873 */
3874 DWORD WINAPI MLClearMLHInstance(DWORD x)
3875 {
3876 FIXME("(0x%08x)stub\n", x);
3877 return 0xabba1247;
3878 }
3879
3880 /*************************************************************************
3881 * @ [SHLWAPI.432]
3882 *
3883 * See SHSendMessageBroadcastW
3884 *
3885 */
3886 DWORD WINAPI SHSendMessageBroadcastA(UINT uMsg, WPARAM wParam, LPARAM lParam)
3887 {
3888 return SendMessageTimeoutA(HWND_BROADCAST, uMsg, wParam, lParam,
3889 SMTO_ABORTIFHUNG, 2000, NULL);
3890 }
3891
3892 /*************************************************************************
3893 * @ [SHLWAPI.433]
3894 *
3895 * A wrapper for sending Broadcast Messages to all top level Windows
3896 *
3897 */
3898 DWORD WINAPI SHSendMessageBroadcastW(UINT uMsg, WPARAM wParam, LPARAM lParam)
3899 {
3900 return SendMessageTimeoutW(