[SHLWAPI]
[reactos.git] / reactos / dll / win32 / shlwapi / ordinal.c
1 /*
2 * SHLWAPI ordinal functions
3 *
4 * Copyright 1997 Marcus Meissner
5 * 1998 J├╝rgen Schmied
6 * 2001-2003 Jon Griffiths
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 */
22
23 #include "precomp.h"
24
25 #include <stdio.h>
26
27 #include <winver.h>
28 #include <winnetwk.h>
29 #include <mmsystem.h>
30 #include <shdeprecated.h>
31 #include <shellapi.h>
32 #include <commdlg.h>
33 #include <mlang.h>
34 #include <mshtmhst.h>
35
36 /* DLL handles for late bound calls */
37 extern HINSTANCE shlwapi_hInstance;
38 extern DWORD SHLWAPI_ThreadRef_index;
39
40 HRESULT WINAPI IUnknown_QueryService(IUnknown*,REFGUID,REFIID,LPVOID*);
41 HRESULT WINAPI SHInvokeCommand(HWND,IShellFolder*,LPCITEMIDLIST,DWORD);
42 BOOL WINAPI SHAboutInfoW(LPWSTR,DWORD);
43
44 /*
45 NOTES: Most functions exported by ordinal seem to be superfluous.
46 The reason for these functions to be there is to provide a wrapper
47 for unicode functions to provide these functions on systems without
48 unicode functions eg. win95/win98. Since we have such functions we just
49 call these. If running Wine with native DLLs, some late bound calls may
50 fail. However, it is better to implement the functions in the forward DLL
51 and recommend the builtin rather than reimplementing the calls here!
52 */
53
54 /*************************************************************************
55 * @ [SHLWAPI.11]
56 *
57 * Copy a sharable memory handle from one process to another.
58 *
59 * PARAMS
60 * hShared [I] Shared memory handle to duplicate
61 * dwSrcProcId [I] ID of the process owning hShared
62 * dwDstProcId [I] ID of the process wanting the duplicated handle
63 * dwAccess [I] Desired DuplicateHandle() access
64 * dwOptions [I] Desired DuplicateHandle() options
65 *
66 * RETURNS
67 * Success: A handle suitable for use by the dwDstProcId process.
68 * Failure: A NULL handle.
69 *
70 */
71 HANDLE WINAPI SHMapHandle(HANDLE hShared, DWORD dwSrcProcId, DWORD dwDstProcId,
72 DWORD dwAccess, DWORD dwOptions)
73 {
74 HANDLE hDst, hSrc;
75 DWORD dwMyProcId = GetCurrentProcessId();
76 HANDLE hRet = NULL;
77
78 TRACE("(%p,%d,%d,%08x,%08x)\n", hShared, dwDstProcId, dwSrcProcId,
79 dwAccess, dwOptions);
80
81 /* Get dest process handle */
82 if (dwDstProcId == dwMyProcId)
83 hDst = GetCurrentProcess();
84 else
85 hDst = OpenProcess(PROCESS_DUP_HANDLE, 0, dwDstProcId);
86
87 if (hDst)
88 {
89 /* Get src process handle */
90 if (dwSrcProcId == dwMyProcId)
91 hSrc = GetCurrentProcess();
92 else
93 hSrc = OpenProcess(PROCESS_DUP_HANDLE, 0, dwSrcProcId);
94
95 if (hSrc)
96 {
97 /* Make handle available to dest process */
98 if (!DuplicateHandle(hSrc, hShared, hDst, &hRet,
99 dwAccess, 0, dwOptions | DUPLICATE_SAME_ACCESS))
100 hRet = NULL;
101
102 if (dwSrcProcId != dwMyProcId)
103 CloseHandle(hSrc);
104 }
105
106 if (dwDstProcId != dwMyProcId)
107 CloseHandle(hDst);
108 }
109
110 TRACE("Returning handle %p\n", hRet);
111 return hRet;
112 }
113
114 /*************************************************************************
115 * @ [SHLWAPI.7]
116 *
117 * Create a block of sharable memory and initialise it with data.
118 *
119 * PARAMS
120 * lpvData [I] Pointer to data to write
121 * dwSize [I] Size of data
122 * dwProcId [I] ID of process owning data
123 *
124 * RETURNS
125 * Success: A shared memory handle
126 * Failure: NULL
127 *
128 * NOTES
129 * Ordinals 7-11 provide a set of calls to create shared memory between a
130 * group of processes. The shared memory is treated opaquely in that its size
131 * is not exposed to clients who map it. This is accomplished by storing
132 * the size of the map as the first DWORD of mapped data, and then offsetting
133 * the view pointer returned by this size.
134 *
135 */
136 HANDLE WINAPI SHAllocShared(LPCVOID lpvData, DWORD dwSize, DWORD dwProcId)
137 {
138 HANDLE hMap;
139 LPVOID pMapped;
140 HANDLE hRet = NULL;
141
142 TRACE("(%p,%d,%d)\n", lpvData, dwSize, dwProcId);
143
144 /* Create file mapping of the correct length */
145 hMap = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, FILE_MAP_READ, 0,
146 dwSize + sizeof(dwSize), NULL);
147 if (!hMap)
148 return hRet;
149
150 /* Get a view in our process address space */
151 pMapped = MapViewOfFile(hMap, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0);
152
153 if (pMapped)
154 {
155 /* Write size of data, followed by the data, to the view */
156 *((DWORD*)pMapped) = dwSize;
157 if (lpvData)
158 memcpy((char *) pMapped + sizeof(dwSize), lpvData, dwSize);
159
160 /* Release view. All further views mapped will be opaque */
161 UnmapViewOfFile(pMapped);
162 hRet = SHMapHandle(hMap, GetCurrentProcessId(), dwProcId,
163 FILE_MAP_ALL_ACCESS, DUPLICATE_SAME_ACCESS);
164 }
165
166 CloseHandle(hMap);
167 return hRet;
168 }
169
170 /*************************************************************************
171 * @ [SHLWAPI.8]
172 *
173 * Get a pointer to a block of shared memory from a shared memory handle.
174 *
175 * PARAMS
176 * hShared [I] Shared memory handle
177 * dwProcId [I] ID of process owning hShared
178 *
179 * RETURNS
180 * Success: A pointer to the shared memory
181 * Failure: NULL
182 *
183 */
184 PVOID WINAPI SHLockShared(HANDLE hShared, DWORD dwProcId)
185 {
186 HANDLE hDup;
187 LPVOID pMapped;
188
189 TRACE("(%p %d)\n", hShared, dwProcId);
190
191 /* Get handle to shared memory for current process */
192 hDup = SHMapHandle(hShared, dwProcId, GetCurrentProcessId(), FILE_MAP_ALL_ACCESS, 0);
193
194 /* Get View */
195 pMapped = MapViewOfFile(hDup, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0);
196 CloseHandle(hDup);
197
198 if (pMapped)
199 return (char *) pMapped + sizeof(DWORD); /* Hide size */
200 return NULL;
201 }
202
203 /*************************************************************************
204 * @ [SHLWAPI.9]
205 *
206 * Release a pointer to a block of shared memory.
207 *
208 * PARAMS
209 * lpView [I] Shared memory pointer
210 *
211 * RETURNS
212 * Success: TRUE
213 * Failure: FALSE
214 *
215 */
216 BOOL WINAPI SHUnlockShared(LPVOID lpView)
217 {
218 TRACE("(%p)\n", lpView);
219 return UnmapViewOfFile((char *) lpView - sizeof(DWORD)); /* Include size */
220 }
221
222 /*************************************************************************
223 * @ [SHLWAPI.10]
224 *
225 * Destroy a block of sharable memory.
226 *
227 * PARAMS
228 * hShared [I] Shared memory handle
229 * dwProcId [I] ID of process owning hShared
230 *
231 * RETURNS
232 * Success: TRUE
233 * Failure: FALSE
234 *
235 */
236 BOOL WINAPI SHFreeShared(HANDLE hShared, DWORD dwProcId)
237 {
238 HANDLE hClose;
239
240 TRACE("(%p %d)\n", hShared, dwProcId);
241
242 /* Get a copy of the handle for our process, closing the source handle */
243 hClose = SHMapHandle(hShared, dwProcId, GetCurrentProcessId(),
244 FILE_MAP_ALL_ACCESS,DUPLICATE_CLOSE_SOURCE);
245 /* Close local copy */
246 return CloseHandle(hClose);
247 }
248
249 /*************************************************************************
250 * @ [SHLWAPI.13]
251 *
252 * Create and register a clipboard enumerator for a web browser.
253 *
254 * PARAMS
255 * lpBC [I] Binding context
256 * lpUnknown [I] An object exposing the IWebBrowserApp interface
257 *
258 * RETURNS
259 * Success: S_OK.
260 * Failure: An HRESULT error code.
261 *
262 * NOTES
263 * The enumerator is stored as a property of the web browser. If it does not
264 * yet exist, it is created and set before being registered.
265 */
266 HRESULT WINAPI RegisterDefaultAcceptHeaders(LPBC lpBC, IUnknown *lpUnknown)
267 {
268 static const WCHAR szProperty[] = { '{','D','0','F','C','A','4','2','0',
269 '-','D','3','F','5','-','1','1','C','F', '-','B','2','1','1','-','0',
270 '0','A','A','0','0','4','A','E','8','3','7','}','\0' };
271 BSTR property;
272 IEnumFORMATETC* pIEnumFormatEtc = NULL;
273 VARIANTARG var;
274 HRESULT hr;
275 IWebBrowserApp* pBrowser;
276
277 TRACE("(%p, %p)\n", lpBC, lpUnknown);
278
279 hr = IUnknown_QueryService(lpUnknown, &IID_IWebBrowserApp, &IID_IWebBrowserApp, (void**)&pBrowser);
280 if (FAILED(hr))
281 return hr;
282
283 V_VT(&var) = VT_EMPTY;
284
285 /* The property we get is the browsers clipboard enumerator */
286 property = SysAllocString(szProperty);
287 hr = IWebBrowserApp_GetProperty(pBrowser, property, &var);
288 SysFreeString(property);
289 if (FAILED(hr)) goto exit;
290
291 if (V_VT(&var) == VT_EMPTY)
292 {
293 /* Iterate through accepted documents and RegisterClipBoardFormatA() them */
294 char szKeyBuff[128], szValueBuff[128];
295 DWORD dwKeySize, dwValueSize, dwRet = 0, dwCount = 0, dwNumValues, dwType;
296 FORMATETC* formatList, *format;
297 HKEY hDocs;
298
299 TRACE("Registering formats and creating IEnumFORMATETC instance\n");
300
301 if (!RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\Current"
302 "Version\\Internet Settings\\Accepted Documents", &hDocs))
303 {
304 hr = E_FAIL;
305 goto exit;
306 }
307
308 /* Get count of values in key */
309 while (!dwRet)
310 {
311 dwKeySize = sizeof(szKeyBuff);
312 dwRet = RegEnumValueA(hDocs,dwCount,szKeyBuff,&dwKeySize,0,&dwType,0,0);
313 dwCount++;
314 }
315
316 dwNumValues = dwCount;
317
318 /* Note: dwCount = number of items + 1; The extra item is the end node */
319 format = formatList = HeapAlloc(GetProcessHeap(), 0, dwCount * sizeof(FORMATETC));
320 if (!formatList)
321 {
322 RegCloseKey(hDocs);
323 hr = E_OUTOFMEMORY;
324 goto exit;
325 }
326
327 if (dwNumValues > 1)
328 {
329 dwRet = 0;
330 dwCount = 0;
331
332 dwNumValues--;
333
334 /* Register clipboard formats for the values and populate format list */
335 while(!dwRet && dwCount < dwNumValues)
336 {
337 dwKeySize = sizeof(szKeyBuff);
338 dwValueSize = sizeof(szValueBuff);
339 dwRet = RegEnumValueA(hDocs, dwCount, szKeyBuff, &dwKeySize, 0, &dwType,
340 (PBYTE)szValueBuff, &dwValueSize);
341 if (!dwRet)
342 {
343 HeapFree(GetProcessHeap(), 0, formatList);
344 RegCloseKey(hDocs);
345 hr = E_FAIL;
346 goto exit;
347 }
348
349 format->cfFormat = RegisterClipboardFormatA(szValueBuff);
350 format->ptd = NULL;
351 format->dwAspect = 1;
352 format->lindex = 4;
353 format->tymed = -1;
354
355 format++;
356 dwCount++;
357 }
358 }
359
360 RegCloseKey(hDocs);
361
362 /* Terminate the (maybe empty) list, last entry has a cfFormat of 0 */
363 format->cfFormat = 0;
364 format->ptd = NULL;
365 format->dwAspect = 1;
366 format->lindex = 4;
367 format->tymed = -1;
368
369 /* Create a clipboard enumerator */
370 hr = CreateFormatEnumerator(dwNumValues, formatList, &pIEnumFormatEtc);
371 HeapFree(GetProcessHeap(), 0, formatList);
372 if (FAILED(hr)) goto exit;
373
374 /* Set our enumerator as the browsers property */
375 V_VT(&var) = VT_UNKNOWN;
376 V_UNKNOWN(&var) = (IUnknown*)pIEnumFormatEtc;
377
378 property = SysAllocString(szProperty);
379 hr = IWebBrowserApp_PutProperty(pBrowser, property, var);
380 SysFreeString(property);
381 if (FAILED(hr))
382 {
383 IEnumFORMATETC_Release(pIEnumFormatEtc);
384 goto exit;
385 }
386 }
387
388 if (V_VT(&var) == VT_UNKNOWN)
389 {
390 /* Our variant is holding the clipboard enumerator */
391 IUnknown* pIUnknown = V_UNKNOWN(&var);
392 IEnumFORMATETC* pClone = NULL;
393
394 TRACE("Retrieved IEnumFORMATETC property\n");
395
396 /* Get an IEnumFormatEtc interface from the variants value */
397 pIEnumFormatEtc = NULL;
398 hr = IUnknown_QueryInterface(pIUnknown, &IID_IEnumFORMATETC, (void**)&pIEnumFormatEtc);
399 if (hr == S_OK && pIEnumFormatEtc)
400 {
401 /* Clone and register the enumerator */
402 hr = IEnumFORMATETC_Clone(pIEnumFormatEtc, &pClone);
403 if (hr == S_OK && pClone)
404 {
405 RegisterFormatEnumerator(lpBC, pClone, 0);
406
407 IEnumFORMATETC_Release(pClone);
408 }
409
410 IUnknown_Release(pIUnknown);
411 }
412 IUnknown_Release(V_UNKNOWN(&var));
413 }
414
415 exit:
416 IWebBrowserApp_Release(pBrowser);
417 return hr;
418 }
419
420 /*************************************************************************
421 * @ [SHLWAPI.15]
422 *
423 * Get Explorers "AcceptLanguage" setting.
424 *
425 * PARAMS
426 * langbuf [O] Destination for language string
427 * buflen [I] Length of langbuf in characters
428 * [0] Success: used length of langbuf
429 *
430 * RETURNS
431 * Success: S_OK. langbuf is set to the language string found.
432 * Failure: E_FAIL, If any arguments are invalid, error occurred, or Explorer
433 * does not contain the setting.
434 * 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