2 * IQueryAssociations object and helper functions
4 * Copyright 2002 Jon Griffiths
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 #include "wine/unicode.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(shell);
36 /**************************************************************************
37 * IQueryAssociations {SHLWAPI}
40 * This object provides a layer of abstraction over the system registry in
41 * order to simplify the process of parsing associations between files.
42 * Associations in this context means the registry entries that link (for
43 * example) the extension of a file with its description, list of
44 * applications to open the file with, and actions that can be performed on it
45 * (the shell displays such information in the context menu of explorer
46 * when you right-click on a file).
49 * You can use this object transparently by calling the helper functions
50 * AssocQueryKeyA(), AssocQueryStringA() and AssocQueryStringByKeyA(). These
51 * create an IQueryAssociations object, perform the requested actions
52 * and then dispose of the object. Alternatively, you can create an instance
53 * of the object using AssocCreate() and call the following methods on it:
58 /* Default IQueryAssociations::Init() flags */
59 #define SHLWAPI_DEF_ASSOCF (ASSOCF_INIT_BYEXENAME|ASSOCF_INIT_DEFAULTTOSTAR| \
60 ASSOCF_INIT_DEFAULTTOFOLDER)
64 const IQueryAssociationsVtbl *lpVtbl;
68 } IQueryAssociationsImpl;
70 static const IQueryAssociationsVtbl IQueryAssociations_vtbl;
72 /**************************************************************************
73 * IQueryAssociations_Constructor [internal]
75 * Construct a new IQueryAssociations object.
77 static IQueryAssociations* IQueryAssociations_Constructor(void)
79 IQueryAssociationsImpl* iface;
81 iface = HeapAlloc(GetProcessHeap(),0,sizeof(IQueryAssociationsImpl));
82 iface->lpVtbl = &IQueryAssociations_vtbl;
84 iface->hkeySource = NULL;
85 iface->hkeyProgID = NULL;
87 TRACE("Returning IQueryAssociations* %p\n", iface);
88 return (IQueryAssociations*)iface;
91 /*************************************************************************
94 * Internal helper function: Convert ASCII parameter to Unicode.
96 static BOOL SHLWAPI_ParamAToW(LPCSTR lpszParam, LPWSTR lpszBuff, DWORD dwLen,
101 DWORD dwStrLen = MultiByteToWideChar(CP_ACP, 0, lpszParam, -1, NULL, 0);
103 if (dwStrLen < dwLen)
105 *lpszOut = lpszBuff; /* Use Buffer, it is big enough */
109 /* Create a new buffer big enough for the string */
110 *lpszOut = HeapAlloc(GetProcessHeap(), 0,
111 dwStrLen * sizeof(WCHAR));
115 MultiByteToWideChar(CP_ACP, 0, lpszParam, -1, *lpszOut, dwStrLen);
122 /*************************************************************************
123 * AssocCreate [SHLWAPI.@]
125 * Create a new IQueryAssociations object.
128 * clsid [I] CLSID of object
129 * refiid [I] REFIID of interface
130 * lpInterface [O] Destination for the created IQueryAssociations object
133 * Success: S_OK. lpInterface contains the new object.
134 * Failure: An HRESULT error code indicating the error.
137 * refiid must be equal to IID_IQueryAssociations, or this function will fail.
139 HRESULT WINAPI AssocCreate(CLSID clsid, REFIID refiid, void **lpInterface)
142 IQueryAssociations* lpAssoc;
144 TRACE("(%s,%s,%p)\n", debugstr_guid(&clsid), debugstr_guid(refiid),
150 *(DWORD*)lpInterface = 0;
152 if (!IsEqualGUID(&clsid, &IID_IQueryAssociations))
155 lpAssoc = IQueryAssociations_Constructor();
158 return E_OUTOFMEMORY;
160 hRet = IQueryAssociations_QueryInterface(lpAssoc, refiid, lpInterface);
161 IQueryAssociations_Release(lpAssoc);
165 /*************************************************************************
166 * AssocQueryKeyW [SHLWAPI.@]
168 * See AssocQueryKeyA.
170 HRESULT WINAPI AssocQueryKeyW(ASSOCF cfFlags, ASSOCKEY assockey, LPCWSTR pszAssoc,
171 LPCWSTR pszExtra, HKEY *phkeyOut)
174 IQueryAssociations* lpAssoc;
176 TRACE("(0x%8x,0x%8x,%s,%s,%p)\n", cfFlags, assockey, debugstr_w(pszAssoc),
177 debugstr_w(pszExtra), phkeyOut);
179 lpAssoc = IQueryAssociations_Constructor();
182 return E_OUTOFMEMORY;
184 cfFlags &= SHLWAPI_DEF_ASSOCF;
185 hRet = IQueryAssociations_Init(lpAssoc, cfFlags, pszAssoc, NULL, NULL);
188 hRet = IQueryAssociations_GetKey(lpAssoc, cfFlags, assockey, pszExtra, phkeyOut);
190 IQueryAssociations_Release(lpAssoc);
194 /*************************************************************************
195 * AssocQueryKeyA [SHLWAPI.@]
197 * Get a file association key from the registry.
200 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
201 * assockey [I] Type of key to get
202 * pszAssoc [I] Key name to search below
203 * pszExtra [I] Extra information about the key location
204 * phkeyOut [O] Destination for the association key
207 * Success: S_OK. phkeyOut contains the key.
208 * Failure: An HRESULT error code indicating the error.
210 HRESULT WINAPI AssocQueryKeyA(ASSOCF cfFlags, ASSOCKEY assockey, LPCSTR pszAssoc,
211 LPCSTR pszExtra, HKEY *phkeyOut)
213 WCHAR szAssocW[MAX_PATH], *lpszAssocW = NULL;
214 WCHAR szExtraW[MAX_PATH], *lpszExtraW = NULL;
215 HRESULT hRet = E_OUTOFMEMORY;
217 TRACE("(0x%8x,0x%8x,%s,%s,%p)\n", cfFlags, assockey, debugstr_a(pszAssoc),
218 debugstr_a(pszExtra), phkeyOut);
220 if (SHLWAPI_ParamAToW(pszAssoc, szAssocW, MAX_PATH, &lpszAssocW) &&
221 SHLWAPI_ParamAToW(pszExtra, szExtraW, MAX_PATH, &lpszExtraW))
223 hRet = AssocQueryKeyW(cfFlags, assockey, lpszAssocW, lpszExtraW, phkeyOut);
226 if (lpszAssocW != szAssocW)
227 HeapFree(GetProcessHeap(), 0, lpszAssocW);
229 if (lpszExtraW != szExtraW)
230 HeapFree(GetProcessHeap(), 0, lpszExtraW);
235 /*************************************************************************
236 * AssocQueryStringW [SHLWAPI.@]
238 * See AssocQueryStringA.
240 HRESULT WINAPI AssocQueryStringW(ASSOCF cfFlags, ASSOCSTR str, LPCWSTR pszAssoc,
241 LPCWSTR pszExtra, LPWSTR pszOut, DWORD *pcchOut)
244 IQueryAssociations* lpAssoc;
246 TRACE("(0x%8x,0x%8x,%s,%s,%p,%p)\n", cfFlags, str, debugstr_w(pszAssoc),
247 debugstr_w(pszExtra), pszOut, pcchOut);
252 lpAssoc = IQueryAssociations_Constructor();
255 return E_OUTOFMEMORY;
257 hRet = IQueryAssociations_Init(lpAssoc, cfFlags & SHLWAPI_DEF_ASSOCF,
258 pszAssoc, NULL, NULL);
261 hRet = IQueryAssociations_GetString(lpAssoc, cfFlags, str, pszExtra,
264 IQueryAssociations_Release(lpAssoc);
268 /*************************************************************************
269 * AssocQueryStringA [SHLWAPI.@]
271 * Get a file association string from the registry.
274 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
275 * str [I] Type of string to get (ASSOCSTR enum from "shlwapi.h")
276 * pszAssoc [I] Key name to search below
277 * pszExtra [I] Extra information about the string location
278 * pszOut [O] Destination for the association string
279 * pcchOut [O] Length of pszOut
282 * Success: S_OK. pszOut contains the string, pcchOut contains its length.
283 * Failure: An HRESULT error code indicating the error.
285 HRESULT WINAPI AssocQueryStringA(ASSOCF cfFlags, ASSOCSTR str, LPCSTR pszAssoc,
286 LPCSTR pszExtra, LPSTR pszOut, DWORD *pcchOut)
288 WCHAR szAssocW[MAX_PATH], *lpszAssocW = NULL;
289 WCHAR szExtraW[MAX_PATH], *lpszExtraW = NULL;
290 HRESULT hRet = E_OUTOFMEMORY;
292 TRACE("(0x%8x,0x%8x,%s,%s,%p,%p)\n", cfFlags, str, debugstr_a(pszAssoc),
293 debugstr_a(pszExtra), pszOut, pcchOut);
297 else if (SHLWAPI_ParamAToW(pszAssoc, szAssocW, MAX_PATH, &lpszAssocW) &&
298 SHLWAPI_ParamAToW(pszExtra, szExtraW, MAX_PATH, &lpszExtraW))
300 WCHAR szReturnW[MAX_PATH], *lpszReturnW = szReturnW;
301 DWORD dwLenOut = *pcchOut;
303 if (dwLenOut >= MAX_PATH)
304 lpszReturnW = HeapAlloc(GetProcessHeap(), 0,
305 (dwLenOut + 1) * sizeof(WCHAR));
307 dwLenOut = sizeof(szReturnW) / sizeof(szReturnW[0]);
310 hRet = E_OUTOFMEMORY;
313 hRet = AssocQueryStringW(cfFlags, str, lpszAssocW, lpszExtraW,
314 lpszReturnW, &dwLenOut);
317 dwLenOut = WideCharToMultiByte(CP_ACP, 0, lpszReturnW, -1,
318 pszOut, *pcchOut, NULL, NULL);
321 if (lpszReturnW != szReturnW)
322 HeapFree(GetProcessHeap(), 0, lpszReturnW);
326 if (lpszAssocW != szAssocW)
327 HeapFree(GetProcessHeap(), 0, lpszAssocW);
328 if (lpszExtraW != szExtraW)
329 HeapFree(GetProcessHeap(), 0, lpszExtraW);
333 /*************************************************************************
334 * AssocQueryStringByKeyW [SHLWAPI.@]
336 * See AssocQueryStringByKeyA.
338 HRESULT WINAPI AssocQueryStringByKeyW(ASSOCF cfFlags, ASSOCSTR str, HKEY hkAssoc,
339 LPCWSTR pszExtra, LPWSTR pszOut,
343 IQueryAssociations* lpAssoc;
345 TRACE("(0x%8x,0x%8x,%p,%s,%p,%p)\n", cfFlags, str, hkAssoc,
346 debugstr_w(pszExtra), pszOut, pcchOut);
348 lpAssoc = IQueryAssociations_Constructor();
351 return E_OUTOFMEMORY;
353 cfFlags &= SHLWAPI_DEF_ASSOCF;
354 hRet = IQueryAssociations_Init(lpAssoc, cfFlags, 0, hkAssoc, NULL);
357 hRet = IQueryAssociations_GetString(lpAssoc, cfFlags, str, pszExtra,
360 IQueryAssociations_Release(lpAssoc);
364 /*************************************************************************
365 * AssocQueryStringByKeyA [SHLWAPI.@]
367 * Get a file association string from the registry, given a starting key.
370 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
371 * str [I] Type of string to get
372 * hkAssoc [I] Key to search below
373 * pszExtra [I] Extra information about the string location
374 * pszOut [O] Destination for the association string
375 * pcchOut [O] Length of pszOut
378 * Success: S_OK. pszOut contains the string, pcchOut contains its length.
379 * Failure: An HRESULT error code indicating the error.
381 HRESULT WINAPI AssocQueryStringByKeyA(ASSOCF cfFlags, ASSOCSTR str, HKEY hkAssoc,
382 LPCSTR pszExtra, LPSTR pszOut,
385 WCHAR szExtraW[MAX_PATH], *lpszExtraW = szExtraW;
386 WCHAR szReturnW[MAX_PATH], *lpszReturnW = szReturnW;
387 HRESULT hRet = E_OUTOFMEMORY;
389 TRACE("(0x%8x,0x%8x,%p,%s,%p,%p)\n", cfFlags, str, hkAssoc,
390 debugstr_a(pszExtra), pszOut, pcchOut);
394 else if (SHLWAPI_ParamAToW(pszExtra, szExtraW, MAX_PATH, &lpszExtraW))
396 DWORD dwLenOut = *pcchOut;
397 if (dwLenOut >= MAX_PATH)
398 lpszReturnW = HeapAlloc(GetProcessHeap(), 0,
399 (dwLenOut + 1) * sizeof(WCHAR));
403 hRet = AssocQueryStringByKeyW(cfFlags, str, hkAssoc, lpszExtraW,
404 lpszReturnW, &dwLenOut);
407 WideCharToMultiByte(CP_ACP,0,szReturnW,-1,pszOut,dwLenOut,0,0);
410 if (lpszReturnW != szReturnW)
411 HeapFree(GetProcessHeap(), 0, lpszReturnW);
415 if (lpszExtraW != szExtraW)
416 HeapFree(GetProcessHeap(), 0, lpszExtraW);
421 /**************************************************************************
422 * AssocIsDangerous (SHLWAPI.@)
424 * Determine if a file association is dangerous (potentially malware).
427 * lpszAssoc [I] Name of file or file extension to check.
430 * TRUE, if lpszAssoc may potentially be malware (executable),
433 BOOL WINAPI AssocIsDangerous(LPCWSTR lpszAssoc)
435 FIXME("%s\n", debugstr_w(lpszAssoc));
439 /**************************************************************************
440 * IQueryAssociations_QueryInterface {SHLWAPI}
442 * See IUnknown_QueryInterface.
444 static HRESULT WINAPI IQueryAssociations_fnQueryInterface(
445 IQueryAssociations* iface,
449 IQueryAssociationsImpl *This = (IQueryAssociationsImpl *)iface;
451 TRACE("(%p,%s,%p)\n",This, debugstr_guid(riid), ppvObj);
455 if (IsEqualIID(riid, &IID_IUnknown) ||
456 IsEqualIID(riid, &IID_IQueryAssociations))
460 IQueryAssociations_AddRef((IQueryAssociations*)*ppvObj);
461 TRACE("Returning IQueryAssociations (%p)\n", *ppvObj);
464 TRACE("Returning E_NOINTERFACE\n");
465 return E_NOINTERFACE;
468 /**************************************************************************
469 * IQueryAssociations_AddRef {SHLWAPI}
471 * See IUnknown_AddRef.
473 static ULONG WINAPI IQueryAssociations_fnAddRef(IQueryAssociations *iface)
475 IQueryAssociationsImpl *This = (IQueryAssociationsImpl *)iface;
476 ULONG refCount = InterlockedIncrement(&This->ref);
478 TRACE("(%p)->(ref before=%u)\n",This, refCount - 1);
483 /**************************************************************************
484 * IQueryAssociations_Release {SHLWAPI}
486 * See IUnknown_Release.
488 static ULONG WINAPI IQueryAssociations_fnRelease(IQueryAssociations *iface)
490 IQueryAssociationsImpl *This = (IQueryAssociationsImpl *)iface;
491 ULONG refCount = InterlockedDecrement(&This->ref);
493 TRACE("(%p)->(ref before=%u)\n",This, refCount + 1);
497 TRACE("Destroying IQueryAssociations (%p)\n", This);
498 RegCloseKey(This->hkeySource);
499 RegCloseKey(This->hkeyProgID);
500 HeapFree(GetProcessHeap(), 0, This);
506 /**************************************************************************
507 * IQueryAssociations_Init {SHLWAPI}
509 * Initialise an IQueryAssociations object.
512 * iface [I] IQueryAssociations interface to initialise
513 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
514 * pszAssoc [I] String for the root key name, or NULL if hkeyProgid is given
515 * hkeyProgid [I] Handle for the root key, or NULL if pszAssoc is given
516 * hWnd [I] Reserved, must be NULL.
519 * Success: S_OK. iface is initialised with the parameters given.
520 * Failure: An HRESULT error code indicating the error.
522 static HRESULT WINAPI IQueryAssociations_fnInit(
523 IQueryAssociations *iface,
529 static const WCHAR szProgID[] = {'P','r','o','g','I','D',0};
530 IQueryAssociationsImpl *This = (IQueryAssociationsImpl *)iface;
533 TRACE("(%p)->(%d,%s,%p,%p)\n", iface,
535 debugstr_w(pszAssoc),
539 FIXME("hwnd != NULL not supported\n");
541 FIXME("unsupported flags: %x\n", cfFlags);
542 if (pszAssoc != NULL)
544 ret = RegOpenKeyExW(HKEY_CLASSES_ROOT,
549 if (ret != ERROR_SUCCESS)
551 /* if this is not a prog id */
552 if ((*pszAssoc == '.') || (*pszAssoc == '{'))
554 RegOpenKeyExW(This->hkeySource,
561 This->hkeyProgID = This->hkeySource;
564 else if (hkeyProgid != NULL)
566 This->hkeyProgID = hkeyProgid;
573 static HRESULT ASSOC_GetValue(HKEY hkey, WCHAR ** pszText)
579 ret = RegQueryValueExW(hkey, NULL, 0, NULL, NULL, &len);
580 if (ret != ERROR_SUCCESS)
581 return HRESULT_FROM_WIN32(ret);
584 *pszText = HeapAlloc(GetProcessHeap(), 0, len);
586 return E_OUTOFMEMORY;
587 ret = RegQueryValueExW(hkey, NULL, 0, NULL, (LPBYTE)*pszText,
589 if (ret != ERROR_SUCCESS)
591 HeapFree(GetProcessHeap(), 0, *pszText);
592 return HRESULT_FROM_WIN32(ret);
597 static HRESULT ASSOC_GetCommand(IQueryAssociationsImpl *This,
598 LPCWSTR pszExtra, WCHAR **ppszCommand)
606 WCHAR * pszExtraFromReg = NULL;
608 static const WCHAR commandW[] = { 'c','o','m','m','a','n','d',0 };
609 static const WCHAR shellW[] = { 's','h','e','l','l',0 };
611 hr = ASSOC_GetValue(This->hkeySource, &pszFileType);
614 ret = RegOpenKeyExW(HKEY_CLASSES_ROOT, pszFileType, 0, KEY_READ, &hkeyFile);
615 HeapFree(GetProcessHeap(), 0, pszFileType);
616 if (ret != ERROR_SUCCESS)
617 return HRESULT_FROM_WIN32(ret);
619 ret = RegOpenKeyExW(hkeyFile, shellW, 0, KEY_READ, &hkeyShell);
620 RegCloseKey(hkeyFile);
621 if (ret != ERROR_SUCCESS)
622 return HRESULT_FROM_WIN32(ret);
626 hr = ASSOC_GetValue(hkeyShell, &pszExtraFromReg);
627 /* if no default action */
628 if (hr == E_FAIL || hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND))
631 ret = RegQueryInfoKeyW(hkeyShell, 0, 0, 0, 0, &rlen, 0, 0, 0, 0, 0, 0);
632 if (ret != ERROR_SUCCESS)
634 RegCloseKey(hkeyShell);
635 return HRESULT_FROM_WIN32(ret);
638 pszExtraFromReg = HeapAlloc(GetProcessHeap(), 0, rlen * sizeof(WCHAR));
639 if (!pszExtraFromReg)
641 RegCloseKey(hkeyShell);
642 return E_OUTOFMEMORY;
644 ret = RegEnumKeyExW(hkeyShell, 0, pszExtraFromReg, &rlen, 0, NULL, NULL, NULL);
645 if (ret != ERROR_SUCCESS)
647 RegCloseKey(hkeyShell);
648 return HRESULT_FROM_WIN32(ret);
653 RegCloseKey(hkeyShell);
658 ret = RegOpenKeyExW(hkeyShell, pszExtra ? pszExtra : pszExtraFromReg, 0,
659 KEY_READ, &hkeyVerb);
660 HeapFree(GetProcessHeap(), 0, pszExtraFromReg);
661 RegCloseKey(hkeyShell);
662 if (ret != ERROR_SUCCESS)
663 return HRESULT_FROM_WIN32(ret);
665 ret = RegOpenKeyExW(hkeyVerb, commandW, 0, KEY_READ, &hkeyCommand);
666 RegCloseKey(hkeyVerb);
667 if (ret != ERROR_SUCCESS)
668 return HRESULT_FROM_WIN32(ret);
669 hr = ASSOC_GetValue(hkeyCommand, ppszCommand);
670 RegCloseKey(hkeyCommand);
674 static HRESULT ASSOC_GetExecutable(IQueryAssociationsImpl *This,
675 LPCWSTR pszExtra, LPWSTR path,
676 DWORD pathlen, DWORD *len)
685 hr = ASSOC_GetCommand(This, pszExtra, &pszCommand);
689 /* cleanup pszCommand */
690 if (pszCommand[0] == '"')
692 pszStart = pszCommand + 1;
693 pszEnd = strchrW(pszStart, '"');
697 pszStart = pszCommand;
698 pszEnd = strchrW(pszStart, ' ');
703 *len = SearchPathW(NULL, pszStart, NULL, pathlen, path, NULL);
704 HeapFree(GetProcessHeap(), 0, pszCommand);
706 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
710 static HRESULT ASSOC_ReturnData(LPWSTR out, DWORD *outlen, LPCWSTR data,
717 if (*outlen < datalen)
723 lstrcpynW(out, data, datalen);
733 /**************************************************************************
734 * IQueryAssociations_GetString {SHLWAPI}
736 * Get a file association string from the registry.
739 * iface [I] IQueryAssociations interface to query
740 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
741 * str [I] Type of string to get (ASSOCSTR enum from "shlwapi.h")
742 * pszExtra [I] Extra information about the string location
743 * pszOut [O] Destination for the association string
744 * pcchOut [I/O] Length of pszOut
747 * Success: S_OK. pszOut contains the string, pcchOut contains its length.
748 * Failure: An HRESULT error code indicating the error.
750 static HRESULT WINAPI IQueryAssociations_fnGetString(
751 IQueryAssociations *iface,
758 IQueryAssociationsImpl *This = (IQueryAssociationsImpl *)iface;
759 const ASSOCF cfUnimplemented = ~(0);
762 WCHAR path[MAX_PATH];
764 TRACE("(%p,0x%8x,0x%8x,%s,%p,%p)\n", This, cfFlags, str,
765 debugstr_w(pszExtra), pszOut, pcchOut);
767 if (cfFlags & cfUnimplemented)
768 FIXME("%08x: unimplemented flags!\n", cfFlags & cfUnimplemented);
775 case ASSOCSTR_COMMAND:
778 hr = ASSOC_GetCommand(This, pszExtra, &command);
781 hr = ASSOC_ReturnData(pszOut, pcchOut, command, strlenW(command) + 1);
782 HeapFree(GetProcessHeap(), 0, command);
787 case ASSOCSTR_EXECUTABLE:
789 hr = ASSOC_GetExecutable(This, pszExtra, path, MAX_PATH, &len);
793 return ASSOC_ReturnData(pszOut, pcchOut, path, len);
796 case ASSOCSTR_FRIENDLYDOCNAME:
802 hr = ASSOC_GetValue(This->hkeySource, &pszFileType);
806 ret = RegGetValueW(HKEY_CLASSES_ROOT, pszFileType, NULL, RRF_RT_REG_SZ, NULL, NULL, &size);
807 if (ret == ERROR_SUCCESS)
809 WCHAR *docName = HeapAlloc(GetProcessHeap(), 0, size);
812 ret = RegGetValueW(HKEY_CLASSES_ROOT, pszFileType, NULL, RRF_RT_REG_SZ, NULL, docName, &size);
813 if (ret == ERROR_SUCCESS)
814 hr = ASSOC_ReturnData(pszOut, pcchOut, docName, strlenW(docName) + 1);
816 hr = HRESULT_FROM_WIN32(ret);
817 HeapFree(GetProcessHeap(), 0, docName);
823 hr = HRESULT_FROM_WIN32(ret);
824 HeapFree(GetProcessHeap(), 0, pszFileType);
828 case ASSOCSTR_FRIENDLYAPPNAME:
830 PVOID verinfoW = NULL;
831 DWORD size, retval = 0;
834 static const WCHAR translationW[] = {
835 '\\','V','a','r','F','i','l','e','I','n','f','o',
836 '\\','T','r','a','n','s','l','a','t','i','o','n',0
838 static const WCHAR fileDescFmtW[] = {
839 '\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o',
840 '\\','%','0','4','x','%','0','4','x',
841 '\\','F','i','l','e','D','e','s','c','r','i','p','t','i','o','n',0
845 hr = ASSOC_GetExecutable(This, pszExtra, path, MAX_PATH, &len);
849 retval = GetFileVersionInfoSizeW(path, &size);
851 goto get_friendly_name_fail;
852 verinfoW = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, retval);
854 return E_OUTOFMEMORY;
855 if (!GetFileVersionInfoW(path, 0, retval, verinfoW))
856 goto get_friendly_name_fail;
857 if (VerQueryValueW(verinfoW, translationW, (LPVOID *)&bufW, &flen))
860 DWORD *langCodeDesc = (DWORD *)bufW;
861 for (i = 0; i < flen / sizeof(DWORD); i++)
863 sprintfW(fileDescW, fileDescFmtW, LOWORD(langCodeDesc[i]),
864 HIWORD(langCodeDesc[i]));
865 if (VerQueryValueW(verinfoW, fileDescW, (LPVOID *)&bufW, &flen))
867 /* Does strlenW(bufW) == 0 mean we use the filename? */
868 len = strlenW(bufW) + 1;
869 TRACE("found FileDescription: %s\n", debugstr_w(bufW));
870 return ASSOC_ReturnData(pszOut, pcchOut, bufW, len);
874 get_friendly_name_fail:
875 PathRemoveExtensionW(path);
876 PathStripPathW(path);
877 TRACE("using filename: %s\n", debugstr_w(path));
878 return ASSOC_ReturnData(pszOut, pcchOut, path, strlenW(path) + 1);
881 case ASSOCSTR_CONTENTTYPE:
883 static const WCHAR Content_TypeW[] = {'C','o','n','t','e','n','t',' ','T','y','p','e',0};
889 ret = RegGetValueW(This->hkeySource, NULL, Content_TypeW, RRF_RT_REG_SZ, NULL, NULL, &size);
890 if (ret != ERROR_SUCCESS)
891 return HRESULT_FROM_WIN32(ret);
892 contentType = HeapAlloc(GetProcessHeap(), 0, size);
893 if (contentType != NULL)
895 ret = RegGetValueW(This->hkeySource, NULL, Content_TypeW, RRF_RT_REG_SZ, NULL, contentType, &size);
896 if (ret == ERROR_SUCCESS)
897 hr = ASSOC_ReturnData(pszOut, pcchOut, contentType, strlenW(contentType) + 1);
899 hr = HRESULT_FROM_WIN32(ret);
900 HeapFree(GetProcessHeap(), 0, contentType);
907 case ASSOCSTR_DEFAULTICON:
909 static const WCHAR DefaultIconW[] = {'D','e','f','a','u','l','t','I','c','o','n',0};
915 hr = ASSOC_GetValue(This->hkeySource, &pszFileType);
918 ret = RegOpenKeyExW(HKEY_CLASSES_ROOT, pszFileType, 0, KEY_READ, &hkeyFile);
919 if (ret == ERROR_SUCCESS)
922 ret = RegGetValueW(hkeyFile, DefaultIconW, NULL, RRF_RT_REG_SZ, NULL, NULL, &size);
923 if (ret == ERROR_SUCCESS)
925 WCHAR *icon = HeapAlloc(GetProcessHeap(), 0, size);
928 ret = RegGetValueW(hkeyFile, DefaultIconW, NULL, RRF_RT_REG_SZ, NULL, icon, &size);
929 if (ret == ERROR_SUCCESS)
930 hr = ASSOC_ReturnData(pszOut, pcchOut, icon, strlenW(icon) + 1);
932 hr = HRESULT_FROM_WIN32(ret);
933 HeapFree(GetProcessHeap(), 0, icon);
939 hr = HRESULT_FROM_WIN32(ret);
940 RegCloseKey(hkeyFile);
943 hr = HRESULT_FROM_WIN32(ret);
944 HeapFree(GetProcessHeap(), 0, pszFileType);
949 FIXME("assocstr %d unimplemented!\n", str);
954 /**************************************************************************
955 * IQueryAssociations_GetKey {SHLWAPI}
957 * Get a file association key from the registry.
960 * iface [I] IQueryAssociations interface to query
961 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
962 * assockey [I] Type of key to get (ASSOCKEY enum from "shlwapi.h")
963 * pszExtra [I] Extra information about the key location
964 * phkeyOut [O] Destination for the association key
967 * Success: S_OK. phkeyOut contains a handle to the key.
968 * Failure: An HRESULT error code indicating the error.
970 static HRESULT WINAPI IQueryAssociations_fnGetKey(
971 IQueryAssociations *iface,
977 IQueryAssociationsImpl *This = (IQueryAssociationsImpl *)iface;
979 FIXME("(%p,0x%8x,0x%8x,%s,%p)-stub!\n", This, cfFlags, assockey,
980 debugstr_w(pszExtra), phkeyOut);
984 /**************************************************************************
985 * IQueryAssociations_GetData {SHLWAPI}
987 * Get the data for a file association key from the registry.
990 * iface [I] IQueryAssociations interface to query
991 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
992 * assocdata [I] Type of data to get (ASSOCDATA enum from "shlwapi.h")
993 * pszExtra [I] Extra information about the data location
994 * pvOut [O] Destination for the association key
995 * pcbOut [I/O] Size of pvOut
998 * Success: S_OK. pszOut contains the data, pcbOut contains its length.
999 * Failure: An HRESULT error code indicating the error.
1001 static HRESULT WINAPI IQueryAssociations_fnGetData(
1002 IQueryAssociations *iface,
1004 ASSOCDATA assocdata,
1009 IQueryAssociationsImpl *This = (IQueryAssociationsImpl *)iface;
1011 FIXME("(%p,0x%8x,0x%8x,%s,%p,%p)-stub!\n", This, cfFlags, assocdata,
1012 debugstr_w(pszExtra), pvOut, pcbOut);
1016 /**************************************************************************
1017 * IQueryAssociations_GetEnum {SHLWAPI}
1019 * Not yet implemented in native Win32.
1022 * iface [I] IQueryAssociations interface to query
1023 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
1024 * assocenum [I] Type of enum to get (ASSOCENUM enum from "shlwapi.h")
1025 * pszExtra [I] Extra information about the enum location
1026 * riid [I] REFIID to look for
1027 * ppvOut [O] Destination for the interface.
1031 * Failure: An HRESULT error code indicating the error.
1034 * Presumably this function returns an enumerator object.
1036 static HRESULT WINAPI IQueryAssociations_fnGetEnum(
1037 IQueryAssociations *iface,
1039 ASSOCENUM assocenum,
1044 IQueryAssociationsImpl *This = (IQueryAssociationsImpl *)iface;
1046 FIXME("(%p,0x%8x,0x%8x,%s,%s,%p)-stub!\n", This, cfFlags, assocenum,
1047 debugstr_w(pszExtra), debugstr_guid(riid), ppvOut);
1051 static const IQueryAssociationsVtbl IQueryAssociations_vtbl =
1053 IQueryAssociations_fnQueryInterface,
1054 IQueryAssociations_fnAddRef,
1055 IQueryAssociations_fnRelease,
1056 IQueryAssociations_fnInit,
1057 IQueryAssociations_fnGetString,
1058 IQueryAssociations_fnGetKey,
1059 IQueryAssociations_fnGetData,
1060 IQueryAssociations_fnGetEnum