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