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
));
308 hRet
= E_OUTOFMEMORY
;
311 hRet
= AssocQueryStringW(cfFlags
, str
, lpszAssocW
, lpszExtraW
,
312 lpszReturnW
, &dwLenOut
);
315 WideCharToMultiByte(CP_ACP
,0,szReturnW
,-1,pszOut
,dwLenOut
,0,0);
318 if (lpszReturnW
!= szReturnW
)
319 HeapFree(GetProcessHeap(), 0, lpszReturnW
);
323 if (lpszAssocW
!= szAssocW
)
324 HeapFree(GetProcessHeap(), 0, lpszAssocW
);
325 if (lpszExtraW
!= szExtraW
)
326 HeapFree(GetProcessHeap(), 0, lpszExtraW
);
330 /*************************************************************************
331 * AssocQueryStringByKeyW [SHLWAPI.@]
333 * See AssocQueryStringByKeyA.
335 HRESULT WINAPI
AssocQueryStringByKeyW(ASSOCF cfFlags
, ASSOCSTR str
, HKEY hkAssoc
,
336 LPCWSTR pszExtra
, LPWSTR pszOut
,
340 IQueryAssociations
* lpAssoc
;
342 TRACE("(0x%8x,0x%8x,%p,%s,%p,%p)\n", cfFlags
, str
, hkAssoc
,
343 debugstr_w(pszExtra
), pszOut
, pcchOut
);
345 lpAssoc
= IQueryAssociations_Constructor();
348 return E_OUTOFMEMORY
;
350 cfFlags
&= SHLWAPI_DEF_ASSOCF
;
351 hRet
= IQueryAssociations_Init(lpAssoc
, cfFlags
, 0, hkAssoc
, NULL
);
354 hRet
= IQueryAssociations_GetString(lpAssoc
, cfFlags
, str
, pszExtra
,
357 IQueryAssociations_Release(lpAssoc
);
361 /*************************************************************************
362 * AssocQueryStringByKeyA [SHLWAPI.@]
364 * Get a file association string from the registry, given a starting key.
367 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
368 * str [I] Type of string to get
369 * hkAssoc [I] Key to search below
370 * pszExtra [I] Extra information about the string location
371 * pszOut [O] Destination for the association string
372 * pcchOut [O] Length of pszOut
375 * Success: S_OK. pszOut contains the string, pcchOut contains its length.
376 * Failure: An HRESULT error code indicating the error.
378 HRESULT WINAPI
AssocQueryStringByKeyA(ASSOCF cfFlags
, ASSOCSTR str
, HKEY hkAssoc
,
379 LPCSTR pszExtra
, LPSTR pszOut
,
382 WCHAR szExtraW
[MAX_PATH
], *lpszExtraW
= szExtraW
;
383 WCHAR szReturnW
[MAX_PATH
], *lpszReturnW
= szReturnW
;
384 HRESULT hRet
= E_OUTOFMEMORY
;
386 TRACE("(0x%8x,0x%8x,%p,%s,%p,%p)\n", cfFlags
, str
, hkAssoc
,
387 debugstr_a(pszExtra
), pszOut
, pcchOut
);
391 else if (SHLWAPI_ParamAToW(pszExtra
, szExtraW
, MAX_PATH
, &lpszExtraW
))
393 DWORD dwLenOut
= *pcchOut
;
394 if (dwLenOut
>= MAX_PATH
)
395 lpszReturnW
= HeapAlloc(GetProcessHeap(), 0,
396 (dwLenOut
+ 1) * sizeof(WCHAR
));
400 hRet
= AssocQueryStringByKeyW(cfFlags
, str
, hkAssoc
, lpszExtraW
,
401 lpszReturnW
, &dwLenOut
);
404 WideCharToMultiByte(CP_ACP
,0,szReturnW
,-1,pszOut
,dwLenOut
,0,0);
407 if (lpszReturnW
!= szReturnW
)
408 HeapFree(GetProcessHeap(), 0, lpszReturnW
);
412 if (lpszExtraW
!= szExtraW
)
413 HeapFree(GetProcessHeap(), 0, lpszExtraW
);
418 /**************************************************************************
419 * AssocIsDangerous (SHLWAPI.@)
421 * Determine if a file association is dangerous (potentially malware).
424 * lpszAssoc [I] Name of file or file extension to check.
427 * TRUE, if lpszAssoc may potentially be malware (executable),
430 BOOL WINAPI
AssocIsDangerous(LPCWSTR lpszAssoc
)
432 FIXME("%s\n", debugstr_w(lpszAssoc
));
436 /**************************************************************************
437 * IQueryAssociations_QueryInterface {SHLWAPI}
439 * See IUnknown_QueryInterface.
441 static HRESULT WINAPI
IQueryAssociations_fnQueryInterface(
442 IQueryAssociations
* iface
,
446 IQueryAssociationsImpl
*This
= (IQueryAssociationsImpl
*)iface
;
448 TRACE("(%p,%s,%p)\n",This
, debugstr_guid(riid
), ppvObj
);
452 if (IsEqualIID(riid
, &IID_IUnknown
) ||
453 IsEqualIID(riid
, &IID_IQueryAssociations
))
455 *ppvObj
= (IQueryAssociations
*)This
;
457 IQueryAssociations_AddRef((IQueryAssociations
*)*ppvObj
);
458 TRACE("Returning IQueryAssociations (%p)\n", *ppvObj
);
461 TRACE("Returning E_NOINTERFACE\n");
462 return E_NOINTERFACE
;
465 /**************************************************************************
466 * IQueryAssociations_AddRef {SHLWAPI}
468 * See IUnknown_AddRef.
470 static ULONG WINAPI
IQueryAssociations_fnAddRef(IQueryAssociations
*iface
)
472 IQueryAssociationsImpl
*This
= (IQueryAssociationsImpl
*)iface
;
473 ULONG refCount
= InterlockedIncrement(&This
->ref
);
475 TRACE("(%p)->(ref before=%u)\n",This
, refCount
- 1);
480 /**************************************************************************
481 * IQueryAssociations_Release {SHLWAPI}
483 * See IUnknown_Release.
485 static ULONG WINAPI
IQueryAssociations_fnRelease(IQueryAssociations
*iface
)
487 IQueryAssociationsImpl
*This
= (IQueryAssociationsImpl
*)iface
;
488 ULONG refCount
= InterlockedDecrement(&This
->ref
);
490 TRACE("(%p)->(ref before=%u)\n",This
, refCount
+ 1);
494 TRACE("Destroying IQueryAssociations (%p)\n", This
);
495 RegCloseKey(This
->hkeySource
);
496 RegCloseKey(This
->hkeyProgID
);
497 HeapFree(GetProcessHeap(), 0, This
);
503 /**************************************************************************
504 * IQueryAssociations_Init {SHLWAPI}
506 * Initialise an IQueryAssociations object.
509 * iface [I] IQueryAssociations interface to initialise
510 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
511 * pszAssoc [I] String for the root key name, or NULL if hkeyProgid is given
512 * hkeyProgid [I] Handle for the root key, or NULL if pszAssoc is given
513 * hWnd [I] Reserved, must be NULL.
516 * Success: S_OK. iface is initialised with the parameters given.
517 * Failure: An HRESULT error code indicating the error.
519 static HRESULT WINAPI
IQueryAssociations_fnInit(
520 IQueryAssociations
*iface
,
526 static const WCHAR szProgID
[] = {'P','r','o','g','I','D',0};
527 IQueryAssociationsImpl
*This
= (IQueryAssociationsImpl
*)iface
;
530 TRACE("(%p)->(%d,%s,%p,%p)\n", iface
,
532 debugstr_w(pszAssoc
),
536 FIXME("hwnd != NULL not supported\n");
538 FIXME("unsupported flags: %x\n", cfFlags
);
539 if (pszAssoc
!= NULL
)
541 ret
= RegOpenKeyExW(HKEY_CLASSES_ROOT
,
546 if (ret
!= ERROR_SUCCESS
)
548 /* if this is not a prog id */
549 if ((*pszAssoc
== '.') || (*pszAssoc
== '{'))
551 RegOpenKeyExW(This
->hkeySource
,
558 This
->hkeyProgID
= This
->hkeySource
;
561 else if (hkeyProgid
!= NULL
)
563 This
->hkeyProgID
= hkeyProgid
;
570 static HRESULT
ASSOC_GetValue(HKEY hkey
, WCHAR
** pszText
)
576 ret
= RegQueryValueExW(hkey
, NULL
, 0, NULL
, NULL
, &len
);
577 if (ret
!= ERROR_SUCCESS
)
578 return HRESULT_FROM_WIN32(ret
);
581 *pszText
= HeapAlloc(GetProcessHeap(), 0, len
);
583 return E_OUTOFMEMORY
;
584 ret
= RegQueryValueExW(hkey
, NULL
, 0, NULL
, (LPBYTE
)*pszText
,
586 if (ret
!= ERROR_SUCCESS
)
588 HeapFree(GetProcessHeap(), 0, *pszText
);
589 return HRESULT_FROM_WIN32(ret
);
594 static HRESULT
ASSOC_GetExecutable(IQueryAssociationsImpl
*This
,
595 LPCWSTR pszExtra
, LPWSTR path
,
596 DWORD pathlen
, DWORD
*len
)
606 WCHAR
* pszExtraFromReg
= NULL
;
609 static const WCHAR commandW
[] = { 'c','o','m','m','a','n','d',0 };
610 static const WCHAR shellW
[] = { 's','h','e','l','l',0 };
614 hr
= ASSOC_GetValue(This
->hkeySource
, &pszFileType
);
617 ret
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, pszFileType
, 0, KEY_READ
, &hkeyFile
);
618 HeapFree(GetProcessHeap(), 0, pszFileType
);
619 if (ret
!= ERROR_SUCCESS
)
620 return HRESULT_FROM_WIN32(ret
);
622 ret
= RegOpenKeyExW(hkeyFile
, shellW
, 0, KEY_READ
, &hkeyShell
);
623 RegCloseKey(hkeyFile
);
624 if (ret
!= ERROR_SUCCESS
)
625 return HRESULT_FROM_WIN32(ret
);
629 hr
= ASSOC_GetValue(hkeyShell
, &pszExtraFromReg
);
630 /* if no default action */
631 if (hr
== E_FAIL
|| hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
))
634 ret
= RegQueryInfoKeyW(hkeyShell
, 0, 0, 0, 0, &rlen
, 0, 0, 0, 0, 0, 0);
635 if (ret
!= ERROR_SUCCESS
)
637 RegCloseKey(hkeyShell
);
638 return HRESULT_FROM_WIN32(ret
);
641 pszExtraFromReg
= HeapAlloc(GetProcessHeap(), 0, rlen
* sizeof(WCHAR
));
642 if (!pszExtraFromReg
)
644 RegCloseKey(hkeyShell
);
645 return E_OUTOFMEMORY
;
647 ret
= RegEnumKeyExW(hkeyShell
, 0, pszExtraFromReg
, &rlen
, 0, NULL
, NULL
, NULL
);
648 if (ret
!= ERROR_SUCCESS
)
650 RegCloseKey(hkeyShell
);
651 return HRESULT_FROM_WIN32(ret
);
656 RegCloseKey(hkeyShell
);
661 ret
= RegOpenKeyExW(hkeyShell
, pszExtra
? pszExtra
: pszExtraFromReg
, 0,
662 KEY_READ
, &hkeyVerb
);
663 HeapFree(GetProcessHeap(), 0, pszExtraFromReg
);
664 RegCloseKey(hkeyShell
);
665 if (ret
!= ERROR_SUCCESS
)
666 return HRESULT_FROM_WIN32(ret
);
668 ret
= RegOpenKeyExW(hkeyVerb
, commandW
, 0, KEY_READ
, &hkeyCommand
);
669 RegCloseKey(hkeyVerb
);
670 if (ret
!= ERROR_SUCCESS
)
671 return HRESULT_FROM_WIN32(ret
);
672 hr
= ASSOC_GetValue(hkeyCommand
, &pszCommand
);
673 RegCloseKey(hkeyCommand
);
677 /* cleanup pszCommand */
678 if (pszCommand
[0] == '"')
680 pszStart
= pszCommand
+ 1;
681 pszEnd
= strchrW(pszStart
, '"');
685 pszStart
= pszCommand
;
686 pszEnd
= strchrW(pszStart
, ' ');
691 *len
= SearchPathW(NULL
, pszStart
, NULL
, pathlen
, path
, NULL
);
692 HeapFree(GetProcessHeap(), 0, pszCommand
);
694 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
698 static HRESULT
ASSOC_ReturnData(LPWSTR out
, DWORD
*outlen
, LPCWSTR data
,
705 if (*outlen
< datalen
)
711 lstrcpynW(out
, data
, datalen
);
721 /**************************************************************************
722 * IQueryAssociations_GetString {SHLWAPI}
724 * Get a file association string from the registry.
727 * iface [I] IQueryAssociations interface to query
728 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
729 * str [I] Type of string to get (ASSOCSTR enum from "shlwapi.h")
730 * pszExtra [I] Extra information about the string location
731 * pszOut [O] Destination for the association string
732 * pcchOut [I/O] Length of pszOut
735 * Success: S_OK. pszOut contains the string, pcchOut contains its length.
736 * Failure: An HRESULT error code indicating the error.
738 static HRESULT WINAPI
IQueryAssociations_fnGetString(
739 IQueryAssociations
*iface
,
746 IQueryAssociationsImpl
*This
= (IQueryAssociationsImpl
*)iface
;
747 const ASSOCF cfUnimplemented
= ~(0);
750 WCHAR path
[MAX_PATH
];
752 TRACE("(%p,0x%8x,0x%8x,%s,%p,%p)\n", This
, cfFlags
, str
,
753 debugstr_w(pszExtra
), pszOut
, pcchOut
);
755 if (cfFlags
& cfUnimplemented
)
756 FIXME("%08x: unimplemented flags!\n", cfFlags
& cfUnimplemented
);
763 case ASSOCSTR_EXECUTABLE
:
765 hr
= ASSOC_GetExecutable(This
, pszExtra
, path
, MAX_PATH
, &len
);
769 return ASSOC_ReturnData(pszOut
, pcchOut
, path
, len
);
772 case ASSOCSTR_FRIENDLYAPPNAME
:
774 PVOID verinfoW
= NULL
;
775 DWORD size
, retval
= 0;
778 static const WCHAR translationW
[] = {
779 '\\','V','a','r','F','i','l','e','I','n','f','o',
780 '\\','T','r','a','n','s','l','a','t','i','o','n',0
782 static const WCHAR fileDescFmtW
[] = {
783 '\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o',
784 '\\','%','0','4','x','%','0','4','x',
785 '\\','F','i','l','e','D','e','s','c','r','i','p','t','i','o','n',0
789 hr
= ASSOC_GetExecutable(This
, pszExtra
, path
, MAX_PATH
, &len
);
793 retval
= GetFileVersionInfoSizeW(path
, &size
);
795 goto get_friendly_name_fail
;
796 verinfoW
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, retval
);
798 return E_OUTOFMEMORY
;
799 if (!GetFileVersionInfoW(path
, 0, retval
, verinfoW
))
800 goto get_friendly_name_fail
;
801 if (VerQueryValueW(verinfoW
, translationW
, (LPVOID
*)&bufW
, &flen
))
804 DWORD
*langCodeDesc
= (DWORD
*)bufW
;
805 for (i
= 0; i
< flen
/ sizeof(DWORD
); i
++)
807 sprintfW(fileDescW
, fileDescFmtW
, LOWORD(langCodeDesc
[i
]),
808 HIWORD(langCodeDesc
[i
]));
809 if (VerQueryValueW(verinfoW
, fileDescW
, (LPVOID
*)&bufW
, &flen
))
811 /* Does strlenW(bufW) == 0 mean we use the filename? */
812 len
= strlenW(bufW
) + 1;
813 TRACE("found FileDescription: %s\n", debugstr_w(bufW
));
814 return ASSOC_ReturnData(pszOut
, pcchOut
, bufW
, len
);
818 get_friendly_name_fail
:
819 PathRemoveExtensionW(path
);
820 PathStripPathW(path
);
821 TRACE("using filename: %s\n", debugstr_w(path
));
822 return ASSOC_ReturnData(pszOut
, pcchOut
, path
, strlenW(path
) + 1);
826 FIXME("assocstr %d unimplemented!\n", str
);
831 /**************************************************************************
832 * IQueryAssociations_GetKey {SHLWAPI}
834 * Get a file association key from the registry.
837 * iface [I] IQueryAssociations interface to query
838 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
839 * assockey [I] Type of key to get (ASSOCKEY enum from "shlwapi.h")
840 * pszExtra [I] Extra information about the key location
841 * phkeyOut [O] Destination for the association key
844 * Success: S_OK. phkeyOut contains a handle to the key.
845 * Failure: An HRESULT error code indicating the error.
847 static HRESULT WINAPI
IQueryAssociations_fnGetKey(
848 IQueryAssociations
*iface
,
854 IQueryAssociationsImpl
*This
= (IQueryAssociationsImpl
*)iface
;
856 FIXME("(%p,0x%8x,0x%8x,%s,%p)-stub!\n", This
, cfFlags
, assockey
,
857 debugstr_w(pszExtra
), phkeyOut
);
861 /**************************************************************************
862 * IQueryAssociations_GetData {SHLWAPI}
864 * Get the data for a file association key from the registry.
867 * iface [I] IQueryAssociations interface to query
868 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
869 * assocdata [I] Type of data to get (ASSOCDATA enum from "shlwapi.h")
870 * pszExtra [I] Extra information about the data location
871 * pvOut [O] Destination for the association key
872 * pcbOut [I/O] Size of pvOut
875 * Success: S_OK. pszOut contains the data, pcbOut contains its length.
876 * Failure: An HRESULT error code indicating the error.
878 static HRESULT WINAPI
IQueryAssociations_fnGetData(
879 IQueryAssociations
*iface
,
886 IQueryAssociationsImpl
*This
= (IQueryAssociationsImpl
*)iface
;
888 FIXME("(%p,0x%8x,0x%8x,%s,%p,%p)-stub!\n", This
, cfFlags
, assocdata
,
889 debugstr_w(pszExtra
), pvOut
, pcbOut
);
893 /**************************************************************************
894 * IQueryAssociations_GetEnum {SHLWAPI}
896 * Not yet implemented in native Win32.
899 * iface [I] IQueryAssociations interface to query
900 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
901 * assocenum [I] Type of enum to get (ASSOCENUM enum from "shlwapi.h")
902 * pszExtra [I] Extra information about the enum location
903 * riid [I] REFIID to look for
904 * ppvOut [O] Destination for the interface.
908 * Failure: An HRESULT error code indicating the error.
911 * Presumably this function returns an enumerator object.
913 static HRESULT WINAPI
IQueryAssociations_fnGetEnum(
914 IQueryAssociations
*iface
,
921 IQueryAssociationsImpl
*This
= (IQueryAssociationsImpl
*)iface
;
923 FIXME("(%p,0x%8x,0x%8x,%s,%s,%p)-stub!\n", This
, cfFlags
, assocenum
,
924 debugstr_w(pszExtra
), debugstr_guid(riid
), ppvOut
);
928 static const IQueryAssociationsVtbl IQueryAssociations_vtbl
=
930 IQueryAssociations_fnQueryInterface
,
931 IQueryAssociations_fnAddRef
,
932 IQueryAssociations_fnRelease
,
933 IQueryAssociations_fnInit
,
934 IQueryAssociations_fnGetString
,
935 IQueryAssociations_fnGetKey
,
936 IQueryAssociations_fnGetData
,
937 IQueryAssociations_fnGetEnum