2 * SHLWAPI ordinal functions
4 * Copyright 1997 Marcus Meissner
6 * 2001-2003 Jon Griffiths
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.
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.
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
30 #include <shdeprecated.h>
36 /* DLL handles for late bound calls */
37 extern HINSTANCE shlwapi_hInstance
;
38 extern DWORD SHLWAPI_ThreadRef_index
;
40 HRESULT WINAPI
IUnknown_QueryService(IUnknown
*,REFGUID
,REFIID
,LPVOID
*);
41 HRESULT WINAPI
SHInvokeCommand(HWND
,IShellFolder
*,LPCITEMIDLIST
,DWORD
);
42 BOOL WINAPI
SHAboutInfoW(LPWSTR
,DWORD
);
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!
54 /*************************************************************************
57 * Copy a sharable memory handle from one process to another.
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
67 * Success: A handle suitable for use by the dwDstProcId process.
68 * Failure: A NULL handle.
71 HANDLE WINAPI
SHMapHandle(HANDLE hShared
, DWORD dwSrcProcId
, DWORD dwDstProcId
,
72 DWORD dwAccess
, DWORD dwOptions
)
75 DWORD dwMyProcId
= GetCurrentProcessId();
78 TRACE("(%p,%d,%d,%08x,%08x)\n", hShared
, dwDstProcId
, dwSrcProcId
,
81 /* Get dest process handle */
82 if (dwDstProcId
== dwMyProcId
)
83 hDst
= GetCurrentProcess();
85 hDst
= OpenProcess(PROCESS_DUP_HANDLE
, 0, dwDstProcId
);
89 /* Get src process handle */
90 if (dwSrcProcId
== dwMyProcId
)
91 hSrc
= GetCurrentProcess();
93 hSrc
= OpenProcess(PROCESS_DUP_HANDLE
, 0, dwSrcProcId
);
97 /* Make handle available to dest process */
98 if (!DuplicateHandle(hSrc
, hShared
, hDst
, &hRet
,
99 dwAccess
, 0, dwOptions
| DUPLICATE_SAME_ACCESS
))
102 if (dwSrcProcId
!= dwMyProcId
)
106 if (dwDstProcId
!= dwMyProcId
)
110 TRACE("Returning handle %p\n", hRet
);
114 /*************************************************************************
117 * Create a block of sharable memory and initialise it with data.
120 * lpvData [I] Pointer to data to write
121 * dwSize [I] Size of data
122 * dwProcId [I] ID of process owning data
125 * Success: A shared memory handle
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.
136 HANDLE WINAPI
SHAllocShared(LPCVOID lpvData
, DWORD dwSize
, DWORD dwProcId
)
142 TRACE("(%p,%d,%d)\n", lpvData
, dwSize
, dwProcId
);
144 /* Create file mapping of the correct length */
145 hMap
= CreateFileMappingA(INVALID_HANDLE_VALUE
, NULL
, FILE_MAP_READ
, 0,
146 dwSize
+ sizeof(dwSize
), NULL
);
150 /* Get a view in our process address space */
151 pMapped
= MapViewOfFile(hMap
, FILE_MAP_READ
| FILE_MAP_WRITE
, 0, 0, 0);
155 /* Write size of data, followed by the data, to the view */
156 *((DWORD
*)pMapped
) = dwSize
;
158 memcpy((char *) pMapped
+ sizeof(dwSize
), lpvData
, dwSize
);
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
);
170 /*************************************************************************
173 * Get a pointer to a block of shared memory from a shared memory handle.
176 * hShared [I] Shared memory handle
177 * dwProcId [I] ID of process owning hShared
180 * Success: A pointer to the shared memory
184 PVOID WINAPI
SHLockShared(HANDLE hShared
, DWORD dwProcId
)
189 TRACE("(%p %d)\n", hShared
, dwProcId
);
191 /* Get handle to shared memory for current process */
192 hDup
= SHMapHandle(hShared
, dwProcId
, GetCurrentProcessId(), FILE_MAP_ALL_ACCESS
, 0);
195 pMapped
= MapViewOfFile(hDup
, FILE_MAP_READ
| FILE_MAP_WRITE
, 0, 0, 0);
199 return (char *) pMapped
+ sizeof(DWORD
); /* Hide size */
203 /*************************************************************************
206 * Release a pointer to a block of shared memory.
209 * lpView [I] Shared memory pointer
216 BOOL WINAPI
SHUnlockShared(LPVOID lpView
)
218 TRACE("(%p)\n", lpView
);
219 return UnmapViewOfFile((char *) lpView
- sizeof(DWORD
)); /* Include size */
222 /*************************************************************************
225 * Destroy a block of sharable memory.
228 * hShared [I] Shared memory handle
229 * dwProcId [I] ID of process owning hShared
236 BOOL WINAPI
SHFreeShared(HANDLE hShared
, DWORD dwProcId
)
240 TRACE("(%p %d)\n", hShared
, dwProcId
);
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
);
249 /*************************************************************************
252 * Create and register a clipboard enumerator for a web browser.
255 * lpBC [I] Binding context
256 * lpUnknown [I] An object exposing the IWebBrowserApp interface
260 * Failure: An HRESULT error code.
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.
266 HRESULT WINAPI
RegisterDefaultAcceptHeaders(LPBC lpBC
, IUnknown
*lpUnknown
)
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' };
272 IEnumFORMATETC
* pIEnumFormatEtc
= NULL
;
275 IWebBrowserApp
* pBrowser
;
277 TRACE("(%p, %p)\n", lpBC
, lpUnknown
);
279 hr
= IUnknown_QueryService(lpUnknown
, &IID_IWebBrowserApp
, &IID_IWebBrowserApp
, (void**)&pBrowser
);
283 V_VT(&var
) = VT_EMPTY
;
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
;
291 if (V_VT(&var
) == VT_EMPTY
)
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
;
299 TRACE("Registering formats and creating IEnumFORMATETC instance\n");
301 if (!RegOpenKeyA(HKEY_LOCAL_MACHINE
, "Software\\Microsoft\\Windows\\Current"
302 "Version\\Internet Settings\\Accepted Documents", &hDocs
))
308 /* Get count of values in key */
311 dwKeySize
= sizeof(szKeyBuff
);
312 dwRet
= RegEnumValueA(hDocs
,dwCount
,szKeyBuff
,&dwKeySize
,0,&dwType
,0,0);
316 dwNumValues
= dwCount
;
318 /* Note: dwCount = number of items + 1; The extra item is the end node */
319 format
= formatList
= HeapAlloc(GetProcessHeap(), 0, dwCount
* sizeof(FORMATETC
));
334 /* Register clipboard formats for the values and populate format list */
335 while(!dwRet
&& dwCount
< dwNumValues
)
337 dwKeySize
= sizeof(szKeyBuff
);
338 dwValueSize
= sizeof(szValueBuff
);
339 dwRet
= RegEnumValueA(hDocs
, dwCount
, szKeyBuff
, &dwKeySize
, 0, &dwType
,
340 (PBYTE
)szValueBuff
, &dwValueSize
);
343 HeapFree(GetProcessHeap(), 0, formatList
);
349 format
->cfFormat
= RegisterClipboardFormatA(szValueBuff
);
351 format
->dwAspect
= 1;
362 /* Terminate the (maybe empty) list, last entry has a cfFormat of 0 */
363 format
->cfFormat
= 0;
365 format
->dwAspect
= 1;
369 /* Create a clipboard enumerator */
370 hr
= CreateFormatEnumerator(dwNumValues
, formatList
, &pIEnumFormatEtc
);
371 HeapFree(GetProcessHeap(), 0, formatList
);
372 if (FAILED(hr
)) goto exit
;
374 /* Set our enumerator as the browsers property */
375 V_VT(&var
) = VT_UNKNOWN
;
376 V_UNKNOWN(&var
) = (IUnknown
*)pIEnumFormatEtc
;
378 property
= SysAllocString(szProperty
);
379 hr
= IWebBrowserApp_PutProperty(pBrowser
, property
, var
);
380 SysFreeString(property
);
383 IEnumFORMATETC_Release(pIEnumFormatEtc
);
388 if (V_VT(&var
) == VT_UNKNOWN
)
390 /* Our variant is holding the clipboard enumerator */
391 IUnknown
* pIUnknown
= V_UNKNOWN(&var
);
392 IEnumFORMATETC
* pClone
= NULL
;
394 TRACE("Retrieved IEnumFORMATETC property\n");
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
)
401 /* Clone and register the enumerator */
402 hr
= IEnumFORMATETC_Clone(pIEnumFormatEtc
, &pClone
);
403 if (hr
== S_OK
&& pClone
)
405 RegisterFormatEnumerator(lpBC
, pClone
, 0);
407 IEnumFORMATETC_Release(pClone
);
410 IUnknown_Release(pIUnknown
);
412 IUnknown_Release(V_UNKNOWN(&var
));
416 IWebBrowserApp_Release(pBrowser
);
420 /*************************************************************************
423 * Get Explorers "AcceptLanguage" setting.
426 * langbuf [O] Destination for language string
427 * buflen [I] Length of langbuf in characters
428 * [0] Success: used length of langbuf
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
436 HRESULT WINAPI
GetAcceptLanguagesW( LPWSTR langbuf
, LPDWORD buflen
)
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
;
452 TRACE("(%p, %p) *%p: %d\n", langbuf
, buflen
, buflen
, buflen
? *buflen
: -1);
454 if(!langbuf
|| !buflen
|| !*buflen
)
457 mystrlen
= (*buflen
> 20) ? *buflen
: 20 ;
458 len
= mystrlen
* sizeof(WCHAR
);
459 mystr
= HeapAlloc(GetProcessHeap(), 0, len
);
461 RegOpenKeyW(HKEY_CURRENT_USER
, szkeyW
, &mykey
);
462 lres
= RegQueryValueExW(mykey
, valueW
, 0, &mytype
, (PBYTE
)mystr
, &len
);
464 len
= lstrlenW(mystr
);
466 if (!lres
&& (*buflen
> len
)) {
467 lstrcpyW(langbuf
, mystr
);
469 HeapFree(GetProcessHeap(), 0, mystr
);
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
);
478 memcpy( langbuf
, mystr
, min(*buflen
, len
+1)*sizeof(WCHAR
) );
479 HeapFree(GetProcessHeap(), 0, mystr
);
487 return __HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
490 /*************************************************************************
493 * Ascii version of GetAcceptLanguagesW.
495 HRESULT WINAPI
GetAcceptLanguagesA( LPSTR langbuf
, LPDWORD buflen
)
498 DWORD buflenW
, convlen
;
501 TRACE("(%p, %p) *%p: %d\n", langbuf
, buflen
, buflen
, buflen
? *buflen
: -1);
503 if(!langbuf
|| !buflen
|| !*buflen
) return E_FAIL
;
506 langbufW
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
) * buflenW
);
507 retval
= GetAcceptLanguagesW(langbufW
, &buflenW
);
511 convlen
= WideCharToMultiByte(CP_ACP
, 0, langbufW
, -1, langbuf
, *buflen
, NULL
, NULL
);
512 convlen
--; /* do not count the terminating 0 */
514 else /* copy partial string anyway */
516 convlen
= WideCharToMultiByte(CP_ACP
, 0, langbufW
, *buflen
, langbuf
, *buflen
, NULL
, NULL
);
517 if (convlen
< *buflen
)
519 langbuf
[convlen
] = 0;
520 convlen
--; /* do not count the terminating 0 */
527 *buflen
= buflenW
? convlen
: 0;
529 HeapFree(GetProcessHeap(), 0, langbufW
);
533 /*************************************************************************
536 * Convert a GUID to a string.
539 * guid [I] GUID to convert
540 * lpszDest [O] Destination for string
541 * cchMax [I] Length of output buffer
544 * The length of the string created.
546 INT WINAPI
SHStringFromGUIDA(REFGUID guid
, LPSTR lpszDest
, INT cchMax
)
551 TRACE("(%s,%p,%d)\n", debugstr_guid(guid
), lpszDest
, cchMax
);
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]);
558 iLen
= strlen(xguid
) + 1;
562 memcpy(lpszDest
, xguid
, iLen
);
566 /*************************************************************************
569 * Convert a GUID to a string.
572 * guid [I] GUID to convert
573 * str [O] Destination for string
574 * cmax [I] Length of output buffer
577 * The length of the string created.
579 INT WINAPI
SHStringFromGUIDW(REFGUID guid
, LPWSTR lpszDest
, INT cchMax
)
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};
587 TRACE("(%s,%p,%d)\n", debugstr_guid(guid
), lpszDest
, cchMax
);
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]);
593 iLen
= strlenW(xguid
) + 1;
597 memcpy(lpszDest
, xguid
, iLen
*sizeof(WCHAR
));
601 /*************************************************************************
604 * Determine if a Unicode character is a blank.
607 * wc [I] Character to check.
610 * TRUE, if wc is a blank,
614 BOOL WINAPI
IsCharBlankW(WCHAR wc
)
618 return GetStringTypeW(CT_CTYPE1
, &wc
, 1, &CharType
) && (CharType
& C1_BLANK
);
621 /*************************************************************************
624 * Determine if a Unicode character is punctuation.
627 * wc [I] Character to check.
630 * TRUE, if wc is punctuation,
633 BOOL WINAPI
IsCharPunctW(WCHAR wc
)
637 return GetStringTypeW(CT_CTYPE1
, &wc
, 1, &CharType
) && (CharType
& C1_PUNCT
);
640 /*************************************************************************
643 * Determine if a Unicode character is a control character.
646 * wc [I] Character to check.
649 * TRUE, if wc is a control character,
652 BOOL WINAPI
IsCharCntrlW(WCHAR wc
)
656 return GetStringTypeW(CT_CTYPE1
, &wc
, 1, &CharType
) && (CharType
& C1_CNTRL
);
659 /*************************************************************************
662 * Determine if a Unicode character is a digit.
665 * wc [I] Character to check.
668 * TRUE, if wc is a digit,
671 BOOL WINAPI
IsCharDigitW(WCHAR wc
)
675 return GetStringTypeW(CT_CTYPE1
, &wc
, 1, &CharType
) && (CharType
& C1_DIGIT
);
678 /*************************************************************************
681 * Determine if a Unicode character is a hex digit.
684 * wc [I] Character to check.
687 * TRUE, if wc is a hex digit,
690 BOOL WINAPI
IsCharXDigitW(WCHAR wc
)
694 return GetStringTypeW(CT_CTYPE1
, &wc
, 1, &CharType
) && (CharType
& C1_XDIGIT
);
697 /*************************************************************************
701 BOOL WINAPI
GetStringType3ExW(LPWSTR src
, INT count
, LPWORD type
)
703 return GetStringTypeW(CT_CTYPE3
, src
, count
, type
);
706 /*************************************************************************
709 * Compare two Ascii strings up to a given length.
712 * lpszSrc [I] Source string
713 * lpszCmp [I] String to compare to lpszSrc
714 * len [I] Maximum length
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.
720 DWORD WINAPI
StrCmpNCA(LPCSTR lpszSrc
, LPCSTR lpszCmp
, INT len
)
722 return StrCmpNA(lpszSrc
, lpszCmp
, len
);
725 /*************************************************************************
728 * Unicode version of StrCmpNCA.
730 DWORD WINAPI
StrCmpNCW(LPCWSTR lpszSrc
, LPCWSTR lpszCmp
, INT len
)
732 return StrCmpNW(lpszSrc
, lpszCmp
, len
);
735 /*************************************************************************
738 * Compare two Ascii strings up to a given length, ignoring case.
741 * lpszSrc [I] Source string
742 * lpszCmp [I] String to compare to lpszSrc
743 * len [I] Maximum length
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.
749 DWORD WINAPI
StrCmpNICA(LPCSTR lpszSrc
, LPCSTR lpszCmp
, DWORD len
)
751 return StrCmpNIA(lpszSrc
, lpszCmp
, len
);
754 /*************************************************************************
757 * Unicode version of StrCmpNICA.
759 DWORD WINAPI
StrCmpNICW(LPCWSTR lpszSrc
, LPCWSTR lpszCmp
, DWORD len
)
761 return StrCmpNIW(lpszSrc
, lpszCmp
, len
);
764 /*************************************************************************
767 * Compare two Ascii strings.
770 * lpszSrc [I] Source string
771 * lpszCmp [I] String to compare to lpszSrc
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.
777 DWORD WINAPI
StrCmpCA(LPCSTR lpszSrc
, LPCSTR lpszCmp
)
779 return lstrcmpA(lpszSrc
, lpszCmp
);
782 /*************************************************************************
785 * Unicode version of StrCmpCA.
787 DWORD WINAPI
StrCmpCW(LPCWSTR lpszSrc
, LPCWSTR lpszCmp
)
789 return lstrcmpW(lpszSrc
, lpszCmp
);
792 /*************************************************************************
795 * Compare two Ascii strings, ignoring case.
798 * lpszSrc [I] Source string
799 * lpszCmp [I] String to compare to lpszSrc
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.
805 DWORD WINAPI
StrCmpICA(LPCSTR lpszSrc
, LPCSTR lpszCmp
)
807 return lstrcmpiA(lpszSrc
, lpszCmp
);
810 /*************************************************************************
813 * Unicode version of StrCmpICA.
815 DWORD WINAPI
StrCmpICW(LPCWSTR lpszSrc
, LPCWSTR lpszCmp
)
817 return lstrcmpiW(lpszSrc
, lpszCmp
);
820 /*************************************************************************
823 * Get an identification string for the OS and explorer.
826 * lpszDest [O] Destination for Id string
827 * dwDestLen [I] Length of lpszDest
830 * TRUE, If the string was created successfully
833 BOOL WINAPI
SHAboutInfoA(LPSTR lpszDest
, DWORD dwDestLen
)
837 TRACE("(%p,%d)\n", lpszDest
, dwDestLen
);
839 if (lpszDest
&& SHAboutInfoW(buff
, dwDestLen
))
841 WideCharToMultiByte(CP_ACP
, 0, buff
, -1, lpszDest
, dwDestLen
, NULL
, NULL
);
847 /*************************************************************************
850 * Unicode version of SHAboutInfoA.
852 BOOL WINAPI
SHAboutInfoW(LPWSTR lpszDest
, DWORD dwDestLen
)
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' };
883 TRACE("(%p,%d)\n", lpszDest
, dwDestLen
);
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
))
898 if (!SHGetValueW(HKEY_LOCAL_MACHINE
, szIEKey
, szVersion
, &dwType
, buff
, &dwLen
))
900 DWORD dwStrLen
= strlenW(buff
);
901 dwLen
= 30 - dwStrLen
;
902 SHGetValueW(HKEY_LOCAL_MACHINE
, szIEKey
,
903 szCustomized
, &dwType
, buff
+dwStrLen
, &dwLen
);
905 StrCatBuffW(lpszDest
, buff
, dwDestLen
);
907 /* ~Registered Owner */
910 if (SHGetValueW(hReg
, szOwner
, 0, &dwType
, buff
+1, &dwLen
))
912 StrCatBuffW(lpszDest
, buff
, dwDestLen
);
914 /* ~Registered Organization */
916 if (SHGetValueW(hReg
, szOrg
, 0, &dwType
, buff
+1, &dwLen
))
918 StrCatBuffW(lpszDest
, buff
, dwDestLen
);
920 /* FIXME: Not sure where this number comes from */
924 StrCatBuffW(lpszDest
, buff
, dwDestLen
);
928 if (SHGetValueW(HKEY_LOCAL_MACHINE
, szRegKey
, szProduct
, &dwType
, buff
+1, &dwLen
))
930 StrCatBuffW(lpszDest
, buff
, dwDestLen
);
934 if(SHGetValueW(HKEY_LOCAL_MACHINE
, szWinKey
, szUpdate
, &dwType
, buff
+1, &dwLen
))
936 StrCatBuffW(lpszDest
, buff
, dwDestLen
);
938 /* ~IE Help String */
940 if(SHGetValueW(hReg
, szHelp
, 0, &dwType
, buff
+1, &dwLen
))
942 StrCatBuffW(lpszDest
, buff
, dwDestLen
);
948 /*************************************************************************
951 * Call IOleCommandTarget_QueryStatus() on an object.
954 * lpUnknown [I] Object supporting the IOleCommandTarget interface
955 * pguidCmdGroup [I] GUID for the command group
957 * prgCmds [O] Commands
958 * pCmdText [O] Command text
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().
966 HRESULT WINAPI
IUnknown_QueryStatus(IUnknown
* lpUnknown
, REFGUID pguidCmdGroup
,
967 ULONG cCmds
, OLECMD
*prgCmds
, OLECMDTEXT
* pCmdText
)
969 HRESULT hRet
= E_FAIL
;
971 TRACE("(%p,%p,%d,%p,%p)\n",lpUnknown
, pguidCmdGroup
, cCmds
, prgCmds
, pCmdText
);
975 IOleCommandTarget
* lpOle
;
977 hRet
= IUnknown_QueryInterface(lpUnknown
, &IID_IOleCommandTarget
,
980 if (SUCCEEDED(hRet
) && lpOle
)
982 hRet
= IOleCommandTarget_QueryStatus(lpOle
, pguidCmdGroup
, cCmds
,
984 IOleCommandTarget_Release(lpOle
);
990 /*************************************************************************
993 * Call IOleCommandTarget_Exec() on an object.
996 * lpUnknown [I] Object supporting the IOleCommandTarget interface
997 * pguidCmdGroup [I] GUID for the command group
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().
1005 HRESULT WINAPI
IUnknown_Exec(IUnknown
* lpUnknown
, REFGUID pguidCmdGroup
,
1006 DWORD nCmdID
, DWORD nCmdexecopt
, VARIANT
* pvaIn
,
1009 HRESULT hRet
= E_FAIL
;
1011 TRACE("(%p,%p,%d,%d,%p,%p)\n",lpUnknown
, pguidCmdGroup
, nCmdID
,
1012 nCmdexecopt
, pvaIn
, pvaOut
);
1016 IOleCommandTarget
* lpOle
;
1018 hRet
= IUnknown_QueryInterface(lpUnknown
, &IID_IOleCommandTarget
,
1020 if (SUCCEEDED(hRet
) && lpOle
)
1022 hRet
= IOleCommandTarget_Exec(lpOle
, pguidCmdGroup
, nCmdID
,
1023 nCmdexecopt
, pvaIn
, pvaOut
);
1024 IOleCommandTarget_Release(lpOle
);
1030 /*************************************************************************
1033 * Retrieve, modify, and re-set a value from a window.
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
1042 * The new value as it was set, or 0 if any parameter is invalid.
1045 * Only bits specified in mask are affected - set if present in flags and
1048 LONG WINAPI
SHSetWindowBits(HWND hwnd
, INT offset
, UINT mask
, UINT flags
)
1050 LONG ret
= GetWindowLongW(hwnd
, offset
);
1051 LONG new_flags
= (flags
& mask
) | (ret
& ~mask
);
1053 TRACE("%p %d %x %x\n", hwnd
, offset
, mask
, flags
);
1055 if (new_flags
!= ret
)
1056 ret
= SetWindowLongW(hwnd
, offset
, new_flags
);
1060 /*************************************************************************
1063 * Change a window's parent.
1066 * hWnd [I] Window to change parent of
1067 * hWndParent [I] New parent window
1070 * The old parent of hWnd.
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.
1076 HWND WINAPI
SHSetParentHwnd(HWND hWnd
, HWND hWndParent
)
1078 TRACE("%p, %p\n", hWnd
, hWndParent
);
1080 if(GetParent(hWnd
) == hWndParent
)
1084 SHSetWindowBits(hWnd
, GWL_STYLE
, WS_CHILD
| WS_POPUP
, WS_CHILD
);
1086 SHSetWindowBits(hWnd
, GWL_STYLE
, WS_CHILD
| WS_POPUP
, WS_POPUP
);
1088 return hWndParent
? SetParent(hWnd
, hWndParent
) : NULL
;
1091 /*************************************************************************
1094 * Locate and advise a connection point in an IConnectionPointContainer object.
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
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.
1111 HRESULT WINAPI
ConnectToConnectionPoint(IUnknown
* lpUnkSink
, REFIID riid
, BOOL fConnect
,
1112 IUnknown
* lpUnknown
, LPDWORD lpCookie
,
1113 IConnectionPoint
**lppCP
)
1116 IConnectionPointContainer
* lpContainer
;
1117 IConnectionPoint
*lpCP
;
1119 if(!lpUnknown
|| (fConnect
&& !lpUnkSink
))
1125 hRet
= IUnknown_QueryInterface(lpUnknown
, &IID_IConnectionPointContainer
,
1126 (void**)&lpContainer
);
1127 if (SUCCEEDED(hRet
))
1129 hRet
= IConnectionPointContainer_FindConnectionPoint(lpContainer
, riid
, &lpCP
);
1131 if (SUCCEEDED(hRet
))
1134 hRet
= IConnectionPoint_Unadvise(lpCP
, *lpCookie
);
1136 hRet
= IConnectionPoint_Advise(lpCP
, lpUnkSink
, lpCookie
);
1141 if (lppCP
&& SUCCEEDED(hRet
))
1142 *lppCP
= lpCP
; /* Caller keeps the interface */
1144 IConnectionPoint_Release(lpCP
); /* Release it */
1147 IConnectionPointContainer_Release(lpContainer
);
1152 /*************************************************************************
1155 * Release an interface and zero a supplied pointer.
1158 * lpUnknown [I] Object to release
1163 void WINAPI
IUnknown_AtomicRelease(IUnknown
** lpUnknown
)
1165 TRACE("(%p)\n", lpUnknown
);
1167 if(!lpUnknown
|| !*lpUnknown
) return;
1169 TRACE("doing Release\n");
1171 IUnknown_Release(*lpUnknown
);
1175 /*************************************************************************
1178 * Skip '//' if present in a string.
1181 * lpszSrc [I] String to check for '//'
1184 * Success: The next character after the '//' or the string if not present
1185 * Failure: NULL, if lpszStr is NULL.
1187 LPCSTR WINAPI
PathSkipLeadingSlashesA(LPCSTR lpszSrc
)
1189 if (lpszSrc
&& lpszSrc
[0] == '/' && lpszSrc
[1] == '/')
1194 /*************************************************************************
1197 * Check if two interfaces come from the same object.
1200 * lpInt1 [I] Interface to check against lpInt2.
1201 * lpInt2 [I] Interface to check against lpInt1.
1204 * TRUE, If the interfaces come from the same object.
1207 BOOL WINAPI
SHIsSameObject(IUnknown
* lpInt1
, IUnknown
* lpInt2
)
1209 IUnknown
*lpUnknown1
, *lpUnknown2
;
1212 TRACE("(%p %p)\n", lpInt1
, lpInt2
);
1214 if (!lpInt1
|| !lpInt2
)
1217 if (lpInt1
== lpInt2
)
1220 if (IUnknown_QueryInterface(lpInt1
, &IID_IUnknown
, (void**)&lpUnknown1
) != S_OK
)
1223 if (IUnknown_QueryInterface(lpInt2
, &IID_IUnknown
, (void**)&lpUnknown2
) != S_OK
)
1225 IUnknown_Release(lpUnknown1
);
1229 ret
= lpUnknown1
== lpUnknown2
;
1231 IUnknown_Release(lpUnknown1
);
1232 IUnknown_Release(lpUnknown2
);
1237 /*************************************************************************
1240 * Get the window handle of an object.
1243 * lpUnknown [I] Object to get the window handle of
1244 * lphWnd [O] Destination for window handle
1247 * Success: S_OK. lphWnd contains the objects window handle.
1248 * Failure: An HRESULT error code.
1251 * lpUnknown is expected to support one of the following interfaces:
1252 * IOleWindow(), IInternetSecurityMgrSite(), or IShellView().
1254 HRESULT WINAPI
IUnknown_GetWindow(IUnknown
*lpUnknown
, HWND
*lphWnd
)
1257 HRESULT hRet
= E_FAIL
;
1259 TRACE("(%p,%p)\n", lpUnknown
, lphWnd
);
1264 hRet
= IUnknown_QueryInterface(lpUnknown
, &IID_IOleWindow
, (void**)&lpOle
);
1268 hRet
= IUnknown_QueryInterface(lpUnknown
,&IID_IShellView
, (void**)&lpOle
);
1272 hRet
= IUnknown_QueryInterface(lpUnknown
, &IID_IInternetSecurityMgrSite
,
1277 if (SUCCEEDED(hRet
))
1279 /* Laziness here - Since GetWindow() is the first method for the above 3
1280 * interfaces, we use the same call for them all.
1282 hRet
= IOleWindow_GetWindow((IOleWindow
*)lpOle
, lphWnd
);
1283 IUnknown_Release(lpOle
);
1285 TRACE("Returning HWND=%p\n", *lphWnd
);
1291 /*************************************************************************
1294 * Call a SetOwner method of IShellService from specified object.
1297 * iface [I] Object that supports IShellService
1298 * pUnk [I] Argument for the SetOwner call
1301 * Corresponding return value from last call or E_FAIL for null input
1303 HRESULT WINAPI
IUnknown_SetOwner(IUnknown
*iface
, IUnknown
*pUnk
)
1305 IShellService
*service
;
1308 TRACE("(%p, %p)\n", iface
, pUnk
);
1310 if (!iface
) return E_FAIL
;
1312 hr
= IUnknown_QueryInterface(iface
, &IID_IShellService
, (void**)&service
);
1315 hr
= IShellService_SetOwner(service
, pUnk
);
1316 IShellService_Release(service
);
1322 /*************************************************************************
1325 * Call either IObjectWithSite_SetSite() or IInternetSecurityManager_SetSecuritySite() on
1329 HRESULT WINAPI
IUnknown_SetSite(
1330 IUnknown
*obj
, /* [in] OLE object */
1331 IUnknown
*site
) /* [in] Site interface */
1334 IObjectWithSite
*iobjwithsite
;
1335 IInternetSecurityManager
*isecmgr
;
1337 if (!obj
) return E_FAIL
;
1339 hr
= IUnknown_QueryInterface(obj
, &IID_IObjectWithSite
, (LPVOID
*)&iobjwithsite
);
1340 TRACE("IID_IObjectWithSite QI ret=%08x, %p\n", hr
, iobjwithsite
);
1343 hr
= IObjectWithSite_SetSite(iobjwithsite
, site
);
1344 TRACE("done IObjectWithSite_SetSite ret=%08x\n", hr
);
1345 IObjectWithSite_Release(iobjwithsite
);
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
;
1353 hr
= IInternetSecurityManager_SetSecuritySite(isecmgr
, (IInternetSecurityMgrSite
*)site
);
1354 TRACE("done IInternetSecurityManager_SetSecuritySite ret=%08x\n", hr
);
1355 IInternetSecurityManager_Release(isecmgr
);
1360 /*************************************************************************
1363 * Call IPersist_GetClassID() on an object.
1366 * lpUnknown [I] Object supporting the IPersist interface
1367 * lpClassId [O] Destination for Class Id
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.
1375 HRESULT WINAPI
IUnknown_GetClassID(IUnknown
*lpUnknown
, CLSID
* lpClassId
)
1377 IPersist
* lpPersist
;
1378 HRESULT hRet
= E_FAIL
;
1380 TRACE("(%p,%s)\n", lpUnknown
, debugstr_guid(lpClassId
));
1384 hRet
= IUnknown_QueryInterface(lpUnknown
,&IID_IPersist
,(void**)&lpPersist
);
1385 if (SUCCEEDED(hRet
))
1387 IPersist_GetClassID(lpPersist
, lpClassId
);
1388 IPersist_Release(lpPersist
);
1394 /*************************************************************************
1397 * Retrieve a Service Interface from an object.
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
1406 * Success: S_OK. lppOut contains an object providing the requested service
1407 * Failure: An HRESULT error code
1410 * lpUnknown is expected to support the IServiceProvider interface.
1412 HRESULT WINAPI
IUnknown_QueryService(IUnknown
* lpUnknown
, REFGUID sid
, REFIID riid
,
1415 IServiceProvider
* pService
= NULL
;
1426 hRet
= IUnknown_QueryInterface(lpUnknown
, &IID_IServiceProvider
,
1427 (LPVOID
*)&pService
);
1429 if (hRet
== S_OK
&& pService
)
1431 TRACE("QueryInterface returned (IServiceProvider*)%p\n", pService
);
1433 /* Get a Service interface from the object */
1434 hRet
= IServiceProvider_QueryService(pService
, sid
, riid
, lppOut
);
1436 TRACE("(IServiceProvider*)%p returned (IUnknown*)%p\n", pService
, *lppOut
);
1438 IServiceProvider_Release(pService
);
1443 /*************************************************************************
1446 * Calls IOleCommandTarget::Exec() for specified service object.
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
1458 * Success: S_OK. lppOut contains an object providing the requested service
1459 * Failure: An HRESULT error code
1462 * lpUnknown is expected to support the IServiceProvider interface.
1464 HRESULT WINAPI
IUnknown_QueryServiceExec(IUnknown
*lpUnknown
, REFIID service
,
1465 const GUID
*group
, DWORD cmdId
, DWORD cmdOpt
, VARIANT
*pIn
, VARIANT
*pOut
)
1467 IOleCommandTarget
*target
;
1470 TRACE("%p %s %s %d %08x %p %p\n", lpUnknown
, debugstr_guid(service
),
1471 debugstr_guid(group
), cmdId
, cmdOpt
, pIn
, pOut
);
1473 hr
= IUnknown_QueryService(lpUnknown
, service
, &IID_IOleCommandTarget
, (void**)&target
);
1476 hr
= IOleCommandTarget_Exec(target
, group
, cmdId
, cmdOpt
, pIn
, pOut
);
1477 IOleCommandTarget_Release(target
);
1480 TRACE("<-- hr=0x%08x\n", hr
);
1485 /*************************************************************************
1488 * Calls IProfferService methods to proffer/revoke specified service.
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
1497 * Success: S_OK. IProffer method returns S_OK
1498 * Failure: An HRESULT error code
1501 * lpUnknown is expected to support the IServiceProvider interface.
1503 HRESULT WINAPI
IUnknown_ProfferService(IUnknown
*lpUnknown
, REFGUID service
, IServiceProvider
*pService
, DWORD
*pCookie
)
1505 IProfferService
*proffer
;
1508 TRACE("%p %s %p %p\n", lpUnknown
, debugstr_guid(service
), pService
, pCookie
);
1510 hr
= IUnknown_QueryService(lpUnknown
, &IID_IProfferService
, &IID_IProfferService
, (void**)&proffer
);
1514 hr
= IProfferService_ProfferService(proffer
, service
, pService
, pCookie
);
1517 hr
= IProfferService_RevokeService(proffer
, *pCookie
);
1521 IProfferService_Release(proffer
);
1527 /*************************************************************************
1530 * Call an object's UIActivateIO method.
1533 * unknown [I] Object to call the UIActivateIO method on
1534 * activate [I] Parameter for UIActivateIO call
1535 * msg [I] Parameter for UIActivateIO call
1538 * Success: Value of UI_ActivateIO call
1539 * Failure: An HRESULT error code
1542 * unknown is expected to support the IInputObject interface.
1544 HRESULT WINAPI
IUnknown_UIActivateIO(IUnknown
*unknown
, BOOL activate
, LPMSG msg
)
1546 IInputObject
* object
= NULL
;
1552 /* Get an IInputObject interface from the object */
1553 ret
= IUnknown_QueryInterface(unknown
, &IID_IInputObject
, (LPVOID
*) &object
);
1557 ret
= IInputObject_UIActivateIO(object
, activate
, msg
);
1558 IInputObject_Release(object
);
1564 /*************************************************************************
1567 * Loads a popup menu.
1570 * hInst [I] Instance handle
1571 * szName [I] Menu name
1577 BOOL WINAPI
SHLoadMenuPopup(HINSTANCE hInst
, LPCWSTR szName
)
1581 TRACE("%p %s\n", hInst
, debugstr_w(szName
));
1583 if ((hMenu
= LoadMenuW(hInst
, szName
)))
1585 if (GetSubMenu(hMenu
, 0))
1586 RemoveMenu(hMenu
, 0, MF_BYPOSITION
);
1594 typedef struct _enumWndData
1599 LRESULT (WINAPI
*pfnPost
)(HWND
,UINT
,WPARAM
,LPARAM
);
1602 /* Callback for SHLWAPI_178 */
1603 static BOOL CALLBACK
SHLWAPI_EnumChildProc(HWND hWnd
, LPARAM lParam
)
1605 enumWndData
*data
= (enumWndData
*)lParam
;
1607 TRACE("(%p,%p)\n", hWnd
, data
);
1608 data
->pfnPost(hWnd
, data
->uiMsgId
, data
->wParam
, data
->lParam
);
1612 /*************************************************************************
1615 * Send or post a message to every child of a window.
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()
1628 * The appropriate ASCII or Unicode function is called for the window.
1630 void WINAPI
SHPropagateMessage(HWND hWnd
, UINT uiMsgId
, WPARAM wParam
, LPARAM lParam
, BOOL bSend
)
1634 TRACE("(%p,%u,%ld,%ld,%d)\n", hWnd
, uiMsgId
, wParam
, lParam
, bSend
);
1638 data
.uiMsgId
= uiMsgId
;
1639 data
.wParam
= wParam
;
1640 data
.lParam
= lParam
;
1643 data
.pfnPost
= IsWindowUnicode(hWnd
) ? (void*)SendMessageW
: (void*)SendMessageA
;
1645 data
.pfnPost
= IsWindowUnicode(hWnd
) ? (void*)PostMessageW
: (void*)PostMessageA
;
1647 EnumChildWindows(hWnd
, SHLWAPI_EnumChildProc
, (LPARAM
)&data
);
1651 /*************************************************************************
1654 * Remove all sub-menus from a menu.
1657 * hMenu [I] Menu to remove sub-menus from
1660 * Success: 0. All sub-menus under hMenu are removed
1661 * Failure: -1, if any parameter is invalid
1663 DWORD WINAPI
SHRemoveAllSubMenus(HMENU hMenu
)
1665 int iItemCount
= GetMenuItemCount(hMenu
) - 1;
1667 TRACE("%p\n", hMenu
);
1669 while (iItemCount
>= 0)
1671 HMENU hSubMenu
= GetSubMenu(hMenu
, iItemCount
);
1673 RemoveMenu(hMenu
, iItemCount
, MF_BYPOSITION
);
1679 /*************************************************************************
1682 * Enable or disable a menu item.
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.
1690 * The return code from EnableMenuItem.
1692 UINT WINAPI
SHEnableMenuItem(HMENU hMenu
, UINT wItemID
, BOOL bEnable
)
1694 TRACE("%p, %u, %d\n", hMenu
, wItemID
, bEnable
);
1695 return EnableMenuItem(hMenu
, wItemID
, bEnable
? MF_ENABLED
: MF_GRAYED
);
1698 /*************************************************************************
1701 * Check or uncheck a menu item.
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.
1709 * The return code from CheckMenuItem.
1711 DWORD WINAPI
SHCheckMenuItem(HMENU hMenu
, UINT uID
, BOOL bCheck
)
1713 TRACE("%p, %u, %d\n", hMenu
, uID
, bCheck
);
1714 return CheckMenuItem(hMenu
, uID
, bCheck
? MF_CHECKED
: MF_UNCHECKED
);
1717 /*************************************************************************
1720 * Register a window class if it isn't already.
1723 * lpWndClass [I] Window class to register
1726 * The result of the RegisterClassA call.
1728 DWORD WINAPI
SHRegisterClassA(WNDCLASSA
*wndclass
)
1731 if (GetClassInfoA(wndclass
->hInstance
, wndclass
->lpszClassName
, &wca
))
1733 return (DWORD
)RegisterClassA(wndclass
);
1736 /*************************************************************************
1739 BOOL WINAPI
SHSimulateDrop(IDropTarget
*pDrop
, IDataObject
*pDataObj
,
1740 DWORD grfKeyState
, PPOINTL lpPt
, DWORD
* pdwEffect
)
1742 DWORD dwEffect
= DROPEFFECT_LINK
| DROPEFFECT_MOVE
| DROPEFFECT_COPY
;
1743 POINTL pt
= { 0, 0 };
1745 TRACE("%p %p 0x%08x %p %p\n", pDrop
, pDataObj
, grfKeyState
, lpPt
, pdwEffect
);
1751 pdwEffect
= &dwEffect
;
1753 IDropTarget_DragEnter(pDrop
, pDataObj
, grfKeyState
, *lpPt
, pdwEffect
);
1755 if (*pdwEffect
!= DROPEFFECT_NONE
)
1756 return IDropTarget_Drop(pDrop
, pDataObj
, grfKeyState
, *lpPt
, pdwEffect
);
1758 IDropTarget_DragLeave(pDrop
);
1762 /*************************************************************************
1765 * Call IPersistPropertyBag_Load() on an object.
1768 * lpUnknown [I] Object supporting the IPersistPropertyBag interface
1769 * lpPropBag [O] Destination for loaded IPropertyBag
1773 * Failure: An HRESULT error code, or E_FAIL if lpUnknown is NULL.
1775 DWORD WINAPI
SHLoadFromPropertyBag(IUnknown
*lpUnknown
, IPropertyBag
* lpPropBag
)
1777 IPersistPropertyBag
* lpPPBag
;
1778 HRESULT hRet
= E_FAIL
;
1780 TRACE("(%p,%p)\n", lpUnknown
, lpPropBag
);
1784 hRet
= IUnknown_QueryInterface(lpUnknown
, &IID_IPersistPropertyBag
,
1786 if (SUCCEEDED(hRet
) && lpPPBag
)
1788 hRet
= IPersistPropertyBag_Load(lpPPBag
, lpPropBag
, NULL
);
1789 IPersistPropertyBag_Release(lpPPBag
);
1795 /*************************************************************************
1798 * Call IOleControlSite_TranslateAccelerator() on an object.
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.
1807 * Failure: An HRESULT error code, or E_INVALIDARG if lpUnknown is NULL.
1809 HRESULT WINAPI
IUnknown_TranslateAcceleratorOCS(IUnknown
*lpUnknown
, LPMSG lpMsg
, DWORD dwModifiers
)
1811 IOleControlSite
* lpCSite
= NULL
;
1812 HRESULT hRet
= E_INVALIDARG
;
1814 TRACE("(%p,%p,0x%08x)\n", lpUnknown
, lpMsg
, dwModifiers
);
1817 hRet
= IUnknown_QueryInterface(lpUnknown
, &IID_IOleControlSite
,
1819 if (SUCCEEDED(hRet
) && lpCSite
)
1821 hRet
= IOleControlSite_TranslateAccelerator(lpCSite
, lpMsg
, dwModifiers
);
1822 IOleControlSite_Release(lpCSite
);
1829 /*************************************************************************
1832 * Call IOleControlSite_OnFocus() on an object.
1835 * lpUnknown [I] Object supporting the IOleControlSite interface.
1836 * fGotFocus [I] Whether focus was gained (TRUE) or lost (FALSE).
1840 * Failure: An HRESULT error code, or E_FAIL if lpUnknown is NULL.
1842 HRESULT WINAPI
IUnknown_OnFocusOCS(IUnknown
*lpUnknown
, BOOL fGotFocus
)
1844 IOleControlSite
* lpCSite
= NULL
;
1845 HRESULT hRet
= E_FAIL
;
1847 TRACE("(%p, %d)\n", lpUnknown
, fGotFocus
);
1850 hRet
= IUnknown_QueryInterface(lpUnknown
, &IID_IOleControlSite
,
1852 if (SUCCEEDED(hRet
) && lpCSite
)
1854 hRet
= IOleControlSite_OnFocus(lpCSite
, fGotFocus
);
1855 IOleControlSite_Release(lpCSite
);
1861 /*************************************************************************
1864 HRESULT WINAPI
IUnknown_HandleIRestrict(LPUNKNOWN lpUnknown
, PVOID lpArg1
,
1865 PVOID lpArg2
, PVOID lpArg3
, PVOID lpArg4
)
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 */
1874 TRACE("(%p,%p,%p,%p,%p)\n", lpUnknown
, lpArg1
, lpArg2
, lpArg3
, lpArg4
);
1876 if (lpUnknown
&& lpArg4
)
1878 hRet
= IUnknown_QueryService(lpUnknown
, (REFGUID
)service_id
,
1879 (REFGUID
)function_id
, (void**)&lpUnkInner
);
1881 if (SUCCEEDED(hRet
) && lpUnkInner
)
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.
1888 hRet
= IParseDisplayName_ParseDisplayName((LPPARSEDISPLAYNAME
)lpUnkInner
,
1889 lpArg1
, lpArg2
, lpArg3
, lpArg4
);
1890 IUnknown_Release(lpUnkInner
);
1896 /*************************************************************************
1899 * Get a sub-menu from a menu item.
1902 * hMenu [I] Menu to get sub-menu from
1903 * uID [I] ID of menu item containing sub-menu
1906 * The sub-menu of the item, or a NULL handle if any parameters are invalid.
1908 HMENU WINAPI
SHGetMenuFromID(HMENU hMenu
, UINT uID
)
1912 TRACE("(%p,%u)\n", hMenu
, uID
);
1914 mi
.cbSize
= sizeof(mi
);
1915 mi
.fMask
= MIIM_SUBMENU
;
1917 if (!GetMenuItemInfoW(hMenu
, uID
, FALSE
, &mi
))
1923 /*************************************************************************
1926 * Get the color depth of the primary display.
1932 * The color depth of the primary display.
1934 DWORD WINAPI
SHGetCurColorRes(void)
1942 ret
= GetDeviceCaps(hdc
, BITSPIXEL
) * GetDeviceCaps(hdc
, PLANES
);
1947 /*************************************************************************
1950 * Wait for a message to arrive, with a timeout.
1953 * hand [I] Handle to query
1954 * dwTimeout [I] Timeout in ticks or INFINITE to never timeout
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.
1961 DWORD WINAPI
SHWaitForSendMessageThread(HANDLE hand
, DWORD dwTimeout
)
1963 DWORD dwEndTicks
= GetTickCount() + dwTimeout
;
1966 while ((dwRet
= MsgWaitForMultipleObjectsEx(1, &hand
, dwTimeout
, QS_SENDMESSAGE
, 0)) == 1)
1970 PeekMessageW(&msg
, NULL
, 0, 0, PM_NOREMOVE
);
1972 if (dwTimeout
!= INFINITE
)
1974 if ((int)(dwTimeout
= dwEndTicks
- GetTickCount()) <= 0)
1975 return WAIT_TIMEOUT
;
1982 /*************************************************************************
1985 * Determine if a shell folder can be expanded.
1988 * lpFolder [I] Parent folder containing the object to test.
1989 * pidl [I] Id of the object to test.
1992 * Success: S_OK, if the object is expandable, S_FALSE otherwise.
1993 * Failure: E_INVALIDARG, if any argument is invalid.
1996 * If the object to be tested does not expose the IQueryInfo() interface it
1997 * will not be identified as an expandable folder.
1999 HRESULT WINAPI
SHIsExpandableFolder(LPSHELLFOLDER lpFolder
, LPCITEMIDLIST pidl
)
2001 HRESULT hRet
= E_INVALIDARG
;
2004 if (lpFolder
&& pidl
)
2006 hRet
= IShellFolder_GetUIObjectOf(lpFolder
, NULL
, 1, &pidl
, &IID_IQueryInfo
,
2007 NULL
, (void**)&lpInfo
);
2009 hRet
= S_FALSE
; /* Doesn't expose IQueryInfo */
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?
2017 hRet
= IQueryInfo_GetInfoFlags(lpInfo
, &dwFlags
);
2019 if (SUCCEEDED(hRet
))
2021 /* 0x2 is an undocumented flag apparently indicating expandability */
2022 hRet
= dwFlags
& 0x2 ? S_OK
: S_FALSE
;
2025 IQueryInfo_Release(lpInfo
);
2031 /*************************************************************************
2034 * Blank out a region of text by drawing the background only.
2037 * hDC [I] Device context to draw in
2038 * pRect [I] Area to draw in
2039 * cRef [I] Color to draw in
2044 DWORD WINAPI
SHFillRectClr(HDC hDC
, LPCRECT pRect
, COLORREF cRef
)
2046 COLORREF cOldColor
= SetBkColor(hDC
, cRef
);
2047 ExtTextOutA(hDC
, 0, 0, ETO_OPAQUE
, pRect
, 0, 0, 0);
2048 SetBkColor(hDC
, cOldColor
);
2052 /*************************************************************************
2055 * Return the value associated with a key in a map.
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
2064 * The value in lpValues associated with iKey, or -1 if iKey is not
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.
2072 int WINAPI
SHSearchMapInt(const int *lpKeys
, const int *lpValues
, int iLen
, int iKey
)
2074 if (lpKeys
&& lpValues
)
2080 if (lpKeys
[i
] == iKey
)
2081 return lpValues
[i
]; /* Found */
2085 return -1; /* Not found */
2089 /*************************************************************************
2092 * Copy an interface pointer
2095 * lppDest [O] Destination for copy
2096 * lpUnknown [I] Source for copy
2101 VOID WINAPI
IUnknown_Set(IUnknown
**lppDest
, IUnknown
*lpUnknown
)
2103 TRACE("(%p,%p)\n", lppDest
, lpUnknown
);
2105 IUnknown_AtomicRelease(lppDest
);
2109 IUnknown_AddRef(lpUnknown
);
2110 *lppDest
= lpUnknown
;
2114 /*************************************************************************
2118 HRESULT WINAPI
MayQSForward(IUnknown
* lpUnknown
, PVOID lpReserved
,
2119 REFGUID riidCmdGrp
, ULONG cCmds
,
2120 OLECMD
*prgCmds
, OLECMDTEXT
* pCmdText
)
2122 FIXME("(%p,%p,%p,%d,%p,%p) - stub\n",
2123 lpUnknown
, lpReserved
, riidCmdGrp
, cCmds
, prgCmds
, pCmdText
);
2125 /* FIXME: Calls IsQSForward & IUnknown_QueryStatus */
2126 return DRAGDROP_E_NOTREGISTERED
;
2129 /*************************************************************************
2133 HRESULT WINAPI
MayExecForward(IUnknown
* lpUnknown
, INT iUnk
, REFGUID pguidCmdGroup
,
2134 DWORD nCmdID
, DWORD nCmdexecopt
, VARIANT
* pvaIn
,
2137 FIXME("(%p,%d,%p,%d,%d,%p,%p) - stub!\n", lpUnknown
, iUnk
, pguidCmdGroup
,
2138 nCmdID
, nCmdexecopt
, pvaIn
, pvaOut
);
2139 return DRAGDROP_E_NOTREGISTERED
;
2142 /*************************************************************************
2146 HRESULT WINAPI
IsQSForward(REFGUID pguidCmdGroup
,ULONG cCmds
, OLECMD
*prgCmds
)
2148 FIXME("(%p,%d,%p) - stub!\n", pguidCmdGroup
, cCmds
, prgCmds
);
2149 return DRAGDROP_E_NOTREGISTERED
;
2152 /*************************************************************************
2155 * Determine if a window is not a child of another window.
2158 * hParent [I] Suspected parent window
2159 * hChild [I] Suspected child window
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
2165 BOOL WINAPI
SHIsChildOrSelf(HWND hParent
, HWND hChild
)
2167 TRACE("(%p,%p)\n", hParent
, hChild
);
2169 if (!hParent
|| !hChild
)
2171 else if(hParent
== hChild
)
2173 return !IsChild(hParent
, hChild
);
2176 /*************************************************************************
2177 * FDSA functions. Manage a dynamic array of fixed size memory blocks.
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 */
2190 #define FDSA_FLAG_INTERNAL_ALLOC 0x01 /* When set we have allocated mem internally */
2192 /*************************************************************************
2195 * Initialize an FDSA array.
2197 BOOL WINAPI
FDSA_Initialize(DWORD block_size
, DWORD inc
, FDSA_info
*info
, void *mem
,
2200 TRACE("(0x%08x 0x%08x %p %p 0x%08x)\n", block_size
, inc
, info
, mem
, init_blocks
);
2206 memset(mem
, 0, block_size
* init_blocks
);
2208 info
->num_items
= 0;
2211 info
->blocks_alloced
= init_blocks
;
2212 info
->block_size
= block_size
;
2218 /*************************************************************************
2221 * Destroy an FDSA array
2223 BOOL WINAPI
FDSA_Destroy(FDSA_info
*info
)
2225 TRACE("(%p)\n", info
);
2227 if(info
->flags
& FDSA_FLAG_INTERNAL_ALLOC
)
2229 HeapFree(GetProcessHeap(), 0, info
->mem
);
2236 /*************************************************************************
2239 * Insert element into an FDSA array
2241 DWORD WINAPI
FDSA_InsertItem(FDSA_info
*info
, DWORD where
, const void *block
)
2243 TRACE("(%p 0x%08x %p)\n", info
, where
, block
);
2244 if(where
> info
->num_items
)
2245 where
= info
->num_items
;
2247 if(info
->num_items
>= info
->blocks_alloced
)
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
);
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
);
2258 info
->blocks_alloced
+= info
->inc
;
2262 if(where
< info
->num_items
)
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
);
2268 memcpy((char*)info
->mem
+ where
* info
->block_size
, block
, info
->block_size
);
2274 /*************************************************************************
2277 * Delete an element from an FDSA array.
2279 BOOL WINAPI
FDSA_DeleteItem(FDSA_info
*info
, DWORD where
)
2281 TRACE("(%p 0x%08x)\n", info
, where
);
2283 if(where
>= info
->num_items
)
2286 if(where
< info
->num_items
- 1)
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
);
2292 memset((char*)info
->mem
+ (info
->num_items
- 1) * info
->block_size
,
2293 0, info
->block_size
);
2298 /*************************************************************************
2301 * Call IUnknown_QueryInterface() on a table of objects.
2305 * Failure: E_POINTER or E_NOINTERFACE.
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 */
2317 TRACE("(%p %p %s %p)\n", base
, table
, debugstr_guid(riid
), ppv
);
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
);
2326 IUnknown_AddRef(a_vtbl
);
2332 if (IsEqualIID(riid
, &IID_IUnknown
)) {
2333 a_vtbl
= (IUnknown
*)(table
->dwOffset
+ (LPBYTE
)base
);
2334 TRACE("returning first for IUnknown (%p)\n", a_vtbl
);
2336 IUnknown_AddRef(a_vtbl
);
2340 ret
= E_NOINTERFACE
;
2344 TRACE("-- 0x%08x\n", ret
);
2348 /*************************************************************************
2351 * Set the Font for a window and the "PropDlgFont" property of the parent window.
2354 * hWnd [I] Parent Window to set the property
2355 * id [I] Index of child Window to set the Font
2361 HRESULT WINAPI
SHSetDefaultDialogFont(HWND hWnd
, INT id
)
2363 FIXME("(%p, %d) stub\n", hWnd
, id
);
2367 /*************************************************************************
2370 * Remove the "PropDlgFont" property from a window.
2373 * hWnd [I] Window to remove the property from
2376 * A handle to the removed property, or NULL if it did not exist.
2378 HANDLE WINAPI
SHRemoveDefaultDialogFont(HWND hWnd
)
2382 TRACE("(%p)\n", hWnd
);
2384 hProp
= GetPropA(hWnd
, "PropDlgFont");
2388 DeleteObject(hProp
);
2389 hProp
= RemovePropA(hWnd
, "PropDlgFont");
2394 /*************************************************************************
2397 * Load the in-process server of a given GUID.
2400 * refiid [I] GUID of the server to load.
2403 * Success: A handle to the loaded server dll.
2404 * Failure: A NULL handle.
2406 HMODULE WINAPI
SHPinDllOfCLSID(REFIID refiid
)
2410 CHAR value
[MAX_PATH
], string
[MAX_PATH
];
2412 strcpy(string
, "CLSID\\");
2413 SHStringFromGUIDA(refiid
, string
+ 6, sizeof(string
)/sizeof(char) - 6);
2414 strcat(string
, "\\InProcServer32");
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);
2423 /*************************************************************************
2426 * Unicode version of SHLWAPI_183.
2428 DWORD WINAPI
SHRegisterClassW(WNDCLASSW
* lpWndClass
)
2432 TRACE("(%p %s)\n",lpWndClass
->hInstance
, debugstr_w(lpWndClass
->lpszClassName
));
2434 if (GetClassInfoW(lpWndClass
->hInstance
, lpWndClass
->lpszClassName
, &WndClass
))
2436 return RegisterClassW(lpWndClass
);
2439 /*************************************************************************
2442 * Unregister a list of classes.
2445 * hInst [I] Application instance that registered the classes
2446 * lppClasses [I] List of class names
2447 * iCount [I] Number of names in lppClasses
2452 void WINAPI
SHUnregisterClassesA(HINSTANCE hInst
, LPCSTR
*lppClasses
, INT iCount
)
2456 TRACE("(%p,%p,%d)\n", hInst
, lppClasses
, iCount
);
2460 if (GetClassInfoA(hInst
, *lppClasses
, &WndClass
))
2461 UnregisterClassA(*lppClasses
, hInst
);
2467 /*************************************************************************
2470 * Unicode version of SHUnregisterClassesA.
2472 void WINAPI
SHUnregisterClassesW(HINSTANCE hInst
, LPCWSTR
*lppClasses
, INT iCount
)
2476 TRACE("(%p,%p,%d)\n", hInst
, lppClasses
, iCount
);
2480 if (GetClassInfoW(hInst
, *lppClasses
, &WndClass
))
2481 UnregisterClassW(*lppClasses
, hInst
);
2487 /*************************************************************************
2490 * Call The correct (Ascii/Unicode) default window procedure for a window.
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
2499 * The result of calling DefWindowProcA() or DefWindowProcW().
2501 LRESULT CALLBACK
SHDefWindowProc(HWND hWnd
, UINT uMessage
, WPARAM wParam
, LPARAM lParam
)
2503 if (IsWindowUnicode(hWnd
))
2504 return DefWindowProcW(hWnd
, uMessage
, wParam
, lParam
);
2505 return DefWindowProcA(hWnd
, uMessage
, wParam
, lParam
);
2508 /*************************************************************************
2511 HRESULT WINAPI
IUnknown_GetSite(LPUNKNOWN lpUnknown
, REFIID iid
, PVOID
*lppSite
)
2513 HRESULT hRet
= E_INVALIDARG
;
2514 LPOBJECTWITHSITE lpSite
= NULL
;
2516 TRACE("(%p,%s,%p)\n", lpUnknown
, debugstr_guid(iid
), lppSite
);
2518 if (lpUnknown
&& iid
&& lppSite
)
2520 hRet
= IUnknown_QueryInterface(lpUnknown
, &IID_IObjectWithSite
,
2522 if (SUCCEEDED(hRet
) && lpSite
)
2524 hRet
= IObjectWithSite_GetSite(lpSite
, iid
, lppSite
);
2525 IObjectWithSite_Release(lpSite
);
2531 /*************************************************************************
2534 * Create a worker window using CreateWindowExA().
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
2545 * Success: The window handle of the newly created window.
2548 HWND WINAPI
SHCreateWorkerWindowA(LONG wndProc
, HWND hWndParent
, DWORD dwExStyle
,
2549 DWORD dwStyle
, HMENU hMenu
, LONG_PTR wnd_extra
)
2551 static const char szClass
[] = "WorkerA";
2555 TRACE("(0x%08x, %p, 0x%08x, 0x%08x, %p, 0x%08lx)\n",
2556 wndProc
, hWndParent
, dwExStyle
, dwStyle
, hMenu
, wnd_extra
);
2558 /* Create Window class */
2560 wc
.lpfnWndProc
= DefWindowProcA
;
2562 wc
.cbWndExtra
= sizeof(LONG_PTR
);
2563 wc
.hInstance
= shlwapi_hInstance
;
2565 wc
.hCursor
= LoadCursorA(NULL
, (LPSTR
)IDC_ARROW
);
2566 wc
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
2567 wc
.lpszMenuName
= NULL
;
2568 wc
.lpszClassName
= szClass
;
2570 SHRegisterClassA(&wc
);
2572 hWnd
= CreateWindowExA(dwExStyle
, szClass
, 0, dwStyle
, 0, 0, 0, 0,
2573 hWndParent
, hMenu
, shlwapi_hInstance
, 0);
2576 SetWindowLongPtrW(hWnd
, 0, wnd_extra
);
2578 if (wndProc
) SetWindowLongPtrA(hWnd
, GWLP_WNDPROC
, wndProc
);
2584 typedef struct tagPOLICYDATA
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
;
2591 #define SHELL_NO_POLICY 0xffffffff
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};
2599 /*************************************************************************
2602 * Retrieve a policy value from the registry.
2605 * lpSubKey [I] registry key name
2606 * lpSubName [I] subname of registry key
2607 * lpValue [I] value name of registry value
2610 * the value associated with the registry key or 0 if not found
2612 DWORD WINAPI
SHGetRestriction(LPCWSTR lpSubKey
, LPCWSTR lpSubName
, LPCWSTR lpValue
)
2614 DWORD retval
, datsize
= sizeof(retval
);
2618 lpSubKey
= strRegistryPolicyW
;
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
)
2626 SHGetValueW(hKey
, lpSubName
, lpValue
, NULL
, &retval
, &datsize
);
2631 /*************************************************************************
2634 * Helper function to retrieve the possibly cached value for a specific policy
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
2643 * The retrieved policy value or 0 if not successful
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
2651 DWORD WINAPI
SHRestrictionLookup(
2654 LPPOLICYDATA polTable
,
2657 TRACE("(0x%08x %s %p %p)\n", policy
, debugstr_w(initial
), polTable
, polArr
);
2659 if (!polTable
|| !polArr
)
2662 for (;polTable
->policy
; polTable
++, polArr
++)
2664 if (policy
== polTable
->policy
)
2666 /* we have a known policy */
2668 /* check if this policy has been cached */
2669 if (*polArr
== SHELL_NO_POLICY
)
2670 *polArr
= SHGetRestriction(initial
, polTable
->appstr
, polTable
->keystr
);
2674 /* we don't know this policy, return 0 */
2675 TRACE("unknown policy: (%08x)\n", policy
);
2679 /*************************************************************************
2682 * Get an interface from an object.
2685 * Success: S_OK. ppv contains the requested interface.
2686 * Failure: An HRESULT error code.
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.
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 */
2700 HRESULT hret
= E_NOINTERFACE
;
2701 TRACE("(pUnk=%p pInner=%p\n\tIID: %s %p)\n",pUnk
,pInner
,debugstr_guid(riid
), ppv
);
2704 if(pUnk
&& pInner
) {
2705 hret
= IUnknown_QueryInterface(pInner
, riid
, ppv
);
2706 if (SUCCEEDED(hret
)) IUnknown_Release(pUnk
);
2708 TRACE("-- 0x%08x\n", hret
);
2712 /*************************************************************************
2715 * Move a reference from one interface to another.
2718 * lpDest [O] Destination to receive the reference
2719 * lppUnknown [O] Source to give up the reference to lpDest
2724 VOID WINAPI
SHWeakReleaseInterface(IUnknown
*lpDest
, IUnknown
**lppUnknown
)
2726 TRACE("(%p,%p)\n", lpDest
, lppUnknown
);
2731 IUnknown_AddRef(lpDest
);
2732 IUnknown_AtomicRelease(lppUnknown
); /* Release existing interface */
2736 /*************************************************************************
2739 * Convert an ASCII string of a CLSID into a CLSID.
2742 * idstr [I] String representing a CLSID in registry format
2743 * id [O] Destination for the converted CLSID
2746 * Success: TRUE. id contains the converted CLSID.
2749 BOOL WINAPI
GUIDFromStringA(LPCSTR idstr
, CLSID
*id
)
2752 MultiByteToWideChar(CP_ACP
, 0, idstr
, -1, wClsid
, sizeof(wClsid
)/sizeof(WCHAR
));
2753 return SUCCEEDED(CLSIDFromString(wClsid
, id
));
2756 /*************************************************************************
2759 * Unicode version of GUIDFromStringA.
2761 BOOL WINAPI
GUIDFromStringW(LPCWSTR idstr
, CLSID
*id
)
2763 return SUCCEEDED(CLSIDFromString((LPCOLESTR
)idstr
, id
));
2766 /*************************************************************************
2769 * Determine if the browser is integrated into the shell, and set a registry
2776 * 1, If the browser is not integrated.
2777 * 2, If the browser is integrated.
2780 * The key "HKLM\Software\Microsoft\Internet Explorer\IntegratedBrowser" is
2781 * either set to TRUE, or removed depending on whether the browser is deemed
2784 DWORD WINAPI
WhichPlatform(void)
2786 static const char szIntegratedBrowser
[] = "IntegratedBrowser";
2787 static DWORD dwState
= 0;
2789 DWORD dwRet
, dwData
, dwSize
;
2795 /* If shell32 exports DllGetVersion(), the browser is integrated */
2797 hshell32
= LoadLibraryA("shell32.dll");
2800 FARPROC pDllGetVersion
;
2801 pDllGetVersion
= GetProcAddress(hshell32
, "DllGetVersion");
2802 dwState
= pDllGetVersion
? 2 : 1;
2803 FreeLibrary(hshell32
);
2806 /* Set or delete the key accordingly */
2807 dwRet
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
2808 "Software\\Microsoft\\Internet Explorer", 0,
2809 KEY_ALL_ACCESS
, &hKey
);
2812 dwRet
= RegQueryValueExA(hKey
, szIntegratedBrowser
, 0, 0,
2813 (LPBYTE
)&dwData
, &dwSize
);
2815 if (!dwRet
&& dwState
== 1)
2817 /* Value exists but browser is not integrated */
2818 RegDeleteValueA(hKey
, szIntegratedBrowser
);
2820 else if (dwRet
&& dwState
== 2)
2822 /* Browser is integrated but value does not exist */
2824 RegSetValueExA(hKey
, szIntegratedBrowser
, 0, REG_DWORD
,
2825 (LPBYTE
)&dwData
, sizeof(dwData
));
2832 /*************************************************************************
2835 * Unicode version of SHCreateWorkerWindowA.
2837 HWND WINAPI
SHCreateWorkerWindowW(LONG wndProc
, HWND hWndParent
, DWORD dwExStyle
,
2838 DWORD dwStyle
, HMENU hMenu
, LONG msg_result
)
2840 static const WCHAR szClass
[] = { 'W', 'o', 'r', 'k', 'e', 'r', 'W', 0 };
2844 TRACE("(0x%08x, %p, 0x%08x, 0x%08x, %p, 0x%08x)\n",
2845 wndProc
, hWndParent
, dwExStyle
, dwStyle
, hMenu
, msg_result
);
2847 /* If our OS is natively ANSI, use the ANSI version */
2848 if (GetVersion() & 0x80000000) /* not NT */
2850 TRACE("fallback to ANSI, ver 0x%08x\n", GetVersion());
2851 return SHCreateWorkerWindowA(wndProc
, hWndParent
, dwExStyle
, dwStyle
, hMenu
, msg_result
);
2854 /* Create Window class */
2856 wc
.lpfnWndProc
= DefWindowProcW
;
2859 wc
.hInstance
= shlwapi_hInstance
;
2861 wc
.hCursor
= LoadCursorW(NULL
, (LPWSTR
)IDC_ARROW
);
2862 wc
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
2863 wc
.lpszMenuName
= NULL
;
2864 wc
.lpszClassName
= szClass
;
2866 SHRegisterClassW(&wc
);
2868 hWnd
= CreateWindowExW(dwExStyle
, szClass
, 0, dwStyle
, 0, 0, 0, 0,
2869 hWndParent
, hMenu
, shlwapi_hInstance
, 0);
2872 SetWindowLongPtrW(hWnd
, DWLP_MSGRESULT
, msg_result
);
2874 if (wndProc
) SetWindowLongPtrW(hWnd
, GWLP_WNDPROC
, wndProc
);
2880 /*************************************************************************
2883 * Get and show a context menu from a shell folder.
2886 * hWnd [I] Window displaying the shell folder
2887 * lpFolder [I] IShellFolder interface
2888 * lpApidl [I] Id for the particular folder desired
2892 * Failure: An HRESULT error code indicating the error.
2894 HRESULT WINAPI
SHInvokeDefaultCommand(HWND hWnd
, IShellFolder
* lpFolder
, LPCITEMIDLIST lpApidl
)
2896 TRACE("%p %p %p\n", hWnd
, lpFolder
, lpApidl
);
2897 return SHInvokeCommand(hWnd
, lpFolder
, lpApidl
, 0);
2900 /*************************************************************************
2903 * _SHPackDispParamsV
2905 HRESULT WINAPI
SHPackDispParamsV(DISPPARAMS
*params
, VARIANTARG
*args
, UINT cnt
, __ms_va_list valist
)
2909 TRACE("(%p %p %u ...)\n", params
, args
, cnt
);
2911 params
->rgvarg
= args
;
2912 params
->rgdispidNamedArgs
= NULL
;
2913 params
->cArgs
= cnt
;
2914 params
->cNamedArgs
= 0;
2918 while(iter
-- > args
) {
2919 V_VT(iter
) = va_arg(valist
, enum VARENUM
);
2921 TRACE("vt=%d\n", V_VT(iter
));
2923 if(V_VT(iter
) & VT_BYREF
) {
2924 V_BYREF(iter
) = va_arg(valist
, LPVOID
);
2926 switch(V_VT(iter
)) {
2928 V_I4(iter
) = va_arg(valist
, LONG
);
2931 V_BSTR(iter
) = va_arg(valist
, BSTR
);
2934 V_DISPATCH(iter
) = va_arg(valist
, IDispatch
*);
2937 V_BOOL(iter
) = va_arg(valist
, int);
2940 V_UNKNOWN(iter
) = va_arg(valist
, IUnknown
*);
2944 V_I4(iter
) = va_arg(valist
, LONG
);
2952 /*************************************************************************
2957 HRESULT WINAPIV
SHPackDispParams(DISPPARAMS
*params
, VARIANTARG
*args
, UINT cnt
, ...)
2959 __ms_va_list valist
;
2962 __ms_va_start(valist
, cnt
);
2963 hres
= SHPackDispParamsV(params
, args
, cnt
, valist
);
2964 __ms_va_end(valist
);
2968 /*************************************************************************
2969 * SHLWAPI_InvokeByIID
2971 * This helper function calls IDispatch::Invoke for each sink
2972 * which implements given iid or IDispatch.
2975 static HRESULT
SHLWAPI_InvokeByIID(
2976 IConnectionPoint
* iCP
,
2979 DISPPARAMS
* dispParams
)
2981 IEnumConnections
*enumerator
;
2983 static DISPPARAMS empty
= {NULL
, NULL
, 0, 0};
2984 DISPPARAMS
* params
= dispParams
;
2986 HRESULT result
= IConnectionPoint_EnumConnections(iCP
, &enumerator
);
2990 /* Invoke is never happening with an NULL dispParams */
2994 while(IEnumConnections_Next(enumerator
, 1, &rgcd
, NULL
)==S_OK
)
2996 IDispatch
*dispIface
;
2997 if ((iid
&& SUCCEEDED(IUnknown_QueryInterface(rgcd
.pUnk
, iid
, (LPVOID
*)&dispIface
))) ||
2998 SUCCEEDED(IUnknown_QueryInterface(rgcd
.pUnk
, &IID_IDispatch
, (LPVOID
*)&dispIface
)))
3000 IDispatch_Invoke(dispIface
, dispId
, &IID_NULL
, 0, DISPATCH_METHOD
, params
, NULL
, NULL
, NULL
);
3001 IDispatch_Release(dispIface
);
3003 IUnknown_Release(rgcd
.pUnk
);
3006 IEnumConnections_Release(enumerator
);
3011 /*************************************************************************
3012 * IConnectionPoint_InvokeWithCancel [SHLWAPI.283]
3014 HRESULT WINAPI
IConnectionPoint_InvokeWithCancel( IConnectionPoint
* iCP
,
3015 DISPID dispId
, DISPPARAMS
* dispParams
,
3016 DWORD unknown1
, DWORD unknown2
)
3021 FIXME("(%p)->(0x%x %p %x %x) partial stub\n", iCP
, dispId
, dispParams
, unknown1
, unknown2
);
3023 result
= IConnectionPoint_GetConnectionInterface(iCP
, &iid
);
3024 if (SUCCEEDED(result
))
3025 result
= SHLWAPI_InvokeByIID(iCP
, &iid
, dispId
, dispParams
);
3027 result
= SHLWAPI_InvokeByIID(iCP
, NULL
, dispId
, dispParams
);
3033 /*************************************************************************
3036 * IConnectionPoint_SimpleInvoke
3038 HRESULT WINAPI
IConnectionPoint_SimpleInvoke(
3039 IConnectionPoint
* iCP
,
3041 DISPPARAMS
* dispParams
)
3046 TRACE("(%p)->(0x%x %p)\n",iCP
,dispId
,dispParams
);
3048 result
= IConnectionPoint_GetConnectionInterface(iCP
, &iid
);
3049 if (SUCCEEDED(result
))
3050 result
= SHLWAPI_InvokeByIID(iCP
, &iid
, dispId
, dispParams
);
3052 result
= SHLWAPI_InvokeByIID(iCP
, NULL
, dispId
, dispParams
);
3057 /*************************************************************************
3060 * Notify an IConnectionPoint object of changes.
3063 * lpCP [I] Object to notify
3068 * Failure: E_NOINTERFACE, if lpCP is NULL or does not support the
3069 * IConnectionPoint interface.
3071 HRESULT WINAPI
IConnectionPoint_OnChanged(IConnectionPoint
* lpCP
, DISPID dispID
)
3073 IEnumConnections
*lpEnum
;
3074 HRESULT hRet
= E_NOINTERFACE
;
3076 TRACE("(%p,0x%8X)\n", lpCP
, dispID
);
3078 /* Get an enumerator for the connections */
3080 hRet
= IConnectionPoint_EnumConnections(lpCP
, &lpEnum
);
3082 if (SUCCEEDED(hRet
))
3084 IPropertyNotifySink
*lpSink
;
3085 CONNECTDATA connData
;
3088 /* Call OnChanged() for every notify sink in the connection point */
3089 while (IEnumConnections_Next(lpEnum
, 1, &connData
, &ulFetched
) == S_OK
)
3091 if (SUCCEEDED(IUnknown_QueryInterface(connData
.pUnk
, &IID_IPropertyNotifySink
, (void**)&lpSink
)) &&
3094 IPropertyNotifySink_OnChanged(lpSink
, dispID
);
3095 IPropertyNotifySink_Release(lpSink
);
3097 IUnknown_Release(connData
.pUnk
);
3100 IEnumConnections_Release(lpEnum
);
3105 /*************************************************************************
3108 * IUnknown_CPContainerInvokeParam
3110 HRESULT WINAPIV
IUnknown_CPContainerInvokeParam(
3111 IUnknown
*container
,
3118 IConnectionPoint
*iCP
;
3119 IConnectionPointContainer
*iCPC
;
3120 DISPPARAMS dispParams
= {buffer
, NULL
, cParams
, 0};
3121 __ms_va_list valist
;
3124 return E_NOINTERFACE
;
3126 result
= IUnknown_QueryInterface(container
, &IID_IConnectionPointContainer
,(LPVOID
*) &iCPC
);
3130 result
= IConnectionPointContainer_FindConnectionPoint(iCPC
, riid
, &iCP
);
3131 IConnectionPointContainer_Release(iCPC
);
3135 __ms_va_start(valist
, cParams
);
3136 SHPackDispParamsV(&dispParams
, buffer
, cParams
, valist
);
3137 __ms_va_end(valist
);
3139 result
= SHLWAPI_InvokeByIID(iCP
, riid
, dispId
, &dispParams
);
3140 IConnectionPoint_Release(iCP
);
3145 /*************************************************************************
3148 * Notify an IConnectionPointContainer object of changes.
3151 * lpUnknown [I] Object to notify
3156 * Failure: E_NOINTERFACE, if lpUnknown is NULL or does not support the
3157 * IConnectionPointContainer interface.
3159 HRESULT WINAPI
IUnknown_CPContainerOnChanged(IUnknown
*lpUnknown
, DISPID dispID
)
3161 IConnectionPointContainer
* lpCPC
= NULL
;
3162 HRESULT hRet
= E_NOINTERFACE
;
3164 TRACE("(%p,0x%8X)\n", lpUnknown
, dispID
);
3167 hRet
= IUnknown_QueryInterface(lpUnknown
, &IID_IConnectionPointContainer
, (void**)&lpCPC
);
3169 if (SUCCEEDED(hRet
))
3171 IConnectionPoint
* lpCP
;
3173 hRet
= IConnectionPointContainer_FindConnectionPoint(lpCPC
, &IID_IPropertyNotifySink
, &lpCP
);
3174 IConnectionPointContainer_Release(lpCPC
);
3176 hRet
= IConnectionPoint_OnChanged(lpCP
, dispID
);
3177 IConnectionPoint_Release(lpCP
);
3182 /*************************************************************************
3187 BOOL WINAPI
PlaySoundWrapW(LPCWSTR pszSound
, HMODULE hmod
, DWORD fdwSound
)
3189 return PlaySoundW(pszSound
, hmod
, fdwSound
);
3192 /*************************************************************************
3195 * Retrieve a key value from an INI file. See GetPrivateProfileString for
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
3206 * Length of string copied into `out'.
3208 DWORD WINAPI
SHGetIniStringW(LPCWSTR appName
, LPCWSTR keyName
, LPWSTR out
,
3209 DWORD outLen
, LPCWSTR filename
)
3214 TRACE("(%s,%s,%p,%08x,%s)\n", debugstr_w(appName
), debugstr_w(keyName
),
3215 out
, outLen
, debugstr_w(filename
));
3220 buf
= HeapAlloc(GetProcessHeap(), 0, outLen
* sizeof(WCHAR
));
3226 ret
= GetPrivateProfileStringW(appName
, keyName
, NULL
, buf
, outLen
, filename
);
3232 HeapFree(GetProcessHeap(), 0, buf
);
3234 return strlenW(out
);
3237 /*************************************************************************
3240 * Set a key value in an INI file. See WritePrivateProfileString for