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/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
37 /**************************************************************************
41 * This object provides a layer of abstraction over the system registry in
42 * order to simplify the process of parsing associations between files.
43 * Associations in this context means the registry entries that link (for
44 * example) the extension of a file with its description, list of
45 * applications to open the file with, and actions that can be performed on it
46 * (the shell displays such information in the context menu of explorer
47 * when you right-click on a file).
50 * You can use this object transparently by calling the helper functions
51 * AssocQueryKeyA(), AssocQueryStringA() and AssocQueryStringByKeyA(). These
52 * create an IQueryAssociations object, perform the requested actions
53 * and then dispose of the object. Alternatively, you can create an instance
54 * of the object using AssocCreate() and call the following methods on it:
61 IQueryAssociations IQueryAssociations_iface
;
65 } IQueryAssociationsImpl
;
69 IApplicationAssociationRegistration IApplicationAssociationRegistration_iface
;
71 } IApplicationAssociationRegistrationImpl
;
74 static inline IQueryAssociationsImpl
*impl_from_IQueryAssociations(IQueryAssociations
*iface
)
76 return CONTAINING_RECORD(iface
, IQueryAssociationsImpl
, IQueryAssociations_iface
);
79 struct enumassochandlers
81 IEnumAssocHandlers IEnumAssocHandlers_iface
;
85 static inline struct enumassochandlers
*impl_from_IEnumAssocHandlers(IEnumAssocHandlers
*iface
)
87 return CONTAINING_RECORD(iface
, struct enumassochandlers
, IEnumAssocHandlers_iface
);
90 static HRESULT
ASSOC_GetValue(HKEY hkey
, const WCHAR
*name
, void **data
, DWORD
*data_size
);
92 /**************************************************************************
93 * IQueryAssociations_QueryInterface
95 * See IUnknown_QueryInterface.
97 static HRESULT WINAPI
IQueryAssociations_fnQueryInterface(
98 IQueryAssociations
* iface
,
102 IQueryAssociationsImpl
*This
= impl_from_IQueryAssociations(iface
);
104 TRACE("(%p,%s,%p)\n",This
, debugstr_guid(riid
), ppvObj
);
111 if (IsEqualIID(riid
, &IID_IUnknown
) ||
112 IsEqualIID(riid
, &IID_IQueryAssociations
))
114 *ppvObj
= &This
->IQueryAssociations_iface
;
116 IQueryAssociations_AddRef((IQueryAssociations
*)*ppvObj
);
117 TRACE("Returning IQueryAssociations (%p)\n", *ppvObj
);
120 TRACE("Returning E_NOINTERFACE\n");
121 return E_NOINTERFACE
;
124 /**************************************************************************
125 * IQueryAssociations_AddRef
127 * See IUnknown_AddRef.
129 static ULONG WINAPI
IQueryAssociations_fnAddRef(IQueryAssociations
*iface
)
131 IQueryAssociationsImpl
*This
= impl_from_IQueryAssociations(iface
);
132 ULONG refCount
= InterlockedIncrement(&This
->ref
);
134 TRACE("(%p)->(ref before=%lu)\n",This
, refCount
- 1);
139 /**************************************************************************
140 * IQueryAssociations_Release
142 * See IUnknown_Release.
144 static ULONG WINAPI
IQueryAssociations_fnRelease(IQueryAssociations
*iface
)
146 IQueryAssociationsImpl
*This
= impl_from_IQueryAssociations(iface
);
147 ULONG refCount
= InterlockedDecrement(&This
->ref
);
149 TRACE("(%p)->(ref before=%lu)\n",This
, refCount
+ 1);
153 TRACE("Destroying IQueryAssociations (%p)\n", This
);
154 RegCloseKey(This
->hkeySource
);
155 RegCloseKey(This
->hkeyProgID
);
162 /**************************************************************************
163 * IQueryAssociations_Init
165 * Initialise an IQueryAssociations object.
168 * iface [I] IQueryAssociations interface to initialise
169 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
170 * pszAssoc [I] String for the root key name, or NULL if hkeyProgid is given
171 * hkeyProgid [I] Handle for the root key, or NULL if pszAssoc is given
172 * hWnd [I] Reserved, must be NULL.
175 * Success: S_OK. iface is initialised with the parameters given.
176 * Failure: An HRESULT error code indicating the error.
178 static HRESULT WINAPI
IQueryAssociations_fnInit(
179 IQueryAssociations
*iface
,
185 IQueryAssociationsImpl
*This
= impl_from_IQueryAssociations(iface
);
188 TRACE("(%p)->(%ld,%s,%p,%p)\n", iface
,
190 debugstr_w(pszAssoc
),
194 FIXME("hwnd != NULL not supported\n");
196 FIXME("unsupported flags: %lx\n", cfFlags
);
198 RegCloseKey(This
->hkeySource
);
199 if (This
->hkeySource
!= This
->hkeyProgID
)
200 RegCloseKey(This
->hkeyProgID
);
201 This
->hkeySource
= This
->hkeyProgID
= NULL
;
203 /* If the process of initializing hkeyProgID fails, just return S_OK. That's what Windows does. */
204 if (pszAssoc
!= NULL
)
209 ret
= RegOpenKeyExW(HKEY_CLASSES_ROOT
,
216 /* if this is a progid */
217 if (*pszAssoc
!= '.' && *pszAssoc
!= '{')
219 This
->hkeyProgID
= This
->hkeySource
;
223 /* if it's not a progid, it's a file extension or clsid */
224 if (*pszAssoc
== '.')
226 /* for a file extension, the progid is the default value */
227 hr
= ASSOC_GetValue(This
->hkeySource
, NULL
, (void**)&progId
, NULL
);
231 else /* if (*pszAssoc == '{') */
234 /* for a clsid, the progid is the default value of the ProgID subkey */
235 ret
= RegOpenKeyExW(This
->hkeySource
, L
"ProgID", 0, KEY_READ
, &progIdKey
);
236 if (ret
!= ERROR_SUCCESS
)
238 hr
= ASSOC_GetValue(progIdKey
, NULL
, (void**)&progId
, NULL
);
241 RegCloseKey(progIdKey
);
244 /* open the actual progid key, the one with the shell subkey */
245 ret
= RegOpenKeyExW(HKEY_CLASSES_ROOT
,
254 else if (hkeyProgid
!= NULL
)
256 /* reopen the key so we don't end up closing a key owned by the caller */
257 RegOpenKeyExW(hkeyProgid
, NULL
, 0, KEY_READ
, &This
->hkeyProgID
);
258 This
->hkeySource
= This
->hkeyProgID
;
265 static HRESULT
ASSOC_GetValue(HKEY hkey
, const WCHAR
*name
, void **data
, DWORD
*data_size
)
270 ret
= RegQueryValueExW(hkey
, name
, 0, NULL
, NULL
, &size
);
271 if (ret
!= ERROR_SUCCESS
)
272 return HRESULT_FROM_WIN32(ret
);
275 *data
= malloc(size
);
277 return E_OUTOFMEMORY
;
278 ret
= RegQueryValueExW(hkey
, name
, 0, NULL
, (LPBYTE
)*data
, &size
);
279 if (ret
!= ERROR_SUCCESS
)
282 return HRESULT_FROM_WIN32(ret
);
289 static HRESULT
ASSOC_GetCommand(IQueryAssociationsImpl
*This
, const WCHAR
*extra
, WCHAR
**command
)
296 WCHAR
*extra_from_reg
= NULL
;
299 /* When looking for file extension it's possible to have a default value
300 that points to another key that contains 'shell/<verb>/command' subtree. */
301 hr
= ASSOC_GetValue(This
->hkeySource
, NULL
, (void**)&filetype
, NULL
);
306 ret
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, filetype
, 0, KEY_READ
, &hkeyFile
);
309 if (ret
== ERROR_SUCCESS
)
311 ret
= RegOpenKeyExW(hkeyFile
, L
"shell", 0, KEY_READ
, &hkeyShell
);
312 RegCloseKey(hkeyFile
);
315 ret
= RegOpenKeyExW(This
->hkeySource
, L
"shell", 0, KEY_READ
, &hkeyShell
);
318 ret
= RegOpenKeyExW(This
->hkeySource
, L
"shell", 0, KEY_READ
, &hkeyShell
);
320 if (ret
) return HRESULT_FROM_WIN32(ret
);
324 /* check for default verb */
325 hr
= ASSOC_GetValue(hkeyShell
, NULL
, (void**)&extra_from_reg
, NULL
);
328 /* no default verb, try first subkey */
329 DWORD max_subkey_len
;
331 ret
= RegQueryInfoKeyW(hkeyShell
, NULL
, NULL
, NULL
, NULL
, &max_subkey_len
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
334 RegCloseKey(hkeyShell
);
335 return HRESULT_FROM_WIN32(ret
);
339 extra_from_reg
= malloc(max_subkey_len
* sizeof(WCHAR
));
342 RegCloseKey(hkeyShell
);
343 return E_OUTOFMEMORY
;
346 ret
= RegEnumKeyExW(hkeyShell
, 0, extra_from_reg
, &max_subkey_len
, NULL
, NULL
, NULL
, NULL
);
349 free(extra_from_reg
);
350 RegCloseKey(hkeyShell
);
351 return HRESULT_FROM_WIN32(ret
);
354 extra
= extra_from_reg
;
357 /* open verb subkey */
358 ret
= RegOpenKeyExW(hkeyShell
, extra
, 0, KEY_READ
, &hkeyVerb
);
359 free(extra_from_reg
);
360 RegCloseKey(hkeyShell
);
361 if (ret
) return HRESULT_FROM_WIN32(ret
);
363 /* open command subkey */
364 ret
= RegOpenKeyExW(hkeyVerb
, L
"command", 0, KEY_READ
, &hkeyCommand
);
365 RegCloseKey(hkeyVerb
);
366 if (ret
) return HRESULT_FROM_WIN32(ret
);
368 hr
= ASSOC_GetValue(hkeyCommand
, NULL
, (void**)command
, NULL
);
369 RegCloseKey(hkeyCommand
);
373 static HRESULT
ASSOC_GetExecutable(IQueryAssociationsImpl
*This
,
374 LPCWSTR pszExtra
, LPWSTR path
,
375 DWORD pathlen
, DWORD
*len
)
382 hr
= ASSOC_GetCommand(This
, pszExtra
, &pszCommand
);
386 /* cleanup pszCommand */
387 if (pszCommand
[0] == '"')
389 pszStart
= pszCommand
+ 1;
390 pszEnd
= wcschr(pszStart
, '"');
393 *len
= SearchPathW(NULL
, pszStart
, NULL
, pathlen
, path
, NULL
);
397 pszStart
= pszCommand
;
398 for (pszEnd
= pszStart
; (pszEnd
= wcschr(pszEnd
, ' ')); pszEnd
++)
402 if ((*len
= SearchPathW(NULL
, pszStart
, NULL
, pathlen
, path
, NULL
)))
407 *len
= SearchPathW(NULL
, pszStart
, NULL
, pathlen
, path
, NULL
);
412 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
416 static HRESULT
ASSOC_ReturnData(void *out
, DWORD
*outlen
, const void *data
,
421 if (*outlen
< datalen
)
427 memcpy(out
, data
, datalen
);
437 static HRESULT
ASSOC_ReturnString(ASSOCF flags
, LPWSTR out
, DWORD
*outlen
, LPCWSTR data
, DWORD datalen
)
442 TRACE("flags=0x%08lx, data=%s\n", flags
, debugstr_w(data
));
450 if (*outlen
< datalen
)
452 if (flags
& ASSOCF_NOTRUNCATE
)
455 if (*outlen
> 0) out
[0] = 0;
460 len
= min(*outlen
, datalen
);
461 hr
= E_NOT_SUFFICIENT_BUFFER
;
469 memcpy(out
, data
, len
*sizeof(WCHAR
));
474 /**************************************************************************
475 * IQueryAssociations_GetString
477 * Get a file association string from the registry.
480 * iface [I] IQueryAssociations interface to query
481 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
482 * str [I] Type of string to get (ASSOCSTR enum from "shlwapi.h")
483 * pszExtra [I] Extra information about the string location
484 * pszOut [O] Destination for the association string
485 * pcchOut [I/O] Length of pszOut
488 * Success: S_OK. pszOut contains the string, pcchOut contains its length.
489 * Failure: An HRESULT error code indicating the error.
491 static HRESULT WINAPI
IQueryAssociations_fnGetString(
492 IQueryAssociations
*iface
,
499 IQueryAssociationsImpl
*This
= impl_from_IQueryAssociations(iface
);
500 const ASSOCF unimplemented_flags
= ~ASSOCF_NOTRUNCATE
;
503 WCHAR path
[MAX_PATH
];
505 TRACE("(%p)->(0x%08lx, %u, %s, %p, %p)\n", This
, flags
, str
, debugstr_w(pszExtra
), pszOut
, pcchOut
);
507 if (flags
& unimplemented_flags
)
508 FIXME("%08lx: unimplemented flags\n", flags
& unimplemented_flags
);
513 if (!This
->hkeySource
&& !This
->hkeyProgID
)
514 return HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION
);
518 case ASSOCSTR_COMMAND
:
521 hr
= ASSOC_GetCommand(This
, pszExtra
, &command
);
524 hr
= ASSOC_ReturnString(flags
, pszOut
, pcchOut
, command
, lstrlenW(command
) + 1);
530 case ASSOCSTR_EXECUTABLE
:
532 hr
= ASSOC_GetExecutable(This
, pszExtra
, path
, MAX_PATH
, &len
);
536 return ASSOC_ReturnString(flags
, pszOut
, pcchOut
, path
, len
);
539 case ASSOCSTR_FRIENDLYDOCNAME
:
543 hr
= ASSOC_GetValue(This
->hkeyProgID
, NULL
, (void**)&docName
, NULL
);
545 /* hKeyProgID is NULL or there is no default value, so fail */
546 return HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION
);
548 hr
= ASSOC_ReturnString(flags
, pszOut
, pcchOut
, docName
, lstrlenW(docName
) + 1);
553 case ASSOCSTR_FRIENDLYAPPNAME
:
555 PVOID verinfoW
= NULL
;
556 DWORD size
, retval
= 0;
561 hr
= ASSOC_GetExecutable(This
, pszExtra
, path
, MAX_PATH
, &len
);
565 retval
= GetFileVersionInfoSizeW(path
, &size
);
567 goto get_friendly_name_fail
;
568 verinfoW
= calloc(1, retval
);
570 return E_OUTOFMEMORY
;
571 if (!GetFileVersionInfoW(path
, 0, retval
, verinfoW
))
572 goto get_friendly_name_fail
;
573 if (VerQueryValueW(verinfoW
, L
"\\VarFileInfo\\Translation", (LPVOID
*)&bufW
, &flen
))
576 DWORD
*langCodeDesc
= (DWORD
*)bufW
;
577 for (i
= 0; i
< flen
/ sizeof(DWORD
); i
++)
579 swprintf(fileDescW
, ARRAY_SIZE(fileDescW
), L
"\\StringFileInfo\\%04x%04x\\FileDescription",
580 LOWORD(langCodeDesc
[i
]), HIWORD(langCodeDesc
[i
]));
581 if (VerQueryValueW(verinfoW
, fileDescW
, (LPVOID
*)&bufW
, &flen
))
583 /* Does lstrlenW(bufW) == 0 mean we use the filename? */
584 len
= lstrlenW(bufW
) + 1;
585 TRACE("found FileDescription: %s\n", debugstr_w(bufW
));
586 hr
= ASSOC_ReturnString(flags
, pszOut
, pcchOut
, bufW
, len
);
592 get_friendly_name_fail
:
593 PathRemoveExtensionW(path
);
594 PathStripPathW(path
);
595 TRACE("using filename: %s\n", debugstr_w(path
));
596 hr
= ASSOC_ReturnString(flags
, pszOut
, pcchOut
, path
, lstrlenW(path
) + 1);
601 case ASSOCSTR_CONTENTTYPE
:
608 ret
= RegGetValueW(This
->hkeySource
, NULL
, L
"Content Type", RRF_RT_REG_SZ
, NULL
, NULL
, &size
);
609 if (ret
!= ERROR_SUCCESS
)
610 return HRESULT_FROM_WIN32(ret
);
611 contentType
= malloc(size
);
612 if (contentType
!= NULL
)
614 ret
= RegGetValueW(This
->hkeySource
, NULL
, L
"Content Type", RRF_RT_REG_SZ
, NULL
, contentType
, &size
);
615 if (ret
== ERROR_SUCCESS
)
616 hr
= ASSOC_ReturnString(flags
, pszOut
, pcchOut
, contentType
, lstrlenW(contentType
) + 1);
618 hr
= HRESULT_FROM_WIN32(ret
);
626 case ASSOCSTR_DEFAULTICON
:
632 ret
= RegGetValueW(This
->hkeyProgID
, L
"DefaultIcon", NULL
, RRF_RT_REG_SZ
, NULL
, NULL
, &size
);
633 if (ret
== ERROR_SUCCESS
)
635 WCHAR
*icon
= malloc(size
);
638 ret
= RegGetValueW(This
->hkeyProgID
, L
"DefaultIcon", NULL
, RRF_RT_REG_SZ
, NULL
, icon
, &size
);
639 if (ret
== ERROR_SUCCESS
)
640 hr
= ASSOC_ReturnString(flags
, pszOut
, pcchOut
, icon
, lstrlenW(icon
) + 1);
642 hr
= HRESULT_FROM_WIN32(ret
);
648 /* there is no DefaultIcon subkey or hkeyProgID is NULL, so return the default document icon */
649 if (This
->hkeyProgID
== NULL
)
650 hr
= ASSOC_ReturnString(flags
, pszOut
, pcchOut
, L
"shell32.dll,0", lstrlenW(L
"shell32.dll,0") + 1);
652 return HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION
);
656 case ASSOCSTR_SHELLEXTENSION
:
658 WCHAR keypath
[ARRAY_SIZE(L
"ShellEx\\") + 39], guid
[39];
664 hr
= CLSIDFromString(pszExtra
, &clsid
);
665 if (FAILED(hr
)) return hr
;
667 lstrcpyW(keypath
, L
"ShellEx\\");
668 lstrcatW(keypath
, pszExtra
);
669 ret
= RegOpenKeyExW(This
->hkeySource
, keypath
, 0, KEY_READ
, &hkey
);
670 if (ret
) return HRESULT_FROM_WIN32(ret
);
673 ret
= RegGetValueW(hkey
, NULL
, NULL
, RRF_RT_REG_SZ
, NULL
, guid
, &size
);
675 if (ret
) return HRESULT_FROM_WIN32(ret
);
677 return ASSOC_ReturnString(flags
, pszOut
, pcchOut
, guid
, size
/ sizeof(WCHAR
));
681 FIXME("assocstr %d unimplemented!\n", str
);
686 /**************************************************************************
687 * IQueryAssociations_GetKey
689 * Get a file association key from the registry.
692 * iface [I] IQueryAssociations interface to query
693 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
694 * assockey [I] Type of key to get (ASSOCKEY enum from "shlwapi.h")
695 * pszExtra [I] Extra information about the key location
696 * phkeyOut [O] Destination for the association key
699 * Success: S_OK. phkeyOut contains a handle to the key.
700 * Failure: An HRESULT error code indicating the error.
702 static HRESULT WINAPI
IQueryAssociations_fnGetKey(
703 IQueryAssociations
*iface
,
709 IQueryAssociationsImpl
*This
= impl_from_IQueryAssociations(iface
);
711 FIXME("(%p,0x%8lx,0x%8x,%s,%p)-stub!\n", This
, cfFlags
, assockey
,
712 debugstr_w(pszExtra
), phkeyOut
);
716 /**************************************************************************
717 * IQueryAssociations_GetData
719 * Get the data for a file association key from the registry.
722 * iface [I] IQueryAssociations interface to query
723 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
724 * assocdata [I] Type of data to get (ASSOCDATA enum from "shlwapi.h")
725 * pszExtra [I] Extra information about the data location
726 * pvOut [O] Destination for the association key
727 * pcbOut [I/O] Size of pvOut
730 * Success: S_OK. pszOut contains the data, pcbOut contains its length.
731 * Failure: An HRESULT error code indicating the error.
733 static HRESULT WINAPI
IQueryAssociations_fnGetData(IQueryAssociations
*iface
,
734 ASSOCF cfFlags
, ASSOCDATA assocdata
, LPCWSTR pszExtra
, LPVOID pvOut
,
737 IQueryAssociationsImpl
*This
= impl_from_IQueryAssociations(iface
);
742 TRACE("(%p,0x%8lx,0x%8x,%s,%p,%p)\n", This
, cfFlags
, assocdata
,
743 debugstr_w(pszExtra
), pvOut
, pcbOut
);
746 FIXME("Unsupported flags: %lx\n", cfFlags
);
749 case ASSOCDATA_EDITFLAGS
:
750 if(!This
->hkeyProgID
)
751 return HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION
);
753 hres
= ASSOC_GetValue(This
->hkeyProgID
, L
"EditFlags", &data
, &size
);
754 if(SUCCEEDED(hres
) && pcbOut
)
755 hres
= ASSOC_ReturnData(pvOut
, pcbOut
, data
, size
);
759 FIXME("Unsupported ASSOCDATA value: %d\n", assocdata
);
764 /**************************************************************************
765 * IQueryAssociations_GetEnum
767 * Not yet implemented in native Win32.
770 * iface [I] IQueryAssociations interface to query
771 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
772 * assocenum [I] Type of enum to get (ASSOCENUM enum from "shlwapi.h")
773 * pszExtra [I] Extra information about the enum location
774 * riid [I] REFIID to look for
775 * ppvOut [O] Destination for the interface.
779 * Failure: An HRESULT error code indicating the error.
782 * Presumably this function returns an enumerator object.
784 static HRESULT WINAPI
IQueryAssociations_fnGetEnum(
785 IQueryAssociations
*iface
,
792 IQueryAssociationsImpl
*This
= impl_from_IQueryAssociations(iface
);
794 FIXME("(%p,0x%8lx,0x%8x,%s,%s,%p)-stub!\n", This
, cfFlags
, assocenum
,
795 debugstr_w(pszExtra
), debugstr_guid(riid
), ppvOut
);
799 static const IQueryAssociationsVtbl IQueryAssociations_vtbl
=
801 IQueryAssociations_fnQueryInterface
,
802 IQueryAssociations_fnAddRef
,
803 IQueryAssociations_fnRelease
,
804 IQueryAssociations_fnInit
,
805 IQueryAssociations_fnGetString
,
806 IQueryAssociations_fnGetKey
,
807 IQueryAssociations_fnGetData
,
808 IQueryAssociations_fnGetEnum
811 /**************************************************************************
812 * IApplicationAssociationRegistration implementation
814 static inline IApplicationAssociationRegistrationImpl
*impl_from_IApplicationAssociationRegistration(IApplicationAssociationRegistration
*iface
)
816 return CONTAINING_RECORD(iface
, IApplicationAssociationRegistrationImpl
, IApplicationAssociationRegistration_iface
);
819 static HRESULT WINAPI
ApplicationAssociationRegistration_QueryInterface(
820 IApplicationAssociationRegistration
* iface
, REFIID riid
, LPVOID
*ppv
)
822 IApplicationAssociationRegistrationImpl
*This
= impl_from_IApplicationAssociationRegistration(iface
);
824 TRACE("(%p, %s, %p)\n",This
, debugstr_guid(riid
), ppv
);
829 if (IsEqualGUID(&IID_IUnknown
, riid
) ||
830 IsEqualGUID(&IID_IApplicationAssociationRegistration
, riid
)) {
831 *ppv
= &This
->IApplicationAssociationRegistration_iface
;
832 IUnknown_AddRef((IUnknown
*)*ppv
);
833 TRACE("returning IApplicationAssociationRegistration: %p\n", *ppv
);
838 FIXME("(%p)->(%s %p) interface not supported\n", This
, debugstr_guid(riid
), ppv
);
839 return E_NOINTERFACE
;
842 static ULONG WINAPI
ApplicationAssociationRegistration_AddRef(IApplicationAssociationRegistration
*iface
)
844 IApplicationAssociationRegistrationImpl
*This
= impl_from_IApplicationAssociationRegistration(iface
);
845 ULONG ref
= InterlockedIncrement(&This
->ref
);
847 TRACE("(%p) ref=%ld\n", This
, ref
);
851 static ULONG WINAPI
ApplicationAssociationRegistration_Release(IApplicationAssociationRegistration
*iface
)
853 IApplicationAssociationRegistrationImpl
*This
= impl_from_IApplicationAssociationRegistration(iface
);
854 ULONG ref
= InterlockedDecrement(&This
->ref
);
856 TRACE("(%p) ref=%ld\n", This
, ref
);
864 static HRESULT WINAPI
ApplicationAssociationRegistration_QueryCurrentDefault(IApplicationAssociationRegistration
*iface
, LPCWSTR query
,
865 ASSOCIATIONTYPE type
, ASSOCIATIONLEVEL level
, LPWSTR
*association
)
867 IApplicationAssociationRegistrationImpl
*This
= impl_from_IApplicationAssociationRegistration(iface
);
868 WCHAR path
[MAX_PATH
];
869 DWORD ret
, keytype
, size
;
871 HRESULT hr
= HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION
);
873 TRACE("(%p)->(%s, %d, %d, %p)\n", This
, debugstr_w(query
), type
, level
, association
);
880 if((type
== AT_URLPROTOCOL
|| type
== AT_FILEEXTENSION
) && !query
[0])
882 else if(type
== AT_FILEEXTENSION
&& query
[0] != '.')
885 if(type
== AT_FILEEXTENSION
)
887 ret
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, query
, 0, KEY_READ
, &hkey
);
888 if(ret
== ERROR_SUCCESS
)
890 ret
= RegGetValueW(hkey
, NULL
, NULL
, RRF_RT_REG_SZ
, &keytype
, NULL
, &size
);
891 if(ret
== ERROR_SUCCESS
)
893 *association
= CoTaskMemAlloc(size
);
896 ret
= RegGetValueW(hkey
, NULL
, NULL
, RRF_RT_REG_SZ
, &keytype
, *association
, &size
);
897 if(ret
== ERROR_SUCCESS
)
901 CoTaskMemFree(*association
);
912 ret
= RegOpenKeyExW(HKEY_CURRENT_USER
, L
"Software\\Microsoft\\Windows\\Shell\\Associations", 0, KEY_READ
, &hkey
);
913 if(ret
== ERROR_SUCCESS
)
915 if(type
== AT_URLPROTOCOL
)
916 swprintf( path
, ARRAY_SIZE(path
), L
"UrlAssociations\\%s\\UserChoice", query
);
917 else if(type
== AT_MIMETYPE
)
918 swprintf( path
, ARRAY_SIZE(path
), L
"MIMEAssociations\\%s\\UserChoice", query
);
921 WARN("Unsupported type (%d).\n", type
);
926 ret
= RegGetValueW(hkey
, path
, L
"Progid", RRF_RT_REG_SZ
, &keytype
, NULL
, &size
);
927 if(ret
== ERROR_SUCCESS
)
929 *association
= CoTaskMemAlloc(size
);
932 ret
= RegGetValueW(hkey
, path
, L
"Progid", RRF_RT_REG_SZ
, &keytype
, *association
, &size
);
933 if(ret
== ERROR_SUCCESS
)
937 CoTaskMemFree(*association
);
952 static HRESULT WINAPI
ApplicationAssociationRegistration_QueryAppIsDefault(IApplicationAssociationRegistration
* This
, LPCWSTR query
,
953 ASSOCIATIONTYPE type
, ASSOCIATIONLEVEL level
, LPCWSTR appname
, BOOL
*is_default
)
955 FIXME("(%p)->(%s, %d, %d, %s, %p)\n", This
, debugstr_w(query
), type
, level
, debugstr_w(appname
), is_default
);
959 static HRESULT WINAPI
ApplicationAssociationRegistration_QueryAppIsDefaultAll(IApplicationAssociationRegistration
* This
, ASSOCIATIONLEVEL level
,
960 LPCWSTR appname
, BOOL
*is_default
)
962 FIXME("(%p)->(%d, %s, %p)\n", This
, level
, debugstr_w(appname
), is_default
);
966 static HRESULT WINAPI
ApplicationAssociationRegistration_SetAppAsDefault(IApplicationAssociationRegistration
* This
, LPCWSTR appname
,
967 LPCWSTR set
, ASSOCIATIONTYPE set_type
)
969 FIXME("(%p)->(%s, %s, %d)\n", This
, debugstr_w(appname
), debugstr_w(set
), set_type
);
973 static HRESULT WINAPI
ApplicationAssociationRegistration_SetAppAsDefaultAll(IApplicationAssociationRegistration
* This
, LPCWSTR appname
)
975 FIXME("(%p)->(%s)\n", This
, debugstr_w(appname
));
980 static HRESULT WINAPI
ApplicationAssociationRegistration_ClearUserAssociations(IApplicationAssociationRegistration
* This
)
982 FIXME("(%p)\n", This
);
987 static const IApplicationAssociationRegistrationVtbl IApplicationAssociationRegistration_vtbl
=
989 ApplicationAssociationRegistration_QueryInterface
,
990 ApplicationAssociationRegistration_AddRef
,
991 ApplicationAssociationRegistration_Release
,
992 ApplicationAssociationRegistration_QueryCurrentDefault
,
993 ApplicationAssociationRegistration_QueryAppIsDefault
,
994 ApplicationAssociationRegistration_QueryAppIsDefaultAll
,
995 ApplicationAssociationRegistration_SetAppAsDefault
,
996 ApplicationAssociationRegistration_SetAppAsDefaultAll
,
997 ApplicationAssociationRegistration_ClearUserAssociations
1000 /**************************************************************************
1001 * IQueryAssociations_Constructor [internal]
1003 * Construct a new IQueryAssociations object.
1005 HRESULT WINAPI
QueryAssociations_Constructor(IUnknown
*pUnkOuter
, REFIID riid
, LPVOID
*ppOutput
)
1007 IQueryAssociationsImpl
* this;
1010 if (pUnkOuter
) return CLASS_E_NOAGGREGATION
;
1012 if (!(this = SHAlloc(sizeof(*this)))) return E_OUTOFMEMORY
;
1013 this->IQueryAssociations_iface
.lpVtbl
= &IQueryAssociations_vtbl
;
1015 this->hkeySource
= 0;
1016 this->hkeyProgID
= 0;
1017 if (FAILED(ret
= IQueryAssociations_QueryInterface(&this->IQueryAssociations_iface
, riid
, ppOutput
))) SHFree( this );
1018 TRACE("returning %p\n", *ppOutput
);
1022 /**************************************************************************
1023 * ApplicationAssociationRegistration_Constructor [internal]
1025 * Construct a IApplicationAssociationRegistration object.
1027 HRESULT WINAPI
ApplicationAssociationRegistration_Constructor(IUnknown
*outer
, REFIID riid
, LPVOID
*ppv
)
1029 IApplicationAssociationRegistrationImpl
*This
;
1033 return CLASS_E_NOAGGREGATION
;
1035 if (!(This
= SHAlloc(sizeof(*This
))))
1036 return E_OUTOFMEMORY
;
1038 This
->IApplicationAssociationRegistration_iface
.lpVtbl
= &IApplicationAssociationRegistration_vtbl
;
1041 hr
= IApplicationAssociationRegistration_QueryInterface(&This
->IApplicationAssociationRegistration_iface
, riid
, ppv
);
1045 TRACE("returning 0x%lx with %p\n", hr
, *ppv
);
1049 static HRESULT WINAPI
enumassochandlers_QueryInterface(IEnumAssocHandlers
*iface
, REFIID riid
, void **obj
)
1051 struct enumassochandlers
*This
= impl_from_IEnumAssocHandlers(iface
);
1053 TRACE("(%p %s %p)\n", This
, debugstr_guid(riid
), obj
);
1055 if (IsEqualIID(riid
, &IID_IEnumAssocHandlers
) ||
1056 IsEqualIID(riid
, &IID_IUnknown
))
1059 IEnumAssocHandlers_AddRef(iface
);
1064 return E_NOINTERFACE
;
1067 static ULONG WINAPI
enumassochandlers_AddRef(IEnumAssocHandlers
*iface
)
1069 struct enumassochandlers
*This
= impl_from_IEnumAssocHandlers(iface
);
1070 ULONG ref
= InterlockedIncrement(&This
->ref
);
1072 TRACE("(%p)->(%lu)\n", This
, ref
);
1076 static ULONG WINAPI
enumassochandlers_Release(IEnumAssocHandlers
*iface
)
1078 struct enumassochandlers
*This
= impl_from_IEnumAssocHandlers(iface
);
1079 ULONG ref
= InterlockedDecrement(&This
->ref
);
1081 TRACE("(%p)->(%lu)\n", This
, ref
);
1089 static HRESULT WINAPI
enumassochandlers_Next(IEnumAssocHandlers
*iface
, ULONG count
, IAssocHandler
**handlers
,
1092 struct enumassochandlers
*This
= impl_from_IEnumAssocHandlers(iface
);
1094 FIXME("(%p)->(%lu %p %p): stub\n", This
, count
, handlers
, fetched
);
1099 static const IEnumAssocHandlersVtbl enumassochandlersvtbl
= {
1100 enumassochandlers_QueryInterface
,
1101 enumassochandlers_AddRef
,
1102 enumassochandlers_Release
,
1103 enumassochandlers_Next
1106 /**************************************************************************
1107 * SHCreateAssociationRegistration [SHELL32.@]
1109 HRESULT WINAPI
SHCreateAssociationRegistration(REFIID riid
, LPVOID
*ppv
)
1111 return ApplicationAssociationRegistration_Constructor(NULL
, riid
, ppv
);
1114 /**************************************************************************
1115 * SHAssocEnumHandlers [SHELL32.@]
1117 HRESULT WINAPI
SHAssocEnumHandlers(const WCHAR
*extra
, ASSOC_FILTER filter
, IEnumAssocHandlers
**enumhandlers
)
1119 struct enumassochandlers
*enumassoc
;
1121 FIXME("(%s %d %p): stub\n", debugstr_w(extra
), filter
, enumhandlers
);
1123 *enumhandlers
= NULL
;
1125 enumassoc
= SHAlloc(sizeof(*enumassoc
));
1127 return E_OUTOFMEMORY
;
1129 enumassoc
->IEnumAssocHandlers_iface
.lpVtbl
= &enumassochandlersvtbl
;
1132 *enumhandlers
= &enumassoc
->IEnumAssocHandlers_iface
;