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 * clsid must be equal to CLSID_QueryAssociations and
138 * refiid must be equal to IID_IQueryAssociations, IID_IUnknown or this function will fail
140 HRESULT WINAPI
AssocCreate(CLSID clsid
, REFIID refiid
, void **lpInterface
)
143 IQueryAssociations
* lpAssoc
;
145 TRACE("(%s,%s,%p)\n", debugstr_guid(&clsid
), debugstr_guid(refiid
),
151 *(DWORD
*)lpInterface
= 0;
153 if (!IsEqualGUID(&clsid
, &CLSID_QueryAssociations
))
154 return CLASS_E_CLASSNOTAVAILABLE
;
156 lpAssoc
= IQueryAssociations_Constructor();
159 return E_OUTOFMEMORY
;
161 hRet
= IQueryAssociations_QueryInterface(lpAssoc
, refiid
, lpInterface
);
162 IQueryAssociations_Release(lpAssoc
);
164 if(hRet
== E_NOINTERFACE
)
165 return CLASS_E_CLASSNOTAVAILABLE
;
170 /*************************************************************************
171 * AssocQueryKeyW [SHLWAPI.@]
173 * See AssocQueryKeyA.
175 HRESULT WINAPI
AssocQueryKeyW(ASSOCF cfFlags
, ASSOCKEY assockey
, LPCWSTR pszAssoc
,
176 LPCWSTR pszExtra
, HKEY
*phkeyOut
)
179 IQueryAssociations
* lpAssoc
;
181 TRACE("(0x%8x,0x%8x,%s,%s,%p)\n", cfFlags
, assockey
, debugstr_w(pszAssoc
),
182 debugstr_w(pszExtra
), phkeyOut
);
184 lpAssoc
= IQueryAssociations_Constructor();
187 return E_OUTOFMEMORY
;
189 cfFlags
&= SHLWAPI_DEF_ASSOCF
;
190 hRet
= IQueryAssociations_Init(lpAssoc
, cfFlags
, pszAssoc
, NULL
, NULL
);
193 hRet
= IQueryAssociations_GetKey(lpAssoc
, cfFlags
, assockey
, pszExtra
, phkeyOut
);
195 IQueryAssociations_Release(lpAssoc
);
199 /*************************************************************************
200 * AssocQueryKeyA [SHLWAPI.@]
202 * Get a file association key from the registry.
205 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
206 * assockey [I] Type of key to get
207 * pszAssoc [I] Key name to search below
208 * pszExtra [I] Extra information about the key location
209 * phkeyOut [O] Destination for the association key
212 * Success: S_OK. phkeyOut contains the key.
213 * Failure: An HRESULT error code indicating the error.
215 HRESULT WINAPI
AssocQueryKeyA(ASSOCF cfFlags
, ASSOCKEY assockey
, LPCSTR pszAssoc
,
216 LPCSTR pszExtra
, HKEY
*phkeyOut
)
218 WCHAR szAssocW
[MAX_PATH
], *lpszAssocW
= NULL
;
219 WCHAR szExtraW
[MAX_PATH
], *lpszExtraW
= NULL
;
220 HRESULT hRet
= E_OUTOFMEMORY
;
222 TRACE("(0x%8x,0x%8x,%s,%s,%p)\n", cfFlags
, assockey
, debugstr_a(pszAssoc
),
223 debugstr_a(pszExtra
), phkeyOut
);
225 if (SHLWAPI_ParamAToW(pszAssoc
, szAssocW
, MAX_PATH
, &lpszAssocW
) &&
226 SHLWAPI_ParamAToW(pszExtra
, szExtraW
, MAX_PATH
, &lpszExtraW
))
228 hRet
= AssocQueryKeyW(cfFlags
, assockey
, lpszAssocW
, lpszExtraW
, phkeyOut
);
231 if (lpszAssocW
!= szAssocW
)
232 HeapFree(GetProcessHeap(), 0, lpszAssocW
);
234 if (lpszExtraW
!= szExtraW
)
235 HeapFree(GetProcessHeap(), 0, lpszExtraW
);
240 /*************************************************************************
241 * AssocQueryStringW [SHLWAPI.@]
243 * See AssocQueryStringA.
245 HRESULT WINAPI
AssocQueryStringW(ASSOCF cfFlags
, ASSOCSTR str
, LPCWSTR pszAssoc
,
246 LPCWSTR pszExtra
, LPWSTR pszOut
, DWORD
*pcchOut
)
249 IQueryAssociations
* lpAssoc
;
251 TRACE("(0x%8x,0x%8x,%s,%s,%p,%p)\n", cfFlags
, str
, debugstr_w(pszAssoc
),
252 debugstr_w(pszExtra
), pszOut
, pcchOut
);
257 lpAssoc
= IQueryAssociations_Constructor();
260 return E_OUTOFMEMORY
;
262 hRet
= IQueryAssociations_Init(lpAssoc
, cfFlags
& SHLWAPI_DEF_ASSOCF
,
263 pszAssoc
, NULL
, NULL
);
266 hRet
= IQueryAssociations_GetString(lpAssoc
, cfFlags
, str
, pszExtra
,
269 IQueryAssociations_Release(lpAssoc
);
273 /*************************************************************************
274 * AssocQueryStringA [SHLWAPI.@]
276 * Get a file association string from the registry.
279 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
280 * str [I] Type of string to get (ASSOCSTR enum from "shlwapi.h")
281 * pszAssoc [I] Key name to search below
282 * pszExtra [I] Extra information about the string location
283 * pszOut [O] Destination for the association string
284 * pcchOut [O] Length of pszOut
287 * Success: S_OK. pszOut contains the string, pcchOut contains its length.
288 * Failure: An HRESULT error code indicating the error.
290 HRESULT WINAPI
AssocQueryStringA(ASSOCF cfFlags
, ASSOCSTR str
, LPCSTR pszAssoc
,
291 LPCSTR pszExtra
, LPSTR pszOut
, DWORD
*pcchOut
)
293 WCHAR szAssocW
[MAX_PATH
], *lpszAssocW
= NULL
;
294 WCHAR szExtraW
[MAX_PATH
], *lpszExtraW
= NULL
;
295 HRESULT hRet
= E_OUTOFMEMORY
;
297 TRACE("(0x%8x,0x%8x,%s,%s,%p,%p)\n", cfFlags
, str
, debugstr_a(pszAssoc
),
298 debugstr_a(pszExtra
), pszOut
, pcchOut
);
302 else if (SHLWAPI_ParamAToW(pszAssoc
, szAssocW
, MAX_PATH
, &lpszAssocW
) &&
303 SHLWAPI_ParamAToW(pszExtra
, szExtraW
, MAX_PATH
, &lpszExtraW
))
305 WCHAR szReturnW
[MAX_PATH
], *lpszReturnW
= szReturnW
;
306 DWORD dwLenOut
= *pcchOut
;
308 if (dwLenOut
>= MAX_PATH
)
309 lpszReturnW
= HeapAlloc(GetProcessHeap(), 0,
310 (dwLenOut
+ 1) * sizeof(WCHAR
));
312 dwLenOut
= sizeof(szReturnW
) / sizeof(szReturnW
[0]);
315 hRet
= E_OUTOFMEMORY
;
318 hRet
= AssocQueryStringW(cfFlags
, str
, lpszAssocW
, lpszExtraW
,
319 lpszReturnW
, &dwLenOut
);
322 dwLenOut
= WideCharToMultiByte(CP_ACP
, 0, lpszReturnW
, -1,
323 pszOut
, *pcchOut
, NULL
, NULL
);
326 if (lpszReturnW
!= szReturnW
)
327 HeapFree(GetProcessHeap(), 0, lpszReturnW
);
331 if (lpszAssocW
!= szAssocW
)
332 HeapFree(GetProcessHeap(), 0, lpszAssocW
);
333 if (lpszExtraW
!= szExtraW
)
334 HeapFree(GetProcessHeap(), 0, lpszExtraW
);
338 /*************************************************************************
339 * AssocQueryStringByKeyW [SHLWAPI.@]
341 * See AssocQueryStringByKeyA.
343 HRESULT WINAPI
AssocQueryStringByKeyW(ASSOCF cfFlags
, ASSOCSTR str
, HKEY hkAssoc
,
344 LPCWSTR pszExtra
, LPWSTR pszOut
,
348 IQueryAssociations
* lpAssoc
;
350 TRACE("(0x%8x,0x%8x,%p,%s,%p,%p)\n", cfFlags
, str
, hkAssoc
,
351 debugstr_w(pszExtra
), pszOut
, pcchOut
);
353 lpAssoc
= IQueryAssociations_Constructor();
356 return E_OUTOFMEMORY
;
358 cfFlags
&= SHLWAPI_DEF_ASSOCF
;
359 hRet
= IQueryAssociations_Init(lpAssoc
, cfFlags
, 0, hkAssoc
, NULL
);
362 hRet
= IQueryAssociations_GetString(lpAssoc
, cfFlags
, str
, pszExtra
,
365 IQueryAssociations_Release(lpAssoc
);
369 /*************************************************************************
370 * AssocQueryStringByKeyA [SHLWAPI.@]
372 * Get a file association string from the registry, given a starting key.
375 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
376 * str [I] Type of string to get
377 * hkAssoc [I] Key to search below
378 * pszExtra [I] Extra information about the string location
379 * pszOut [O] Destination for the association string
380 * pcchOut [O] Length of pszOut
383 * Success: S_OK. pszOut contains the string, pcchOut contains its length.
384 * Failure: An HRESULT error code indicating the error.
386 HRESULT WINAPI
AssocQueryStringByKeyA(ASSOCF cfFlags
, ASSOCSTR str
, HKEY hkAssoc
,
387 LPCSTR pszExtra
, LPSTR pszOut
,
390 WCHAR szExtraW
[MAX_PATH
], *lpszExtraW
= szExtraW
;
391 WCHAR szReturnW
[MAX_PATH
], *lpszReturnW
= szReturnW
;
392 HRESULT hRet
= E_OUTOFMEMORY
;
394 TRACE("(0x%8x,0x%8x,%p,%s,%p,%p)\n", cfFlags
, str
, hkAssoc
,
395 debugstr_a(pszExtra
), pszOut
, pcchOut
);
399 else if (SHLWAPI_ParamAToW(pszExtra
, szExtraW
, MAX_PATH
, &lpszExtraW
))
401 DWORD dwLenOut
= *pcchOut
;
402 if (dwLenOut
>= MAX_PATH
)
403 lpszReturnW
= HeapAlloc(GetProcessHeap(), 0,
404 (dwLenOut
+ 1) * sizeof(WCHAR
));
408 hRet
= AssocQueryStringByKeyW(cfFlags
, str
, hkAssoc
, lpszExtraW
,
409 lpszReturnW
, &dwLenOut
);
412 WideCharToMultiByte(CP_ACP
,0,szReturnW
,-1,pszOut
,dwLenOut
,0,0);
415 if (lpszReturnW
!= szReturnW
)
416 HeapFree(GetProcessHeap(), 0, lpszReturnW
);
420 if (lpszExtraW
!= szExtraW
)
421 HeapFree(GetProcessHeap(), 0, lpszExtraW
);
426 /**************************************************************************
427 * AssocIsDangerous (SHLWAPI.@)
429 * Determine if a file association is dangerous (potentially malware).
432 * lpszAssoc [I] Name of file or file extension to check.
435 * TRUE, if lpszAssoc may potentially be malware (executable),
438 BOOL WINAPI
AssocIsDangerous(LPCWSTR lpszAssoc
)
440 FIXME("%s\n", debugstr_w(lpszAssoc
));
444 /**************************************************************************
445 * IQueryAssociations_QueryInterface {SHLWAPI}
447 * See IUnknown_QueryInterface.
449 static HRESULT WINAPI
IQueryAssociations_fnQueryInterface(
450 IQueryAssociations
* iface
,
454 IQueryAssociationsImpl
*This
= (IQueryAssociationsImpl
*)iface
;
456 TRACE("(%p,%s,%p)\n",This
, debugstr_guid(riid
), ppvObj
);
460 if (IsEqualIID(riid
, &IID_IUnknown
) ||
461 IsEqualIID(riid
, &IID_IQueryAssociations
))
465 IQueryAssociations_AddRef((IQueryAssociations
*)*ppvObj
);
466 TRACE("Returning IQueryAssociations (%p)\n", *ppvObj
);
469 TRACE("Returning E_NOINTERFACE\n");
470 return E_NOINTERFACE
;
473 /**************************************************************************
474 * IQueryAssociations_AddRef {SHLWAPI}
476 * See IUnknown_AddRef.
478 static ULONG WINAPI
IQueryAssociations_fnAddRef(IQueryAssociations
*iface
)
480 IQueryAssociationsImpl
*This
= (IQueryAssociationsImpl
*)iface
;
481 ULONG refCount
= InterlockedIncrement(&This
->ref
);
483 TRACE("(%p)->(ref before=%u)\n",This
, refCount
- 1);
488 /**************************************************************************
489 * IQueryAssociations_Release {SHLWAPI}
491 * See IUnknown_Release.
493 static ULONG WINAPI
IQueryAssociations_fnRelease(IQueryAssociations
*iface
)
495 IQueryAssociationsImpl
*This
= (IQueryAssociationsImpl
*)iface
;
496 ULONG refCount
= InterlockedDecrement(&This
->ref
);
498 TRACE("(%p)->(ref before=%u)\n",This
, refCount
+ 1);
502 TRACE("Destroying IQueryAssociations (%p)\n", This
);
503 RegCloseKey(This
->hkeySource
);
504 RegCloseKey(This
->hkeyProgID
);
505 HeapFree(GetProcessHeap(), 0, This
);
511 /**************************************************************************
512 * IQueryAssociations_Init {SHLWAPI}
514 * Initialise an IQueryAssociations object.
517 * iface [I] IQueryAssociations interface to initialise
518 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
519 * pszAssoc [I] String for the root key name, or NULL if hkeyProgid is given
520 * hkeyProgid [I] Handle for the root key, or NULL if pszAssoc is given
521 * hWnd [I] Reserved, must be NULL.
524 * Success: S_OK. iface is initialised with the parameters given.
525 * Failure: An HRESULT error code indicating the error.
527 static HRESULT WINAPI
IQueryAssociations_fnInit(
528 IQueryAssociations
*iface
,
534 static const WCHAR szProgID
[] = {'P','r','o','g','I','D',0};
535 IQueryAssociationsImpl
*This
= (IQueryAssociationsImpl
*)iface
;
538 TRACE("(%p)->(%d,%s,%p,%p)\n", iface
,
540 debugstr_w(pszAssoc
),
544 FIXME("hwnd != NULL not supported\n");
546 FIXME("unsupported flags: %x\n", cfFlags
);
547 if (pszAssoc
!= NULL
)
549 ret
= RegOpenKeyExW(HKEY_CLASSES_ROOT
,
554 if (ret
!= ERROR_SUCCESS
)
556 /* if this is not a prog id */
557 if ((*pszAssoc
== '.') || (*pszAssoc
== '{'))
559 RegOpenKeyExW(This
->hkeySource
,
566 This
->hkeyProgID
= This
->hkeySource
;
569 else if (hkeyProgid
!= NULL
)
571 This
->hkeyProgID
= hkeyProgid
;
578 static HRESULT
ASSOC_GetValue(HKEY hkey
, WCHAR
** pszText
)
584 ret
= RegQueryValueExW(hkey
, NULL
, 0, NULL
, NULL
, &len
);
585 if (ret
!= ERROR_SUCCESS
)
586 return HRESULT_FROM_WIN32(ret
);
589 *pszText
= HeapAlloc(GetProcessHeap(), 0, len
);
591 return E_OUTOFMEMORY
;
592 ret
= RegQueryValueExW(hkey
, NULL
, 0, NULL
, (LPBYTE
)*pszText
,
594 if (ret
!= ERROR_SUCCESS
)
596 HeapFree(GetProcessHeap(), 0, *pszText
);
597 return HRESULT_FROM_WIN32(ret
);
602 static HRESULT
ASSOC_GetCommand(IQueryAssociationsImpl
*This
,
603 LPCWSTR pszExtra
, WCHAR
**ppszCommand
)
611 WCHAR
* pszExtraFromReg
= NULL
;
613 static const WCHAR commandW
[] = { 'c','o','m','m','a','n','d',0 };
614 static const WCHAR shellW
[] = { 's','h','e','l','l',0 };
616 hr
= ASSOC_GetValue(This
->hkeySource
, &pszFileType
);
619 ret
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, pszFileType
, 0, KEY_READ
, &hkeyFile
);
620 HeapFree(GetProcessHeap(), 0, pszFileType
);
621 if (ret
!= ERROR_SUCCESS
)
622 return HRESULT_FROM_WIN32(ret
);
624 ret
= RegOpenKeyExW(hkeyFile
, shellW
, 0, KEY_READ
, &hkeyShell
);
625 RegCloseKey(hkeyFile
);
626 if (ret
!= ERROR_SUCCESS
)
627 return HRESULT_FROM_WIN32(ret
);
631 hr
= ASSOC_GetValue(hkeyShell
, &pszExtraFromReg
);
632 /* if no default action */
633 if (hr
== E_FAIL
|| hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
))
636 ret
= RegQueryInfoKeyW(hkeyShell
, 0, 0, 0, 0, &rlen
, 0, 0, 0, 0, 0, 0);
637 if (ret
!= ERROR_SUCCESS
)
639 RegCloseKey(hkeyShell
);
640 return HRESULT_FROM_WIN32(ret
);
643 pszExtraFromReg
= HeapAlloc(GetProcessHeap(), 0, rlen
* sizeof(WCHAR
));
644 if (!pszExtraFromReg
)
646 RegCloseKey(hkeyShell
);
647 return E_OUTOFMEMORY
;
649 ret
= RegEnumKeyExW(hkeyShell
, 0, pszExtraFromReg
, &rlen
, 0, NULL
, NULL
, NULL
);
650 if (ret
!= ERROR_SUCCESS
)
652 RegCloseKey(hkeyShell
);
653 return HRESULT_FROM_WIN32(ret
);
658 RegCloseKey(hkeyShell
);
663 ret
= RegOpenKeyExW(hkeyShell
, pszExtra
? pszExtra
: pszExtraFromReg
, 0,
664 KEY_READ
, &hkeyVerb
);
665 HeapFree(GetProcessHeap(), 0, pszExtraFromReg
);
666 RegCloseKey(hkeyShell
);
667 if (ret
!= ERROR_SUCCESS
)
668 return HRESULT_FROM_WIN32(ret
);
670 ret
= RegOpenKeyExW(hkeyVerb
, commandW
, 0, KEY_READ
, &hkeyCommand
);
671 RegCloseKey(hkeyVerb
);
672 if (ret
!= ERROR_SUCCESS
)
673 return HRESULT_FROM_WIN32(ret
);
674 hr
= ASSOC_GetValue(hkeyCommand
, ppszCommand
);
675 RegCloseKey(hkeyCommand
);
679 static HRESULT
ASSOC_GetExecutable(IQueryAssociationsImpl
*This
,
680 LPCWSTR pszExtra
, LPWSTR path
,
681 DWORD pathlen
, DWORD
*len
)
690 hr
= ASSOC_GetCommand(This
, pszExtra
, &pszCommand
);
694 /* cleanup pszCommand */
695 if (pszCommand
[0] == '"')
697 pszStart
= pszCommand
+ 1;
698 pszEnd
= strchrW(pszStart
, '"');
702 pszStart
= pszCommand
;
703 pszEnd
= strchrW(pszStart
, ' ');
708 *len
= SearchPathW(NULL
, pszStart
, NULL
, pathlen
, path
, NULL
);
709 HeapFree(GetProcessHeap(), 0, pszCommand
);
711 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
715 static HRESULT
ASSOC_ReturnData(LPWSTR out
, DWORD
*outlen
, LPCWSTR data
,
722 if (*outlen
< datalen
)
728 lstrcpynW(out
, data
, datalen
);
738 /**************************************************************************
739 * IQueryAssociations_GetString {SHLWAPI}
741 * Get a file association string from the registry.
744 * iface [I] IQueryAssociations interface to query
745 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
746 * str [I] Type of string to get (ASSOCSTR enum from "shlwapi.h")
747 * pszExtra [I] Extra information about the string location
748 * pszOut [O] Destination for the association string
749 * pcchOut [I/O] Length of pszOut
752 * Success: S_OK. pszOut contains the string, pcchOut contains its length.
753 * Failure: An HRESULT error code indicating the error.
755 static HRESULT WINAPI
IQueryAssociations_fnGetString(
756 IQueryAssociations
*iface
,
763 IQueryAssociationsImpl
*This
= (IQueryAssociationsImpl
*)iface
;
764 const ASSOCF cfUnimplemented
= ~(0);
767 WCHAR path
[MAX_PATH
];
769 TRACE("(%p,0x%8x,0x%8x,%s,%p,%p)\n", This
, cfFlags
, str
,
770 debugstr_w(pszExtra
), pszOut
, pcchOut
);
772 if (cfFlags
& cfUnimplemented
)
773 FIXME("%08x: unimplemented flags!\n", cfFlags
& cfUnimplemented
);
780 case ASSOCSTR_COMMAND
:
783 hr
= ASSOC_GetCommand(This
, pszExtra
, &command
);
786 hr
= ASSOC_ReturnData(pszOut
, pcchOut
, command
, strlenW(command
) + 1);
787 HeapFree(GetProcessHeap(), 0, command
);
792 case ASSOCSTR_EXECUTABLE
:
794 hr
= ASSOC_GetExecutable(This
, pszExtra
, path
, MAX_PATH
, &len
);
798 return ASSOC_ReturnData(pszOut
, pcchOut
, path
, len
);
801 case ASSOCSTR_FRIENDLYDOCNAME
:
807 hr
= ASSOC_GetValue(This
->hkeySource
, &pszFileType
);
811 ret
= RegGetValueW(HKEY_CLASSES_ROOT
, pszFileType
, NULL
, RRF_RT_REG_SZ
, NULL
, NULL
, &size
);
812 if (ret
== ERROR_SUCCESS
)
814 WCHAR
*docName
= HeapAlloc(GetProcessHeap(), 0, size
);
817 ret
= RegGetValueW(HKEY_CLASSES_ROOT
, pszFileType
, NULL
, RRF_RT_REG_SZ
, NULL
, docName
, &size
);
818 if (ret
== ERROR_SUCCESS
)
819 hr
= ASSOC_ReturnData(pszOut
, pcchOut
, docName
, strlenW(docName
) + 1);
821 hr
= HRESULT_FROM_WIN32(ret
);
822 HeapFree(GetProcessHeap(), 0, docName
);
828 hr
= HRESULT_FROM_WIN32(ret
);
829 HeapFree(GetProcessHeap(), 0, pszFileType
);
833 case ASSOCSTR_FRIENDLYAPPNAME
:
835 PVOID verinfoW
= NULL
;
836 DWORD size
, retval
= 0;
839 static const WCHAR translationW
[] = {
840 '\\','V','a','r','F','i','l','e','I','n','f','o',
841 '\\','T','r','a','n','s','l','a','t','i','o','n',0
843 static const WCHAR fileDescFmtW
[] = {
844 '\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o',
845 '\\','%','0','4','x','%','0','4','x',
846 '\\','F','i','l','e','D','e','s','c','r','i','p','t','i','o','n',0
850 hr
= ASSOC_GetExecutable(This
, pszExtra
, path
, MAX_PATH
, &len
);
854 retval
= GetFileVersionInfoSizeW(path
, &size
);
856 goto get_friendly_name_fail
;
857 verinfoW
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, retval
);
859 return E_OUTOFMEMORY
;
860 if (!GetFileVersionInfoW(path
, 0, retval
, verinfoW
))
861 goto get_friendly_name_fail
;
862 if (VerQueryValueW(verinfoW
, translationW
, (LPVOID
*)&bufW
, &flen
))
865 DWORD
*langCodeDesc
= (DWORD
*)bufW
;
866 for (i
= 0; i
< flen
/ sizeof(DWORD
); i
++)
868 sprintfW(fileDescW
, fileDescFmtW
, LOWORD(langCodeDesc
[i
]),
869 HIWORD(langCodeDesc
[i
]));
870 if (VerQueryValueW(verinfoW
, fileDescW
, (LPVOID
*)&bufW
, &flen
))
872 /* Does strlenW(bufW) == 0 mean we use the filename? */
873 len
= strlenW(bufW
) + 1;
874 TRACE("found FileDescription: %s\n", debugstr_w(bufW
));
875 return ASSOC_ReturnData(pszOut
, pcchOut
, bufW
, len
);
879 get_friendly_name_fail
:
880 PathRemoveExtensionW(path
);
881 PathStripPathW(path
);
882 TRACE("using filename: %s\n", debugstr_w(path
));
883 return ASSOC_ReturnData(pszOut
, pcchOut
, path
, strlenW(path
) + 1);
886 case ASSOCSTR_CONTENTTYPE
:
888 static const WCHAR Content_TypeW
[] = {'C','o','n','t','e','n','t',' ','T','y','p','e',0};
894 ret
= RegGetValueW(This
->hkeySource
, NULL
, Content_TypeW
, RRF_RT_REG_SZ
, NULL
, NULL
, &size
);
895 if (ret
!= ERROR_SUCCESS
)
896 return HRESULT_FROM_WIN32(ret
);
897 contentType
= HeapAlloc(GetProcessHeap(), 0, size
);
898 if (contentType
!= NULL
)
900 ret
= RegGetValueW(This
->hkeySource
, NULL
, Content_TypeW
, RRF_RT_REG_SZ
, NULL
, contentType
, &size
);
901 if (ret
== ERROR_SUCCESS
)
902 hr
= ASSOC_ReturnData(pszOut
, pcchOut
, contentType
, strlenW(contentType
) + 1);
904 hr
= HRESULT_FROM_WIN32(ret
);
905 HeapFree(GetProcessHeap(), 0, contentType
);
912 case ASSOCSTR_DEFAULTICON
:
914 static const WCHAR DefaultIconW
[] = {'D','e','f','a','u','l','t','I','c','o','n',0};
920 hr
= ASSOC_GetValue(This
->hkeySource
, &pszFileType
);
923 ret
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, pszFileType
, 0, KEY_READ
, &hkeyFile
);
924 if (ret
== ERROR_SUCCESS
)
927 ret
= RegGetValueW(hkeyFile
, DefaultIconW
, NULL
, RRF_RT_REG_SZ
, NULL
, NULL
, &size
);
928 if (ret
== ERROR_SUCCESS
)
930 WCHAR
*icon
= HeapAlloc(GetProcessHeap(), 0, size
);
933 ret
= RegGetValueW(hkeyFile
, DefaultIconW
, NULL
, RRF_RT_REG_SZ
, NULL
, icon
, &size
);
934 if (ret
== ERROR_SUCCESS
)
935 hr
= ASSOC_ReturnData(pszOut
, pcchOut
, icon
, strlenW(icon
) + 1);
937 hr
= HRESULT_FROM_WIN32(ret
);
938 HeapFree(GetProcessHeap(), 0, icon
);
944 hr
= HRESULT_FROM_WIN32(ret
);
945 RegCloseKey(hkeyFile
);
948 hr
= HRESULT_FROM_WIN32(ret
);
949 HeapFree(GetProcessHeap(), 0, pszFileType
);
954 FIXME("assocstr %d unimplemented!\n", str
);
959 /**************************************************************************
960 * IQueryAssociations_GetKey {SHLWAPI}
962 * Get a file association key from the registry.
965 * iface [I] IQueryAssociations interface to query
966 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
967 * assockey [I] Type of key to get (ASSOCKEY enum from "shlwapi.h")
968 * pszExtra [I] Extra information about the key location
969 * phkeyOut [O] Destination for the association key
972 * Success: S_OK. phkeyOut contains a handle to the key.
973 * Failure: An HRESULT error code indicating the error.
975 static HRESULT WINAPI
IQueryAssociations_fnGetKey(
976 IQueryAssociations
*iface
,
982 IQueryAssociationsImpl
*This
= (IQueryAssociationsImpl
*)iface
;
984 FIXME("(%p,0x%8x,0x%8x,%s,%p)-stub!\n", This
, cfFlags
, assockey
,
985 debugstr_w(pszExtra
), phkeyOut
);
989 /**************************************************************************
990 * IQueryAssociations_GetData {SHLWAPI}
992 * Get the data for a file association key from the registry.
995 * iface [I] IQueryAssociations interface to query
996 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
997 * assocdata [I] Type of data to get (ASSOCDATA enum from "shlwapi.h")
998 * pszExtra [I] Extra information about the data location
999 * pvOut [O] Destination for the association key
1000 * pcbOut [I/O] Size of pvOut
1003 * Success: S_OK. pszOut contains the data, pcbOut contains its length.
1004 * Failure: An HRESULT error code indicating the error.
1006 static HRESULT WINAPI
IQueryAssociations_fnGetData(
1007 IQueryAssociations
*iface
,
1009 ASSOCDATA assocdata
,
1014 IQueryAssociationsImpl
*This
= (IQueryAssociationsImpl
*)iface
;
1016 FIXME("(%p,0x%8x,0x%8x,%s,%p,%p)-stub!\n", This
, cfFlags
, assocdata
,
1017 debugstr_w(pszExtra
), pvOut
, pcbOut
);
1021 /**************************************************************************
1022 * IQueryAssociations_GetEnum {SHLWAPI}
1024 * Not yet implemented in native Win32.
1027 * iface [I] IQueryAssociations interface to query
1028 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
1029 * assocenum [I] Type of enum to get (ASSOCENUM enum from "shlwapi.h")
1030 * pszExtra [I] Extra information about the enum location
1031 * riid [I] REFIID to look for
1032 * ppvOut [O] Destination for the interface.
1036 * Failure: An HRESULT error code indicating the error.
1039 * Presumably this function returns an enumerator object.
1041 static HRESULT WINAPI
IQueryAssociations_fnGetEnum(
1042 IQueryAssociations
*iface
,
1044 ASSOCENUM assocenum
,
1049 IQueryAssociationsImpl
*This
= (IQueryAssociationsImpl
*)iface
;
1051 FIXME("(%p,0x%8x,0x%8x,%s,%s,%p)-stub!\n", This
, cfFlags
, assocenum
,
1052 debugstr_w(pszExtra
), debugstr_guid(riid
), ppvOut
);
1056 static const IQueryAssociationsVtbl IQueryAssociations_vtbl
=
1058 IQueryAssociations_fnQueryInterface
,
1059 IQueryAssociations_fnAddRef
,
1060 IQueryAssociations_fnRelease
,
1061 IQueryAssociations_fnInit
,
1062 IQueryAssociations_fnGetString
,
1063 IQueryAssociations_fnGetKey
,
1064 IQueryAssociations_fnGetData
,
1065 IQueryAssociations_fnGetEnum