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 "shell32_main.h"
33 #include "wine/unicode.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
38 /**************************************************************************
42 * This object provides a layer of abstraction over the system registry in
43 * order to simplify the process of parsing associations between files.
44 * Associations in this context means the registry entries that link (for
45 * example) the extension of a file with its description, list of
46 * applications to open the file with, and actions that can be performed on it
47 * (the shell displays such information in the context menu of explorer
48 * when you right-click on a file).
51 * You can use this object transparently by calling the helper functions
52 * AssocQueryKeyA(), AssocQueryStringA() and AssocQueryStringByKeyA(). These
53 * create an IQueryAssociations object, perform the requested actions
54 * and then dispose of the object. Alternatively, you can create an instance
55 * of the object using AssocCreate() and call the following methods on it:
62 IQueryAssociations IQueryAssociations_iface
;
66 } IQueryAssociationsImpl
;
70 IApplicationAssociationRegistration IApplicationAssociationRegistration_iface
;
72 } IApplicationAssociationRegistrationImpl
;
75 static inline IQueryAssociationsImpl
*impl_from_IQueryAssociations(IQueryAssociations
*iface
)
77 return CONTAINING_RECORD(iface
, IQueryAssociationsImpl
, IQueryAssociations_iface
);
80 struct enumassochandlers
82 IEnumAssocHandlers IEnumAssocHandlers_iface
;
86 static inline struct enumassochandlers
*impl_from_IEnumAssocHandlers(IEnumAssocHandlers
*iface
)
88 return CONTAINING_RECORD(iface
, struct enumassochandlers
, IEnumAssocHandlers_iface
);
91 static HRESULT
ASSOC_GetValue(HKEY hkey
, const WCHAR
*name
, void **data
, DWORD
*data_size
);
93 /**************************************************************************
94 * IQueryAssociations_QueryInterface
96 * See IUnknown_QueryInterface.
98 static HRESULT WINAPI
IQueryAssociations_fnQueryInterface(
99 IQueryAssociations
* iface
,
103 IQueryAssociationsImpl
*This
= impl_from_IQueryAssociations(iface
);
105 TRACE("(%p,%s,%p)\n",This
, debugstr_guid(riid
), ppvObj
);
112 if (IsEqualIID(riid
, &IID_IUnknown
) ||
113 IsEqualIID(riid
, &IID_IQueryAssociations
))
115 *ppvObj
= &This
->IQueryAssociations_iface
;
117 IQueryAssociations_AddRef((IQueryAssociations
*)*ppvObj
);
118 TRACE("Returning IQueryAssociations (%p)\n", *ppvObj
);
121 TRACE("Returning E_NOINTERFACE\n");
122 return E_NOINTERFACE
;
125 /**************************************************************************
126 * IQueryAssociations_AddRef
128 * See IUnknown_AddRef.
130 static ULONG WINAPI
IQueryAssociations_fnAddRef(IQueryAssociations
*iface
)
132 IQueryAssociationsImpl
*This
= impl_from_IQueryAssociations(iface
);
133 ULONG refCount
= InterlockedIncrement(&This
->ref
);
135 TRACE("(%p)->(ref before=%u)\n",This
, refCount
- 1);
140 /**************************************************************************
141 * IQueryAssociations_Release
143 * See IUnknown_Release.
145 static ULONG WINAPI
IQueryAssociations_fnRelease(IQueryAssociations
*iface
)
147 IQueryAssociationsImpl
*This
= impl_from_IQueryAssociations(iface
);
148 ULONG refCount
= InterlockedDecrement(&This
->ref
);
150 TRACE("(%p)->(ref before=%u)\n",This
, refCount
+ 1);
154 TRACE("Destroying IQueryAssociations (%p)\n", This
);
155 RegCloseKey(This
->hkeySource
);
156 RegCloseKey(This
->hkeyProgID
);
163 /**************************************************************************
164 * IQueryAssociations_Init
166 * Initialise an IQueryAssociations object.
169 * iface [I] IQueryAssociations interface to initialise
170 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
171 * pszAssoc [I] String for the root key name, or NULL if hkeyProgid is given
172 * hkeyProgid [I] Handle for the root key, or NULL if pszAssoc is given
173 * hWnd [I] Reserved, must be NULL.
176 * Success: S_OK. iface is initialised with the parameters given.
177 * Failure: An HRESULT error code indicating the error.
179 static HRESULT WINAPI
IQueryAssociations_fnInit(
180 IQueryAssociations
*iface
,
186 static const WCHAR szProgID
[] = {'P','r','o','g','I','D',0};
187 IQueryAssociationsImpl
*This
= impl_from_IQueryAssociations(iface
);
190 TRACE("(%p)->(%d,%s,%p,%p)\n", iface
,
192 debugstr_w(pszAssoc
),
196 FIXME("hwnd != NULL not supported\n");
198 FIXME("unsupported flags: %x\n", cfFlags
);
200 RegCloseKey(This
->hkeySource
);
201 if (This
->hkeySource
!= This
->hkeyProgID
)
202 RegCloseKey(This
->hkeyProgID
);
203 This
->hkeySource
= This
->hkeyProgID
= NULL
;
205 /* If the process of initializing hkeyProgID fails, just return S_OK. That's what Windows does. */
206 if (pszAssoc
!= NULL
)
211 ret
= RegOpenKeyExW(HKEY_CLASSES_ROOT
,
218 /* if this is a progid */
219 if (*pszAssoc
!= '.' && *pszAssoc
!= '{')
221 This
->hkeyProgID
= This
->hkeySource
;
225 /* if it's not a progid, it's a file extension or clsid */
226 if (*pszAssoc
== '.')
228 /* for a file extension, the progid is the default value */
229 hr
= ASSOC_GetValue(This
->hkeySource
, NULL
, (void**)&progId
, NULL
);
233 else /* if (*pszAssoc == '{') */
236 /* for a clsid, the progid is the default value of the ProgID subkey */
237 ret
= RegOpenKeyExW(This
->hkeySource
,
242 if (ret
!= ERROR_SUCCESS
)
244 hr
= ASSOC_GetValue(progIdKey
, NULL
, (void**)&progId
, NULL
);
247 RegCloseKey(progIdKey
);
250 /* open the actual progid key, the one with the shell subkey */
251 ret
= RegOpenKeyExW(HKEY_CLASSES_ROOT
,
260 else if (hkeyProgid
!= NULL
)
262 /* reopen the key so we don't end up closing a key owned by the caller */
263 RegOpenKeyExW(hkeyProgid
, NULL
, 0, KEY_READ
, &This
->hkeyProgID
);
264 This
->hkeySource
= This
->hkeyProgID
;
271 static HRESULT
ASSOC_GetValue(HKEY hkey
, const WCHAR
*name
, void **data
, DWORD
*data_size
)
276 ret
= RegQueryValueExW(hkey
, name
, 0, NULL
, NULL
, &size
);
277 if (ret
!= ERROR_SUCCESS
)
278 return HRESULT_FROM_WIN32(ret
);
281 *data
= heap_alloc(size
);
283 return E_OUTOFMEMORY
;
284 ret
= RegQueryValueExW(hkey
, name
, 0, NULL
, (LPBYTE
)*data
, &size
);
285 if (ret
!= ERROR_SUCCESS
)
288 return HRESULT_FROM_WIN32(ret
);
295 static HRESULT
ASSOC_GetCommand(IQueryAssociationsImpl
*This
, const WCHAR
*extra
, WCHAR
**command
)
302 WCHAR
*extra_from_reg
= NULL
;
304 static const WCHAR commandW
[] = { 'c','o','m','m','a','n','d',0 };
305 static const WCHAR shellW
[] = { 's','h','e','l','l',0 };
307 /* When looking for file extension it's possible to have a default value
308 that points to another key that contains 'shell/<verb>/command' subtree. */
309 hr
= ASSOC_GetValue(This
->hkeySource
, NULL
, (void**)&filetype
, NULL
);
314 ret
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, filetype
, 0, KEY_READ
, &hkeyFile
);
317 if (ret
== ERROR_SUCCESS
)
319 ret
= RegOpenKeyExW(hkeyFile
, shellW
, 0, KEY_READ
, &hkeyShell
);
320 RegCloseKey(hkeyFile
);
323 ret
= RegOpenKeyExW(This
->hkeySource
, shellW
, 0, KEY_READ
, &hkeyShell
);
326 ret
= RegOpenKeyExW(This
->hkeySource
, shellW
, 0, KEY_READ
, &hkeyShell
);
328 if (ret
) return HRESULT_FROM_WIN32(ret
);
332 /* check for default verb */
333 hr
= ASSOC_GetValue(hkeyShell
, NULL
, (void**)&extra_from_reg
, NULL
);
336 /* no default verb, try first subkey */
337 DWORD max_subkey_len
;
339 ret
= RegQueryInfoKeyW(hkeyShell
, NULL
, NULL
, NULL
, NULL
, &max_subkey_len
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
342 RegCloseKey(hkeyShell
);
343 return HRESULT_FROM_WIN32(ret
);
347 extra_from_reg
= heap_alloc(max_subkey_len
* sizeof(WCHAR
));
350 RegCloseKey(hkeyShell
);
351 return E_OUTOFMEMORY
;
354 ret
= RegEnumKeyExW(hkeyShell
, 0, extra_from_reg
, &max_subkey_len
, NULL
, NULL
, NULL
, NULL
);
357 heap_free(extra_from_reg
);
358 RegCloseKey(hkeyShell
);
359 return HRESULT_FROM_WIN32(ret
);
362 extra
= extra_from_reg
;
365 /* open verb subkey */
366 ret
= RegOpenKeyExW(hkeyShell
, extra
, 0, KEY_READ
, &hkeyVerb
);
367 heap_free(extra_from_reg
);
368 RegCloseKey(hkeyShell
);
369 if (ret
) return HRESULT_FROM_WIN32(ret
);
371 /* open command subkey */
372 ret
= RegOpenKeyExW(hkeyVerb
, commandW
, 0, KEY_READ
, &hkeyCommand
);
373 RegCloseKey(hkeyVerb
);
374 if (ret
) return HRESULT_FROM_WIN32(ret
);
376 hr
= ASSOC_GetValue(hkeyCommand
, NULL
, (void**)command
, NULL
);
377 RegCloseKey(hkeyCommand
);
381 static HRESULT
ASSOC_GetExecutable(IQueryAssociationsImpl
*This
,
382 LPCWSTR pszExtra
, LPWSTR path
,
383 DWORD pathlen
, DWORD
*len
)
390 hr
= ASSOC_GetCommand(This
, pszExtra
, &pszCommand
);
394 /* cleanup pszCommand */
395 if (pszCommand
[0] == '"')
397 pszStart
= pszCommand
+ 1;
398 pszEnd
= strchrW(pszStart
, '"');
401 *len
= SearchPathW(NULL
, pszStart
, NULL
, pathlen
, path
, NULL
);
405 pszStart
= pszCommand
;
406 for (pszEnd
= pszStart
; (pszEnd
= strchrW(pszEnd
, ' ')); pszEnd
++)
410 if ((*len
= SearchPathW(NULL
, pszStart
, NULL
, pathlen
, path
, NULL
)))
415 *len
= SearchPathW(NULL
, pszStart
, NULL
, pathlen
, path
, NULL
);
418 heap_free(pszCommand
);
420 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
424 static HRESULT
ASSOC_ReturnData(void *out
, DWORD
*outlen
, const void *data
,
429 if (*outlen
< datalen
)
435 memcpy(out
, data
, datalen
);
445 static HRESULT
ASSOC_ReturnString(ASSOCF flags
, LPWSTR out
, DWORD
*outlen
, LPCWSTR data
, DWORD datalen
)
450 TRACE("flags=0x%08x, data=%s\n", flags
, debugstr_w(data
));
458 if (*outlen
< datalen
)
460 if (flags
& ASSOCF_NOTRUNCATE
)
463 if (*outlen
> 0) out
[0] = 0;
468 len
= min(*outlen
, datalen
);
469 hr
= E_NOT_SUFFICIENT_BUFFER
;
477 memcpy(out
, data
, len
*sizeof(WCHAR
));
482 /**************************************************************************
483 * IQueryAssociations_GetString
485 * Get a file association string from the registry.
488 * iface [I] IQueryAssociations interface to query
489 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
490 * str [I] Type of string to get (ASSOCSTR enum from "shlwapi.h")
491 * pszExtra [I] Extra information about the string location
492 * pszOut [O] Destination for the association string
493 * pcchOut [I/O] Length of pszOut
496 * Success: S_OK. pszOut contains the string, pcchOut contains its length.
497 * Failure: An HRESULT error code indicating the error.
499 static HRESULT WINAPI
IQueryAssociations_fnGetString(
500 IQueryAssociations
*iface
,
507 IQueryAssociationsImpl
*This
= impl_from_IQueryAssociations(iface
);
508 const ASSOCF unimplemented_flags
= ~ASSOCF_NOTRUNCATE
;
511 WCHAR path
[MAX_PATH
];
513 TRACE("(%p)->(0x%08x, %u, %s, %p, %p)\n", This
, flags
, str
, debugstr_w(pszExtra
), pszOut
, pcchOut
);
515 if (flags
& unimplemented_flags
)
516 FIXME("%08x: unimplemented flags\n", flags
& unimplemented_flags
);
521 if (!This
->hkeySource
&& !This
->hkeyProgID
)
522 return HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION
);
526 case ASSOCSTR_COMMAND
:
529 hr
= ASSOC_GetCommand(This
, pszExtra
, &command
);
532 hr
= ASSOC_ReturnString(flags
, pszOut
, pcchOut
, command
, strlenW(command
) + 1);
538 case ASSOCSTR_EXECUTABLE
:
540 hr
= ASSOC_GetExecutable(This
, pszExtra
, path
, MAX_PATH
, &len
);
544 return ASSOC_ReturnString(flags
, pszOut
, pcchOut
, path
, len
);
547 case ASSOCSTR_FRIENDLYDOCNAME
:
551 hr
= ASSOC_GetValue(This
->hkeyProgID
, NULL
, (void**)&docName
, NULL
);
553 /* hKeyProgID is NULL or there is no default value, so fail */
554 return HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION
);
556 hr
= ASSOC_ReturnString(flags
, pszOut
, pcchOut
, docName
, strlenW(docName
) + 1);
561 case ASSOCSTR_FRIENDLYAPPNAME
:
563 PVOID verinfoW
= NULL
;
564 DWORD size
, retval
= 0;
567 static const WCHAR translationW
[] = {
568 '\\','V','a','r','F','i','l','e','I','n','f','o',
569 '\\','T','r','a','n','s','l','a','t','i','o','n',0
571 static const WCHAR fileDescFmtW
[] = {
572 '\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o',
573 '\\','%','0','4','x','%','0','4','x',
574 '\\','F','i','l','e','D','e','s','c','r','i','p','t','i','o','n',0
578 hr
= ASSOC_GetExecutable(This
, pszExtra
, path
, MAX_PATH
, &len
);
582 retval
= GetFileVersionInfoSizeW(path
, &size
);
584 goto get_friendly_name_fail
;
585 verinfoW
= heap_alloc_zero(retval
);
587 return E_OUTOFMEMORY
;
588 if (!GetFileVersionInfoW(path
, 0, retval
, verinfoW
))
589 goto get_friendly_name_fail
;
590 if (VerQueryValueW(verinfoW
, translationW
, (LPVOID
*)&bufW
, &flen
))
593 DWORD
*langCodeDesc
= (DWORD
*)bufW
;
594 for (i
= 0; i
< flen
/ sizeof(DWORD
); i
++)
596 sprintfW(fileDescW
, fileDescFmtW
, LOWORD(langCodeDesc
[i
]),
597 HIWORD(langCodeDesc
[i
]));
598 if (VerQueryValueW(verinfoW
, fileDescW
, (LPVOID
*)&bufW
, &flen
))
600 /* Does strlenW(bufW) == 0 mean we use the filename? */
601 len
= strlenW(bufW
) + 1;
602 TRACE("found FileDescription: %s\n", debugstr_w(bufW
));
603 hr
= ASSOC_ReturnString(flags
, pszOut
, pcchOut
, bufW
, len
);
609 get_friendly_name_fail
:
610 PathRemoveExtensionW(path
);
611 PathStripPathW(path
);
612 TRACE("using filename: %s\n", debugstr_w(path
));
613 hr
= ASSOC_ReturnString(flags
, pszOut
, pcchOut
, path
, strlenW(path
) + 1);
618 case ASSOCSTR_CONTENTTYPE
:
620 static const WCHAR Content_TypeW
[] = {'C','o','n','t','e','n','t',' ','T','y','p','e',0};
626 ret
= RegGetValueW(This
->hkeySource
, NULL
, Content_TypeW
, RRF_RT_REG_SZ
, NULL
, NULL
, &size
);
627 if (ret
!= ERROR_SUCCESS
)
628 return HRESULT_FROM_WIN32(ret
);
629 contentType
= heap_alloc(size
);
630 if (contentType
!= NULL
)
632 ret
= RegGetValueW(This
->hkeySource
, NULL
, Content_TypeW
, RRF_RT_REG_SZ
, NULL
, contentType
, &size
);
633 if (ret
== ERROR_SUCCESS
)
634 hr
= ASSOC_ReturnString(flags
, pszOut
, pcchOut
, contentType
, strlenW(contentType
) + 1);
636 hr
= HRESULT_FROM_WIN32(ret
);
637 heap_free(contentType
);
644 case ASSOCSTR_DEFAULTICON
:
646 static const WCHAR DefaultIconW
[] = {'D','e','f','a','u','l','t','I','c','o','n',0};
647 static const WCHAR documentIcon
[] = {'s','h','e','l','l','3','2','.','d','l','l',',','0',0};
652 ret
= RegGetValueW(This
->hkeyProgID
, DefaultIconW
, NULL
, RRF_RT_REG_SZ
, NULL
, NULL
, &size
);
653 if (ret
== ERROR_SUCCESS
)
655 WCHAR
*icon
= heap_alloc(size
);
658 ret
= RegGetValueW(This
->hkeyProgID
, DefaultIconW
, NULL
, RRF_RT_REG_SZ
, NULL
, icon
, &size
);
659 if (ret
== ERROR_SUCCESS
)
660 hr
= ASSOC_ReturnString(flags
, pszOut
, pcchOut
, icon
, strlenW(icon
) + 1);
662 hr
= HRESULT_FROM_WIN32(ret
);
668 /* there is no DefaultIcon subkey or hkeyProgID is NULL, so return the default document icon */
669 if (This
->hkeyProgID
== NULL
)
670 hr
= ASSOC_ReturnString(flags
, pszOut
, pcchOut
, documentIcon
, strlenW(documentIcon
) + 1);
672 return HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION
);
676 case ASSOCSTR_SHELLEXTENSION
:
678 static const WCHAR shellexW
[] = {'S','h','e','l','l','E','x','\\',0};
679 WCHAR keypath
[sizeof(shellexW
) / sizeof(shellexW
[0]) + 39], guid
[39];
685 hr
= CLSIDFromString(pszExtra
, &clsid
);
686 if (FAILED(hr
)) return hr
;
688 strcpyW(keypath
, shellexW
);
689 strcatW(keypath
, pszExtra
);
690 ret
= RegOpenKeyExW(This
->hkeySource
, keypath
, 0, KEY_READ
, &hkey
);
691 if (ret
) return HRESULT_FROM_WIN32(ret
);
694 ret
= RegGetValueW(hkey
, NULL
, NULL
, RRF_RT_REG_SZ
, NULL
, guid
, &size
);
696 if (ret
) return HRESULT_FROM_WIN32(ret
);
698 return ASSOC_ReturnString(flags
, pszOut
, pcchOut
, guid
, size
/ sizeof(WCHAR
));
702 FIXME("assocstr %d unimplemented!\n", str
);
707 /**************************************************************************
708 * IQueryAssociations_GetKey
710 * Get a file association key from the registry.
713 * iface [I] IQueryAssociations interface to query
714 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
715 * assockey [I] Type of key to get (ASSOCKEY enum from "shlwapi.h")
716 * pszExtra [I] Extra information about the key location
717 * phkeyOut [O] Destination for the association key
720 * Success: S_OK. phkeyOut contains a handle to the key.
721 * Failure: An HRESULT error code indicating the error.
723 static HRESULT WINAPI
IQueryAssociations_fnGetKey(
724 IQueryAssociations
*iface
,
730 IQueryAssociationsImpl
*This
= impl_from_IQueryAssociations(iface
);
732 FIXME("(%p,0x%8x,0x%8x,%s,%p)-stub!\n", This
, cfFlags
, assockey
,
733 debugstr_w(pszExtra
), phkeyOut
);
737 /**************************************************************************
738 * IQueryAssociations_GetData
740 * Get the data for a file association key from the registry.
743 * iface [I] IQueryAssociations interface to query
744 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
745 * assocdata [I] Type of data to get (ASSOCDATA enum from "shlwapi.h")
746 * pszExtra [I] Extra information about the data location
747 * pvOut [O] Destination for the association key
748 * pcbOut [I/O] Size of pvOut
751 * Success: S_OK. pszOut contains the data, pcbOut contains its length.
752 * Failure: An HRESULT error code indicating the error.
754 static HRESULT WINAPI
IQueryAssociations_fnGetData(IQueryAssociations
*iface
,
755 ASSOCF cfFlags
, ASSOCDATA assocdata
, LPCWSTR pszExtra
, LPVOID pvOut
,
758 static const WCHAR edit_flags
[] = {'E','d','i','t','F','l','a','g','s',0};
760 IQueryAssociationsImpl
*This
= impl_from_IQueryAssociations(iface
);
765 TRACE("(%p,0x%8x,0x%8x,%s,%p,%p)\n", This
, cfFlags
, assocdata
,
766 debugstr_w(pszExtra
), pvOut
, pcbOut
);
769 FIXME("Unsupported flags: %x\n", cfFlags
);
772 case ASSOCDATA_EDITFLAGS
:
773 if(!This
->hkeyProgID
)
774 return HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION
);
776 hres
= ASSOC_GetValue(This
->hkeyProgID
, edit_flags
, &data
, &size
);
777 if(SUCCEEDED(hres
) && pcbOut
)
778 hres
= ASSOC_ReturnData(pvOut
, pcbOut
, data
, size
);
782 FIXME("Unsupported ASSOCDATA value: %d\n", assocdata
);
787 /**************************************************************************
788 * IQueryAssociations_GetEnum
790 * Not yet implemented in native Win32.
793 * iface [I] IQueryAssociations interface to query
794 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
795 * assocenum [I] Type of enum to get (ASSOCENUM enum from "shlwapi.h")
796 * pszExtra [I] Extra information about the enum location
797 * riid [I] REFIID to look for
798 * ppvOut [O] Destination for the interface.
802 * Failure: An HRESULT error code indicating the error.
805 * Presumably this function returns an enumerator object.
807 static HRESULT WINAPI
IQueryAssociations_fnGetEnum(
808 IQueryAssociations
*iface
,
815 IQueryAssociationsImpl
*This
= impl_from_IQueryAssociations(iface
);
817 FIXME("(%p,0x%8x,0x%8x,%s,%s,%p)-stub!\n", This
, cfFlags
, assocenum
,
818 debugstr_w(pszExtra
), debugstr_guid(riid
), ppvOut
);
822 static const IQueryAssociationsVtbl IQueryAssociations_vtbl
=
824 IQueryAssociations_fnQueryInterface
,
825 IQueryAssociations_fnAddRef
,
826 IQueryAssociations_fnRelease
,
827 IQueryAssociations_fnInit
,
828 IQueryAssociations_fnGetString
,
829 IQueryAssociations_fnGetKey
,
830 IQueryAssociations_fnGetData
,
831 IQueryAssociations_fnGetEnum
834 /**************************************************************************
835 * IApplicationAssociationRegistration implementation
837 static inline IApplicationAssociationRegistrationImpl
*impl_from_IApplicationAssociationRegistration(IApplicationAssociationRegistration
*iface
)
839 return CONTAINING_RECORD(iface
, IApplicationAssociationRegistrationImpl
, IApplicationAssociationRegistration_iface
);
842 static HRESULT WINAPI
ApplicationAssociationRegistration_QueryInterface(
843 IApplicationAssociationRegistration
* iface
, REFIID riid
, LPVOID
*ppv
)
845 IApplicationAssociationRegistrationImpl
*This
= impl_from_IApplicationAssociationRegistration(iface
);
847 TRACE("(%p, %s, %p)\n",This
, debugstr_guid(riid
), ppv
);
852 if (IsEqualGUID(&IID_IUnknown
, riid
) ||
853 IsEqualGUID(&IID_IApplicationAssociationRegistration
, riid
)) {
854 *ppv
= &This
->IApplicationAssociationRegistration_iface
;
855 IUnknown_AddRef((IUnknown
*)*ppv
);
856 TRACE("returning IApplicationAssociationRegistration: %p\n", *ppv
);
861 FIXME("(%p)->(%s %p) interface not supported\n", This
, debugstr_guid(riid
), ppv
);
862 return E_NOINTERFACE
;
865 static ULONG WINAPI
ApplicationAssociationRegistration_AddRef(IApplicationAssociationRegistration
*iface
)
867 IApplicationAssociationRegistrationImpl
*This
= impl_from_IApplicationAssociationRegistration(iface
);
868 ULONG ref
= InterlockedIncrement(&This
->ref
);
870 TRACE("(%p) ref=%d\n", This
, ref
);
874 static ULONG WINAPI
ApplicationAssociationRegistration_Release(IApplicationAssociationRegistration
*iface
)
876 IApplicationAssociationRegistrationImpl
*This
= impl_from_IApplicationAssociationRegistration(iface
);
877 ULONG ref
= InterlockedDecrement(&This
->ref
);
879 TRACE("(%p) ref=%d\n", This
, ref
);
887 static HRESULT WINAPI
ApplicationAssociationRegistration_QueryCurrentDefault(IApplicationAssociationRegistration
*iface
, LPCWSTR query
,
888 ASSOCIATIONTYPE type
, ASSOCIATIONLEVEL level
, LPWSTR
*association
)
890 IApplicationAssociationRegistrationImpl
*This
= impl_from_IApplicationAssociationRegistration(iface
);
891 static WCHAR urlassoc
[] = {'U','r','l','A','s','s','o','c','i','a','t','i','o','n','s',0};
892 static WCHAR mimeassoc
[] = {'M','I','M','E','A','s','s','o','c','i','a','t','i','o','n','s',0};
893 static WCHAR assocations
[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
894 'W','i','n','d','o','w','s','\\','S','h','e','l','l','\\',
895 'A','s','s','o','c','i','a','t','i','o','n','s',0};
896 static WCHAR slash
[] = {'\\',0};
897 static WCHAR choice
[] = {'U','s','e','r','C','h','o','i','c','e',0};
898 static WCHAR propid
[] = {'P','r','o','g','i','d',0};
899 WCHAR path
[MAX_PATH
] = {0};
900 DWORD ret
, keytype
, size
;
902 HRESULT hr
= HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION
);
904 TRACE("(%p)->(%s, %d, %d, %p)\n", This
, debugstr_w(query
), type
, level
, association
);
911 if((type
== AT_URLPROTOCOL
|| type
== AT_FILEEXTENSION
) && !query
[0])
913 else if(type
== AT_FILEEXTENSION
&& query
[0] != '.')
916 if(type
== AT_FILEEXTENSION
)
918 ret
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, query
, 0, KEY_READ
, &hkey
);
919 if(ret
== ERROR_SUCCESS
)
921 ret
= RegGetValueW(hkey
, NULL
, NULL
, RRF_RT_REG_SZ
, &keytype
, NULL
, &size
);
922 if(ret
== ERROR_SUCCESS
)
924 *association
= CoTaskMemAlloc(size
);
927 ret
= RegGetValueW(hkey
, NULL
, NULL
, RRF_RT_REG_SZ
, &keytype
, *association
, &size
);
928 if(ret
== ERROR_SUCCESS
)
932 CoTaskMemFree(*association
);
943 ret
= RegOpenKeyExW(HKEY_CURRENT_USER
, assocations
, 0, KEY_READ
, &hkey
);
944 if(ret
== ERROR_SUCCESS
)
946 if(type
== AT_URLPROTOCOL
)
947 lstrcpyW(path
, urlassoc
);
948 else if(type
== AT_MIMETYPE
)
949 lstrcpyW(path
, mimeassoc
);
952 WARN("Unsupported type (%d).\n", type
);
957 lstrcatW(path
, slash
);
958 lstrcatW(path
, query
);
959 lstrcatW(path
, slash
);
960 lstrcatW(path
, choice
);
962 ret
= RegGetValueW(hkey
, path
, propid
, RRF_RT_REG_SZ
, &keytype
, NULL
, &size
);
963 if(ret
== ERROR_SUCCESS
)
965 *association
= CoTaskMemAlloc(size
);
968 ret
= RegGetValueW(hkey
, path
, propid
, RRF_RT_REG_SZ
, &keytype
, *association
, &size
);
969 if(ret
== ERROR_SUCCESS
)
973 CoTaskMemFree(*association
);
988 static HRESULT WINAPI
ApplicationAssociationRegistration_QueryAppIsDefault(IApplicationAssociationRegistration
* This
, LPCWSTR query
,
989 ASSOCIATIONTYPE type
, ASSOCIATIONLEVEL level
, LPCWSTR appname
, BOOL
*is_default
)
991 FIXME("(%p)->(%s, %d, %d, %s, %p)\n", This
, debugstr_w(query
), type
, level
, debugstr_w(appname
), is_default
);
995 static HRESULT WINAPI
ApplicationAssociationRegistration_QueryAppIsDefaultAll(IApplicationAssociationRegistration
* This
, ASSOCIATIONLEVEL level
,
996 LPCWSTR appname
, BOOL
*is_default
)
998 FIXME("(%p)->(%d, %s, %p)\n", This
, level
, debugstr_w(appname
), is_default
);
1002 static HRESULT WINAPI
ApplicationAssociationRegistration_SetAppAsDefault(IApplicationAssociationRegistration
* This
, LPCWSTR appname
,
1003 LPCWSTR set
, ASSOCIATIONTYPE set_type
)
1005 FIXME("(%p)->(%s, %s, %d)\n", This
, debugstr_w(appname
), debugstr_w(set
), set_type
);
1009 static HRESULT WINAPI
ApplicationAssociationRegistration_SetAppAsDefaultAll(IApplicationAssociationRegistration
* This
, LPCWSTR appname
)
1011 FIXME("(%p)->(%s)\n", This
, debugstr_w(appname
));
1016 static HRESULT WINAPI
ApplicationAssociationRegistration_ClearUserAssociations(IApplicationAssociationRegistration
* This
)
1018 FIXME("(%p)\n", This
);
1023 static const IApplicationAssociationRegistrationVtbl IApplicationAssociationRegistration_vtbl
=
1025 ApplicationAssociationRegistration_QueryInterface
,
1026 ApplicationAssociationRegistration_AddRef
,
1027 ApplicationAssociationRegistration_Release
,
1028 ApplicationAssociationRegistration_QueryCurrentDefault
,
1029 ApplicationAssociationRegistration_QueryAppIsDefault
,
1030 ApplicationAssociationRegistration_QueryAppIsDefaultAll
,
1031 ApplicationAssociationRegistration_SetAppAsDefault
,
1032 ApplicationAssociationRegistration_SetAppAsDefaultAll
,
1033 ApplicationAssociationRegistration_ClearUserAssociations
1036 /**************************************************************************
1037 * IQueryAssociations_Constructor [internal]
1039 * Construct a new IQueryAssociations object.
1041 HRESULT WINAPI
QueryAssociations_Constructor(IUnknown
*pUnkOuter
, REFIID riid
, LPVOID
*ppOutput
)
1043 IQueryAssociationsImpl
* this;
1046 if (pUnkOuter
) return CLASS_E_NOAGGREGATION
;
1048 if (!(this = SHAlloc(sizeof(*this)))) return E_OUTOFMEMORY
;
1049 this->IQueryAssociations_iface
.lpVtbl
= &IQueryAssociations_vtbl
;
1051 this->hkeySource
= 0;
1052 this->hkeyProgID
= 0;
1053 if (FAILED(ret
= IQueryAssociations_QueryInterface(&this->IQueryAssociations_iface
, riid
, ppOutput
))) SHFree( this );
1054 TRACE("returning %p\n", *ppOutput
);
1058 /**************************************************************************
1059 * ApplicationAssociationRegistration_Constructor [internal]
1061 * Construct a IApplicationAssociationRegistration object.
1063 HRESULT WINAPI
ApplicationAssociationRegistration_Constructor(IUnknown
*outer
, REFIID riid
, LPVOID
*ppv
)
1065 IApplicationAssociationRegistrationImpl
*This
;
1069 return CLASS_E_NOAGGREGATION
;
1071 if (!(This
= SHAlloc(sizeof(*This
))))
1072 return E_OUTOFMEMORY
;
1074 This
->IApplicationAssociationRegistration_iface
.lpVtbl
= &IApplicationAssociationRegistration_vtbl
;
1077 hr
= IApplicationAssociationRegistration_QueryInterface(&This
->IApplicationAssociationRegistration_iface
, riid
, ppv
);
1081 TRACE("returning 0x%x with %p\n", hr
, *ppv
);
1085 static HRESULT WINAPI
enumassochandlers_QueryInterface(IEnumAssocHandlers
*iface
, REFIID riid
, void **obj
)
1087 struct enumassochandlers
*This
= impl_from_IEnumAssocHandlers(iface
);
1089 TRACE("(%p %s %p)\n", This
, debugstr_guid(riid
), obj
);
1091 if (IsEqualIID(riid
, &IID_IEnumAssocHandlers
) ||
1092 IsEqualIID(riid
, &IID_IUnknown
))
1095 IEnumAssocHandlers_AddRef(iface
);
1100 return E_NOINTERFACE
;
1103 static ULONG WINAPI
enumassochandlers_AddRef(IEnumAssocHandlers
*iface
)
1105 struct enumassochandlers
*This
= impl_from_IEnumAssocHandlers(iface
);
1106 ULONG ref
= InterlockedIncrement(&This
->ref
);
1108 TRACE("(%p)->(%u)\n", This
, ref
);
1112 static ULONG WINAPI
enumassochandlers_Release(IEnumAssocHandlers
*iface
)
1114 struct enumassochandlers
*This
= impl_from_IEnumAssocHandlers(iface
);
1115 ULONG ref
= InterlockedDecrement(&This
->ref
);
1117 TRACE("(%p)->(%u)\n", This
, ref
);
1125 static HRESULT WINAPI
enumassochandlers_Next(IEnumAssocHandlers
*iface
, ULONG count
, IAssocHandler
**handlers
,
1128 struct enumassochandlers
*This
= impl_from_IEnumAssocHandlers(iface
);
1130 FIXME("(%p)->(%u %p %p): stub\n", This
, count
, handlers
, fetched
);
1135 static const IEnumAssocHandlersVtbl enumassochandlersvtbl
= {
1136 enumassochandlers_QueryInterface
,
1137 enumassochandlers_AddRef
,
1138 enumassochandlers_Release
,
1139 enumassochandlers_Next
1142 /**************************************************************************
1143 * SHAssocEnumHandlers [SHELL32.@]
1145 HRESULT WINAPI
SHAssocEnumHandlers(const WCHAR
*extra
, ASSOC_FILTER filter
, IEnumAssocHandlers
**enumhandlers
)
1147 struct enumassochandlers
*enumassoc
;
1149 FIXME("(%s %d %p): stub\n", debugstr_w(extra
), filter
, enumhandlers
);
1151 *enumhandlers
= NULL
;
1153 enumassoc
= SHAlloc(sizeof(*enumassoc
));
1155 return E_OUTOFMEMORY
;
1157 enumassoc
->IEnumAssocHandlers_iface
.lpVtbl
= &enumassochandlersvtbl
;
1160 *enumhandlers
= &enumassoc
->IEnumAssocHandlers_iface
;