* Sync up to trunk head (r64829).
[reactos.git] / dll / win32 / shlwapi / ordinal.c
1 /*
2 * SHLWAPI ordinal functions
3 *
4 * Copyright 1997 Marcus Meissner
5 * 1998 Jürgen Schmied
6 * 2001-2003 Jon Griffiths
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 */
22
23 #include "precomp.h"
24
25 #include <stdio.h>
26
27 #include <winver.h>
28 #include <winnetwk.h>
29 #include <mmsystem.h>
30 #include <shdeprecated.h>
31 #include <shellapi.h>
32 #include <commdlg.h>
33 #include <mlang.h>
34 #include <mshtmhst.h>
35
36 /* DLL handles for late bound calls */
37 extern HINSTANCE shlwapi_hInstance;
38 extern DWORD SHLWAPI_ThreadRef_index;
39
40 HRESULT WINAPI IUnknown_QueryService(IUnknown*,REFGUID,REFIID,LPVOID*);
41 HRESULT WINAPI SHInvokeCommand(HWND,IShellFolder*,LPCITEMIDLIST,DWORD);
42 BOOL WINAPI SHAboutInfoW(LPWSTR,DWORD);
43
44 /*
45 NOTES: Most functions exported by ordinal seem to be superfluous.
46 The reason for these functions to be there is to provide a wrapper
47 for unicode functions to provide these functions on systems without
48 unicode functions eg. win95/win98. Since we have such functions we just
49 call these. If running Wine with native DLLs, some late bound calls may
50 fail. However, it is better to implement the functions in the forward DLL
51 and recommend the builtin rather than reimplementing the calls here!
52 */
53
54 /*************************************************************************
55 * @ [SHLWAPI.11]
56 *
57 * Copy a sharable memory handle from one process to another.
58 *
59 * PARAMS
60 * hShared [I] Shared memory handle to duplicate
61 * dwSrcProcId [I] ID of the process owning hShared
62 * dwDstProcId [I] ID of the process wanting the duplicated handle
63 * dwAccess [I] Desired DuplicateHandle() access
64 * dwOptions [I] Desired DuplicateHandle() options
65 *
66 * RETURNS
67 * Success: A handle suitable for use by the dwDstProcId process.
68 * Failure: A NULL handle.
69 *
70 */
71 HANDLE WINAPI SHMapHandle(HANDLE hShared, DWORD dwSrcProcId, DWORD dwDstProcId,
72 DWORD dwAccess, DWORD dwOptions)
73 {
74 HANDLE hDst, hSrc;
75 DWORD dwMyProcId = GetCurrentProcessId();
76 HANDLE hRet = NULL;
77
78 TRACE("(%p,%d,%d,%08x,%08x)\n", hShared, dwDstProcId, dwSrcProcId,
79 dwAccess, dwOptions);
80
81 /* Get dest process handle */
82 if (dwDstProcId == dwMyProcId)
83 hDst = GetCurrentProcess();
84 else
85 hDst = OpenProcess(PROCESS_DUP_HANDLE, 0, dwDstProcId);
86
87 if (hDst)
88 {
89 /* Get src process handle */
90 if (dwSrcProcId == dwMyProcId)
91 hSrc = GetCurrentProcess();
92 else
93 hSrc = OpenProcess(PROCESS_DUP_HANDLE, 0, dwSrcProcId);
94
95 if (hSrc)
96 {
97 /* Make handle available to dest process */
98 if (!DuplicateHandle(hSrc, hShared, hDst, &hRet,
99 dwAccess, 0, dwOptions | DUPLICATE_SAME_ACCESS))
100 hRet = NULL;
101
102 if (dwSrcProcId != dwMyProcId)
103 CloseHandle(hSrc);
104 }
105
106 if (dwDstProcId != dwMyProcId)
107 CloseHandle(hDst);
108 }
109
110 TRACE("Returning handle %p\n", hRet);
111 return hRet;
112 }
113
114 /*************************************************************************
115 * @ [SHLWAPI.7]
116 *
117 * Create a block of sharable memory and initialise it with data.
118 *
119 * PARAMS
120 * lpvData [I] Pointer to data to write
121 * dwSize [I] Size of data
122 * dwProcId [I] ID of process owning data
123 *
124 * RETURNS
125 * Success: A shared memory handle
126 * Failure: NULL
127 *
128 * NOTES
129 * Ordinals 7-11 provide a set of calls to create shared memory between a
130 * group of processes. The shared memory is treated opaquely in that its size
131 * is not exposed to clients who map it. This is accomplished by storing
132 * the size of the map as the first DWORD of mapped data, and then offsetting
133 * the view pointer returned by this size.
134 *
135 */
136 HANDLE WINAPI SHAllocShared(LPCVOID lpvData, DWORD dwSize, DWORD dwProcId)
137 {
138 HANDLE hMap;
139 LPVOID pMapped;
140 HANDLE hRet = NULL;
141
142 TRACE("(%p,%d,%d)\n", lpvData, dwSize, dwProcId);
143
144 /* Create file mapping of the correct length */
145 hMap = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, FILE_MAP_READ, 0,
146 dwSize + sizeof(dwSize), NULL);
147 if (!hMap)
148 return hRet;
149
150 /* Get a view in our process address space */
151 pMapped = MapViewOfFile(hMap, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0);
152
153 if (pMapped)
154 {
155 /* Write size of data, followed by the data, to the view */
156 *((DWORD*)pMapped) = dwSize;
157 if (lpvData)
158 memcpy((char *) pMapped + sizeof(dwSize), lpvData, dwSize);
159
160 /* Release view. All further views mapped will be opaque */
161 UnmapViewOfFile(pMapped);
162 hRet = SHMapHandle(hMap, GetCurrentProcessId(), dwProcId,
163 FILE_MAP_ALL_ACCESS, DUPLICATE_SAME_ACCESS);
164 }
165
166 CloseHandle(hMap);
167 return hRet;
168 }
169
170 /*************************************************************************
171 * @ [SHLWAPI.8]
172 *
173 * Get a pointer to a block of shared memory from a shared memory handle.
174 *
175 * PARAMS
176 * hShared [I] Shared memory handle
177 * dwProcId [I] ID of process owning hShared
178 *
179 * RETURNS
180 * Success: A pointer to the shared memory
181 * Failure: NULL
182 *
183 */
184 PVOID WINAPI SHLockShared(HANDLE hShared, DWORD dwProcId)
185 {
186 HANDLE hDup;
187 LPVOID pMapped;
188
189 TRACE("(%p %d)\n", hShared, dwProcId);
190
191 /* Get handle to shared memory for current process */
192 hDup = SHMapHandle(hShared, dwProcId, GetCurrentProcessId(), FILE_MAP_ALL_ACCESS, 0);
193
194 /* Get View */
195 pMapped = MapViewOfFile(hDup, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0);
196 CloseHandle(hDup);
197
198 if (pMapped)
199 return (char *) pMapped + sizeof(DWORD); /* Hide size */
200 return NULL;
201 }
202
203 /*************************************************************************
204 * @ [SHLWAPI.9]
205 *
206 * Release a pointer to a block of shared memory.
207 *
208 * PARAMS
209 * lpView [I] Shared memory pointer
210 *
211 * RETURNS
212 * Success: TRUE
213 * Failure: FALSE
214 *
215 */
216 BOOL WINAPI SHUnlockShared(LPVOID lpView)
217 {
218 TRACE("(%p)\n", lpView);
219 return UnmapViewOfFile((char *) lpView - sizeof(DWORD)); /* Include size */
220 }
221
222 /*************************************************************************
223 * @ [SHLWAPI.10]
224 *
225 * Destroy a block of sharable memory.
226 *
227 * PARAMS
228 * hShared [I] Shared memory handle
229 * dwProcId [I] ID of process owning hShared
230 *
231 * RETURNS
232 * Success: TRUE
233 * Failure: FALSE
234 *
235 */
236 BOOL WINAPI SHFreeShared(HANDLE hShared, DWORD dwProcId)
237 {
238 HANDLE hClose;
239
240 TRACE("(%p %d)\n", hShared, dwProcId);
241
242 /* 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 * HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_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 __HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_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 * lpClassId [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* lpClassId)
1376 {
1377 IPersist* lpPersist;
1378 HRESULT hRet = E_FAIL;
1379
1380 TRACE("(%p,%s)\n", lpUnknown, debugstr_guid(lpClassId));
1381
1382 if (lpUnknown)
1383 {
1384 hRet = IUnknown_QueryInterface(lpUnknown,&IID_IPersist,(void**)&lpPersist);
1385 if (SUCCEEDED(hRet))
1386 {
1387 IPersist_GetClassID(lpPersist, lpClassId);
1388 IPersist_Release(lpPersist);
1389 }
1390 }
1391 return hRet;
1392 }
1393
1394 /*************************************************************************
1395 * @ [SHLWAPI.176]
1396 *
1397 * Retrieve a Service Interface from an object.
1398 *
1399 * PARAMS
1400 * lpUnknown [I] Object to get an IServiceProvider interface from
1401 * sid [I] Service ID for IServiceProvider_QueryService() call
1402 * riid [I] Function requested for QueryService call
1403 * lppOut [O] Destination for the service interface pointer
1404 *
1405 * RETURNS
1406 * Success: S_OK. lppOut contains an object providing the requested service
1407 * Failure: An HRESULT error code
1408 *
1409 * NOTES
1410 * lpUnknown is expected to support the IServiceProvider interface.
1411 */
1412 HRESULT WINAPI IUnknown_QueryService(IUnknown* lpUnknown, REFGUID sid, REFIID riid,
1413 LPVOID *lppOut)
1414 {
1415 IServiceProvider* pService = NULL;
1416 HRESULT hRet;
1417
1418 if (!lppOut)
1419 return E_FAIL;
1420
1421 *lppOut = NULL;
1422
1423 if (!lpUnknown)
1424 return E_FAIL;
1425
1426 hRet = IUnknown_QueryInterface(lpUnknown, &IID_IServiceProvider,
1427 (LPVOID*)&pService);
1428
1429 if (hRet == S_OK && pService)
1430 {
1431 TRACE("QueryInterface returned (IServiceProvider*)%p\n", pService);
1432
1433 /* Get a Service interface from the object */
1434 hRet = IServiceProvider_QueryService(pService, sid, riid, lppOut);
1435
1436 TRACE("(IServiceProvider*)%p returned (IUnknown*)%p\n", pService, *lppOut);
1437
1438 IServiceProvider_Release(pService);
1439 }
1440 return hRet;
1441 }
1442
1443 /*************************************************************************
1444 * @ [SHLWAPI.484]
1445 *
1446 * Calls IOleCommandTarget::Exec() for specified service object.
1447 *
1448 * PARAMS
1449 * lpUnknown [I] Object to get an IServiceProvider interface from
1450 * service [I] Service ID for IServiceProvider_QueryService() call
1451 * group [I] Group ID for IOleCommandTarget::Exec() call
1452 * cmdId [I] Command ID for IOleCommandTarget::Exec() call
1453 * cmdOpt [I] Options flags for command
1454 * pIn [I] Input arguments for command
1455 * pOut [O] Output arguments for command
1456 *
1457 * RETURNS
1458 * Success: S_OK. lppOut contains an object providing the requested service
1459 * Failure: An HRESULT error code
1460 *
1461 * NOTES
1462 * lpUnknown is expected to support the IServiceProvider interface.
1463 */
1464 HRESULT WINAPI IUnknown_QueryServiceExec(IUnknown *lpUnknown, REFIID service,
1465 const GUID *group, DWORD cmdId, DWORD cmdOpt, VARIANT *pIn, VARIANT *pOut)
1466 {
1467 IOleCommandTarget *target;
1468 HRESULT hr;
1469
1470 TRACE("%p %s %s %d %08x %p %p\n", lpUnknown, debugstr_guid(service),
1471 debugstr_guid(group), cmdId, cmdOpt, pIn, pOut);
1472
1473 hr = IUnknown_QueryService(lpUnknown, service, &IID_IOleCommandTarget, (void**)&target);
1474 if (hr == S_OK)
1475 {
1476 hr = IOleCommandTarget_Exec(target, group, cmdId, cmdOpt, pIn, pOut);
1477 IOleCommandTarget_Release(target);
1478 }
1479
1480 TRACE("<-- hr=0x%08x\n", hr);
1481
1482 return hr;
1483 }
1484
1485 /*************************************************************************
1486 * @ [SHLWAPI.514]
1487 *
1488 * Calls IProfferService methods to proffer/revoke specified service.
1489 *
1490 * PARAMS
1491 * lpUnknown [I] Object to get an IServiceProvider interface from
1492 * service [I] Service ID for IProfferService::Proffer/Revoke calls
1493 * pService [I] Service to proffer. If NULL ::Revoke is called
1494 * pCookie [IO] Group ID for IOleCommandTarget::Exec() call
1495 *
1496 * RETURNS
1497 * Success: S_OK. IProffer method returns S_OK
1498 * Failure: An HRESULT error code
1499 *
1500 * NOTES
1501 * lpUnknown is expected to support the IServiceProvider interface.
1502 */
1503 HRESULT WINAPI IUnknown_ProfferService(IUnknown *lpUnknown, REFGUID service, IServiceProvider *pService, DWORD *pCookie)
1504 {
1505 IProfferService *proffer;
1506 HRESULT hr;
1507
1508 TRACE("%p %s %p %p\n", lpUnknown, debugstr_guid(service), pService, pCookie);
1509
1510 hr = IUnknown_QueryService(lpUnknown, &IID_IProfferService, &IID_IProfferService, (void**)&proffer);
1511 if (hr == S_OK)
1512 {
1513 if (pService)
1514 hr = IProfferService_ProfferService(proffer, service, pService, pCookie);
1515 else
1516 {
1517 hr = IProfferService_RevokeService(proffer, *pCookie);
1518 *pCookie = 0;
1519 }
1520
1521 IProfferService_Release(proffer);
1522 }
1523
1524 return hr;
1525 }
1526
1527 /*************************************************************************
1528 * @ [SHLWAPI.479]
1529 *
1530 * Call an object's UIActivateIO method.
1531 *
1532 * PARAMS
1533 * unknown [I] Object to call the UIActivateIO method on
1534 * activate [I] Parameter for UIActivateIO call
1535 * msg [I] Parameter for UIActivateIO call
1536 *
1537 * RETURNS
1538 * Success: Value of UI_ActivateIO call
1539 * Failure: An HRESULT error code
1540 *
1541 * NOTES
1542 * unknown is expected to support the IInputObject interface.
1543 */
1544 HRESULT WINAPI IUnknown_UIActivateIO(IUnknown *unknown, BOOL activate, LPMSG msg)
1545 {
1546 IInputObject* object = NULL;
1547 HRESULT ret;
1548
1549 if (!unknown)
1550 return E_FAIL;
1551
1552 /* Get an IInputObject interface from the object */
1553 ret = IUnknown_QueryInterface(unknown, &IID_IInputObject, (LPVOID*) &object);
1554
1555 if (ret == S_OK)
1556 {
1557 ret = IInputObject_UIActivateIO(object, activate, msg);
1558 IInputObject_Release(object);
1559 }
1560
1561 return ret;
1562 }
1563
1564 /*************************************************************************
1565 * @ [SHLWAPI.177]
1566 *
1567 * Loads a popup menu.
1568 *
1569 * PARAMS
1570 * hInst [I] Instance handle
1571 * szName [I] Menu name
1572 *
1573 * RETURNS
1574 * Success: TRUE.
1575 * Failure: FALSE.
1576 */
1577 BOOL WINAPI SHLoadMenuPopup(HINSTANCE hInst, LPCWSTR szName)
1578 {
1579 HMENU hMenu;
1580
1581 TRACE("%p %s\n", hInst, debugstr_w(szName));
1582
1583 if ((hMenu = LoadMenuW(hInst, szName)))
1584 {
1585 if (GetSubMenu(hMenu, 0))
1586 RemoveMenu(hMenu, 0, MF_BYPOSITION);
1587
1588 DestroyMenu(hMenu);
1589 return TRUE;
1590 }
1591 return FALSE;
1592 }
1593
1594 typedef struct _enumWndData
1595 {
1596 UINT uiMsgId;
1597 WPARAM wParam;
1598 LPARAM lParam;
1599 LRESULT (WINAPI *pfnPost)(HWND,UINT,WPARAM,LPARAM);
1600 } enumWndData;
1601
1602 /* Callback for SHLWAPI_178 */
1603 static BOOL CALLBACK SHLWAPI_EnumChildProc(HWND hWnd, LPARAM lParam)
1604 {
1605 enumWndData *data = (enumWndData *)lParam;
1606
1607 TRACE("(%p,%p)\n", hWnd, data);
1608 data->pfnPost(hWnd, data->uiMsgId, data->wParam, data->lParam);
1609 return TRUE;
1610 }
1611
1612 /*************************************************************************
1613 * @ [SHLWAPI.178]
1614 *
1615 * Send or post a message to every child of a window.
1616 *
1617 * PARAMS
1618 * hWnd [I] Window whose children will get the messages
1619 * uiMsgId [I] Message Id
1620 * wParam [I] WPARAM of message
1621 * lParam [I] LPARAM of message
1622 * bSend [I] TRUE = Use SendMessageA(), FALSE = Use PostMessageA()
1623 *
1624 * RETURNS
1625 * Nothing.
1626 *
1627 * NOTES
1628 * The appropriate ASCII or Unicode function is called for the window.
1629 */
1630 void WINAPI SHPropagateMessage(HWND hWnd, UINT uiMsgId, WPARAM wParam, LPARAM lParam, BOOL bSend)
1631 {
1632 enumWndData data;
1633
1634 TRACE("(%p,%u,%ld,%ld,%d)\n", hWnd, uiMsgId, wParam, lParam, bSend);
1635
1636 if(hWnd)
1637 {
1638 data.uiMsgId = uiMsgId;
1639 data.wParam = wParam;
1640 data.lParam = lParam;
1641
1642 if (bSend)
1643 data.pfnPost = IsWindowUnicode(hWnd) ? (void*)SendMessageW : (void*)SendMessageA;
1644 else
1645 data.pfnPost = IsWindowUnicode(hWnd) ? (void*)PostMessageW : (void*)PostMessageA;
1646
1647 EnumChildWindows(hWnd, SHLWAPI_EnumChildProc, (LPARAM)&data);
1648 }
1649 }
1650
1651 /*************************************************************************
1652 * @ [SHLWAPI.180]
1653 *
1654 * Remove all sub-menus from a menu.
1655 *
1656 * PARAMS
1657 * hMenu [I] Menu to remove sub-menus from
1658 *
1659 * RETURNS
1660 * Success: 0. All sub-menus under hMenu are removed
1661 * Failure: -1, if any parameter is invalid
1662 */
1663 DWORD WINAPI SHRemoveAllSubMenus(HMENU hMenu)
1664 {
1665 int iItemCount = GetMenuItemCount(hMenu) - 1;
1666
1667 TRACE("%p\n", hMenu);
1668
1669 while (iItemCount >= 0)
1670 {
1671 HMENU hSubMenu = GetSubMenu(hMenu, iItemCount);
1672 if (hSubMenu)
1673 RemoveMenu(hMenu, iItemCount, MF_BYPOSITION);
1674 iItemCount--;
1675 }
1676 return iItemCount;
1677 }
1678
1679 /*************************************************************************
1680 * @ [SHLWAPI.181]
1681 *
1682 * Enable or disable a menu item.
1683 *
1684 * PARAMS
1685 * hMenu [I] Menu holding menu item
1686 * uID [I] ID of menu item to enable/disable
1687 * bEnable [I] Whether to enable (TRUE) or disable (FALSE) the item.
1688 *
1689 * RETURNS
1690 * The return code from EnableMenuItem.
1691 */
1692 UINT WINAPI SHEnableMenuItem(HMENU hMenu, UINT wItemID, BOOL bEnable)
1693 {
1694 TRACE("%p, %u, %d\n", hMenu, wItemID, bEnable);
1695 return EnableMenuItem(hMenu, wItemID, bEnable ? MF_ENABLED : MF_GRAYED);
1696 }
1697
1698 /*************************************************************************
1699 * @ [SHLWAPI.182]
1700 *
1701 * Check or uncheck a menu item.
1702 *
1703 * PARAMS
1704 * hMenu [I] Menu holding menu item
1705 * uID [I] ID of menu item to check/uncheck
1706 * bCheck [I] Whether to check (TRUE) or uncheck (FALSE) the item.
1707 *
1708 * RETURNS
1709 * The return code from CheckMenuItem.
1710 */
1711 DWORD WINAPI SHCheckMenuItem(HMENU hMenu, UINT uID, BOOL bCheck)
1712 {
1713 TRACE("%p, %u, %d\n", hMenu, uID, bCheck);
1714 return CheckMenuItem(hMenu, uID, bCheck ? MF_CHECKED : MF_UNCHECKED);
1715 }
1716
1717 /*************************************************************************
1718 * @ [SHLWAPI.183]
1719 *
1720 * Register a window class if it isn't already.
1721 *
1722 * PARAMS
1723 * lpWndClass [I] Window class to register
1724 *
1725 * RETURNS
1726 * The result of the RegisterClassA call.
1727 */
1728 DWORD WINAPI SHRegisterClassA(WNDCLASSA *wndclass)
1729 {
1730 WNDCLASSA wca;
1731 if (GetClassInfoA(wndclass->hInstance, wndclass->lpszClassName, &wca))
1732 return TRUE;
1733 return (DWORD)RegisterClassA(wndclass);
1734 }
1735
1736 /*************************************************************************
1737 * @ [SHLWAPI.186]
1738 */
1739 BOOL WINAPI SHSimulateDrop(IDropTarget *pDrop, IDataObject *pDataObj,
1740 DWORD grfKeyState, PPOINTL lpPt, DWORD* pdwEffect)
1741 {
1742 DWORD dwEffect = DROPEFFECT_LINK | DROPEFFECT_MOVE | DROPEFFECT_COPY;
1743 POINTL pt = { 0, 0 };
1744
1745 TRACE("%p %p 0x%08x %p %p\n", pDrop, pDataObj, grfKeyState, lpPt, pdwEffect);
1746
1747 if (!lpPt)
1748 lpPt = &pt;
1749
1750 if (!pdwEffect)
1751 pdwEffect = &dwEffect;
1752
1753 IDropTarget_DragEnter(pDrop, pDataObj, grfKeyState, *lpPt, pdwEffect);
1754
1755 if (*pdwEffect != DROPEFFECT_NONE)
1756 return IDropTarget_Drop(pDrop, pDataObj, grfKeyState, *lpPt, pdwEffect);
1757
1758 IDropTarget_DragLeave(pDrop);
1759 return TRUE;
1760 }
1761
1762 /*************************************************************************
1763 * @ [SHLWAPI.187]
1764 *
1765 * Call IPersistPropertyBag_Load() on an object.
1766 *
1767 * PARAMS
1768 * lpUnknown [I] Object supporting the IPersistPropertyBag interface
1769 * lpPropBag [O] Destination for loaded IPropertyBag
1770 *
1771 * RETURNS
1772 * Success: S_OK.
1773 * Failure: An HRESULT error code, or E_FAIL if lpUnknown is NULL.
1774 */
1775 DWORD WINAPI SHLoadFromPropertyBag(IUnknown *lpUnknown, IPropertyBag* lpPropBag)
1776 {
1777 IPersistPropertyBag* lpPPBag;
1778 HRESULT hRet = E_FAIL;
1779
1780 TRACE("(%p,%p)\n", lpUnknown, lpPropBag);
1781
1782 if (lpUnknown)
1783 {
1784 hRet = IUnknown_QueryInterface(lpUnknown, &IID_IPersistPropertyBag,
1785 (void**)&lpPPBag);
1786 if (SUCCEEDED(hRet) && lpPPBag)
1787 {
1788 hRet = IPersistPropertyBag_Load(lpPPBag, lpPropBag, NULL);
1789 IPersistPropertyBag_Release(lpPPBag);
1790 }
1791 }
1792 return hRet;
1793 }
1794
1795 /*************************************************************************
1796 * @ [SHLWAPI.188]
1797 *
1798 * Call IOleControlSite_TranslateAccelerator() on an object.
1799 *
1800 * PARAMS
1801 * lpUnknown [I] Object supporting the IOleControlSite interface.
1802 * lpMsg [I] Key message to be processed.
1803 * dwModifiers [I] Flags containing the state of the modifier keys.
1804 *
1805 * RETURNS
1806 * Success: S_OK.
1807 * Failure: An HRESULT error code, or E_INVALIDARG if lpUnknown is NULL.
1808 */
1809 HRESULT WINAPI IUnknown_TranslateAcceleratorOCS(IUnknown *lpUnknown, LPMSG lpMsg, DWORD dwModifiers)
1810 {
1811 IOleControlSite* lpCSite = NULL;
1812 HRESULT hRet = E_INVALIDARG;
1813
1814 TRACE("(%p,%p,0x%08x)\n", lpUnknown, lpMsg, dwModifiers);
1815 if (lpUnknown)
1816 {
1817 hRet = IUnknown_QueryInterface(lpUnknown, &IID_IOleControlSite,
1818 (void**)&lpCSite);
1819 if (SUCCEEDED(hRet) && lpCSite)
1820 {
1821 hRet = IOleControlSite_TranslateAccelerator(lpCSite, lpMsg, dwModifiers);
1822 IOleControlSite_Release(lpCSite);
1823 }
1824 }
1825 return hRet;
1826 }
1827
1828
1829 /*************************************************************************
1830 * @ [SHLWAPI.189]
1831 *
1832 * Call IOleControlSite_OnFocus() on an object.
1833 *
1834 * PARAMS
1835 * lpUnknown [I] Object supporting the IOleControlSite interface.
1836 * fGotFocus [I] Whether focus was gained (TRUE) or lost (FALSE).
1837 *
1838 * RETURNS
1839 * Success: S_OK.
1840 * Failure: An HRESULT error code, or E_FAIL if lpUnknown is NULL.
1841 */
1842 HRESULT WINAPI IUnknown_OnFocusOCS(IUnknown *lpUnknown, BOOL fGotFocus)
1843 {
1844 IOleControlSite* lpCSite = NULL;
1845 HRESULT hRet = E_FAIL;
1846
1847 TRACE("(%p, %d)\n", lpUnknown, fGotFocus);
1848 if (lpUnknown)
1849 {
1850 hRet = IUnknown_QueryInterface(lpUnknown, &IID_IOleControlSite,
1851 (void**)&lpCSite);
1852 if (SUCCEEDED(hRet) && lpCSite)
1853 {
1854 hRet = IOleControlSite_OnFocus(lpCSite, fGotFocus);
1855 IOleControlSite_Release(lpCSite);
1856 }
1857 }
1858 return hRet;
1859 }
1860
1861 /*************************************************************************
1862 * @ [SHLWAPI.190]
1863 */
1864 HRESULT WINAPI IUnknown_HandleIRestrict(LPUNKNOWN lpUnknown, PVOID lpArg1,
1865 PVOID lpArg2, PVOID lpArg3, PVOID lpArg4)
1866 {
1867 /* FIXME: {D12F26B2-D90A-11D0-830D-00AA005B4383} - What object does this represent? */
1868 static const DWORD service_id[] = { 0xd12f26b2, 0x11d0d90a, 0xaa000d83, 0x83435b00 };
1869 /* FIXME: {D12F26B1-D90A-11D0-830D-00AA005B4383} - Also Unknown/undocumented */
1870 static const DWORD function_id[] = { 0xd12f26b1, 0x11d0d90a, 0xaa000d83, 0x83435b00 };
1871 HRESULT hRet = E_INVALIDARG;
1872 LPUNKNOWN lpUnkInner = NULL; /* FIXME: Real type is unknown */
1873
1874 TRACE("(%p,%p,%p,%p,%p)\n", lpUnknown, lpArg1, lpArg2, lpArg3, lpArg4);
1875
1876 if (lpUnknown && lpArg4)
1877 {
1878 hRet = IUnknown_QueryService(lpUnknown, (REFGUID)service_id,
1879 (REFGUID)function_id, (void**)&lpUnkInner);
1880
1881 if (SUCCEEDED(hRet) && lpUnkInner)
1882 {
1883 /* FIXME: The type of service object requested is unknown, however
1884 * testing shows that its first method is called with 4 parameters.
1885 * Fake this by using IParseDisplayName_ParseDisplayName since the
1886 * signature and position in the vtable matches our unknown object type.
1887 */
1888 hRet = IParseDisplayName_ParseDisplayName((LPPARSEDISPLAYNAME)lpUnkInner,
1889 lpArg1, lpArg2, lpArg3, lpArg4);
1890 IUnknown_Release(lpUnkInner);
1891 }
1892 }
1893 return hRet;
1894 }
1895
1896 /*************************************************************************
1897 * @ [SHLWAPI.192]
1898 *
1899 * Get a sub-menu from a menu item.
1900 *
1901 * PARAMS
1902 * hMenu [I] Menu to get sub-menu from
1903 * uID [I] ID of menu item containing sub-menu
1904 *
1905 * RETURNS
1906 * The sub-menu of the item, or a NULL handle if any parameters are invalid.
1907 */
1908 HMENU WINAPI SHGetMenuFromID(HMENU hMenu, UINT uID)
1909 {
1910 MENUITEMINFOW mi;
1911
1912 TRACE("(%p,%u)\n", hMenu, uID);
1913
1914 mi.cbSize = sizeof(mi);
1915 mi.fMask = MIIM_SUBMENU;
1916
1917 if (!GetMenuItemInfoW(hMenu, uID, FALSE, &mi))
1918 return NULL;
1919
1920 return mi.hSubMenu;
1921 }
1922
1923 /*************************************************************************
1924 * @ [SHLWAPI.193]
1925 *
1926 * Get the color depth of the primary display.
1927 *
1928 * PARAMS
1929 * None.
1930 *
1931 * RETURNS
1932 * The color depth of the primary display.
1933 */
1934 DWORD WINAPI SHGetCurColorRes(void)
1935 {
1936 HDC hdc;
1937 DWORD ret;
1938
1939 TRACE("()\n");
1940
1941 hdc = GetDC(0);
1942 ret = GetDeviceCaps(hdc, BITSPIXEL) * GetDeviceCaps(hdc, PLANES);
1943 ReleaseDC(0, hdc);
1944 return ret;
1945 }
1946
1947 /*************************************************************************
1948 * @ [SHLWAPI.194]
1949 *
1950 * Wait for a message to arrive, with a timeout.
1951 *
1952 * PARAMS
1953 * hand [I] Handle to query
1954 * dwTimeout [I] Timeout in ticks or INFINITE to never timeout
1955 *
1956 * RETURNS
1957 * STATUS_TIMEOUT if no message is received before dwTimeout ticks passes.
1958 * Otherwise returns the value from MsgWaitForMultipleObjectsEx when a
1959 * message is available.
1960 */
1961 DWORD WINAPI SHWaitForSendMessageThread(HANDLE hand, DWORD dwTimeout)
1962 {
1963 DWORD dwEndTicks = GetTickCount() + dwTimeout;
1964 DWORD dwRet;
1965
1966 while ((dwRet = MsgWaitForMultipleObjectsEx(1, &hand, dwTimeout, QS_SENDMESSAGE, 0)) == 1)
1967 {
1968 MSG msg;
1969
1970 PeekMessageW(&msg, NULL, 0, 0, PM_NOREMOVE);
1971
1972 if (dwTimeout != INFINITE)
1973 {
1974 if ((int)(dwTimeout = dwEndTicks - GetTickCount()) <= 0)
1975 return WAIT_TIMEOUT;
1976 }
1977 }
1978
1979 return dwRet;
1980 }
1981
1982 /*************************************************************************
1983 * @ [SHLWAPI.195]
1984 *
1985 * Determine if a shell folder can be expanded.
1986 *
1987 * PARAMS
1988 * lpFolder [I] Parent folder containing the object to test.
1989 * pidl [I] Id of the object to test.
1990 *
1991 * RETURNS
1992 * Success: S_OK, if the object is expandable, S_FALSE otherwise.
1993 * Failure: E_INVALIDARG, if any argument is invalid.
1994 *
1995 * NOTES
1996 * If the object to be tested does not expose the IQueryInfo() interface it
1997 * will not be identified as an expandable folder.
1998 */
1999 HRESULT WINAPI SHIsExpandableFolder(LPSHELLFOLDER lpFolder, LPCITEMIDLIST pidl)
2000 {
2001 HRESULT hRet = E_INVALIDARG;
2002 IQueryInfo *lpInfo;
2003
2004 if (lpFolder && pidl)
2005 {
2006 hRet = IShellFolder_GetUIObjectOf(lpFolder, NULL, 1, &pidl, &IID_IQueryInfo,
2007 NULL, (void**)&lpInfo);
2008 if (FAILED(hRet))
2009 hRet = S_FALSE; /* Doesn't expose IQueryInfo */
2010 else
2011 {
2012 DWORD dwFlags = 0;
2013
2014 /* MSDN states of IQueryInfo_GetInfoFlags() that "This method is not
2015 * currently used". Really? You wouldn't be holding out on me would you?
2016 */
2017 hRet = IQueryInfo_GetInfoFlags(lpInfo, &dwFlags);
2018
2019 if (SUCCEEDED(hRet))
2020 {
2021 /* 0x2 is an undocumented flag apparently indicating expandability */
2022 hRet = dwFlags & 0x2 ? S_OK : S_FALSE;
2023 }
2024
2025 IQueryInfo_Release(lpInfo);
2026 }
2027 }
2028 return hRet;
2029 }
2030
2031 /*************************************************************************
2032 * @ [SHLWAPI.197]
2033 *
2034 * Blank out a region of text by drawing the background only.
2035 *
2036 * PARAMS
2037 * hDC [I] Device context to draw in
2038 * pRect [I] Area to draw in
2039 * cRef [I] Color to draw in
2040 *
2041 * RETURNS
2042 * Nothing.
2043 */
2044 DWORD WINAPI SHFillRectClr(HDC hDC, LPCRECT pRect, COLORREF cRef)
2045 {
2046 COLORREF cOldColor = SetBkColor(hDC, cRef);
2047 ExtTextOutA(hDC, 0, 0, ETO_OPAQUE, pRect, 0, 0, 0);
2048 SetBkColor(hDC, cOldColor);
2049 return 0;
2050 }
2051
2052 /*************************************************************************
2053 * @ [SHLWAPI.198]
2054 *
2055 * Return the value associated with a key in a map.
2056 *
2057 * PARAMS
2058 * lpKeys [I] A list of keys of length iLen
2059 * lpValues [I] A list of values associated with lpKeys, of length iLen
2060 * iLen [I] Length of both lpKeys and lpValues
2061 * iKey [I] The key value to look up in lpKeys
2062 *
2063 * RETURNS
2064 * The value in lpValues associated with iKey, or -1 if iKey is not
2065 * found in lpKeys.
2066 *
2067 * NOTES
2068 * - If two elements in the map share the same key, this function returns
2069 * the value closest to the start of the map
2070 * - The native version of this function crashes if lpKeys or lpValues is NULL.
2071 */
2072 int WINAPI SHSearchMapInt(const int *lpKeys, const int *lpValues, int iLen, int iKey)
2073 {
2074 if (lpKeys && lpValues)
2075 {
2076 int i = 0;
2077
2078 while (i < iLen)
2079 {
2080 if (lpKeys[i] == iKey)
2081 return lpValues[i]; /* Found */
2082 i++;
2083 }
2084 }
2085 return -1; /* Not found */
2086 }
2087
2088
2089 /*************************************************************************
2090 * @ [SHLWAPI.199]
2091 *
2092 * Copy an interface pointer
2093 *
2094 * PARAMS
2095 * lppDest [O] Destination for copy
2096 * lpUnknown [I] Source for copy
2097 *
2098 * RETURNS
2099 * Nothing.
2100 */
2101 VOID WINAPI IUnknown_Set(IUnknown **lppDest, IUnknown *lpUnknown)
2102 {
2103 TRACE("(%p,%p)\n", lppDest, lpUnknown);
2104
2105 IUnknown_AtomicRelease(lppDest);
2106
2107 if (lpUnknown)
2108 {
2109 IUnknown_AddRef(lpUnknown);
2110 *lppDest = lpUnknown;
2111 }
2112 }
2113
2114 /*************************************************************************
2115 * @ [SHLWAPI.200]
2116 *
2117 */
2118 HRESULT WINAPI MayQSForward(IUnknown* lpUnknown, PVOID lpReserved,
2119 REFGUID riidCmdGrp, ULONG cCmds,
2120 OLECMD *prgCmds, OLECMDTEXT* pCmdText)
2121 {
2122 FIXME("(%p,%p,%p,%d,%p,%p) - stub\n",
2123 lpUnknown, lpReserved, riidCmdGrp, cCmds, prgCmds, pCmdText);
2124
2125 /* FIXME: Calls IsQSForward & IUnknown_QueryStatus */
2126 return DRAGDROP_E_NOTREGISTERED;
2127 }
2128
2129 /*************************************************************************
2130 * @ [SHLWAPI.201]
2131 *
2132 */
2133 HRESULT WINAPI MayExecForward(IUnknown* lpUnknown, INT iUnk, REFGUID pguidCmdGroup,
2134 DWORD nCmdID, DWORD nCmdexecopt, VARIANT* pvaIn,
2135 VARIANT* pvaOut)
2136 {
2137 FIXME("(%p,%d,%p,%d,%d,%p,%p) - stub!\n", lpUnknown, iUnk, pguidCmdGroup,
2138 nCmdID, nCmdexecopt, pvaIn, pvaOut);
2139 return DRAGDROP_E_NOTREGISTERED;
2140 }
2141
2142 /*************************************************************************
2143 * @ [SHLWAPI.202]
2144 *
2145 */
2146 HRESULT WINAPI IsQSForward(REFGUID pguidCmdGroup,ULONG cCmds, OLECMD *prgCmds)
2147 {
2148 FIXME("(%p,%d,%p) - stub!\n", pguidCmdGroup, cCmds, prgCmds);
2149 return DRAGDROP_E_NOTREGISTERED;
2150 }
2151
2152 /*************************************************************************
2153 * @ [SHLWAPI.204]
2154 *
2155 * Determine if a window is not a child of another window.
2156 *
2157 * PARAMS
2158 * hParent [I] Suspected parent window
2159 * hChild [I] Suspected child window
2160 *
2161 * RETURNS
2162 * TRUE: If hChild is a child window of hParent
2163 * FALSE: If hChild is not a child window of hParent, or they are equal
2164 */
2165 BOOL WINAPI SHIsChildOrSelf(HWND hParent, HWND hChild)
2166 {
2167 TRACE("(%p,%p)\n", hParent, hChild);
2168
2169 if (!hParent || !hChild)
2170 return TRUE;
2171 else if(hParent == hChild)
2172 return FALSE;
2173 return !IsChild(hParent, hChild);
2174 }
2175
2176 /*************************************************************************
2177 * FDSA functions. Manage a dynamic array of fixed size memory blocks.
2178 */
2179
2180 typedef struct
2181 {
2182 DWORD num_items; /* Number of elements inserted */
2183 void *mem; /* Ptr to array */
2184 DWORD blocks_alloced; /* Number of elements allocated */
2185 BYTE inc; /* Number of elements to grow by when we need to expand */
2186 BYTE block_size; /* Size in bytes of an element */
2187 BYTE flags; /* Flags */
2188 } FDSA_info;
2189
2190 #define FDSA_FLAG_INTERNAL_ALLOC 0x01 /* When set we have allocated mem internally */
2191
2192 /*************************************************************************
2193 * @ [SHLWAPI.208]
2194 *
2195 * Initialize an FDSA array.
2196 */
2197 BOOL WINAPI FDSA_Initialize(DWORD block_size, DWORD inc, FDSA_info *info, void *mem,
2198 DWORD init_blocks)
2199 {
2200 TRACE("(0x%08x 0x%08x %p %p 0x%08x)\n", block_size, inc, info, mem, init_blocks);
2201
2202 if(inc == 0)
2203 inc = 1;
2204
2205 if(mem)
2206 memset(mem, 0, block_size * init_blocks);
2207
2208 info->num_items = 0;
2209 info->inc = inc;
2210 info->mem = mem;
2211 info->blocks_alloced = init_blocks;
2212 info->block_size = block_size;
2213 info->flags = 0;
2214
2215 return TRUE;
2216 }
2217
2218 /*************************************************************************
2219 * @ [SHLWAPI.209]
2220 *
2221 * Destroy an FDSA array
2222 */
2223 BOOL WINAPI FDSA_Destroy(FDSA_info *info)
2224 {
2225 TRACE("(%p)\n", info);
2226
2227 if(info->flags & FDSA_FLAG_INTERNAL_ALLOC)
2228 {
2229 HeapFree(GetProcessHeap(), 0, info->mem);
2230 return FALSE;
2231 }
2232
2233 return TRUE;
2234 }
2235
2236 /*************************************************************************
2237 * @ [SHLWAPI.210]
2238 *
2239 * Insert element into an FDSA array
2240 */
2241 DWORD WINAPI FDSA_InsertItem(FDSA_info *info, DWORD where, const void *block)
2242 {
2243 TRACE("(%p 0x%08x %p)\n", info, where, block);
2244 if(where > info->num_items)
2245 where = info->num_items;
2246
2247 if(info->num_items >= info->blocks_alloced)
2248 {
2249 DWORD size = (info->blocks_alloced + info->inc) * info->block_size;
2250 if(info->flags & 0x1)
2251 info->mem = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, info->mem, size);
2252 else
2253 {
2254 void *old_mem = info->mem;
2255 info->mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
2256 memcpy(info->mem, old_mem, info->blocks_alloced * info->block_size);
2257 }
2258 info->blocks_alloced += info->inc;
2259 info->flags |= 0x1;
2260 }
2261
2262 if(where < info->num_items)
2263 {
2264 memmove((char*)info->mem + (where + 1) * info->block_size,
2265 (char*)info->mem + where * info->block_size,
2266 (info->num_items - where) * info->block_size);
2267 }
2268 memcpy((char*)info->mem + where * info->block_size, block, info->block_size);
2269
2270 info->num_items++;
2271 return where;
2272 }
2273
2274 /*************************************************************************
2275 * @ [SHLWAPI.211]
2276 *
2277 * Delete an element from an FDSA array.
2278 */
2279 BOOL WINAPI FDSA_DeleteItem(FDSA_info *info, DWORD where)
2280 {
2281 TRACE("(%p 0x%08x)\n", info, where);
2282
2283 if(where >= info->num_items)
2284 return FALSE;
2285
2286 if(where < info->num_items - 1)
2287 {
2288 memmove((char*)info->mem + where * info->block_size,
2289 (char*)info->mem + (where + 1) * info->block_size,
2290 (info->num_items - where - 1) * info->block_size);
2291 }
2292 memset((char*)info->mem + (info->num_items - 1) * info->block_size,
2293 0, info->block_size);
2294 info->num_items--;
2295 return TRUE;
2296 }
2297
2298 /*************************************************************************
2299 * @ [SHLWAPI.219]
2300 *
2301 * Call IUnknown_QueryInterface() on a table of objects.
2302 *
2303 * RETURNS
2304 * Success: S_OK.
2305 * Failure: E_POINTER or E_NOINTERFACE.
2306 */
2307 HRESULT WINAPI QISearch(
2308 void *base, /* [in] Table of interfaces */
2309 const QITAB *table, /* [in] Array of REFIIDs and indexes into the table */
2310 REFIID riid, /* [in] REFIID to get interface for */
2311 void **ppv) /* [out] Destination for interface pointer */
2312 {
2313 HRESULT ret;
2314 IUnknown *a_vtbl;
2315 const QITAB *xmove;
2316
2317 TRACE("(%p %p %s %p)\n", base, table, debugstr_guid(riid), ppv);
2318 if (ppv) {
2319 xmove = table;
2320 while (xmove->piid) {
2321 TRACE("trying (offset %d) %s\n", xmove->dwOffset, debugstr_guid(xmove->piid));
2322 if (IsEqualIID(riid, xmove->piid)) {
2323 a_vtbl = (IUnknown*)(xmove->dwOffset + (LPBYTE)base);
2324 TRACE("matched, returning (%p)\n", a_vtbl);
2325 *ppv = a_vtbl;
2326 IUnknown_AddRef(a_vtbl);
2327 return S_OK;
2328 }
2329 xmove++;
2330 }
2331
2332 if (IsEqualIID(riid, &IID_IUnknown)) {
2333 a_vtbl = (IUnknown*)(table->dwOffset + (LPBYTE)base);
2334 TRACE("returning first for IUnknown (%p)\n", a_vtbl);
2335 *ppv = a_vtbl;
2336 IUnknown_AddRef(a_vtbl);
2337 return S_OK;
2338 }
2339 *ppv = 0;
2340 ret = E_NOINTERFACE;
2341 } else
2342 ret = E_POINTER;
2343
2344 TRACE("-- 0x%08x\n", ret);
2345 return ret;
2346 }
2347
2348 /*************************************************************************
2349 * @ [SHLWAPI.220]
2350 *
2351 * Set the Font for a window and the "PropDlgFont" property of the parent window.
2352 *
2353 * PARAMS
2354 * hWnd [I] Parent Window to set the property
2355 * id [I] Index of child Window to set the Font
2356 *
2357 * RETURNS
2358 * Success: S_OK
2359 *
2360 */
2361 HRESULT WINAPI SHSetDefaultDialogFont(HWND hWnd, INT id)
2362 {
2363 FIXME("(%p, %d) stub\n", hWnd, id);
2364 return S_OK;
2365 }
2366
2367 /*************************************************************************
2368 * @ [SHLWAPI.221]
2369 *
2370 * Remove the "PropDlgFont" property from a window.
2371 *
2372 * PARAMS
2373 * hWnd [I] Window to remove the property from
2374 *
2375 * RETURNS
2376 * A handle to the removed property, or NULL if it did not exist.
2377 */
2378 HANDLE WINAPI SHRemoveDefaultDialogFont(HWND hWnd)
2379 {
2380 HANDLE hProp;
2381
2382 TRACE("(%p)\n", hWnd);
2383
2384 hProp = GetPropA(hWnd, "PropDlgFont");
2385
2386 if(hProp)
2387 {
2388 DeleteObject(hProp);
2389 hProp = RemovePropA(hWnd, "PropDlgFont");
2390 }
2391 return hProp;
2392 }
2393
2394 /*************************************************************************
2395 * @ [SHLWAPI.236]
2396 *
2397 * Load the in-process server of a given GUID.
2398 *
2399 * PARAMS
2400 * refiid [I] GUID of the server to load.
2401 *
2402 * RETURNS
2403 * Success: A handle to the loaded server dll.
2404 * Failure: A NULL handle.
2405 */
2406 HMODULE WINAPI SHPinDllOfCLSID(REFIID refiid)
2407 {
2408 HKEY newkey;
2409 DWORD type, count;
2410 CHAR value[MAX_PATH], string[MAX_PATH];
2411
2412 strcpy(string, "CLSID\\");
2413 SHStringFromGUIDA(refiid, string + 6, sizeof(string)/sizeof(char) - 6);
2414 strcat(string, "\\InProcServer32");
2415
2416 count = MAX_PATH;
2417 RegOpenKeyExA(HKEY_CLASSES_ROOT, string, 0, 1, &newkey);
2418 RegQueryValueExA(newkey, 0, 0, &type, (PBYTE)value, &count);
2419 RegCloseKey(newkey);
2420 return LoadLibraryExA(value, 0, 0);
2421 }
2422
2423 /*************************************************************************
2424 * @ [SHLWAPI.237]
2425 *
2426 * Unicode version of SHLWAPI_183.
2427 */
2428 DWORD WINAPI SHRegisterClassW(WNDCLASSW * lpWndClass)
2429 {
2430 WNDCLASSW WndClass;
2431
2432 TRACE("(%p %s)\n",lpWndClass->hInstance, debugstr_w(lpWndClass->lpszClassName));
2433
2434 if (GetClassInfoW(lpWndClass->hInstance, lpWndClass->lpszClassName, &WndClass))
2435 return TRUE;
2436 return RegisterClassW(lpWndClass);
2437 }
2438
2439 /*************************************************************************
2440 * @ [SHLWAPI.238]
2441 *
2442 * Unregister a list of classes.
2443 *
2444 * PARAMS
2445 * hInst [I] Application instance that registered the classes
2446 * lppClasses [I] List of class names
2447 * iCount [I] Number of names in lppClasses
2448 *
2449 * RETURNS
2450 * Nothing.
2451 */
2452 void WINAPI SHUnregisterClassesA(HINSTANCE hInst, LPCSTR *lppClasses, INT iCount)
2453 {
2454 WNDCLASSA WndClass;
2455
2456 TRACE("(%p,%p,%d)\n", hInst, lppClasses, iCount);
2457
2458 while (iCount > 0)
2459 {
2460 if (GetClassInfoA(hInst, *lppClasses, &WndClass))
2461 UnregisterClassA(*lppClasses, hInst);
2462 lppClasses++;
2463 iCount--;
2464 }
2465 }
2466
2467 /*************************************************************************
2468 * @ [SHLWAPI.239]
2469 *
2470 * Unicode version of SHUnregisterClassesA.
2471 */
2472 void WINAPI SHUnregisterClassesW(HINSTANCE hInst, LPCWSTR *lppClasses, INT iCount)
2473 {
2474 WNDCLASSW WndClass;
2475
2476 TRACE("(%p,%p,%d)\n", hInst, lppClasses, iCount);
2477
2478 while (iCount > 0)
2479 {
2480 if (GetClassInfoW(hInst, *lppClasses, &WndClass))
2481 UnregisterClassW(*lppClasses, hInst);
2482 lppClasses++;
2483 iCount--;
2484 }
2485 }
2486
2487 /*************************************************************************
2488 * @ [SHLWAPI.240]
2489 *
2490 * Call The correct (Ascii/Unicode) default window procedure for a window.
2491 *
2492 * PARAMS
2493 * hWnd [I] Window to call the default procedure for
2494 * uMessage [I] Message ID
2495 * wParam [I] WPARAM of message
2496 * lParam [I] LPARAM of message
2497 *
2498 * RETURNS
2499 * The result of calling DefWindowProcA() or DefWindowProcW().
2500 */
2501 LRESULT CALLBACK SHDefWindowProc(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
2502 {
2503 if (IsWindowUnicode(hWnd))
2504 return DefWindowProcW(hWnd, uMessage, wParam, lParam);
2505 return DefWindowProcA(hWnd, uMessage, wParam, lParam);
2506 }
2507
2508 /*************************************************************************
2509 * @ [SHLWAPI.256]
2510 */
2511 HRESULT WINAPI IUnknown_GetSite(LPUNKNOWN lpUnknown, REFIID iid, PVOID *lppSite)
2512 {
2513 HRESULT hRet = E_INVALIDARG;
2514 LPOBJECTWITHSITE lpSite = NULL;
2515
2516 TRACE("(%p,%s,%p)\n", lpUnknown, debugstr_guid(iid), lppSite);
2517
2518 if (lpUnknown && iid && lppSite)
2519 {
2520 hRet = IUnknown_QueryInterface(lpUnknown, &IID_IObjectWithSite,
2521 (void**)&lpSite);
2522 if (SUCCEEDED(hRet) && lpSite)
2523 {
2524 hRet = IObjectWithSite_GetSite(lpSite, iid, lppSite);
2525 IObjectWithSite_Release(lpSite);
2526 }
2527 }
2528 return hRet;
2529 }
2530
2531 /*************************************************************************
2532 * @ [SHLWAPI.257]
2533 *
2534 * Create a worker window using CreateWindowExA().
2535 *
2536 * PARAMS
2537 * wndProc [I] Window procedure
2538 * hWndParent [I] Parent window
2539 * dwExStyle [I] Extra style flags
2540 * dwStyle [I] Style flags
2541 * hMenu [I] Window menu
2542 * wnd_extra [I] Window extra bytes value
2543 *
2544 * RETURNS
2545 * Success: The window handle of the newly created window.
2546 * Failure: 0.
2547 */
2548 HWND WINAPI SHCreateWorkerWindowA(LONG wndProc, HWND hWndParent, DWORD dwExStyle,
2549 DWORD dwStyle, HMENU hMenu, LONG_PTR wnd_extra)
2550 {
2551 static const char szClass[] = "WorkerA";
2552 WNDCLASSA wc;
2553 HWND hWnd;
2554
2555 TRACE("(0x%08x, %p, 0x%08x, 0x%08x, %p, 0x%08lx)\n",
2556 wndProc, hWndParent, dwExStyle, dwStyle, hMenu, wnd_extra);
2557
2558 /* Create Window class */
2559 wc.style = 0;
2560 wc.lpfnWndProc = DefWindowProcA;
2561 wc.cbClsExtra = 0;
2562 wc.cbWndExtra = sizeof(LONG_PTR);
2563 wc.hInstance = shlwapi_hInstance;
2564 wc.hIcon = NULL;
2565 wc.hCursor = LoadCursorA(NULL, (LPSTR)IDC_ARROW);
2566 wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
2567 wc.lpszMenuName = NULL;
2568 wc.lpszClassName = szClass;
2569
2570 SHRegisterClassA(&wc);
2571
2572 hWnd = CreateWindowExA(dwExStyle, szClass, 0, dwStyle, 0, 0, 0, 0,
2573 hWndParent, hMenu, shlwapi_hInstance, 0);
2574 if (hWnd)
2575 {
2576 SetWindowLongPtrW(hWnd, 0, wnd_extra);
2577
2578 if (wndProc) SetWindowLongPtrA(hWnd, GWLP_WNDPROC, wndProc);
2579 }
2580
2581 return hWnd;
2582 }
2583
2584 typedef struct tagPOLICYDATA
2585 {
2586 DWORD policy; /* flags value passed to SHRestricted */
2587 LPCWSTR appstr; /* application str such as "Explorer" */
2588 LPCWSTR keystr; /* name of the actual registry key / policy */
2589 } POLICYDATA, *LPPOLICYDATA;
2590
2591 #define SHELL_NO_POLICY 0xffffffff
2592
2593 /* default shell policy registry key */
2594 static const WCHAR strRegistryPolicyW[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o',
2595 's','o','f','t','\\','W','i','n','d','o','w','s','\\',
2596 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',
2597 '\\','P','o','l','i','c','i','e','s',0};
2598
2599 /*************************************************************************
2600 * @ [SHLWAPI.271]
2601 *
2602 * Retrieve a policy value from the registry.
2603 *
2604 * PARAMS
2605 * lpSubKey [I] registry key name
2606 * lpSubName [I] subname of registry key
2607 * lpValue [I] value name of registry value
2608 *
2609 * RETURNS
2610 * the value associated with the registry key or 0 if not found
2611 */
2612 DWORD WINAPI SHGetRestriction(LPCWSTR lpSubKey, LPCWSTR lpSubName, LPCWSTR lpValue)
2613 {
2614 DWORD retval, datsize = sizeof(retval);
2615 HKEY hKey;
2616
2617 if (!lpSubKey)
2618 lpSubKey = strRegistryPolicyW;
2619
2620 retval = RegOpenKeyW(HKEY_LOCAL_MACHINE, lpSubKey, &hKey);
2621 if (retval != ERROR_SUCCESS)
2622 retval = RegOpenKeyW(HKEY_CURRENT_USER, lpSubKey, &hKey);
2623 if (retval != ERROR_SUCCESS)
2624 return 0;
2625
2626 SHGetValueW(hKey, lpSubName, lpValue, NULL, &retval, &datsize);
2627 RegCloseKey(hKey);
2628 return retval;
2629 }
2630
2631 /*************************************************************************
2632 * @ [SHLWAPI.266]
2633 *
2634 * Helper function to retrieve the possibly cached value for a specific policy
2635 *
2636 * PARAMS
2637 * policy [I] The policy to look for
2638 * initial [I] Main registry key to open, if NULL use default
2639 * polTable [I] Table of known policies, 0 terminated
2640 * polArr [I] Cache array of policy values
2641 *
2642 * RETURNS
2643 * The retrieved policy value or 0 if not successful
2644 *
2645 * NOTES
2646 * This function is used by the native SHRestricted function to search for the
2647 * policy and cache it once retrieved. The current Wine implementation uses a
2648 * different POLICYDATA structure and implements a similar algorithm adapted to
2649 * that structure.
2650 */
2651 DWORD WINAPI SHRestrictionLookup(
2652 DWORD policy,
2653 LPCWSTR initial,
2654 LPPOLICYDATA polTable,
2655 LPDWORD polArr)
2656 {
2657 TRACE("(0x%08x %s %p %p)\n", policy, debugstr_w(initial), polTable, polArr);
2658
2659 if (!polTable || !polArr)
2660 return 0;
2661
2662 for (;polTable->policy; polTable++, polArr++)
2663 {
2664 if (policy == polTable->policy)
2665 {
2666 /* we have a known policy */
2667
2668 /* check if this policy has been cached */
2669 if (*polArr == SHELL_NO_POLICY)
2670 *polArr = SHGetRestriction(initial, polTable->appstr, polTable->keystr);
2671 return *polArr;
2672 }
2673 }
2674 /* we don't know this policy, return 0 */
2675 TRACE("unknown policy: (%08x)\n", policy);
2676 return 0;
2677 }
2678
2679 /*************************************************************************
2680 * @ [SHLWAPI.267]
2681 *
2682 * Get an interface from an object.
2683 *
2684 * RETURNS
2685 * Success: S_OK. ppv contains the requested interface.
2686 * Failure: An HRESULT error code.
2687 *
2688 * NOTES
2689 * This QueryInterface asks the inner object for an interface. In case
2690 * of aggregation this request would be forwarded by the inner to the
2691 * outer object. This function asks the inner object directly for the
2692 * interface circumventing the forwarding to the outer object.
2693 */
2694 HRESULT WINAPI SHWeakQueryInterface(
2695 IUnknown * pUnk, /* [in] Outer object */
2696 IUnknown * pInner, /* [in] Inner object */
2697 IID * riid, /* [in] Interface GUID to query for */
2698 LPVOID* ppv) /* [out] Destination for queried interface */
2699 {
2700 HRESULT hret = E_NOINTERFACE;
2701 TRACE("(pUnk=%p pInner=%p\n\tIID: %s %p)\n",pUnk,pInner,debugstr_guid(riid), ppv);
2702
2703 *ppv = NULL;
2704 if(pUnk && pInner) {
2705 hret = IUnknown_QueryInterface(pInner, riid, ppv);
2706 if (SUCCEEDED(hret)) IUnknown_Release(pUnk);
2707 }
2708 TRACE("-- 0x%08x\n", hret);
2709 return hret;
2710 }
2711
2712 /*************************************************************************
2713 * @ [SHLWAPI.268]
2714 *
2715 * Move a reference from one interface to another.
2716 *
2717 * PARAMS
2718 * lpDest [O] Destination to receive the reference
2719 * lppUnknown [O] Source to give up the reference to lpDest
2720 *
2721 * RETURNS
2722 * Nothing.
2723 */
2724 VOID WINAPI SHWeakReleaseInterface(IUnknown *lpDest, IUnknown **lppUnknown)
2725 {
2726 TRACE("(%p,%p)\n", lpDest, lppUnknown);
2727
2728 if (*lppUnknown)
2729 {
2730 /* Copy Reference*/
2731 IUnknown_AddRef(lpDest);
2732 IUnknown_AtomicRelease(lppUnknown); /* Release existing interface */
2733 }
2734 }
2735
2736 /*************************************************************************
2737 * @ [SHLWAPI.269]
2738 *
2739 * Convert an ASCII string of a CLSID into a CLSID.
2740 *
2741 * PARAMS
2742 * idstr [I] String representing a CLSID in registry format
2743 * id [O] Destination for the converted CLSID
2744 *
2745 * RETURNS
2746 * Success: TRUE. id contains the converted CLSID.
2747 * Failure: FALSE.
2748 */
2749 BOOL WINAPI GUIDFromStringA(LPCSTR idstr, CLSID *id)
2750 {
2751 WCHAR wClsid[40];
2752 MultiByteToWideChar(CP_ACP, 0, idstr, -1, wClsid, sizeof(wClsid)/sizeof(WCHAR));
2753 return SUCCEEDED(CLSIDFromString(wClsid, id));
2754 }
2755
2756 /*************************************************************************
2757 * @ [SHLWAPI.270]
2758 *
2759 * Unicode version of GUIDFromStringA.
2760 */
2761 BOOL WINAPI GUIDFromStringW(LPCWSTR idstr, CLSID *id)
2762 {
2763 return SUCCEEDED(CLSIDFromString((LPCOLESTR)idstr, id));
2764 }
2765
2766 /*************************************************************************
2767 * @ [SHLWAPI.276]
2768 *
2769 * Determine if the browser is integrated into the shell, and set a registry
2770 * key accordingly.
2771 *
2772 * PARAMS
2773 * None.
2774 *
2775 * RETURNS
2776 * 1, If the browser is not integrated.
2777 * 2, If the browser is integrated.
2778 *
2779 * NOTES
2780 * The key "HKLM\Software\Microsoft\Internet Explorer\IntegratedBrowser" is
2781 * either set to TRUE, or removed depending on whether the browser is deemed
2782 * to be integrated.
2783 */
2784 DWORD WINAPI WhichPlatform(void)
2785 {
2786 static const char szIntegratedBrowser[] = "IntegratedBrowser";
2787 static DWORD dwState = 0;
2788 HKEY hKey;
2789 DWORD dwRet, dwData, dwSize;
2790 HMODULE hshell32;
2791
2792 if (dwState)
2793 return dwState;
2794
2795 /* If shell32 exports DllGetVersion(), the browser is integrated */
2796 dwState = 1;
2797 hshell32 = LoadLibraryA("shell32.dll");
2798 if (hshell32)
2799 {
2800 FARPROC pDllGetVersion;
2801 pDllGetVersion = GetProcAddress(hshell32, "DllGetVersion");
2802 dwState = pDllGetVersion ? 2 : 1;
2803 FreeLibrary(hshell32);
2804 }
2805
2806 /* Set or delete the key accordingly */
2807 dwRet = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
2808 "Software\\Microsoft\\Internet Explorer", 0,
2809 KEY_ALL_ACCESS, &hKey);
2810 if (!dwRet)
2811 {
2812 dwRet = RegQueryValueExA(hKey, szIntegratedBrowser, 0, 0,
2813 (LPBYTE)&dwData, &dwSize);
2814
2815 if (!dwRet && dwState == 1)
2816 {
2817 /* Value exists but browser is not integrated */
2818 RegDeleteValueA(hKey, szIntegratedBrowser);
2819 }
2820 else if (dwRet && dwState == 2)
2821 {
2822 /* Browser is integrated but value does not exist */
2823 dwData = TRUE;
2824 RegSetValueExA(hKey, szIntegratedBrowser, 0, REG_DWORD,
2825 (LPBYTE)&dwData, sizeof(dwData));
2826 }
2827 RegCloseKey(hKey);
2828 }
2829 return dwState;
2830 }
2831
2832 /*************************************************************************
2833 * @ [SHLWAPI.278]
2834 *
2835 * Unicode version of SHCreateWorkerWindowA.
2836 */
2837 HWND WINAPI SHCreateWorkerWindowW(LONG wndProc, HWND hWndParent, DWORD dwExStyle,
2838 DWORD dwStyle, HMENU hMenu, LONG msg_result)
2839 {
2840 static const WCHAR szClass[] = { 'W', 'o', 'r', 'k', 'e', 'r', 'W', 0 };
2841 WNDCLASSW wc;
2842 HWND hWnd;
2843
2844 TRACE("(0x%08x, %p, 0x%08x, 0x%08x, %p, 0x%08x)\n",
2845 wndProc, hWndParent, dwExStyle, dwStyle, hMenu, msg_result);
2846
2847 /* If our OS is natively ANSI, use the ANSI version */
2848 if (GetVersion() & 0x80000000) /* not NT */
2849 {
2850 TRACE("fallback to ANSI, ver 0x%08x\n", GetVersion());
2851 return SHCreateWorkerWindowA(wndProc, hWndParent, dwExStyle, dwStyle, hMenu, msg_result);
2852 }
2853
2854 /* Create Window class */
2855 wc.style = 0;
2856 wc.lpfnWndProc = DefWindowProcW;
2857 wc.cbClsExtra = 0;
2858 wc.cbWndExtra = 4;
2859 wc.hInstance = shlwapi_hInstance;
2860 wc.hIcon = NULL;
2861 wc.hCursor = LoadCursorW(NULL, (LPWSTR)IDC_ARROW);
2862 wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
2863 wc.lpszMenuName = NULL;
2864 wc.lpszClassName = szClass;
2865
2866 SHRegisterClassW(&wc);
2867
2868 hWnd = CreateWindowExW(dwExStyle, szClass, 0, dwStyle, 0, 0, 0, 0,
2869 hWndParent, hMenu, shlwapi_hInstance, 0);
2870 if (hWnd)
2871 {
2872 SetWindowLongPtrW(hWnd, DWLP_MSGRESULT, msg_result);
2873
2874 if (wndProc) SetWindowLongPtrW(hWnd, GWLP_WNDPROC, wndProc);
2875 }
2876
2877 return hWnd;
2878 }
2879
2880 /*************************************************************************
2881 * @ [SHLWAPI.279]
2882 *
2883 * Get and show a context menu from a shell folder.
2884 *
2885 * PARAMS
2886 * hWnd [I] Window displaying the shell folder
2887 * lpFolder [I] IShellFolder interface
2888 * lpApidl [I] Id for the particular folder desired
2889 *
2890 * RETURNS
2891 * Success: S_OK.
2892 * Failure: An HRESULT error code indicating the error.
2893 */
2894 HRESULT WINAPI SHInvokeDefaultCommand(HWND hWnd, IShellFolder* lpFolder, LPCITEMIDLIST lpApidl)
2895 {
2896 TRACE("%p %p %p\n", hWnd, lpFolder, lpApidl);
2897 return SHInvokeCommand(hWnd, lpFolder, lpApidl, 0);
2898 }
2899
2900 /*************************************************************************
2901 * @ [SHLWAPI.281]
2902 *
2903 * _SHPackDispParamsV
2904 */
2905 HRESULT WINAPI SHPackDispParamsV(DISPPARAMS *params, VARIANTARG *args, UINT cnt, __ms_va_list valist)
2906 {
2907 VARIANTARG *iter;
2908
2909 TRACE("(%p %p %u ...)\n", params, args, cnt);
2910
2911 params->rgvarg = args;
2912 params->rgdispidNamedArgs = NULL;
2913 params->cArgs = cnt;
2914 params->cNamedArgs = 0;
2915
2916 iter = args+cnt;
2917
2918 while(iter-- > args) {
2919 V_VT(iter) = va_arg(valist, enum VARENUM);
2920
2921 TRACE("vt=%d\n", V_VT(iter));
2922
2923 if(V_VT(iter) & VT_BYREF) {
2924 V_BYREF(iter) = va_arg(valist, LPVOID);
2925 } else {
2926 switch(V_VT(iter)) {
2927 case VT_I4:
2928 V_I4(iter) = va_arg(valist, LONG);
2929 break;
2930 case VT_BSTR:
2931 V_BSTR(iter) = va_arg(valist, BSTR);
2932 break;
2933 case VT_DISPATCH:
2934 V_DISPATCH(iter) = va_arg(valist, IDispatch*);
2935 break;
2936 case VT_BOOL:
2937 V_BOOL(iter) = va_arg(valist, int);
2938 break;
2939 case VT_UNKNOWN:
2940 V_UNKNOWN(iter) = va_arg(valist, IUnknown*);
2941 break;
2942 default:
2943 V_VT(iter) = VT_I4;
2944 V_I4(iter) = va_arg(valist, LONG);
2945 }
2946 }
2947 }
2948
2949 return S_OK;
2950 }
2951
2952 /*************************************************************************
2953 * @ [SHLWAPI.282]
2954 *
2955 * SHPackDispParams
2956 */
2957 HRESULT WINAPIV SHPackDispParams(DISPPARAMS *params, VARIANTARG *args, UINT cnt, ...)
2958 {
2959 __ms_va_list valist;
2960 HRESULT hres;
2961
2962 __ms_va_start(valist, cnt);
2963 hres = SHPackDispParamsV(params, args, cnt, valist);
2964 __ms_va_end(valist);
2965 return hres;
2966 }
2967
2968 /*************************************************************************
2969 * SHLWAPI_InvokeByIID
2970 *
2971 * This helper function calls IDispatch::Invoke for each sink
2972 * which implements given iid or IDispatch.
2973 *
2974 */
2975 static HRESULT SHLWAPI_InvokeByIID(
2976 IConnectionPoint* iCP,
2977 REFIID iid,
2978 DISPID dispId,
2979 DISPPARAMS* dispParams)
2980 {
2981 IEnumConnections *enumerator;
2982 CONNECTDATA rgcd;
2983 static DISPPARAMS empty = {NULL, NULL, 0, 0};
2984 DISPPARAMS* params = dispParams;
2985
2986 HRESULT result = IConnectionPoint_EnumConnections(iCP, &enumerator);
2987 if (FAILED(result))
2988 return result;
2989
2990 /* Invoke is never happening with an NULL dispParams */
2991 if (!params)
2992 params = &empty;
2993
2994 while(IEnumConnections_Next(enumerator, 1, &rgcd, NULL)==S_OK)
2995 {
2996 IDispatch *dispIface;
2997 if ((iid && SUCCEEDED(IUnknown_QueryInterface(rgcd.pUnk, iid, (LPVOID*)&dispIface))) ||
2998 SUCCEEDED(IUnknown_QueryInterface(rgcd.pUnk, &IID_IDispatch, (LPVOID*)&dispIface)))
2999 {
3000 IDispatch_Invoke(dispIface, dispId, &IID_NULL, 0, DISPATCH_METHOD, params, NULL, NULL, NULL);
3001 IDispatch_Release(dispIface);
3002 }
3003 IUnknown_Release(rgcd.pUnk);
3004 }
3005
3006 IEnumConnections_Release(enumerator);
3007
3008 return S_OK;
3009 }
3010
3011 /*************************************************************************
3012 * IConnectionPoint_InvokeWithCancel [SHLWAPI.283]
3013 */
3014 HRESULT WINAPI IConnectionPoint_InvokeWithCancel( IConnectionPoint* iCP,
3015 DISPID dispId, DISPPARAMS* dispParams,
3016 DWORD unknown1, DWORD unknown2 )
3017 {
3018 IID iid;
3019 HRESULT result;
3020
3021 FIXME("(%p)->(0x%x %p %x %x) partial stub\n", iCP, dispId, dispParams, unknown1, unknown2);
3022
3023 result = IConnectionPoint_GetConnectionInterface(iCP, &iid);
3024 if (SUCCEEDED(result))
3025 result = SHLWAPI_InvokeByIID(iCP, &iid, dispId, dispParams);
3026 else
3027 result = SHLWAPI_InvokeByIID(iCP, NULL, dispId, dispParams);
3028
3029 return result;
3030 }
3031
3032
3033 /*************************************************************************
3034 * @ [SHLWAPI.284]
3035 *
3036 * IConnectionPoint_SimpleInvoke
3037 */
3038 HRESULT WINAPI IConnectionPoint_SimpleInvoke(
3039 IConnectionPoint* iCP,
3040 DISPID dispId,
3041 DISPPARAMS* dispParams)
3042 {
3043 IID iid;
3044 HRESULT result;
3045
3046 TRACE("(%p)->(0x%x %p)\n",iCP,dispId,dispParams);
3047
3048 result = IConnectionPoint_GetConnectionInterface(iCP, &iid);
3049 if (SUCCEEDED(result))
3050 result = SHLWAPI_InvokeByIID(iCP, &iid, dispId, dispParams);
3051 else
3052 result = SHLWAPI_InvokeByIID(iCP, NULL, dispId, dispParams);
3053
3054 return result;
3055 }
3056
3057 /*************************************************************************
3058 * @ [SHLWAPI.285]
3059 *
3060 * Notify an IConnectionPoint object of changes.
3061 *
3062 * PARAMS
3063 * lpCP [I] Object to notify
3064 * dispID [I]
3065 *
3066 * RETURNS
3067 * Success: S_OK.
3068 * Failure: E_NOINTERFACE, if lpCP is NULL or does not support the
3069 * IConnectionPoint interface.
3070 */
3071 HRESULT WINAPI IConnectionPoint_OnChanged(IConnectionPoint* lpCP, DISPID dispID)
3072 {
3073 IEnumConnections *lpEnum;
3074 HRESULT hRet = E_NOINTERFACE;
3075
3076 TRACE("(%p,0x%8X)\n", lpCP, dispID);
3077
3078 /* Get an enumerator for the connections */
3079 if (lpCP)
3080 hRet = IConnectionPoint_EnumConnections(lpCP, &lpEnum);
3081
3082 if (SUCCEEDED(hRet))
3083 {
3084 IPropertyNotifySink *lpSink;
3085 CONNECTDATA connData;
3086 ULONG ulFetched;
3087
3088 /* Call OnChanged() for every notify sink in the connection point */
3089 while (IEnumConnections_Next(lpEnum, 1, &connData, &ulFetched) == S_OK)
3090 {
3091 if (SUCCEEDED(IUnknown_QueryInterface(connData.pUnk, &IID_IPropertyNotifySink, (void**)&lpSink)) &&
3092 lpSink)
3093 {
3094 IPropertyNotifySink_OnChanged(lpSink, dispID);
3095 IPropertyNotifySink_Release(lpSink);
3096 }
3097 IUnknown_Release(connData.pUnk);
3098 }
3099
3100 IEnumConnections_Release(lpEnum);
3101 }
3102 return hRet;
3103 }
3104
3105 /*************************************************************************
3106 * @ [SHLWAPI.286]
3107 *
3108 * IUnknown_CPContainerInvokeParam
3109 */
3110 HRESULT WINAPIV IUnknown_CPContainerInvokeParam(
3111 IUnknown *container,
3112 REFIID riid,
3113 DISPID dispId,
3114 VARIANTARG* buffer,
3115 DWORD cParams, ...)
3116 {
3117 HRESULT result;
3118 IConnectionPoint *iCP;
3119 IConnectionPointContainer *iCPC;
3120 DISPPARAMS dispParams = {buffer, NULL, cParams, 0};
3121 __ms_va_list valist;
3122
3123 if (!container)
3124 return E_NOINTERFACE;
3125
3126 result = IUnknown_QueryInterface(container, &IID_IConnectionPointContainer,(LPVOID*) &iCPC);
3127 if (FAILED(result))
3128 return result;
3129
3130 result = IConnectionPointContainer_FindConnectionPoint(iCPC, riid, &iCP);
3131 IConnectionPointContainer_Release(iCPC);
3132 if(FAILED(result))
3133 return result;
3134
3135 __ms_va_start(valist, cParams);
3136 SHPackDispParamsV(&dispParams, buffer, cParams, valist);
3137 __ms_va_end(valist);
3138
3139 result = SHLWAPI_InvokeByIID(iCP, riid, dispId, &dispParams);
3140 IConnectionPoint_Release(iCP);
3141
3142 return result;
3143 }
3144
3145 /*************************************************************************
3146 * @ [SHLWAPI.287]
3147 *
3148 * Notify an IConnectionPointContainer object of changes.
3149 *
3150 * PARAMS
3151 * lpUnknown [I] Object to notify
3152 * dispID [I]
3153 *
3154 * RETURNS
3155 * Success: S_OK.
3156 * Failure: E_NOINTERFACE, if lpUnknown is NULL or does not support the
3157 * IConnectionPointContainer interface.
3158 */
3159 HRESULT WINAPI IUnknown_CPContainerOnChanged(IUnknown *lpUnknown, DISPID dispID)
3160 {
3161 IConnectionPointContainer* lpCPC = NULL;
3162 HRESULT hRet = E_NOINTERFACE;
3163
3164 TRACE("(%p,0x%8X)\n", lpUnknown, dispID);
3165
3166 if (lpUnknown)
3167 hRet = IUnknown_QueryInterface(lpUnknown, &IID_IConnectionPointContainer, (void**)&lpCPC);
3168
3169 if (SUCCEEDED(hRet))
3170 {
3171 IConnectionPoint* lpCP;
3172
3173 hRet = IConnectionPointContainer_FindConnectionPoint(lpCPC, &IID_IPropertyNotifySink, &lpCP);
3174 IConnectionPointContainer_Release(lpCPC);
3175
3176 hRet = IConnectionPoint_OnChanged(lpCP, dispID);
3177 IConnectionPoint_Release(lpCP);
3178 }
3179 return hRet;
3180 }
3181
3182 /*************************************************************************
3183 * @ [SHLWAPI.289]
3184 *
3185 * See PlaySoundW.
3186 */
3187 BOOL WINAPI PlaySoundWrapW(LPCWSTR pszSound, HMODULE hmod, DWORD fdwSound)
3188 {
3189 return PlaySoundW(pszSound, hmod, fdwSound);
3190 }
3191
3192 /*************************************************************************
3193 * @ [SHLWAPI.294]
3194 *
3195 * Retrieve a key value from an INI file. See GetPrivateProfileString for
3196 * more information.
3197 *
3198 * PARAMS
3199 * appName [I] The section in the INI file that contains the key
3200 * keyName [I] The key to be retrieved
3201 * out [O] The buffer into which the key's value will be copied
3202 * outLen [I] The length of the `out' buffer
3203 * filename [I] The location of the INI file
3204 *
3205 * RETURNS
3206 * Length of string copied into `out'.
3207 */
3208 DWORD WINAPI SHGetIniStringW(LPCWSTR appName, LPCWSTR keyName, LPWSTR out,
3209 DWORD outLen, LPCWSTR filename)
3210 {
3211 INT ret;
3212 WCHAR *buf;
3213
3214 TRACE("(%s,%s,%p,%08x,%s)\n", debugstr_w(appName), debugstr_w(keyName),
3215 out, outLen, debugstr_w(filename));
3216
3217 if(outLen == 0)
3218 return 0;
3219
3220 buf = HeapAlloc(GetProcessHeap(), 0, outLen * sizeof(WCHAR));
3221 if(!buf){
3222 *out = 0;
3223 return 0;
3224 }
3225
3226 ret = GetPrivateProfileStringW(appName, keyName, NULL, buf, outLen, filename);
3227 if(ret)
3228 strcpyW(out, buf);
3229 else
3230 *out = 0;
3231
3232 HeapFree(GetProcessHeap(), 0, buf);
3233
3234 return strlenW(out);
3235 }
3236
3237 /*************************************************************************
3238 * @ [SHLWAPI.295]
3239 *
3240 * Set a key value in an INI file. See WritePrivateProfileString for
3241 * more information.
3242 *
3243 * PARAMS
3244 * appName [I] The section in the INI file that contains the key
3245 * keyName [I] The key to be set
3246 * str [O] The value of the key
3247 * filename [I] The location of the INI file
3248 *
3249 * RETURNS
3250 * Success: TRUE
3251 * Failure: FALSE
3252 */
3253 BOOL WINAPI SHSetIniStringW(LPCWSTR appName, LPCWSTR keyName, LPCWSTR str,
3254 LPCWSTR filename)
3255 {
3256 TRACE("(%s, %p, %s, %s)\n", debugstr_w(appName), keyName, debugstr_w(str),
3257 debugstr_w(filename));
3258
3259 return WritePrivateProfileStringW(appName, keyName, str, filename);
3260 }
3261
3262 /*************************************************************************
3263 * @ [SHLWAPI.313]
3264 *
3265 * See SHGetFileInfoW.
3266 */
3267 DWORD WINAPI SHGetFileInfoWrapW(LPCWSTR path, DWORD dwFileAttributes,
3268 SHFILEINFOW *psfi, UINT sizeofpsfi, UINT flags)
3269 {
3270 return SHGetFileInfoW(path, dwFileAttributes, psfi, sizeofpsfi, flags);
3271 }
3272
3273 /*************************************************************************
3274 * @ [SHLWAPI.318]
3275 *
3276 * See DragQueryFileW.
3277 */
3278 UINT WINAPI DragQueryFileWrapW(HDROP hDrop, UINT lFile, LPWSTR lpszFile, UINT lLength)
3279 {
3280 return DragQueryFileW(hDrop, lFile, lpszFile, lLength);
3281 }
3282
3283 /*************************************************************************
3284 * @ [SHLWAPI.333]
3285 *
3286 * See SHBrowseForFolderW.
3287 */
3288 LPITEMIDLIST WINAPI SHBrowseForFolderWrapW(LPBROWSEINFOW lpBi)
3289 {
3290 return SHBrowseForFolderW(lpBi);
3291 }
3292
3293 /*************************************************************************
3294 * @ [SHLWAPI.334]
3295 *
3296 * See SHGetPathFromIDListW.
3297 */
3298 BOOL WINAPI SHGetPathFromIDListWrapW(LPCITEMIDLIST pidl,LPWSTR pszPath)
3299 {
3300 return SHGetPathFromIDListW(pidl, pszPath);
3301 }
3302
3303 /*************************************************************************
3304 * @ [SHLWAPI.335]
3305 *
3306 * See ShellExecuteExW.
3307 */
3308 BOOL WINAPI ShellExecuteExWrapW(LPSHELLEXECUTEINFOW lpExecInfo)
3309 {
3310 return ShellExecuteExW(lpExecInfo);
3311 }
3312
3313 /*************************************************************************
3314 * @ [SHLWAPI.336]
3315 *
3316 * See SHFileOperationW.
3317 */
3318 INT WINAPI SHFileOperationWrapW(LPSHFILEOPSTRUCTW lpFileOp)
3319 {
3320 return SHFileOperationW(lpFileOp);
3321 }
3322
3323 /*************************************************************************
3324 * @ [SHLWAPI.342]
3325 *
3326 */
3327 PVOID WINAPI SHInterlockedCompareExchange( PVOID *dest, PVOID xchg, PVOID compare )
3328 {
3329 return InterlockedCompareExchangePointer( dest, xchg, compare );
3330 }
3331
3332 /*************************************************************************
3333 * @ [SHLWAPI.350]
3334 *
3335 * See GetFileVersionInfoSizeW.
3336 */
3337 DWORD WINAPI GetFileVersionInfoSizeWrapW( LPCWSTR filename, LPDWORD handle )
3338 {
3339 return GetFileVersionInfoSizeW( filename, handle );
3340 }
3341
3342 /*************************************************************************
3343 * @ [SHLWAPI.351]
3344 *
3345 * See GetFileVersionInfoW.
3346 */
3347 BOOL WINAPI GetFileVersionInfoWrapW( LPCWSTR filename, DWORD handle,
3348 DWORD datasize, LPVOID data )
3349 {
3350 return GetFileVersionInfoW( filename, handle, datasize, data );
3351 }
3352
3353 /*************************************************************************
3354 * @ [SHLWAPI.352]
3355 *
3356 * See VerQueryValueW.
3357 */
3358 WORD WINAPI VerQueryValueWrapW( LPVOID pBlock, LPCWSTR lpSubBlock,
3359 LPVOID *lplpBuffer, UINT *puLen )
3360 {
3361 return VerQueryValueW( pBlock, lpSubBlock, lplpBuffer, puLen );
3362 }
3363
3364 #define IsIface(type) SUCCEEDED((hRet = IUnknown_QueryInterface(lpUnknown, &IID_##type, (void**)&lpObj)))
3365 #define IShellBrowser_EnableModeless IShellBrowser_EnableModelessSB
3366 #define EnableModeless(type) type##_EnableModeless((type*)lpObj, bModeless)
3367
3368 /*************************************************************************
3369 * @ [SHLWAPI.355]
3370 *
3371 * Change the modality of a shell object.
3372 *
3373 * PARAMS
3374 * lpUnknown [I] Object to make modeless
3375 * bModeless [I] TRUE=Make modeless, FALSE=Make modal
3376 *
3377 * RETURNS
3378 * Success: S_OK. The modality lpUnknown is changed.
3379 * Failure: An HRESULT error code indicating the error.
3380 *
3381 * NOTES
3382 * lpUnknown must support the IOleInPlaceFrame interface, the
3383 * IInternetSecurityMgrSite interface, the IShellBrowser interface
3384 * the IDocHostUIHandler interface, or the IOleInPlaceActiveObject interface,
3385 * or this call will fail.
3386 */
3387 HRESULT WINAPI IUnknown_EnableModeless(IUnknown *lpUnknown, BOOL bModeless)
3388 {
3389 IUnknown *lpObj;
3390 HRESULT hRet;
3391
3392 TRACE("(%p,%d)\n", lpUnknown, bModeless);
3393
3394 if (!lpUnknown)
3395 return E_FAIL;
3396
3397 if (IsIface(IOleInPlaceActiveObject))
3398 EnableModeless(IOleInPlaceActiveObject);
3399 else if (IsIface(IOleInPlaceFrame))
3400 EnableModeless(IOleInPlaceFrame);
3401 else if (IsIface(IShellBrowser))
3402 EnableModeless(IShellBrowser);
3403 else if (IsIface(IInternetSecurityMgrSite))
3404 EnableModeless(IInternetSecurityMgrSite);
3405 else if (IsIface(IDocHostUIHandler))
3406 EnableModeless(IDocHostUIHandler);
3407 else
3408 return hRet;
3409
3410 IUnknown_Release(lpObj);
3411 return S_OK;
3412 }
3413
3414 /*************************************************************************
3415 * @ [SHLWAPI.357]
3416 *
3417 * See SHGetNewLinkInfoW.
3418 */
3419 BOOL WINAPI SHGetNewLinkInfoWrapW(LPCWSTR pszLinkTo, LPCWSTR pszDir, LPWSTR pszName,
3420 BOOL *pfMustCopy, UINT uFlags)
3421 {
3422 return SHGetNewLinkInfoW(pszLinkTo, pszDir, pszName, pfMustCopy, uFlags);
3423 }
3424
3425 /*************************************************************************
3426 * @ [SHLWAPI.358]
3427 *
3428 * See SHDefExtractIconW.
3429 */
3430 UINT WINAPI SHDefExtractIconWrapW(LPCWSTR pszIconFile, int iIndex, UINT uFlags, HICON* phiconLarge,
3431 HICON* phiconSmall, UINT nIconSize)
3432 {
3433 return SHDefExtractIconW(pszIconFile, iIndex, uFlags, phiconLarge, phiconSmall, nIconSize);
3434 }
3435
3436 /*************************************************************************
3437 * @ [SHLWAPI.363]
3438 *
3439 * Get and show a context menu from a shell folder.
3440 *
3441 * PARAMS
3442 * hWnd [I] Window displaying the shell folder
3443 * lpFolder [I] IShellFolder interface
3444 * lpApidl [I] Id for the particular folder desired
3445 * dwCommandId [I] The command ID to invoke (0=invoke default)
3446 *
3447 * RETURNS
3448 * Success: S_OK. If bInvokeDefault is TRUE, the default menu action was
3449 * executed.
3450 * Failure: An HRESULT error code indicating the error.
3451 */
3452 HRESULT WINAPI SHInvokeCommand(HWND hWnd, IShellFolder* lpFolder, LPCITEMIDLIST lpApidl, DWORD dwCommandId)
3453 {
3454 IContextMenu *iContext;
3455 HRESULT hRet;
3456
3457 TRACE("(%p, %p, %p, %u)\n", hWnd, lpFolder, lpApidl, dwCommandId);
3458
3459 if (!lpFolder)
3460 return E_FAIL;
3461
3462 /* Get the context menu from the shell folder */
3463 hRet = IShellFolder_GetUIObjectOf(lpFolder, hWnd, 1, &lpApidl,
3464 &IID_IContextMenu, 0, (void**)&iContext);
3465 if (SUCCEEDED(hRet))
3466 {
3467 HMENU hMenu;
3468 if ((hMenu = CreatePopupMenu()))
3469 {
3470 HRESULT hQuery;
3471
3472 /* Add the context menu entries to the popup */
3473 hQuery = IContextMenu_QueryContextMenu(iContext, hMenu, 0, 1, 0x7FFF,
3474 dwCommandId ? CMF_NORMAL : CMF_DEFAULTONLY);
3475
3476 if (SUCCEEDED(hQuery))
3477 {
3478 if (!dwCommandId)
3479 dwCommandId = GetMenuDefaultItem(hMenu, 0, 0);
3480 if (dwCommandId != (UINT)-1)
3481 {
3482 CMINVOKECOMMANDINFO cmIci;
3483 /* Invoke the default item */
3484 memset(&cmIci,0,sizeof(cmIci));
3485 cmIci.cbSize = sizeof(cmIci);
3486 cmIci.fMask = CMIC_MASK_ASYNCOK;
3487 cmIci.hwnd = hWnd;
3488 cmIci.lpVerb = MAKEINTRESOURCEA(dwCommandId);
3489 cmIci.nShow = SW_SHOWNORMAL;
3490
3491 hRet = IContextMenu_InvokeCommand(iContext, &cmIci);
3492 }
3493 }
3494 DestroyMenu(hMenu);
3495 }
3496 IContextMenu_Release(iContext);
3497 }
3498 return hRet;
3499 }
3500
3501 /*************************************************************************
3502 * @ [SHLWAPI.370]
3503 *
3504 * See ExtractIconW.
3505 */
3506 HICON WINAPI ExtractIconWrapW(HINSTANCE hInstance, LPCWSTR lpszExeFileName,
3507 UINT nIconIndex)
3508 {
3509 return ExtractIconW(hInstance, lpszExeFileName, nIconIndex);
3510 }
3511
3512 /*************************************************************************
3513 * @ [SHLWAPI.377]
3514 *
3515 * Load a library from the directory of a particular process.
3516 *
3517 * PARAMS
3518 * new_mod [I] Library name
3519 * inst_hwnd [I] Module whose directory is to be used
3520 * dwCrossCodePage [I] Should be FALSE (currently ignored)
3521 *
3522 * RETURNS
3523 * Success: A handle to the loaded module
3524 * Failure: A NULL handle.
3525 */
3526 HMODULE WINAPI MLLoadLibraryA(LPCSTR new_mod, HMODULE inst_hwnd, DWORD dwCrossCodePage)
3527 {
3528 /* FIXME: Native appears to do DPA_Create and a DPA_InsertPtr for
3529 * each call here.
3530 * FIXME: Native shows calls to:
3531 * SHRegGetUSValue for "Software\Microsoft\Internet Explorer\International"
3532 * CheckVersion
3533 * RegOpenKeyExA for "HKLM\Software\Microsoft\Internet Explorer"
3534 * RegQueryValueExA for "LPKInstalled"
3535 * RegCloseKey
3536 * RegOpenKeyExA for "HKCU\Software\Microsoft\Internet Explorer\International"
3537 * RegQueryValueExA for "ResourceLocale"
3538 * RegCloseKey
3539 * RegOpenKeyExA for "HKLM\Software\Microsoft\Active Setup\Installed Components\{guid}"
3540 * RegQueryValueExA for "Locale"
3541 * RegCloseKey
3542 * and then tests the Locale ("en" for me).
3543 * code below
3544 * after the code then a DPA_Create (first time) and DPA_InsertPtr are done.
3545 */
3546 CHAR mod_path[2*MAX_PATH];
3547 LPSTR ptr;
3548 DWORD len;
3549
3550 FIXME("(%s,%p,%d) semi-stub!\n", debugstr_a(new_mod), inst_hwnd, dwCrossCodePage);
3551 len = GetModuleFileNameA(inst_hwnd, mod_path, sizeof(mod_path));
3552 if (!len || len >= sizeof(mod_path)) return NULL;
3553
3554 ptr = strrchr(mod_path, '\\');
3555 if (ptr) {
3556 strcpy(ptr+1, new_mod);
3557 TRACE("loading %s\n", debugstr_a(mod_path));
3558 return LoadLibraryA(mod_path);
3559 }
3560 return NULL;
3561 }
3562
3563 /*************************************************************************
3564 * @ [SHLWAPI.378]
3565 *
3566 * Unicode version of MLLoadLibraryA.
3567 */
3568 HMODULE WINAPI MLLoadLibraryW(LPCWSTR new_mod, HMODULE inst_hwnd, DWORD dwCrossCodePage)
3569 {
3570 WCHAR mod_path[2*MAX_PATH];
3571 LPWSTR ptr;
3572 DWORD len;
3573
3574 FIXME("(%s,%p,%d) semi-stub!\n", debugstr_w(new_mod), inst_hwnd, dwCrossCodePage);
3575 len = GetModuleFileNameW(inst_hwnd, mod_path, sizeof(mod_path) / sizeof(WCHAR));
3576 if (!len || len >= sizeof(mod_path) / sizeof(WCHAR)) return NULL;
3577
3578 ptr = strrchrW(mod_path, '\\');
3579 if (ptr) {
3580 strcpyW(ptr+1, new_mod);
3581 TRACE("loading %s\n", debugstr_w(mod_path));
3582 return LoadLibraryW(mod_path);
3583 }
3584 return NULL;
3585 }
3586
3587 /*************************************************************************
3588 * ColorAdjustLuma [SHLWAPI.@]
3589 *
3590 * Adjust the luminosity of a color
3591 *
3592 * PARAMS
3593 * cRGB [I] RGB value to convert
3594 * dwLuma [I] Luma adjustment
3595 * bUnknown [I] Unknown
3596 *
3597 * RETURNS
3598 * The adjusted RGB color.
3599 */
3600 COLORREF WINAPI ColorAdjustLuma(COLORREF cRGB, int dwLuma, BOOL bUnknown)
3601 {
3602 TRACE("(0x%8x,%d,%d)\n", cRGB, dwLuma, bUnknown);
3603
3604 if (dwLuma)
3605 {
3606 WORD wH, wL, wS;
3607
3608 ColorRGBToHLS(cRGB, &wH, &wL, &wS);
3609
3610 FIXME("Ignoring luma adjustment\n");
3611
3612 /* FIXME: The adjustment is not linear */
3613
3614 cRGB = ColorHLSToRGB(wH, wL, wS);
3615 }
3616 return cRGB;
3617 }
3618
3619 /*************************************************************************
3620 * @ [SHLWAPI.389]
3621 *
3622 * See GetSaveFileNameW.
3623 */
3624 BOOL WINAPI GetSaveFileNameWrapW(LPOPENFILENAMEW ofn)
3625 {
3626 return GetSaveFileNameW(ofn);
3627 }
3628
3629 /*************************************************************************
3630 * @ [SHLWAPI.390]
3631 *
3632 * See WNetRestoreConnectionW.
3633 */
3634 DWORD WINAPI WNetRestoreConnectionWrapW(HWND hwndOwner, LPWSTR lpszDevice)
3635 {
3636 return WNetRestoreConnectionW(hwndOwner, lpszDevice);
3637 }
3638
3639 /*************************************************************************
3640 * @ [SHLWAPI.391]
3641 *
3642 * See WNetGetLastErrorW.
3643 */
3644 DWORD WINAPI WNetGetLastErrorWrapW(LPDWORD lpError, LPWSTR lpErrorBuf, DWORD nErrorBufSize,
3645 LPWSTR lpNameBuf, DWORD nNameBufSize)
3646 {
3647 return WNetGetLastErrorW(lpError, lpErrorBuf, nErrorBufSize, lpNameBuf, nNameBufSize);
3648 }
3649
3650 /*************************************************************************
3651 * @ [SHLWAPI.401]
3652 *
3653 * See PageSetupDlgW.
3654 */
3655 BOOL WINAPI PageSetupDlgWrapW(LPPAGESETUPDLGW pagedlg)
3656 {
3657 return PageSetupDlgW(pagedlg);
3658 }
3659
3660 /*************************************************************************
3661 * @ [SHLWAPI.402]
3662 *
3663 * See PrintDlgW.
3664 */
3665 BOOL WINAPI PrintDlgWrapW(LPPRINTDLGW printdlg)
3666 {
3667 return PrintDlgW(printdlg);
3668 }
3669
3670 /*************************************************************************
3671 * @ [SHLWAPI.403]
3672 *
3673 * See GetOpenFileNameW.
3674 */
3675 BOOL WINAPI GetOpenFileNameWrapW(LPOPENFILENAMEW ofn)
3676 {
3677 return GetOpenFileNameW(ofn);
3678 }
3679
3680 /*************************************************************************
3681 * @ [SHLWAPI.404]
3682 */
3683 HRESULT WINAPI SHIShellFolder_EnumObjects(LPSHELLFOLDER lpFolder, HWND hwnd, SHCONTF flags, IEnumIDList **ppenum)
3684 {
3685 /* Windows attempts to get an IPersist interface and, if that fails, an
3686 * IPersistFolder interface on the folder passed-in here. If one of those
3687 * interfaces is available, it then calls GetClassID on the folder... and
3688 * then calls IShellFolder_EnumObjects no matter what, even crashing if
3689 * lpFolder isn't actually an IShellFolder object. The purpose of getting
3690 * the ClassID is unknown, so we don't do it here.
3691 *
3692 * For discussion and detailed tests, see:
3693 * "shlwapi: Be less strict on which type of IShellFolder can be enumerated"
3694 * wine-devel mailing list, 3 Jun 2010
3695 */
3696
3697 return IShellFolder_EnumObjects(lpFolder, hwnd, flags, ppenum);
3698 }
3699
3700 /* INTERNAL: Map from HLS color space to RGB */
3701 static WORD ConvertHue(int wHue, WORD wMid1, WORD wMid2)
3702 {
3703 wHue = wHue > 240 ? wHue - 240 : wHue < 0 ? wHue + 240 : wHue;
3704
3705 if (wHue > 160)
3706 return wMid1;
3707 else if (wHue > 120)
3708 wHue = 160 - wHue;
3709 else if (wHue > 40)
3710 return wMid2;
3711
3712 return ((wHue * (wMid2 - wMid1) + 20) / 40) + wMid1;
3713 }
3714
3715 /* Convert to RGB and scale into RGB range (0..255) */
3716 #define GET_RGB(h) (ConvertHue(h, wMid1, wMid2) * 255 + 120) / 240
3717
3718 /*************************************************************************
3719 * ColorHLSToRGB [SHLWAPI.@]
3720 *
3721 * Convert from hls color space into an rgb COLORREF.
3722 *
3723 * PARAMS
3724 * wHue [I] Hue amount
3725 * wLuminosity [I] Luminosity amount
3726 * wSaturation [I] Saturation amount
3727 *
3728 * RETURNS
3729 * A COLORREF representing the converted color.
3730 *
3731 * NOTES
3732 * Input hls values are constrained to the range (0..240).
3733 */
3734 COLORREF WINAPI ColorHLSToRGB(WORD wHue, WORD wLuminosity, WORD wSaturation)
3735 {
3736 WORD wRed;
3737
3738 if (wSaturation)
3739 {
3740 WORD wGreen, wBlue, wMid1, wMid2;
3741
3742 if (wLuminosity > 120)
3743 wMid2 = wSaturation + wLuminosity - (wSaturation * wLuminosity + 120) / 240;
3744 else
3745 wMid2 = ((wSaturation + 240) * wLuminosity + 120) / 240;
3746
3747 wMid1 = wLuminosity * 2 - wMid2;
3748
3749 wRed = GET_RGB(wHue + 80);
3750 wGreen = GET_RGB(wHue);
3751 wBlue = GET_RGB(wHue - 80);
3752
3753 return RGB(wRed, wGreen, wBlue);
3754 }
3755
3756 wRed = wLuminosity * 255 / 240;
3757 return RGB(wRed, wRed, wRed);
3758 }
3759
3760 /*************************************************************************
3761 * @ [SHLWAPI.413]
3762 *
3763 * Get the current docking status of the system.
3764 *
3765 * PARAMS
3766 * dwFlags [I] DOCKINFO_ flags from "winbase.h", unused
3767 *
3768 * RETURNS
3769 * One of DOCKINFO_UNDOCKED, DOCKINFO_UNDOCKED, or 0 if the system is not
3770 * a notebook.
3771 */
3772 DWORD WINAPI SHGetMachineInfo(DWORD dwFlags)
3773 {
3774 HW_PROFILE_INFOA hwInfo;
3775
3776 TRACE("(0x%08x)\n", dwFlags);
3777
3778 GetCurrentHwProfileA(&hwInfo);
3779 switch (hwInfo.dwDockInfo & (DOCKINFO_DOCKED|DOCKINFO_UNDOCKED))
3780 {
3781 case DOCKINFO_DOCKED:
3782 case DOCKINFO_UNDOCKED:
3783 return hwInfo.dwDockInfo & (DOCKINFO_DOCKED|DOCKINFO_UNDOCKED);
3784 default:
3785 return 0;
3786 }
3787 }
3788
3789 /*************************************************************************
3790 * @ [SHLWAPI.416]
3791 *
3792 */
3793 DWORD WINAPI SHWinHelpOnDemandW(HWND hwnd, LPCWSTR helpfile, DWORD flags1, VOID *ptr1, DWORD flags2)
3794 {
3795
3796 FIXME("(%p, %s, 0x%x, %p, %d)\n", hwnd, debugstr_w(helpfile), flags1, ptr1, flags2);
3797 return 0;
3798 }
3799
3800 /*************************************************************************
3801 * @ [SHLWAPI.417]
3802 *
3803 */
3804 DWORD WINAPI SHWinHelpOnDemandA(HWND hwnd, LPCSTR helpfile, DWORD flags1, VOID *ptr1, DWORD flags2)
3805 {
3806
3807 FIXME("(%p, %s, 0x%x, %p, %d)\n", hwnd, debugstr_a(helpfile), flags1, ptr1, flags2);
3808 return 0;
3809 }
3810
3811 /*************************************************************************
3812 * @ [SHLWAPI.418]
3813 *
3814 * Function seems to do FreeLibrary plus other things.
3815 *
3816 * FIXME native shows the following calls:
3817 * RtlEnterCriticalSection
3818 * LocalFree
3819 * GetProcAddress(Comctl32??, 150L)
3820 * DPA_DeletePtr
3821 * RtlLeaveCriticalSection
3822 * followed by the FreeLibrary.
3823 * The above code may be related to .377 above.
3824 */
3825 BOOL WINAPI MLFreeLibrary(HMODULE hModule)
3826 {
3827 FIXME("(%p) semi-stub\n", hModule);
3828 return FreeLibrary(hModule);
3829 }
3830
3831 /*************************************************************************
3832 * @ [SHLWAPI.419]
3833 */
3834 BOOL WINAPI SHFlushSFCacheWrap(void) {
3835 FIXME(": stub\n");
3836 return TRUE;
3837 }
3838
3839 /*************************************************************************
3840 * @ [SHLWAPI.429]
3841 * FIXME I have no idea what this function does or what its arguments are.
3842 */
3843 BOOL WINAPI MLIsMLHInstance(HINSTANCE hInst)
3844 {
3845 FIXME("(%p) stub\n", hInst);
3846 return FALSE;
3847 }
3848
3849
3850 /*************************************************************************
3851 * @ [SHLWAPI.430]
3852 */
3853 DWORD WINAPI MLSetMLHInstance(HINSTANCE hInst, HANDLE hHeap)
3854 {
3855 FIXME("(%p,%p) stub\n", hInst, hHeap);
3856 return E_FAIL; /* This is what is used if shlwapi not loaded */
3857 }
3858
3859 /*************************************************************************
3860 * @ [SHLWAPI.431]
3861 */
3862 DWORD WINAPI MLClearMLHInstance(DWORD x)
3863 {
3864 FIXME("(0x%08x)stub\n", x);
3865 return 0xabba1247;
3866 }
3867
3868 /*************************************************************************
3869 * @ [SHLWAPI.432]
3870 *
3871 * See SHSendMessageBroadcastW
3872 *
3873 */
3874 DWORD WINAPI SHSendMessageBroadcastA(UINT uMsg, WPARAM wParam, LPARAM lParam)
3875 {
3876 return SendMessageTimeoutA(HWND_BROADCAST, uMsg, wParam, lParam,
3877 SMTO_ABORTIFHUNG, 2000, NULL);
3878 }
3879
3880 /*************************************************************************
3881 * @ [SHLWAPI.433]
3882 *
3883 * A wrapper for sending Broadcast Messages to all top level Windows
3884 *
3885 */
3886 DWORD WINAPI SHSendMessageBroadcastW(UINT uMsg, WPARAM wParam, LPARAM lParam)
3887 {
3888 return SendMessageTimeoutW(HWND_BROADCAST, uMsg, wParam, lParam,
3889 SMTO_ABORTIFHUNG, 2000, NULL);
3890 }
3891
3892 /*************************************************************************
3893 * @ [SHLWAPI.436]
3894 *
3895 * Convert a Unicode string CLSID into a CLSID.
3896 *
3897 * PARAMS
3898 * idstr [I] string containing a CLSID in text form
3899 * id [O] CLSID extracted from the string
3900 *
3901 * RETURNS
3902 * S_OK on success or E_INVALIDARG on failure
3903 */
3904 HRESULT WINAPI CLSIDFromStringWrap(LPCWSTR idstr, CLSID *id)
3905 {
3906 return CLSIDFromString((LPCOLESTR)idstr, id);
3907 }
3908
3909 /*************************************************************************
3910 * @ [SHLWAPI.437]
3911 *
3912 * Determine if the OS supports a given feature.
3913 *
3914 * PARAMS
3915 * dwFeature [I] Feature requested (undocumented)
3916 *
3917 * RETURNS
3918 * TRUE If the feature is available.
3919 * FALSE If the feature is not available.
3920 */
3921 BOOL WINAPI IsOS(DWORD feature)
3922 {
3923 OSVERSIONINFOA osvi;
3924 DWORD platform, majorv, minorv;
3925
3926 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
3927 if(!GetVersionExA(&osvi)) {
3928 ERR("GetVersionEx failed\n");
3929 return FALSE;
3930 }
3931
3932 majorv = osvi.dwMajorVersion;
3933 minorv = osvi.dwMinorVersion;
3934 platform = osvi.dwPlatformId;
3935
3936 #define ISOS_RETURN(x) \
3937 TRACE("(0x%x) ret=%d\n",feature,(x)); \
3938 return (x);
3939
3940 switch(feature) {
3941 case OS_WIN32SORGREATER:
3942 ISOS_RETURN(platform == VER_PLATFORM_WIN32s
3943 || platform == VER_PLATFORM_WIN32_WINDOWS)
3944 case OS_NT:
3945 ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT)
3946 case OS_WIN95ORGREATER:
3947 ISOS_RETURN(platform == VER_PLATFORM_WIN32_WINDOWS)
3948 case OS_NT4ORGREATER:
3949 ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT && majorv >= 4)
3950 case OS_WIN2000ORGREATER_ALT:
3951 case OS_WIN2000ORGREATER:
3952 ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT && majorv >= 5)
3953 case OS_WIN98ORGREATER:
3954 ISOS_RETURN(platform == VER_PLATFORM_WIN32_WINDOWS && minorv >= 10)
3955 case OS_WIN98_GOLD:
3956 ISOS_RETURN(platform == VER_PLATFORM_WIN32_WINDOWS && minorv == 10)
3957 case OS_WIN2000PRO:
3958 ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT && majorv >= 5)
3959 case OS_WIN2000SERVER:
3960 ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT && (minorv == 0 || minorv == 1))
3961 case OS_WIN2000ADVSERVER:
3962 ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT && (minorv == 0 || minorv == 1))
3963 case OS_WIN2000DATACENTER:
3964 ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT && (minorv == 0 || minorv == 1))
3965 case OS_WIN2000TERMINAL:
3966 ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT && (minorv == 0 || minorv == 1))
3967 case OS_EMBEDDED:
3968 FIXME("(OS_EMBEDDED) What should we return here?\n");
3969 return FALSE;
3970 case OS_TERMINALCLIENT:
3971 FIXME("(OS_TERMINALCLIENT) What should we return here?\n");
3972 return FALSE;
3973 case OS_TERMINALREMOTEADMIN:
3974 FIXME("(OS_TERMINALREMOTEADMIN) What should we return here?\n");
3975 return FALSE;
3976 case OS_WIN95_GOLD:
3977 ISOS_RETURN(platform == VER_PLATFORM_WIN32_WINDOWS && minorv == 0)
3978 case OS_MEORGREATER:
3979 ISOS_RETURN(platform == VER_PLATFORM_WIN32_WINDOWS && minorv >= 90)
3980 case OS_XPORGREATER:
3981 ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT && majorv >= 5 && minorv >= 1)
3982 case OS_HOME:
3983 ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT && majorv >= 5 && minorv >= 1)
3984 case OS_PROFESSIONAL:
3985 ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT)
3986 case OS_DATACENTER:
3987 ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT)
3988 case OS_ADVSERVER:
3989 ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT && majorv >= 5)
3990 case OS_SERVER:
3991 ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT)
3992 case OS_TERMINALSERVER:
3993 ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT)
3994 case OS_PERSONALTERMINALSERVER:
3995 ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT && minorv >= 1 && majorv >= 5)
3996 case OS_FASTUSERSWITCHING:
3997 FIXME("(OS_FASTUSERSWITCHING) What should we return here?\n");
3998 return TRUE;
3999 case OS_WELCOMELOGONUI:
4000 FIXME("(OS_WELCOMELOGONUI) What should we return here?\n");
4001 return FALSE;
4002 case OS_DOMAINMEMBER:
4003 FIXME("(OS_DOMAINMEMBER) What should we return here?\n");
4004 return TRUE;
4005 case OS_ANYSERVER:
4006 ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT)
4007 case OS_WOW6432:
4008 {
4009 BOOL is_wow64;
4010 IsWow64Process(GetCurrentProcess(), &is_wow64);
4011 return is_wow64;
4012 }
4013 case OS_WEBSERVER:
4014 ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT)
4015 case OS_SMALLBUSINESSSERVER:
4016 ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT)
4017 case OS_TABLETPC:
4018 FIXME("(OS_TABLEPC) What should we return here?\n");
4019 return FALSE;
4020 case OS_SERVERADMINUI:
4021 FIXME("(OS_SERVERADMINUI) What should we return here?\n");
4022 return FALSE;
4023 case OS_MEDIACENTER:
4024 FIXME("(OS_MEDIACENTER) What should we return here?\n");
4025 return FALSE;
4026 case OS_APPLIANCE:
4027 FIXME("(OS_APPLIANCE) What should we return here?\n");
4028 return FALSE;
4029 case 0x25: /*OS_VISTAORGREATER*/
4030 ISOS_RETURN(platform == VER_PLATFORM_WIN32_NT && majorv >= 6)
4031 }
4032
4033 #undef ISOS_RETURN
4034
4035 WARN("(0x%x) unknown parameter\n",feature);
4036
4037 return FALSE;
4038 }
4039
4040 /*************************************************************************
4041 * @ [SHLWAPI.439]
4042 */
4043 HRESULT WINAPI SHLoadRegUIStringW(HKEY hkey, LPCWSTR value, LPWSTR buf, DWORD size)
4044 {
4045 DWORD type, sz = size;
4046
4047 if(RegQueryValueExW(hkey, value, NULL, &type, (LPBYTE)buf, &sz) != ERROR_SUCCESS)
4048 return E_FAIL;
4049
4050 return SHLoadIndirectString(buf, buf, size, NULL);
4051 }
4052
4053 /*************************************************************************
4054 * @ [SHLWAPI.478]
4055 *
4056 * Call IInputObject_TranslateAcceleratorIO() on an object.
4057 *
4058 * PARAMS
4059 * lpUnknown [I] Object supporting the IInputObject interface.
4060 * lpMsg [I] Key message to be processed.
4061 *
4062 * RETURNS
4063 * Success: S_OK.
4064 * Failure: An HRESULT error code, or E_INVALIDARG if lpUnknown is NULL.
4065 */
4066 HRESULT WINAPI IUnknown_TranslateAcceleratorIO(IUnknown *lpUnknown, LPMSG lpMsg)
4067 {
4068 IInputObject* lpInput = NULL;
4069 HRESULT hRet = E_INVALIDARG;
4070
4071 TRACE("(%p,%p)\n", lpUnknown, lpMsg);
4072 if (lpUnknown)
4073 {
4074 hRet = IUnknown_QueryInterface(lpUnknown, &IID_IInputObject,
4075 (void**)&lpInput);
4076 if (SUCCEEDED(hRet) && lpInput)
4077 {
4078 hRet = IInputObject_TranslateAcceleratorIO(lpInput, lpMsg);
4079 IInputObject_Release(lpInput);
4080 }
4081 }
4082 return hRet;
4083 }
4084
4085 /*************************************************************************
4086 * @ [SHLWAPI.481]
4087 *
4088 * Call IInputObject_HasFocusIO() on an object.
4089 *
4090 * PARAMS
4091 * lpUnknown [I] Object supporting the IInputObject interface.
4092 *
4093 * RETURNS
4094 * Success: S_OK, if lpUnknown is an IInputObject object and has the focus,
4095 * or S_FALSE otherwise.
4096 * Failure: An HRESULT error code, or E_INVALIDARG if lpUnknown is NULL.
4097 */
4098 HRESULT WINAPI IUnknown_HasFocusIO(IUnknown *lpUnknown)
4099 {
4100 IInputObject* lpInput = NULL;
4101 HRESULT hRet = E_INVALIDARG;
4102
4103 TRACE("(%p)\n", lpUnknown);
4104 if (lpUnknown)
4105 {
4106 hRet = IUnknown_QueryInterface(lpUnknown, &IID_IInputObject,
4107 (void**)&lpInput);
4108 if (SUCCEEDED(hRet) && lpInput)
4109 {
4110 hRet = IInputObject_HasFocusIO(lpInput);
4111 IInputObject_Release(lpInput);
4112 }
4113 }
4114 return hRet;
4115 }
4116
4117 /*************************************************************************
4118 * ColorRGBToHLS [SHLWAPI.@]
4119 *
4120 * Convert an rgb COLORREF into the hls color space.
4121 *
4122 * PARAMS
4123 * cRGB [I] Source rgb value
4124 * pwHue [O] Destination for converted hue
4125 * pwLuminance [O] Destination for converted luminance
4126 * pwSaturation [O] Destination for converted saturation
4127 *
4128 * RETURNS
4129 * Nothing. pwHue, pwLuminance and pwSaturation are set to the converted
4130 * values.
4131 *
4132 * NOTES
4133 * Output HLS values are constrained to the range (0..240).
4134 * For Achromatic conversions, Hue is set to 160.
4135 */
4136 VOID WINAPI ColorRGBToHLS(COLORREF cRGB, LPWORD pwHue,
4137 LPWORD pwLuminance, LPWORD pwSaturation)
4138 {
4139 int wR, wG, wB, wMax, wMin, wHue, wLuminosity, wSaturation;
4140
4141 TRACE("(%08x,%p,%p,%p)\n", cRGB, pwHue, pwLuminance, pwSaturation);
4142
4143 wR = GetRValue(cRGB);
4144 wG = GetGValue(cRGB);
4145 wB = GetBValue(cRGB);
4146
4147 wMax = max(wR, max(wG, wB));
4148 wMin = min(wR, min(wG, wB));
4149
4150 /* Luminosity */
4151 wLuminosity = ((wMax + wMin) * 240 + 255) / 510;
4152
4153 if (wMax == wMin)
4154 {
4155 /* Achromatic case */
4156 wSaturation = 0;
4157 /* Hue is now unrepresentable, but this is what native returns... */
4158 wHue = 160;
4159 }
4160 else
4161 {
4162 /* Chromatic case */
4163 int wDelta = wMax - wMin, wRNorm, wGNorm, wBNorm;
4164
4165 /* Saturation */
4166 if (wLuminosity <= 120)
4167 wSaturation = ((wMax + wMin)/2 + wDelta * 240) / (wMax + wMin);
4168 else
4169 wSaturation = ((510 - wMax - wMin)/2 + wDelta * 240) / (510 - wMax - wMin);
4170
4171 /* Hue */
4172 wRNorm = (wDelta/2 + wMax * 40 - wR * 40) / wDelta;
4173 wGNorm = (wDelta/2 + wMax * 40 - wG * 40) / wDelta;
4174 wBNorm = (wDelta/2 + wMax * 40 - wB * 40) / wDelta;
4175
4176 if (wR == wMax)
4177 wHue = wBNorm - wGNorm;
4178 else if (wG == wMax)
4179 wHue = 80 + wRNorm - wBNorm;
4180 else
4181 wHue = 160 + wGNorm - wRNorm;
4182 if (wHue < 0)
4183 wHue += 240;
4184 else if (wHue > 240)
4185 wHue -= 240;
4186 }
4187 if (pwHue)
4188 *pwHue = wHue;
4189 if (pwLuminance)
4190 *pwLuminance = wLuminosity;
4191 if (pwSaturation)
4192 *pwSaturation = wSaturation;
4193 }
4194
4195 /*************************************************************************
4196 * SHCreateShellPalette [SHLWAPI.@]
4197 */
4198 HPALETTE WINAPI SHCreateShellPalette(HDC hdc)
4199 {
4200 FIXME("stub\n");
4201 return CreateHalftonePalette(hdc);
4202 }
4203
4204 /*************************************************************************
4205 * SHGetInverseCMAP (SHLWAPI.@)
4206 *
4207 * Get an inverse color map table.
4208 *
4209 * PARAMS
4210 * lpCmap [O] Destination for color map
4211 * dwSize [I] Size of memory pointed to by lpCmap
4212 *
4213 * RETURNS
4214 * Success: S_OK.
4215 * Failure: E_POINTER, If lpCmap is invalid.
4216 * E_INVALIDARG, If dwFlags is invalid
4217 * E_OUTOFMEMORY, If there is no memory available
4218 *
4219 * NOTES
4220 * dwSize may only be CMAP_PTR_SIZE (4) or CMAP_SIZE (8192).
4221 * If dwSize = CMAP_PTR_SIZE, *lpCmap is set to the address of this DLL's
4222 * internal CMap.
4223 * If dwSize = CMAP_SIZE, lpCmap is filled with a copy of the data from
4224 * this DLL's internal CMap.
4225 */
4226 HRESULT WINAPI SHGetInverseCMAP(LPDWORD dest, DWORD dwSize)
4227 {
4228 if (dwSize == 4) {
4229 FIXME(" - returning bogus address for SHGetInverseCMAP\n");
4230 *dest = (DWORD)0xabba1249;
4231 return 0;
4232 }
4233 FIXME("(%p, %#x) stub\n", dest, dwSize);
4234 return 0;
4235 }
4236
4237 /*************************************************************************
4238 * SHIsLowMemoryMachine [SHLWAPI.@]
4239 *
4240 * Determine if the current computer has low memory.
4241 *
4242 * PARAMS
4243 * x [I] FIXME
4244 *
4245 * RETURNS
4246 * TRUE if the users machine has 16 Megabytes of memory or less,
4247 * FALSE otherwise.
4248 */
4249 BOOL WINAPI SHIsLowMemoryMachine (DWORD x)
4250 {
4251 FIXME("(0x%08x) stub\n", x);
4252 return FALSE;
4253 }
4254
4255 /*************************************************************************
4256 * GetMenuPosFromID [SHLWAPI.@]
4257 *
4258 * Return the position of a menu item from its Id.
4259 *
4260 * PARAMS
4261 * hMenu [I] Menu containing the item
4262 * wID [I] Id of the menu item
4263 *
4264 * RETURNS
4265 * Success: The index of the menu item in hMenu.
4266 * Failure: -1, If the item is not found.
4267 */
4268 INT WINAPI GetMenuPosFromID(HMENU hMenu, UINT wID)
4269 {
4270 MENUITEMINFOW mi;
4271 INT nCount = GetMenuItemCount(hMenu), nIter = 0;
4272
4273 TRACE("%p %u\n", hMenu, wID);
4274
4275 while (nIter < nCount)
4276 {
4277 mi.cbSize = sizeof(mi);
4278 mi.fMask = MIIM_ID;
4279 if (GetMenuItemInfoW(hMenu, nIter, TRUE, &mi) && mi.wID == wID)
4280 {
4281 TRACE("ret %d\n", nIter);
4282 return nIter;
4283 }
4284 nIter++;
4285 }
4286
4287 return -1;
4288 }
4289
4290 /*************************************************************************
4291 * @ [SHLWAPI.179]
4292 *
4293 * Same as SHLWAPI.GetMenuPosFromID
4294 */
4295 DWORD WINAPI SHMenuIndexFromID(HMENU hMenu, UINT uID)
4296 {
4297 TRACE("%p %u\n", hMenu, uID);
4298 return GetMenuPosFromID(hMenu, uID);
4299 }
4300
4301
4302 /*************************************************************************
4303 * @ [SHLWAPI.448]
4304 */
4305 VOID WINAPI FixSlashesAndColonW(LPWSTR lpwstr)
4306 {
4307 while (*lpwstr)
4308 {
4309 if (*lpwstr == '/')
4310 *lpwstr = '\\';
4311 lpwstr++;
4312 }
4313 }
4314
4315
4316 /*************************************************************************
4317 * @ [SHLWAPI.461]
4318 */
4319 DWORD WINAPI SHGetAppCompatFlags(DWORD dwUnknown)
4320 {
4321 FIXME("(0x%08x) stub\n", dwUnknown);
4322 return 0;
4323 }
4324
4325
4326 /*************************************************************************
4327 * @ [SHLWAPI.549]
4328 */
4329 HRESULT WINAPI SHCoCreateInstanceAC(REFCLSID rclsid, LPUNKNOWN pUnkOuter,
4330 DWORD dwClsContext, REFIID iid, LPVOID *ppv)
4331 {
4332 return CoCreateInstance(rclsid, pUnkOuter, dwClsContext, iid, ppv);
4333 }
4334
4335 /*************************************************************************
4336 * SHSkipJunction [SHLWAPI.@]
4337 *
4338 * Determine if a bind context can be bound to an object
4339 *
4340 * PARAMS
4341 * pbc [I] Bind context to check
4342 * pclsid [I] CLSID of object to be bound to
4343 *
4344 * RETURNS
4345 * TRUE: If it is safe to bind
4346 * FALSE: If pbc is invalid or binding would not be safe
4347 *
4348 */
4349 BOOL WINAPI SHSkipJunction(IBindCtx *pbc, const CLSID *pclsid)
4350 {
4351 static WCHAR szSkipBinding[] = { 'S','k','i','p',' ',
4352 'B','i','n','d','i','n','g',' ','C','L','S','I','D','\0' };
4353 BOOL bRet = FALSE;
4354
4355 if (pbc)
4356 {
4357 IUnknown* lpUnk;
4358
4359 if (SUCCEEDED(IBindCtx_GetObjectParam(pbc, szSkipBinding, &lpUnk)))
4360 {
4361 CLSID clsid;
4362
4363 if (SUCCEEDED(IUnknown_GetClassID(lpUnk, &clsid)) &&
4364 IsEqualGUID(pclsid, &clsid))
4365 bRet = TRUE;
4366
4367 IUnknown_Release(lpUnk);
4368 }
4369 }
4370 return bRet;
4371 }
4372
4373 /***********************************************************************
4374 * SHGetShellKey (SHLWAPI.491)
4375 */
4376 HKEY WINAPI SHGetShellKey(DWORD flags, LPCWSTR sub_key, BOOL create)
4377 {
4378 enum _shellkey_flags {
4379 SHKEY_Root_HKCU = 0x1,
4380 SHKEY_Root_HKLM = 0x2,
4381 SHKEY_Key_Explorer = 0x00,
4382 SHKEY_Key_Shell = 0x10,
4383 SHKEY_Key_ShellNoRoam = 0x20,
4384 SHKEY_Key_Classes = 0x30,
4385 SHKEY_Subkey_Default = 0x0000,
4386 SHKEY_Subkey_ResourceName = 0x1000,
4387 SHKEY_Subkey_Handlers = 0x2000,
4388 SHKEY_Subkey_Associations = 0x3000,
4389 SHKEY_Subkey_Volatile = 0x4000,
4390 SHKEY_Subkey_MUICache = 0x5000,
4391 SHKEY_Subkey_FileExts = 0x6000
4392 };
4393
4394 static const WCHAR explorerW[] = {'S','o','f','t','w','a','r','e','\\',
4395 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
4396 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
4397 'E','x','p','l','o','r','e','r','\\'};
4398 static const WCHAR shellW[] = {'S','o','f','t','w','a','r','e','\\',
4399 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
4400 'S','h','e','l','l','\\'};
4401 static const WCHAR shell_no_roamW[] = {'S','o','f','t','w','a','r','e','\\',
4402 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
4403 'S','h','e','l','l','N','o','R','o','a','m','\\'};
4404 static const WCHAR classesW[] = {'S','o','f','t','w','a','r','e','\\',
4405 'C','l','a','s','s','e','s','\\'};
4406
4407 static const WCHAR localized_resource_nameW[] = {'L','o','c','a','l','i','z','e','d',
4408 'R','e','s','o','u','r','c','e','N','a','m','e','\\'};
4409 static const WCHAR handlersW[] = {'H','a','n','d','l','e','r','s','\\'};
4410 static const WCHAR associationsW[] = {'A','s','s','o','c','i','a','t','i','o','n','s','\\'};
4411 static const WCHAR volatileW[] = {'V','o','l','a','t','i','l','e','\\'};
4412 static const WCHAR mui_cacheW[] = {'M','U','I','C','a','c','h','e','\\'};
4413 static const WCHAR file_extsW[] = {'F','i','l','e','E','x','t','s','\\'};
4414
4415 WCHAR *path;
4416 const WCHAR *key, *subkey;
4417 int size_key, size_subkey, size_user;
4418 HKEY hkey = NULL;
4419
4420 TRACE("(0x%08x, %s, %d)\n", flags, debugstr_w(sub_key), create);
4421
4422 /* For compatibility with Vista+ */
4423 if(flags == 0x1ffff)
4424 flags = 0x21;
4425
4426 switch(flags&0xff0) {
4427 case SHKEY_Key_Explorer:
4428 key = explorerW;
4429 size_key = sizeof(explorerW);
4430 break;
4431 case SHKEY_Key_Shell:
4432 key = shellW;
4433 size_key = sizeof(shellW);
4434 break;
4435 case SHKEY_Key_ShellNoRoam:
4436 key = shell_no_roamW;
4437 size_key = sizeof(shell_no_roamW);
4438 break;
4439 case SHKEY_Key_Classes:
4440 key = classesW;
4441 size_key = sizeof(classesW);
4442 break;
4443 default:
4444 FIXME("unsupported flags (0x%08x)\n", flags);
4445 return NULL;
4446 }
4447
4448 switch(flags&0xff000) {
4449 case SHKEY_Subkey_Default:
4450 subkey = NULL;
4451 size_subkey = 0;
4452 break;
4453 case SHKEY_Subkey_ResourceName:
4454 subkey = localized_resource_nameW;
4455 size_subkey = sizeof(localized_resource_nameW);
4456 break;
4457 case SHKEY_Subkey_Handlers:
4458 subkey = handlersW;
4459 size_subkey = sizeof(handlersW);
4460 break;
4461 case SHKEY_Subkey_Associations:
4462 subkey = associationsW;
4463 size_subkey = sizeof(associationsW);
4464 break;
4465 case SHKEY_Subkey_Volatile:
4466 subkey = volatileW;
4467 size_subkey = sizeof(volatileW);
4468 break;
4469 case SHKEY_Subkey_MUICache:
4470 subkey = mui_cacheW;
4471 size_subkey = sizeof(mui_cacheW);
4472 break;
4473 case SHKEY_Subkey_FileExts:
4474 subkey = file_extsW;
4475 size_subkey = sizeof(file_extsW);
4476 break;
4477 default:
4478 FIXME("unsupported flags (0x%08x)\n", flags);
4479 return NULL;
4480 }
4481
4482 if(sub_key)
4483 size_user = lstrlenW(sub_key)*sizeof(WCHAR);
4484 else
4485 size_user = 0;
4486
4487 path = HeapAlloc(GetProcessHeap(), 0, size_key+size_subkey+size_user+sizeof(WCHAR));
4488 if(!path) {
4489 ERR("Out of memory\n");
4490 return NULL;
4491 }
4492
4493 memcpy(path, key, size_key);
4494 if(subkey)
4495 memcpy(path+size_key/sizeof(WCHAR), subkey, size_subkey);
4496 if(sub_key)
4497 memcpy(path+(size_key+size_subkey)/sizeof(WCHAR), sub_key, size_user);
4498 path[(size_key+size_subkey+size_user)/sizeof(WCHAR)] = '\0';
4499
4500 if(create)
4501 RegCreateKeyExW((flags&0xf)==SHKEY_Root_HKLM?HKEY_LOCAL_MACHINE:HKEY_CURRENT_USER,
4502 path, 0, NULL, 0, MAXIMUM_ALLOWED, NULL, &hkey, NULL);
4503 else
4504 RegOpenKeyExW((flags&0xf)==SHKEY_Root_HKLM?HKEY_LOCAL_MACHINE:HKEY_CURRENT_USER,
4505 path, 0, MAXIMUM_ALLOWED, &hkey);
4506
4507 HeapFree(GetProcessHeap(), 0, path);
4508 return hkey;
4509 }
4510
4511 /***********************************************************************
4512 * SHQueueUserWorkItem (SHLWAPI.@)
4513 */
4514 BOOL WINAPI SHQueueUserWorkItem(LPTHREAD_START_ROUTINE pfnCallback,
4515 LPVOID pContext, LONG lPriority, DWORD_PTR dwTag,
4516 DWORD_PTR *pdwId, LPCSTR pszModule, DWORD dwFlags)
4517 {
4518 TRACE("(%p, %p, %d, %lx, %p, %s, %08x)\n", pfnCallback, pContext,
4519 lPriority, dwTag, pdwId, debugstr_a(pszModule), dwFlags);
4520
4521 if(lPriority || dwTag || pdwId || pszModule || dwFlags)
4522 FIXME("Unsupported arguments\n");
4523
4524 return QueueUserWorkItem(pfnCallback, pContext, 0);
4525 }
4526
4527 /***********************************************************************
4528 * SHSetTimerQueueTimer (SHLWAPI.263)
4529 */
4530 HANDLE WINAPI SHSetTimerQueueTimer(HANDLE hQueue,
4531 WAITORTIMERCALLBACK pfnCallback, LPVOID pContext, DWORD dwDueTime,
4532 DWORD dwPeriod, LPCSTR lpszLibrary, DWORD dwFlags)
4533 {
4534 HANDLE hNewTimer;
4535
4536 /* SHSetTimerQueueTimer flags -> CreateTimerQueueTimer flags */
4537 if (dwFlags & TPS_LONGEXECTIME) {
4538 dwFlags &= ~TPS_LONGEXECTIME;
4539 dwFlags |= WT_EXECUTELONGFUNCTION;
4540 }
4541 if (dwFlags & TPS_EXECUTEIO) {
4542 dwFlags &= ~TPS_EXECUTEIO;
4543 dwFlags |= WT_EXECUTEINIOTHREAD;
4544 }
4545
4546 if (!CreateTimerQueueTimer(&hNewTimer, hQueue, pfnCallback, pContext,
4547 dwDueTime, dwPeriod, dwFlags))
4548 return NULL;
4549
4550 return hNewTimer;
4551 }
4552
4553 /***********************************************************************
4554 * IUnknown_OnFocusChangeIS (SHLWAPI.@)
4555 */
4556 HRESULT WINAPI IUnknown_OnFocusChangeIS(LPUNKNOWN lpUnknown, LPUNKNOWN pFocusObject, BOOL bFocus)
4557 {
4558 IInputObjectSite *pIOS = NULL;
4559 HRESULT hRet = E_INVALIDARG;
4560
4561 TRACE("(%p, %p, %s)\n", lpUnknown, pFocusObject, bFocus ? "TRUE" : "FALSE");
4562
4563 if (lpUnknown)
4564 {
4565 hRet = IUnknown_QueryInterface(lpUnknown, &IID_IInputObjectSite,
4566 (void **)&pIOS);
4567 if (SUCCEEDED(hRet) && pIOS)
4568 {
4569 hRet = IInputObjectSite_OnFocusChangeIS(pIOS, pFocusObject, bFocus);
4570 IInputObjectSite_Release(pIOS);
4571 }
4572 }
4573 return hRet;
4574 }
4575
4576 /***********************************************************************
4577 * SKAllocValueW (SHLWAPI.519)
4578 */
4579 HRESULT WINAPI SKAllocValueW(DWORD flags, LPCWSTR subkey, LPCWSTR value, DWORD *type,
4580 LPVOID *data, DWORD *count)
4581 {
4582 DWORD ret, size;
4583 HKEY hkey;
4584
4585 TRACE("(0x%x, %s, %s, %p, %p, %p)\n", flags, debugstr_w(subkey),
4586 debugstr_w(value), type, data, count);
4587
4588 hkey = SHGetShellKey(flags, subkey, FALSE);
4589 if (!hkey)
4590 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
4591
4592 ret = SHQueryValueExW(hkey, value, NULL, type, NULL, &size);
4593 if (ret) {
4594 RegCloseKey(hkey);
4595 return HRESULT_FROM_WIN32(ret);
4596 }
4597
4598 size += 2;
4599 *data = LocalAlloc(0, size);
4600 if (!*data) {
4601 RegCloseKey(hkey);
4602 return E_OUTOFMEMORY;
4603 }
4604
4605 ret = SHQueryValueExW(hkey, value, NULL, type, *data, &size);
4606 if (count)
4607 *count = size;
4608
4609 RegCloseKey(hkey);
4610 return HRESULT_FROM_WIN32(ret);
4611 }
4612
4613 /***********************************************************************
4614 * SKDeleteValueW (SHLWAPI.518)
4615 */
4616 HRESULT WINAPI SKDeleteValueW(DWORD flags, LPCWSTR subkey, LPCWSTR value)
4617 {
4618 DWORD ret;
4619 HKEY hkey;
4620
4621 TRACE("(0x%x, %s %s)\n", flags, debugstr_w(subkey), debugstr_w(value));
4622
4623 hkey = SHGetShellKey(flags, subkey, FALSE);
4624 if (!hkey)
4625 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
4626
4627 ret = RegDeleteValueW(hkey, value);
4628
4629 RegCloseKey(hkey);
4630 return HRESULT_FROM_WIN32(ret);
4631 }
4632
4633 /***********************************************************************
4634 * SKGetValueW (SHLWAPI.516)
4635 */
4636 HRESULT WINAPI SKGetValueW(DWORD flags, LPCWSTR subkey, LPCWSTR value, DWORD *type,
4637 void *data, DWORD *count)
4638 {
4639 DWORD ret;
4640 HKEY hkey;
4641
4642 TRACE("(0x%x, %s, %s, %p, %p, %p)\n", flags, debugstr_w(subkey),
4643 debugstr_w(value), type, data, count);
4644
4645 hkey = SHGetShellKey(flags, subkey, FALSE);
4646 if (!hkey)
4647 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
4648
4649 ret = SHQueryValueExW(hkey, value, NULL, type, data, count);
4650
4651 RegCloseKey(hkey);
4652 return HRESULT_FROM_WIN32(ret);
4653 }
4654
4655 /***********************************************************************
4656 * SKSetValueW (SHLWAPI.516)
4657 */
4658 HRESULT WINAPI SKSetValueW(DWORD flags, LPCWSTR subkey, LPCWSTR value,
4659 DWORD type, void *data, DWORD count)
4660 {
4661 DWORD ret;
4662 HKEY hkey;
4663
4664 TRACE("(0x%x, %s, %s, %x, %p, %d)\n", flags, debugstr_w(subkey),
4665 debugstr_w(value), type, data, count);
4666
4667 hkey = SHGetShellKey(flags, subkey, TRUE);
4668 if (!hkey)
4669 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
4670
4671 ret = RegSetValueExW(hkey, value, 0, type, data, count);
4672
4673 RegCloseKey(hkey);
4674 return HRESULT_FROM_WIN32(ret);
4675 }
4676
4677 typedef HRESULT (WINAPI *DllGetVersion_func)(DLLVERSIONINFO *);
4678
4679 /***********************************************************************
4680 * GetUIVersion (SHLWAPI.452)
4681 */
4682 DWORD WINAPI GetUIVersion(void)
4683 {
4684 static DWORD version;
4685
4686 if (!version)
4687 {
4688 DllGetVersion_func pDllGetVersion;
4689 HMODULE dll = LoadLibraryA("shell32.dll");
4690 if (!dll) return 0;
4691
4692 pDllGetVersion = (DllGetVersion_func)GetProcAddress(dll, "DllGetVersion");
4693 if (pDllGetVersion)
4694 {
4695 DLLVERSIONINFO dvi;
4696 dvi.cbSize = sizeof(DLLVERSIONINFO);
4697 if (pDllGetVersion(&dvi) == S_OK) version = dvi.dwMajorVersion;
4698 }
4699 FreeLibrary( dll );
4700 if (!version) version = 3; /* old shell dlls don't have DllGetVersion */
4701 }
4702 return version;
4703 }
4704
4705 /***********************************************************************
4706 * ShellMessageBoxWrapW [SHLWAPI.388]
4707 *
4708 * See shell32.ShellMessageBoxW
4709 *
4710 * NOTE:
4711 * shlwapi.ShellMessageBoxWrapW is a duplicate of shell32.ShellMessageBoxW
4712 * because we can't forward to it in the .spec file since it's exported by
4713 * ordinal. If you change the implementation here please update the code in
4714 * shell32 as well.
4715 */
4716 INT WINAPIV ShellMessageBoxWrapW(HINSTANCE hInstance, HWND hWnd, LPCWSTR lpText,
4717 LPCWSTR lpCaption, UINT uType, ...)
4718 {
4719 WCHAR *szText = NULL, szTitle[100];
4720 LPCWSTR pszText, pszTitle = szTitle;
4721 LPWSTR pszTemp;
4722 __ms_va_list args;
4723 int ret;
4724
4725 __ms_va_start(args, uType);
4726
4727 TRACE("(%p,%p,%p,%p,%08x)\n", hInstance, hWnd, lpText, lpCaption, uType);
4728
4729 if (IS_INTRESOURCE(lpCaption))
4730 LoadStringW(hInstance, LOWORD(lpCaption), szTitle, sizeof(szTitle)/sizeof(szTitle[0]));
4731 else
4732 pszTitle = lpCaption;
4733
4734 if (IS_INTRESOURCE(lpText))
4735 {
4736 const WCHAR *ptr;
4737 UINT len = LoadStringW(hInstance, LOWORD(lpText), (LPWSTR)&ptr, 0);
4738
4739 if (len)
4740 {
4741 szText = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
4742 if (szText) LoadStringW(hInstance, LOWORD(lpText), szText, len + 1);
4743 }
4744 pszText = szText;
4745 if (!pszText) {
4746 WARN("Failed to load id %d\n", LOWORD(lpText));
4747 __ms_va_end(args);
4748 return 0;
4749 }
4750 }
4751 else
4752 pszText = lpText;
4753
4754 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING,
4755 pszText, 0, 0, (LPWSTR)&pszTemp, 0, &args);
4756
4757 __ms_va_end(args);
4758
4759 ret = MessageBoxW(hWnd, pszTemp, pszTitle, uType);
4760
4761 HeapFree(GetProcessHeap(), 0, szText);
4762 LocalFree(pszTemp);
4763 return ret;
4764 }
4765
4766 /***********************************************************************
4767 * ZoneComputePaneSize [SHLWAPI.382]
4768 */
4769 UINT WINAPI ZoneComputePaneSize(HWND hwnd)
4770 {
4771 FIXME("\n");
4772 return 0x95;
4773 }
4774
4775 /***********************************************************************
4776 * SHChangeNotifyWrap [SHLWAPI.394]
4777 */
4778 void WINAPI SHChangeNotifyWrap(LONG wEventId, UINT uFlags, LPCVOID dwItem1, LPCVOID dwItem2)
4779 {
4780 SHChangeNotify(wEventId, uFlags, dwItem1, dwItem2);
4781 }
4782
4783 typedef struct SHELL_USER_SID { /* according to MSDN this should be in shlobj.h... */
4784 SID_IDENTIFIER_AUTHORITY sidAuthority;
4785 DWORD dwUserGroupID;
4786 DWORD dwUserID;
4787 } SHELL_USER_SID, *PSHELL_USER_SID;
4788
4789 typedef struct SHELL_USER_PERMISSION { /* ...and this should be in shlwapi.h */
4790 SHELL_USER_SID susID;
4791 DWORD dwAccessType;
4792 BOOL fInherit;
4793 DWORD dwAccessMask;
4794 DWORD dwInheritMask;
4795 DWORD dwInheritAccessMask;
4796 } SHELL_USER_PERMISSION, *PSHELL_USER_PERMISSION;
4797
4798 /***********************************************************************
4799 * GetShellSecurityDescriptor [SHLWAPI.475]
4800 *
4801 * prepares SECURITY_DESCRIPTOR from a set of ACEs
4802 *
4803 * PARAMS
4804 * apUserPerm [I] array of pointers to SHELL_USER_PERMISSION structures,
4805 * each of which describes permissions to apply
4806 * cUserPerm [I] number of entries in apUserPerm array
4807 *
4808 * RETURNS
4809 * success: pointer to SECURITY_DESCRIPTOR
4810 * failure: NULL
4811 *
4812 * NOTES
4813 * Call should free returned descriptor with LocalFree
4814 */
4815 PSECURITY_DESCRIPTOR WINAPI GetShellSecurityDescriptor(PSHELL_USER_PERMISSION *apUserPerm, int cUserPerm)
4816 {
4817 PSID *sidlist;
4818 PSID cur_user = NULL;
4819 BYTE tuUser[2000];
4820 DWORD acl_size;
4821 int sid_count, i;
4822 PSECURITY_DESCRIPTOR psd = NULL;
4823
4824 TRACE("%p %d\n", apUserPerm, cUserPerm);
4825
4826 if (apUserPerm == NULL || cUserPerm <= 0)
4827 return NULL;
4828
4829 sidlist = HeapAlloc(GetProcessHeap(), 0, cUserPerm * sizeof(PSID));
4830 if (!sidlist)
4831 return NULL;
4832
4833 acl_size = sizeof(ACL);
4834
4835 for(sid_count = 0; sid_count < cUserPerm; sid_count++)
4836 {
4837 static SHELL_USER_SID null_sid = {{SECURITY_NULL_SID_AUTHORITY}, 0, 0};
4838 PSHELL_USER_PERMISSION perm = apUserPerm[sid_count];
4839 PSHELL_USER_SID sid = &perm->susID;
4840 PSID pSid;
4841 BOOL ret = TRUE;
4842
4843 if (!memcmp((void*)sid, (void*)&null_sid, sizeof(SHELL_USER_SID)))
4844 { /* current user's SID */
4845 if (!cur_user)
4846 {
4847 HANDLE Token;
4848 DWORD bufsize = sizeof(tuUser);
4849
4850 ret = OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &Token);
4851 if (ret)
4852 {
4853 ret = GetTokenInformation(Token, TokenUser, (void*)tuUser, bufsize, &bufsize );
4854 if (ret)
4855 cur_user = ((PTOKEN_USER)tuUser)->User.Sid;
4856 CloseHandle(Token);
4857 }
4858 }
4859 pSid = cur_user;
4860 } else if (sid->dwUserID==0) /* one sub-authority */
4861 ret = AllocateAndInitializeSid(&sid->sidAuthority, 1, sid->dwUserGroupID, 0,
4862 0, 0, 0, 0, 0, 0, &pSid);
4863 else
4864 ret = AllocateAndInitializeSid(&sid->sidAuthority, 2, sid->dwUserGroupID, sid->dwUserID,
4865 0, 0, 0, 0, 0, 0, &pSid);
4866 if (!ret)
4867 goto free_sids;
4868
4869 sidlist[sid_count] = pSid;
4870 /* increment acl_size (1 ACE for non-inheritable and 2 ACEs for inheritable records */
4871 acl_size += (sizeof(ACCESS_ALLOWED_ACE)-sizeof(DWORD) + GetLengthSid(pSid)) * (perm->fInherit ? 2 : 1);
4872 }
4873
4874 psd = LocalAlloc(0, sizeof(SECURITY_DESCRIPTOR) + acl_size);
4875
4876 if (psd != NULL)
4877 {
4878 PACL pAcl = (PACL)(((BYTE*)psd)+sizeof(SECURITY_DESCRIPTOR));
4879
4880 if (!InitializeSecurityDescriptor(psd, SECURITY_DESCRIPTOR_REVISION))
4881 goto error;
4882
4883 if (!InitializeAcl(pAcl, acl_size, ACL_REVISION))
4884 goto error;
4885
4886 for(i = 0; i < sid_count; i++)
4887 {
4888 PSHELL_USER_PERMISSION sup = apUserPerm[i];
4889 PSID sid = sidlist[i];
4890
4891 switch(sup->dwAccessType)
4892 {
4893 case ACCESS_ALLOWED_ACE_TYPE:
4894 if (!AddAccessAllowedAce(pAcl, ACL_REVISION, sup->dwAccessMask, sid))
4895 goto error;
4896 if (sup->fInherit && !AddAccessAllowedAceEx(pAcl, ACL_REVISION,
4897 (BYTE)sup->dwInheritMask, sup->dwInheritAccessMask, sid))
4898 goto error;
4899 break;
4900 case ACCESS_DENIED_ACE_TYPE:
4901 if (!AddAccessDeniedAce(pAcl, ACL_REVISION, sup->dwAccessMask, sid))
4902 goto error;
4903 if (sup->fInherit && !AddAccessDeniedAceEx(pAcl, ACL_REVISION,
4904 (BYTE)sup->dwInheritMask, sup->dwInheritAccessMask, sid))
4905 goto error;
4906 break;
4907 default:
4908 goto error;
4909 }
4910 }
4911
4912 if (!SetSecurityDescriptorDacl(psd, TRUE, pAcl, FALSE))
4913 goto error;
4914 }
4915 goto free_sids;
4916
4917 error:
4918 LocalFree(psd);
4919 psd = NULL;
4920 free_sids:
4921 for(i = 0; i < sid_count; i++)
4922 {
4923 if (!cur_user || sidlist[i] != cur_user)
4924 FreeSid(sidlist[i]);
4925 }
4926 HeapFree(GetProcessHeap(), 0, sidlist);
4927
4928 return psd;
4929 }
4930
4931 /***********************************************************************
4932 * SHCreatePropertyBagOnRegKey [SHLWAPI.471]
4933 *
4934 * Creates a property bag from a registry key
4935 *
4936 * PARAMS
4937 * hKey [I] Handle to the desired registry key
4938 * subkey [I] Name of desired subkey, or NULL to open hKey directly
4939 * grfMode [I] Optional flags
4940 * riid [I] IID of requested property bag interface
4941 * ppv [O] Address to receive pointer to the new interface
4942 *
4943 * RETURNS
4944 * success: 0
4945 * failure: error code
4946 *
4947 */
4948 HRESULT WINAPI SHCreatePropertyBagOnRegKey (HKEY hKey, LPCWSTR subkey,
4949 DWORD grfMode, REFIID riid, void **ppv)
4950 {
4951 FIXME("%p %s %d %s %p STUB\n", hKey, debugstr_w(subkey), grfMode,
4952 debugstr_guid(riid), ppv);
4953
4954 return E_NOTIMPL;
4955 }
4956
4957 /***********************************************************************
4958 * SHGetViewStatePropertyBag [SHLWAPI.515]
4959 *
4960 * Retrieves a property bag in which the view state information of a folder
4961 * can be stored.
4962 *
4963 * PARAMS
4964 * pidl [I] PIDL of the folder requested
4965 * bag_name [I] Name of the property bag requested
4966 * flags [I] Optional flags
4967 * riid [I] IID of requested property bag interface
4968 * ppv [O] Address to receive pointer to the new interface
4969 *
4970 * RETURNS
4971 * success: S_OK
4972 * failure: error code
4973 *
4974 */
4975 HRESULT WINAPI SHGetViewStatePropertyBag(LPCITEMIDLIST pidl, LPWSTR bag_name,
4976 DWORD flags, REFIID riid, void **ppv)
4977 {
4978 FIXME("%p %s %d %s %p STUB\n", pidl, debugstr_w(bag_name), flags,
4979 debugstr_guid(riid), ppv);
4980
4981 return E_NOTIMPL;
4982 }
4983
4984 /***********************************************************************
4985 * SHFormatDateTimeW [SHLWAPI.354]
4986 *
4987 * Produces a string representation of a time.
4988 *
4989 * PARAMS
4990 * fileTime [I] Pointer to FILETIME structure specifying the time
4991 * flags [I] Flags specifying the desired output
4992 * buf [O] Pointer to buffer for output
4993 * size [I] Number of characters that can be contained in buffer
4994 *
4995 * RETURNS
4996 * success: number of characters written to the buffer
4997 * failure: 0
4998 *
4999 */
5000 INT WINAPI SHFormatDateTimeW(const FILETIME UNALIGNED *fileTime, DWORD *flags,
5001 LPWSTR buf, UINT size)
5002 {
5003 #define SHFORMATDT_UNSUPPORTED_FLAGS (FDTF_RELATIVE | FDTF_LTRDATE | FDTF_RTLDATE | FDTF_NOAUTOREADINGORDER)
5004 DWORD fmt_flags = flags ? *flags : FDTF_DEFAULT;
5005 SYSTEMTIME st;
5006 FILETIME ft;
5007 INT ret = 0;
5008
5009 TRACE("%p %p %p %u\n", fileTime, flags, buf, size);
5010
5011 if (!buf || !size)
5012 return 0;
5013
5014 if (fmt_flags & SHFORMATDT_UNSUPPORTED_FLAGS)
5015 FIXME("ignoring some flags - 0x%08x\n", fmt_flags & SHFORMATDT_UNSUPPORTED_FLAGS);
5016
5017 FileTimeToLocalFileTime(fileTime, &ft);
5018 FileTimeToSystemTime(&ft, &st);
5019
5020 /* first of all date */
5021 if (fmt_flags & (FDTF_LONGDATE | FDTF_SHORTDATE))
5022 {
5023 static const WCHAR sep1[] = {',',' ',0};
5024 static const WCHAR sep2[] = {' ',0};
5025
5026 DWORD date = fmt_flags & FDTF_LONGDATE ? DATE_LONGDATE : DATE_SHORTDATE;
5027 ret = GetDateFormatW(LOCALE_USER_DEFAULT, date, &st, NULL, buf, size);
5028 if (ret >= size) return ret;
5029
5030 /* add separator */
5031 if (ret < size && (fmt_flags & (FDTF_LONGTIME | FDTF_SHORTTIME)))
5032 {
5033 if ((fmt_flags & FDTF_LONGDATE) && (ret < size + 2))
5034 {
5035 if (ret < size + 2)
5036 {
5037 lstrcatW(&buf[ret-1], sep1);
5038 ret += 2;
5039 }
5040 }
5041 else
5042 {
5043 lstrcatW(&buf[ret-1], sep2);
5044 ret++;
5045 }
5046 }
5047 }
5048 /* time part */
5049 if (fmt_flags & (FDTF_LONGTIME | FDTF_SHORTTIME))
5050 {
5051 DWORD time = fmt_flags & FDTF_LONGTIME ? 0 : TIME_NOSECONDS;
5052
5053 if (ret) ret--;
5054 ret += GetTimeFormatW(LOCALE_USER_DEFAULT, time, &st, NULL, &buf[ret], size - ret);
5055 }
5056
5057 return ret;
5058
5059 #undef SHFORMATDT_UNSUPPORTED_FLAGS
5060 }
5061
5062 /***********************************************************************
5063 * SHFormatDateTimeA [SHLWAPI.353]
5064 *
5065 * See SHFormatDateTimeW.
5066 *
5067 */
5068 INT WINAPI SHFormatDateTimeA(const FILETIME UNALIGNED *fileTime, DWORD *flags,
5069 LPSTR buf, UINT size)
5070 {
5071 WCHAR *bufW;
5072 INT retval;
5073
5074 if (!buf || !size)
5075 return 0;
5076
5077 bufW = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * size);
5078 retval = SHFormatDateTimeW(fileTime, flags, bufW, size);
5079
5080 if (retval != 0)
5081 WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, size, NULL, NULL);
5082
5083 HeapFree(GetProcessHeap(), 0, bufW);
5084 return retval;
5085 }
5086
5087 /***********************************************************************
5088 * ZoneCheckUrlExW [SHLWAPI.231]
5089 *
5090 * Checks the details of the security zone for the supplied site. (?)
5091 *
5092 * PARAMS
5093 *
5094 * szURL [I] Pointer to the URL to check
5095 *
5096 * Other parameters currently unknown.
5097 *
5098 * RETURNS
5099 * unknown
5100 */
5101
5102 INT WINAPI ZoneCheckUrlExW(LPWSTR szURL, PVOID pUnknown, DWORD dwUnknown2,
5103 DWORD dwUnknown3, DWORD dwUnknown4, DWORD dwUnknown5, DWORD dwUnknown6,
5104 DWORD dwUnknown7)
5105 {
5106 FIXME("(%s,%p,%x,%x,%x,%x,%x,%x) STUB\n", debugstr_w(szURL), pUnknown, dwUnknown2,
5107 dwUnknown3, dwUnknown4, dwUnknown5, dwUnknown6, dwUnknown7);
5108
5109 return 0;
5110 }
5111
5112 /***********************************************************************
5113 * SHVerbExistsNA [SHLWAPI.196]
5114 *
5115 *
5116 * PARAMS
5117 *
5118 * verb [I] a string, often appears to be an extension.
5119 *
5120 * Other parameters currently unknown.
5121 *
5122 * RETURNS
5123 * unknown
5124 */
5125 INT WINAPI SHVerbExistsNA(LPSTR verb, PVOID pUnknown, PVOID pUnknown2, DWORD dwUnknown3)
5126 {
5127 FIXME("(%s, %p, %p, %i) STUB\n",verb, pUnknown, pUnknown2, dwUnknown3);
5128 return 0;
5129 }
5130
5131 /*************************************************************************
5132 * @ [SHLWAPI.538]
5133 *
5134 * Undocumented: Implementation guessed at via Name and behavior
5135 *
5136 * PARAMS
5137 * lpUnknown [I] Object to get an IServiceProvider interface from
5138 * riid [I] Function requested for QueryService call
5139 * lppOut [O] Destination for the service interface pointer
5140 *
5141 * RETURNS
5142 * Success: S_OK. lppOut contains an object providing the requested service
5143 * Failure: An HRESULT error code
5144 *
5145 * NOTES
5146 * lpUnknown is expected to support the IServiceProvider interface.
5147 */
5148 HRESULT WINAPI IUnknown_QueryServiceForWebBrowserApp(IUnknown* lpUnknown,
5149 REFGUID riid, LPVOID *lppOut)
5150 {
5151 FIXME("%p %s %p semi-STUB\n", lpUnknown, debugstr_guid(riid), lppOut);
5152 return IUnknown_QueryService(lpUnknown,&IID_IWebBrowserApp,riid,lppOut);
5153 }
5154
5155 /**************************************************************************
5156 * SHPropertyBag_ReadLONG (SHLWAPI.496)
5157 *
5158 * This function asks a property bag to read a named property as a LONG.
5159 *
5160 * PARAMS
5161 * ppb: a IPropertyBag interface
5162 * pszPropName: Unicode string that names the property
5163 * pValue: address to receive the property value as a 32-bit signed integer
5164 *
5165 * RETURNS
5166 * 0 for Success
5167 */
5168 BOOL WINAPI SHPropertyBag_ReadLONG(IPropertyBag *ppb, LPCWSTR pszPropName, LPLONG pValue)
5169 {
5170 VARIANT var;
5171 HRESULT hr;
5172 TRACE("%p %s %p\n", ppb,debugstr_w(pszPropName),pValue);
5173 if (!pszPropName || !ppb || !pValue)
5174 return E_INVALIDARG;
5175 V_VT(&var) = VT_I4;
5176 hr = IPropertyBag_Read(ppb, pszPropName, &var, NULL);
5177 if (SUCCEEDED(hr))
5178 {
5179 if (V_VT(&var) == VT_I4)
5180 *pValue = V_I4(&var);
5181 else
5182 hr = DISP_E_BADVARTYPE;
5183 }
5184 return hr;
5185 }
5186
5187 /* return flags for SHGetObjectCompatFlags, names derived from registry value names */
5188 #define OBJCOMPAT_OTNEEDSSFCACHE 0x00000001
5189 #define OBJCOMPAT_NO_WEBVIEW 0x00000002
5190 #define OBJCOMPAT_UNBINDABLE 0x00000004
5191 #define OBJCOMPAT_PINDLL 0x00000008
5192 #define OBJCOMPAT_NEEDSFILESYSANCESTOR 0x00000010
5193 #define OBJCOMPAT_NOTAFILESYSTEM 0x00000020
5194 #define OBJCOMPAT_CTXMENU_NOVERBS 0x00000040
5195 #define OBJCOMPAT_CTXMENU_LIMITEDQI 0x00000080
5196 #define OBJCOMPAT_COCREATESHELLFOLDERONLY 0x00000100
5197 #define OBJCOMPAT_NEEDSSTORAGEANCESTOR 0x00000200
5198 #define OBJCOMPAT_NOLEGACYWEBVIEW 0x00000400
5199 #define OBJCOMPAT_CTXMENU_XPQCMFLAGS 0x00001000
5200 #define OBJCOMPAT_NOIPROPERTYSTORE 0x00002000
5201
5202 /* a search table for compatibility flags */
5203 struct objcompat_entry {
5204 const WCHAR name[30];
5205 DWORD value;
5206 };
5207
5208 /* expected to be sorted by name */
5209 static const struct objcompat_entry objcompat_table[] = {
5210 { {'C','O','C','R','E','A','T','E','S','H','E','L','L','F','O','L','D','E','R','O','N','L','Y',0},
5211 OBJCOMPAT_COCREATESHELLFOLDERONLY },
5212 { {'C','T','X','M','E','N','U','_','L','I','M','I','T','E','D','Q','I',0},
5213 OBJCOMPAT_CTXMENU_LIMITEDQI },
5214 { {'C','T','X','M','E','N','U','_','N','O','V','E','R','B','S',0},
5215 OBJCOMPAT_CTXMENU_LIMITEDQI },
5216 { {'C','T','X','M','E','N','U','_','X','P','Q','C','M','F','L','A','G','S',0},
5217 OBJCOMPAT_CTXMENU_XPQCMFLAGS },
5218 { {'N','E','E','D','S','F','I','L','E','S','Y','S','A','N','C','E','S','T','O','R',0},
5219 OBJCOMPAT_NEEDSFILESYSANCESTOR },
5220 { {'N','E','E','D','S','S','T','O','R','A','G','E','A','N','C','E','S','T','O','R',0},
5221 OBJCOMPAT_NEEDSSTORAGEANCESTOR },
5222 { {'N','O','I','P','R','O','P','E','R','T','Y','S','T','O','R','E',0},
5223 OBJCOMPAT_NOIPROPERTYSTORE },
5224 { {'N','O','L','E','G','A','C','Y','W','E','B','V','I','E','W',0},
5225 OBJCOMPAT_NOLEGACYWEBVIEW },
5226 { {'N','O','T','A','F','I','L','E','S','Y','S','T','E','M',0},
5227 OBJCOMPAT_NOTAFILESYSTEM },
5228 { {'N','O','_','W','E','B','V','I','E','W',0},
5229 OBJCOMPAT_NO_WEBVIEW },
5230 { {'O','T','N','E','E','D','S','S','F','C','A','C','H','E',0},
5231 OBJCOMPAT_OTNEEDSSFCACHE },
5232 { {'P','I','N','D','L','L',0},
5233 OBJCOMPAT_PINDLL },
5234 { {'U','N','B','I','N','D','A','B','L','E',0},
5235 OBJCOMPAT_UNBINDABLE }
5236 };
5237
5238 /**************************************************************************
5239 * SHGetObjectCompatFlags (SHLWAPI.476)
5240 *
5241 * Function returns an integer representation of compatibility flags stored
5242 * in registry for CLSID under ShellCompatibility subkey.
5243 *
5244 * PARAMS
5245 * pUnk: pointer to object IUnknown interface, idetifies CLSID
5246 * clsid: pointer to CLSID to retrieve data for
5247 *
5248 * RETURNS
5249 * 0 on failure, flags set on success
5250 */
5251 DWORD WINAPI SHGetObjectCompatFlags(IUnknown *pUnk, const CLSID *clsid)
5252 {
5253 static const WCHAR compatpathW[] =
5254 {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
5255 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
5256 'S','h','e','l','l','C','o','m','p','a','t','i','b','i','l','i','t','y','\\',
5257 'O','b','j','e','c','t','s','\\','%','s',0};
5258 WCHAR strW[sizeof(compatpathW)/sizeof(WCHAR) + 38 /* { CLSID } */];
5259 DWORD ret, length = sizeof(strW)/sizeof(WCHAR);
5260 OLECHAR *clsid_str;
5261 HKEY key;
5262 INT i;
5263
5264 TRACE("%p %s\n", pUnk, debugstr_guid(clsid));
5265
5266 if (!pUnk && !clsid) return 0;
5267
5268 if (pUnk && !clsid)
5269 {
5270 FIXME("iface not handled\n");
5271 return 0;
5272 }
5273
5274 StringFromCLSID(clsid, &clsid_str);
5275 sprintfW(strW, compatpathW, clsid_str);
5276 CoTaskMemFree(clsid_str);
5277
5278 ret = RegOpenKeyW(HKEY_LOCAL_MACHINE, strW, &key);
5279 if (ret != ERROR_SUCCESS) return 0;
5280
5281 /* now collect flag values */
5282 ret = 0;
5283 for (i = 0; RegEnumValueW(key, i, strW, &length, NULL, NULL, NULL, NULL) == ERROR_SUCCESS; i++)
5284 {
5285 INT left, right, res, x;
5286
5287 /* search in table */
5288 left = 0;
5289 right = sizeof(objcompat_table) / sizeof(struct objcompat_entry) - 1;
5290
5291 while (right >= left) {
5292 x = (left + right) / 2;
5293 res = strcmpW(strW, objcompat_table[x].name);
5294 if (res == 0)
5295 {
5296 ret |= objcompat_table[x].value;
5297 break;
5298 }
5299 else if (res < 0)
5300 right = x - 1;
5301 else
5302 left = x + 1;
5303 }
5304
5305 length = sizeof(strW)/sizeof(WCHAR);
5306 }
5307
5308 return ret;
5309 }