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 /**************************************************************************
92 * IQueryAssociations_QueryInterface
94 * See IUnknown_QueryInterface.
96 static HRESULT WINAPI
IQueryAssociations_fnQueryInterface(
97 IQueryAssociations
* iface
,
101 IQueryAssociationsImpl
*This
= impl_from_IQueryAssociations(iface
);
103 TRACE("(%p,%s,%p)\n",This
, debugstr_guid(riid
), ppvObj
);
110 if (IsEqualIID(riid
, &IID_IUnknown
) ||
111 IsEqualIID(riid
, &IID_IQueryAssociations
))
113 *ppvObj
= &This
->IQueryAssociations_iface
;
115 IQueryAssociations_AddRef((IQueryAssociations
*)*ppvObj
);
116 TRACE("Returning IQueryAssociations (%p)\n", *ppvObj
);
119 TRACE("Returning E_NOINTERFACE\n");
120 return E_NOINTERFACE
;
123 /**************************************************************************
124 * IQueryAssociations_AddRef
126 * See IUnknown_AddRef.
128 static ULONG WINAPI
IQueryAssociations_fnAddRef(IQueryAssociations
*iface
)
130 IQueryAssociationsImpl
*This
= impl_from_IQueryAssociations(iface
);
131 ULONG refCount
= InterlockedIncrement(&This
->ref
);
133 TRACE("(%p)->(ref before=%u)\n",This
, refCount
- 1);
138 /**************************************************************************
139 * IQueryAssociations_Release
141 * See IUnknown_Release.
143 static ULONG WINAPI
IQueryAssociations_fnRelease(IQueryAssociations
*iface
)
145 IQueryAssociationsImpl
*This
= impl_from_IQueryAssociations(iface
);
146 ULONG refCount
= InterlockedDecrement(&This
->ref
);
148 TRACE("(%p)->(ref before=%u)\n",This
, refCount
+ 1);
152 TRACE("Destroying IQueryAssociations (%p)\n", This
);
153 RegCloseKey(This
->hkeySource
);
154 RegCloseKey(This
->hkeyProgID
);
161 /**************************************************************************
162 * IQueryAssociations_Init
164 * Initialise an IQueryAssociations object.
167 * iface [I] IQueryAssociations interface to initialise
168 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
169 * pszAssoc [I] String for the root key name, or NULL if hkeyProgid is given
170 * hkeyProgid [I] Handle for the root key, or NULL if pszAssoc is given
171 * hWnd [I] Reserved, must be NULL.
174 * Success: S_OK. iface is initialised with the parameters given.
175 * Failure: An HRESULT error code indicating the error.
177 static HRESULT WINAPI
IQueryAssociations_fnInit(
178 IQueryAssociations
*iface
,
184 static const WCHAR szProgID
[] = {'P','r','o','g','I','D',0};
185 IQueryAssociationsImpl
*This
= impl_from_IQueryAssociations(iface
);
188 TRACE("(%p)->(%d,%s,%p,%p)\n", iface
,
190 debugstr_w(pszAssoc
),
194 FIXME("hwnd != NULL not supported\n");
196 FIXME("unsupported flags: %x\n", cfFlags
);
198 RegCloseKey(This
->hkeySource
);
199 RegCloseKey(This
->hkeyProgID
);
200 This
->hkeySource
= This
->hkeyProgID
= NULL
;
201 if (pszAssoc
!= NULL
)
203 ret
= RegOpenKeyExW(HKEY_CLASSES_ROOT
,
210 /* if this is not a prog id */
211 if ((*pszAssoc
== '.') || (*pszAssoc
== '{'))
213 RegOpenKeyExW(This
->hkeySource
,
220 This
->hkeyProgID
= This
->hkeySource
;
223 else if (hkeyProgid
!= NULL
)
225 This
->hkeyProgID
= hkeyProgid
;
232 static HRESULT
ASSOC_GetValue(HKEY hkey
, const WCHAR
*name
, void **data
, DWORD
*data_size
)
237 ret
= RegQueryValueExW(hkey
, name
, 0, NULL
, NULL
, &size
);
238 if (ret
!= ERROR_SUCCESS
)
239 return HRESULT_FROM_WIN32(ret
);
242 *data
= HeapAlloc(GetProcessHeap(), 0, size
);
244 return E_OUTOFMEMORY
;
245 ret
= RegQueryValueExW(hkey
, name
, 0, NULL
, (LPBYTE
)*data
, &size
);
246 if (ret
!= ERROR_SUCCESS
)
248 HeapFree(GetProcessHeap(), 0, *data
);
249 return HRESULT_FROM_WIN32(ret
);
256 static HRESULT
ASSOC_GetCommand(IQueryAssociationsImpl
*This
, const WCHAR
*extra
, WCHAR
**command
)
263 WCHAR
*extra_from_reg
= NULL
;
265 static const WCHAR commandW
[] = { 'c','o','m','m','a','n','d',0 };
266 static const WCHAR shellW
[] = { 's','h','e','l','l',0 };
268 /* When looking for file extension it's possible to have a default value
269 that points to another key that contains 'shell/<verb>/command' subtree. */
270 hr
= ASSOC_GetValue(This
->hkeySource
, NULL
, (void**)&filetype
, NULL
);
275 ret
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, filetype
, 0, KEY_READ
, &hkeyFile
);
276 HeapFree(GetProcessHeap(), 0, filetype
);
278 if (ret
== ERROR_SUCCESS
)
280 ret
= RegOpenKeyExW(hkeyFile
, shellW
, 0, KEY_READ
, &hkeyShell
);
281 RegCloseKey(hkeyFile
);
284 ret
= RegOpenKeyExW(This
->hkeySource
, shellW
, 0, KEY_READ
, &hkeyShell
);
287 ret
= RegOpenKeyExW(This
->hkeySource
, shellW
, 0, KEY_READ
, &hkeyShell
);
289 if (ret
) return HRESULT_FROM_WIN32(ret
);
293 /* check for default verb */
294 hr
= ASSOC_GetValue(hkeyShell
, NULL
, (void**)&extra_from_reg
, NULL
);
297 /* no default verb, try first subkey */
298 DWORD max_subkey_len
;
300 ret
= RegQueryInfoKeyW(hkeyShell
, NULL
, NULL
, NULL
, NULL
, &max_subkey_len
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
303 RegCloseKey(hkeyShell
);
304 return HRESULT_FROM_WIN32(ret
);
308 extra_from_reg
= HeapAlloc(GetProcessHeap(), 0, max_subkey_len
* sizeof(WCHAR
));
311 RegCloseKey(hkeyShell
);
312 return E_OUTOFMEMORY
;
315 ret
= RegEnumKeyExW(hkeyShell
, 0, extra_from_reg
, &max_subkey_len
, NULL
, NULL
, NULL
, NULL
);
318 HeapFree(GetProcessHeap(), 0, extra_from_reg
);
319 RegCloseKey(hkeyShell
);
320 return HRESULT_FROM_WIN32(ret
);
323 extra
= extra_from_reg
;
326 /* open verb subkey */
327 ret
= RegOpenKeyExW(hkeyShell
, extra
, 0, KEY_READ
, &hkeyVerb
);
328 HeapFree(GetProcessHeap(), 0, extra_from_reg
);
329 RegCloseKey(hkeyShell
);
330 if (ret
) return HRESULT_FROM_WIN32(ret
);
332 /* open command subkey */
333 ret
= RegOpenKeyExW(hkeyVerb
, commandW
, 0, KEY_READ
, &hkeyCommand
);
334 RegCloseKey(hkeyVerb
);
335 if (ret
) return HRESULT_FROM_WIN32(ret
);
337 hr
= ASSOC_GetValue(hkeyCommand
, NULL
, (void**)command
, NULL
);
338 RegCloseKey(hkeyCommand
);
342 static HRESULT
ASSOC_GetExecutable(IQueryAssociationsImpl
*This
,
343 LPCWSTR pszExtra
, LPWSTR path
,
344 DWORD pathlen
, DWORD
*len
)
351 hr
= ASSOC_GetCommand(This
, pszExtra
, &pszCommand
);
355 /* cleanup pszCommand */
356 if (pszCommand
[0] == '"')
358 pszStart
= pszCommand
+ 1;
359 pszEnd
= strchrW(pszStart
, '"');
362 *len
= SearchPathW(NULL
, pszStart
, NULL
, pathlen
, path
, NULL
);
366 pszStart
= pszCommand
;
367 for (pszEnd
= pszStart
; (pszEnd
= strchrW(pszEnd
, ' ')); pszEnd
++)
371 if ((*len
= SearchPathW(NULL
, pszStart
, NULL
, pathlen
, path
, NULL
)))
376 *len
= SearchPathW(NULL
, pszStart
, NULL
, pathlen
, path
, NULL
);
379 HeapFree(GetProcessHeap(), 0, pszCommand
);
381 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
385 static HRESULT
ASSOC_ReturnData(void *out
, DWORD
*outlen
, const void *data
,
390 if (*outlen
< datalen
)
396 memcpy(out
, data
, datalen
);
406 static HRESULT
ASSOC_ReturnString(ASSOCF flags
, LPWSTR out
, DWORD
*outlen
, LPCWSTR data
, DWORD datalen
)
411 TRACE("flags=0x%08x, data=%s\n", flags
, debugstr_w(data
));
419 if (*outlen
< datalen
)
421 if (flags
& ASSOCF_NOTRUNCATE
)
424 if (*outlen
> 0) out
[0] = 0;
429 len
= min(*outlen
, datalen
);
430 hr
= E_NOT_SUFFICIENT_BUFFER
;
438 memcpy(out
, data
, len
*sizeof(WCHAR
));
443 /**************************************************************************
444 * IQueryAssociations_GetString
446 * Get a file association string from the registry.
449 * iface [I] IQueryAssociations interface to query
450 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
451 * str [I] Type of string to get (ASSOCSTR enum from "shlwapi.h")
452 * pszExtra [I] Extra information about the string location
453 * pszOut [O] Destination for the association string
454 * pcchOut [I/O] Length of pszOut
457 * Success: S_OK. pszOut contains the string, pcchOut contains its length.
458 * Failure: An HRESULT error code indicating the error.
460 static HRESULT WINAPI
IQueryAssociations_fnGetString(
461 IQueryAssociations
*iface
,
468 IQueryAssociationsImpl
*This
= impl_from_IQueryAssociations(iface
);
469 const ASSOCF unimplemented_flags
= ~ASSOCF_NOTRUNCATE
;
472 WCHAR path
[MAX_PATH
];
474 TRACE("(%p)->(0x%08x, %u, %s, %p, %p)\n", This
, flags
, str
, debugstr_w(pszExtra
), pszOut
, pcchOut
);
476 if (flags
& unimplemented_flags
)
477 FIXME("%08x: unimplemented flags\n", flags
& unimplemented_flags
);
482 if (!This
->hkeySource
&& !This
->hkeyProgID
)
483 return HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION
);
487 case ASSOCSTR_COMMAND
:
490 hr
= ASSOC_GetCommand(This
, pszExtra
, &command
);
493 hr
= ASSOC_ReturnString(flags
, pszOut
, pcchOut
, command
, strlenW(command
) + 1);
494 HeapFree(GetProcessHeap(), 0, command
);
499 case ASSOCSTR_EXECUTABLE
:
501 hr
= ASSOC_GetExecutable(This
, pszExtra
, path
, MAX_PATH
, &len
);
505 return ASSOC_ReturnString(flags
, pszOut
, pcchOut
, path
, len
);
508 case ASSOCSTR_FRIENDLYDOCNAME
:
514 hr
= ASSOC_GetValue(This
->hkeySource
, NULL
, (void**)&pszFileType
, NULL
);
518 ret
= RegGetValueW(HKEY_CLASSES_ROOT
, pszFileType
, NULL
, RRF_RT_REG_SZ
, NULL
, NULL
, &size
);
519 if (ret
== ERROR_SUCCESS
)
521 WCHAR
*docName
= HeapAlloc(GetProcessHeap(), 0, size
);
524 ret
= RegGetValueW(HKEY_CLASSES_ROOT
, pszFileType
, NULL
, RRF_RT_REG_SZ
, NULL
, docName
, &size
);
525 if (ret
== ERROR_SUCCESS
)
526 hr
= ASSOC_ReturnString(flags
, pszOut
, pcchOut
, docName
, strlenW(docName
) + 1);
528 hr
= HRESULT_FROM_WIN32(ret
);
529 HeapFree(GetProcessHeap(), 0, docName
);
535 hr
= HRESULT_FROM_WIN32(ret
);
536 HeapFree(GetProcessHeap(), 0, pszFileType
);
540 case ASSOCSTR_FRIENDLYAPPNAME
:
542 PVOID verinfoW
= NULL
;
543 DWORD size
, retval
= 0;
546 static const WCHAR translationW
[] = {
547 '\\','V','a','r','F','i','l','e','I','n','f','o',
548 '\\','T','r','a','n','s','l','a','t','i','o','n',0
550 static const WCHAR fileDescFmtW
[] = {
551 '\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o',
552 '\\','%','0','4','x','%','0','4','x',
553 '\\','F','i','l','e','D','e','s','c','r','i','p','t','i','o','n',0
557 hr
= ASSOC_GetExecutable(This
, pszExtra
, path
, MAX_PATH
, &len
);
561 retval
= GetFileVersionInfoSizeW(path
, &size
);
563 goto get_friendly_name_fail
;
564 verinfoW
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, retval
);
566 return E_OUTOFMEMORY
;
567 if (!GetFileVersionInfoW(path
, 0, retval
, verinfoW
))
568 goto get_friendly_name_fail
;
569 if (VerQueryValueW(verinfoW
, translationW
, (LPVOID
*)&bufW
, &flen
))
572 DWORD
*langCodeDesc
= (DWORD
*)bufW
;
573 for (i
= 0; i
< flen
/ sizeof(DWORD
); i
++)
575 sprintfW(fileDescW
, fileDescFmtW
, LOWORD(langCodeDesc
[i
]),
576 HIWORD(langCodeDesc
[i
]));
577 if (VerQueryValueW(verinfoW
, fileDescW
, (LPVOID
*)&bufW
, &flen
))
579 /* Does strlenW(bufW) == 0 mean we use the filename? */
580 len
= strlenW(bufW
) + 1;
581 TRACE("found FileDescription: %s\n", debugstr_w(bufW
));
582 hr
= ASSOC_ReturnString(flags
, pszOut
, pcchOut
, bufW
, len
);
583 HeapFree(GetProcessHeap(), 0, verinfoW
);
588 get_friendly_name_fail
:
589 PathRemoveExtensionW(path
);
590 PathStripPathW(path
);
591 TRACE("using filename: %s\n", debugstr_w(path
));
592 hr
= ASSOC_ReturnString(flags
, pszOut
, pcchOut
, path
, strlenW(path
) + 1);
593 HeapFree(GetProcessHeap(), 0, verinfoW
);
597 case ASSOCSTR_CONTENTTYPE
:
599 static const WCHAR Content_TypeW
[] = {'C','o','n','t','e','n','t',' ','T','y','p','e',0};
605 ret
= RegGetValueW(This
->hkeySource
, NULL
, Content_TypeW
, RRF_RT_REG_SZ
, NULL
, NULL
, &size
);
606 if (ret
!= ERROR_SUCCESS
)
607 return HRESULT_FROM_WIN32(ret
);
608 contentType
= HeapAlloc(GetProcessHeap(), 0, size
);
609 if (contentType
!= NULL
)
611 ret
= RegGetValueW(This
->hkeySource
, NULL
, Content_TypeW
, RRF_RT_REG_SZ
, NULL
, contentType
, &size
);
612 if (ret
== ERROR_SUCCESS
)
613 hr
= ASSOC_ReturnString(flags
, pszOut
, pcchOut
, contentType
, strlenW(contentType
) + 1);
615 hr
= HRESULT_FROM_WIN32(ret
);
616 HeapFree(GetProcessHeap(), 0, contentType
);
623 case ASSOCSTR_DEFAULTICON
:
625 static const WCHAR DefaultIconW
[] = {'D','e','f','a','u','l','t','I','c','o','n',0};
631 hr
= ASSOC_GetValue(This
->hkeySource
, NULL
, (void**)&pszFileType
, NULL
);
634 ret
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, pszFileType
, 0, KEY_READ
, &hkeyFile
);
635 if (ret
== ERROR_SUCCESS
)
638 ret
= RegGetValueW(hkeyFile
, DefaultIconW
, NULL
, RRF_RT_REG_SZ
, NULL
, NULL
, &size
);
639 if (ret
== ERROR_SUCCESS
)
641 WCHAR
*icon
= HeapAlloc(GetProcessHeap(), 0, size
);
644 ret
= RegGetValueW(hkeyFile
, DefaultIconW
, NULL
, RRF_RT_REG_SZ
, NULL
, icon
, &size
);
645 if (ret
== ERROR_SUCCESS
)
646 hr
= ASSOC_ReturnString(flags
, pszOut
, pcchOut
, icon
, strlenW(icon
) + 1);
648 hr
= HRESULT_FROM_WIN32(ret
);
649 HeapFree(GetProcessHeap(), 0, icon
);
655 hr
= HRESULT_FROM_WIN32(ret
);
656 RegCloseKey(hkeyFile
);
659 hr
= HRESULT_FROM_WIN32(ret
);
660 HeapFree(GetProcessHeap(), 0, pszFileType
);
663 case ASSOCSTR_SHELLEXTENSION
:
665 static const WCHAR shellexW
[] = {'S','h','e','l','l','E','x','\\',0};
666 WCHAR keypath
[sizeof(shellexW
) / sizeof(shellexW
[0]) + 39], guid
[39];
672 hr
= CLSIDFromString(pszExtra
, &clsid
);
673 if (FAILED(hr
)) return hr
;
675 strcpyW(keypath
, shellexW
);
676 strcatW(keypath
, pszExtra
);
677 ret
= RegOpenKeyExW(This
->hkeySource
, keypath
, 0, KEY_READ
, &hkey
);
678 if (ret
) return HRESULT_FROM_WIN32(ret
);
681 ret
= RegGetValueW(hkey
, NULL
, NULL
, RRF_RT_REG_SZ
, NULL
, guid
, &size
);
683 if (ret
) return HRESULT_FROM_WIN32(ret
);
685 return ASSOC_ReturnString(flags
, pszOut
, pcchOut
, guid
, size
/ sizeof(WCHAR
));
689 FIXME("assocstr %d unimplemented!\n", str
);
694 /**************************************************************************
695 * IQueryAssociations_GetKey
697 * Get a file association key from the registry.
700 * iface [I] IQueryAssociations interface to query
701 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
702 * assockey [I] Type of key to get (ASSOCKEY enum from "shlwapi.h")
703 * pszExtra [I] Extra information about the key location
704 * phkeyOut [O] Destination for the association key
707 * Success: S_OK. phkeyOut contains a handle to the key.
708 * Failure: An HRESULT error code indicating the error.
710 static HRESULT WINAPI
IQueryAssociations_fnGetKey(
711 IQueryAssociations
*iface
,
717 IQueryAssociationsImpl
*This
= impl_from_IQueryAssociations(iface
);
719 FIXME("(%p,0x%8x,0x%8x,%s,%p)-stub!\n", This
, cfFlags
, assockey
,
720 debugstr_w(pszExtra
), phkeyOut
);
724 /**************************************************************************
725 * IQueryAssociations_GetData
727 * Get the data for a file association key from the registry.
730 * iface [I] IQueryAssociations interface to query
731 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
732 * assocdata [I] Type of data to get (ASSOCDATA enum from "shlwapi.h")
733 * pszExtra [I] Extra information about the data location
734 * pvOut [O] Destination for the association key
735 * pcbOut [I/O] Size of pvOut
738 * Success: S_OK. pszOut contains the data, pcbOut contains its length.
739 * Failure: An HRESULT error code indicating the error.
741 static HRESULT WINAPI
IQueryAssociations_fnGetData(IQueryAssociations
*iface
,
742 ASSOCF cfFlags
, ASSOCDATA assocdata
, LPCWSTR pszExtra
, LPVOID pvOut
,
745 static const WCHAR edit_flags
[] = {'E','d','i','t','F','l','a','g','s',0};
747 IQueryAssociationsImpl
*This
= impl_from_IQueryAssociations(iface
);
752 TRACE("(%p,0x%8x,0x%8x,%s,%p,%p)\n", This
, cfFlags
, assocdata
,
753 debugstr_w(pszExtra
), pvOut
, pcbOut
);
756 FIXME("Unsupported flags: %x\n", cfFlags
);
759 case ASSOCDATA_EDITFLAGS
:
760 if(!This
->hkeyProgID
)
761 return HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION
);
763 hres
= ASSOC_GetValue(This
->hkeyProgID
, edit_flags
, &data
, &size
);
764 if(FAILED(hres
) || !pcbOut
)
767 hres
= ASSOC_ReturnData(pvOut
, pcbOut
, data
, size
);
768 HeapFree(GetProcessHeap(), 0, data
);
771 FIXME("Unsupported ASSOCDATA value: %d\n", assocdata
);
776 /**************************************************************************
777 * IQueryAssociations_GetEnum
779 * Not yet implemented in native Win32.
782 * iface [I] IQueryAssociations interface to query
783 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
784 * assocenum [I] Type of enum to get (ASSOCENUM enum from "shlwapi.h")
785 * pszExtra [I] Extra information about the enum location
786 * riid [I] REFIID to look for
787 * ppvOut [O] Destination for the interface.
791 * Failure: An HRESULT error code indicating the error.
794 * Presumably this function returns an enumerator object.
796 static HRESULT WINAPI
IQueryAssociations_fnGetEnum(
797 IQueryAssociations
*iface
,
804 IQueryAssociationsImpl
*This
= impl_from_IQueryAssociations(iface
);
806 FIXME("(%p,0x%8x,0x%8x,%s,%s,%p)-stub!\n", This
, cfFlags
, assocenum
,
807 debugstr_w(pszExtra
), debugstr_guid(riid
), ppvOut
);
811 static const IQueryAssociationsVtbl IQueryAssociations_vtbl
=
813 IQueryAssociations_fnQueryInterface
,
814 IQueryAssociations_fnAddRef
,
815 IQueryAssociations_fnRelease
,
816 IQueryAssociations_fnInit
,
817 IQueryAssociations_fnGetString
,
818 IQueryAssociations_fnGetKey
,
819 IQueryAssociations_fnGetData
,
820 IQueryAssociations_fnGetEnum
823 /**************************************************************************
824 * IApplicationAssociationRegistration implementation
826 static inline IApplicationAssociationRegistrationImpl
*impl_from_IApplicationAssociationRegistration(IApplicationAssociationRegistration
*iface
)
828 return CONTAINING_RECORD(iface
, IApplicationAssociationRegistrationImpl
, IApplicationAssociationRegistration_iface
);
831 static HRESULT WINAPI
ApplicationAssociationRegistration_QueryInterface(
832 IApplicationAssociationRegistration
* iface
, REFIID riid
, LPVOID
*ppv
)
834 IApplicationAssociationRegistrationImpl
*This
= impl_from_IApplicationAssociationRegistration(iface
);
836 TRACE("(%p, %s, %p)\n",This
, debugstr_guid(riid
), ppv
);
841 if (IsEqualGUID(&IID_IUnknown
, riid
) ||
842 IsEqualGUID(&IID_IApplicationAssociationRegistration
, riid
)) {
843 *ppv
= &This
->IApplicationAssociationRegistration_iface
;
844 IUnknown_AddRef((IUnknown
*)*ppv
);
845 TRACE("returning IApplicationAssociationRegistration: %p\n", *ppv
);
850 FIXME("(%p)->(%s %p) interface not supported\n", This
, debugstr_guid(riid
), ppv
);
851 return E_NOINTERFACE
;
854 static ULONG WINAPI
ApplicationAssociationRegistration_AddRef(IApplicationAssociationRegistration
*iface
)
856 IApplicationAssociationRegistrationImpl
*This
= impl_from_IApplicationAssociationRegistration(iface
);
857 ULONG ref
= InterlockedIncrement(&This
->ref
);
859 TRACE("(%p) ref=%d\n", This
, ref
);
863 static ULONG WINAPI
ApplicationAssociationRegistration_Release(IApplicationAssociationRegistration
*iface
)
865 IApplicationAssociationRegistrationImpl
*This
= impl_from_IApplicationAssociationRegistration(iface
);
866 ULONG ref
= InterlockedDecrement(&This
->ref
);
868 TRACE("(%p) ref=%d\n", This
, ref
);
876 static HRESULT WINAPI
ApplicationAssociationRegistration_QueryCurrentDefault(IApplicationAssociationRegistration
*iface
, LPCWSTR query
,
877 ASSOCIATIONTYPE type
, ASSOCIATIONLEVEL level
, LPWSTR
*association
)
879 IApplicationAssociationRegistrationImpl
*This
= impl_from_IApplicationAssociationRegistration(iface
);
880 static WCHAR urlassoc
[] = {'U','r','l','A','s','s','o','c','i','a','t','i','o','n','s',0};
881 static WCHAR mimeassoc
[] = {'M','I','M','E','A','s','s','o','c','i','a','t','i','o','n','s',0};
882 static WCHAR assocations
[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
883 'W','i','n','d','o','w','s','\\','S','h','e','l','l','\\',
884 'A','s','s','o','c','i','a','t','i','o','n','s',0};
885 static WCHAR slash
[] = {'\\',0};
886 static WCHAR choice
[] = {'U','s','e','r','C','h','o','i','c','e',0};
887 static WCHAR propid
[] = {'P','r','o','g','i','d',0};
888 WCHAR path
[MAX_PATH
] = {0};
889 DWORD ret
, keytype
, size
;
891 HRESULT hr
= HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION
);
893 TRACE("(%p)->(%s, %d, %d, %p)\n", This
, debugstr_w(query
), type
, level
, association
);
900 if((type
== AT_URLPROTOCOL
|| type
== AT_FILEEXTENSION
) && !query
[0])
902 else if(type
== AT_FILEEXTENSION
&& query
[0] != '.')
905 if(type
== AT_FILEEXTENSION
)
907 ret
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, query
, 0, KEY_READ
, &hkey
);
908 if(ret
== ERROR_SUCCESS
)
910 ret
= RegGetValueW(hkey
, NULL
, NULL
, RRF_RT_REG_SZ
, &keytype
, NULL
, &size
);
911 if(ret
== ERROR_SUCCESS
)
913 *association
= CoTaskMemAlloc(size
);
916 ret
= RegGetValueW(hkey
, NULL
, NULL
, RRF_RT_REG_SZ
, &keytype
, *association
, &size
);
917 if(ret
== ERROR_SUCCESS
)
921 CoTaskMemFree(*association
);
932 ret
= RegOpenKeyExW(HKEY_CURRENT_USER
, assocations
, 0, KEY_READ
, &hkey
);
933 if(ret
== ERROR_SUCCESS
)
935 if(type
== AT_URLPROTOCOL
)
936 lstrcpyW(path
, urlassoc
);
937 else if(type
== AT_MIMETYPE
)
938 lstrcpyW(path
, mimeassoc
);
941 WARN("Unsupported type (%d).\n", type
);
946 lstrcatW(path
, slash
);
947 lstrcatW(path
, query
);
948 lstrcatW(path
, slash
);
949 lstrcatW(path
, choice
);
951 ret
= RegGetValueW(hkey
, path
, propid
, RRF_RT_REG_SZ
, &keytype
, NULL
, &size
);
952 if(ret
== ERROR_SUCCESS
)
954 *association
= CoTaskMemAlloc(size
);
957 ret
= RegGetValueW(hkey
, path
, propid
, RRF_RT_REG_SZ
, &keytype
, *association
, &size
);
958 if(ret
== ERROR_SUCCESS
)
962 CoTaskMemFree(*association
);
977 static HRESULT WINAPI
ApplicationAssociationRegistration_QueryAppIsDefault(IApplicationAssociationRegistration
* This
, LPCWSTR query
,
978 ASSOCIATIONTYPE type
, ASSOCIATIONLEVEL level
, LPCWSTR appname
, BOOL
*is_default
)
980 FIXME("(%p)->(%s, %d, %d, %s, %p)\n", This
, debugstr_w(query
), type
, level
, debugstr_w(appname
), is_default
);
984 static HRESULT WINAPI
ApplicationAssociationRegistration_QueryAppIsDefaultAll(IApplicationAssociationRegistration
* This
, ASSOCIATIONLEVEL level
,
985 LPCWSTR appname
, BOOL
*is_default
)
987 FIXME("(%p)->(%d, %s, %p)\n", This
, level
, debugstr_w(appname
), is_default
);
991 static HRESULT WINAPI
ApplicationAssociationRegistration_SetAppAsDefault(IApplicationAssociationRegistration
* This
, LPCWSTR appname
,
992 LPCWSTR set
, ASSOCIATIONTYPE set_type
)
994 FIXME("(%p)->(%s, %s, %d)\n", This
, debugstr_w(appname
), debugstr_w(set
), set_type
);
998 static HRESULT WINAPI
ApplicationAssociationRegistration_SetAppAsDefaultAll(IApplicationAssociationRegistration
* This
, LPCWSTR appname
)
1000 FIXME("(%p)->(%s)\n", This
, debugstr_w(appname
));
1005 static HRESULT WINAPI
ApplicationAssociationRegistration_ClearUserAssociations(IApplicationAssociationRegistration
* This
)
1007 FIXME("(%p)\n", This
);
1012 static const IApplicationAssociationRegistrationVtbl IApplicationAssociationRegistration_vtbl
=
1014 ApplicationAssociationRegistration_QueryInterface
,
1015 ApplicationAssociationRegistration_AddRef
,
1016 ApplicationAssociationRegistration_Release
,
1017 ApplicationAssociationRegistration_QueryCurrentDefault
,
1018 ApplicationAssociationRegistration_QueryAppIsDefault
,
1019 ApplicationAssociationRegistration_QueryAppIsDefaultAll
,
1020 ApplicationAssociationRegistration_SetAppAsDefault
,
1021 ApplicationAssociationRegistration_SetAppAsDefaultAll
,
1022 ApplicationAssociationRegistration_ClearUserAssociations
1025 /**************************************************************************
1026 * IQueryAssociations_Constructor [internal]
1028 * Construct a new IQueryAssociations object.
1030 HRESULT WINAPI
QueryAssociations_Constructor(IUnknown
*pUnkOuter
, REFIID riid
, LPVOID
*ppOutput
)
1032 IQueryAssociationsImpl
* this;
1035 if (pUnkOuter
) return CLASS_E_NOAGGREGATION
;
1037 if (!(this = SHAlloc(sizeof(*this)))) return E_OUTOFMEMORY
;
1038 this->IQueryAssociations_iface
.lpVtbl
= &IQueryAssociations_vtbl
;
1040 this->hkeySource
= 0;
1041 this->hkeyProgID
= 0;
1042 if (FAILED(ret
= IQueryAssociations_QueryInterface(&this->IQueryAssociations_iface
, riid
, ppOutput
))) SHFree( this );
1043 TRACE("returning %p\n", *ppOutput
);
1047 /**************************************************************************
1048 * ApplicationAssociationRegistration_Constructor [internal]
1050 * Construct a IApplicationAssociationRegistration object.
1052 HRESULT WINAPI
ApplicationAssociationRegistration_Constructor(IUnknown
*outer
, REFIID riid
, LPVOID
*ppv
)
1054 IApplicationAssociationRegistrationImpl
*This
;
1058 return CLASS_E_NOAGGREGATION
;
1060 if (!(This
= SHAlloc(sizeof(*This
))))
1061 return E_OUTOFMEMORY
;
1063 This
->IApplicationAssociationRegistration_iface
.lpVtbl
= &IApplicationAssociationRegistration_vtbl
;
1066 hr
= IApplicationAssociationRegistration_QueryInterface(&This
->IApplicationAssociationRegistration_iface
, riid
, ppv
);
1070 TRACE("returning 0x%x with %p\n", hr
, *ppv
);
1074 static HRESULT WINAPI
enumassochandlers_QueryInterface(IEnumAssocHandlers
*iface
, REFIID riid
, void **obj
)
1076 struct enumassochandlers
*This
= impl_from_IEnumAssocHandlers(iface
);
1078 TRACE("(%p %s %p)\n", This
, debugstr_guid(riid
), obj
);
1080 if (IsEqualIID(riid
, &IID_IEnumAssocHandlers
) ||
1081 IsEqualIID(riid
, &IID_IUnknown
))
1084 IEnumAssocHandlers_AddRef(iface
);
1089 return E_NOINTERFACE
;
1092 static ULONG WINAPI
enumassochandlers_AddRef(IEnumAssocHandlers
*iface
)
1094 struct enumassochandlers
*This
= impl_from_IEnumAssocHandlers(iface
);
1095 ULONG ref
= InterlockedIncrement(&This
->ref
);
1097 TRACE("(%p)->(%u)\n", This
, ref
);
1101 static ULONG WINAPI
enumassochandlers_Release(IEnumAssocHandlers
*iface
)
1103 struct enumassochandlers
*This
= impl_from_IEnumAssocHandlers(iface
);
1104 ULONG ref
= InterlockedDecrement(&This
->ref
);
1106 TRACE("(%p)->(%u)\n", This
, ref
);
1114 static HRESULT WINAPI
enumassochandlers_Next(IEnumAssocHandlers
*iface
, ULONG count
, IAssocHandler
**handlers
,
1117 struct enumassochandlers
*This
= impl_from_IEnumAssocHandlers(iface
);
1119 FIXME("(%p)->(%u %p %p): stub\n", This
, count
, handlers
, fetched
);
1124 static const IEnumAssocHandlersVtbl enumassochandlersvtbl
= {
1125 enumassochandlers_QueryInterface
,
1126 enumassochandlers_AddRef
,
1127 enumassochandlers_Release
,
1128 enumassochandlers_Next
1131 /**************************************************************************
1132 * SHAssocEnumHandlers [SHELL32.@]
1134 HRESULT WINAPI
SHAssocEnumHandlers(const WCHAR
*extra
, ASSOC_FILTER filter
, IEnumAssocHandlers
**enumhandlers
)
1136 struct enumassochandlers
*enumassoc
;
1138 FIXME("(%s %d %p): stub\n", debugstr_w(extra
), filter
, enumhandlers
);
1140 *enumhandlers
= NULL
;
1142 enumassoc
= SHAlloc(sizeof(*enumassoc
));
1144 return E_OUTOFMEMORY
;
1146 enumassoc
->IEnumAssocHandlers_iface
.lpVtbl
= &enumassochandlersvtbl
;
1149 *enumhandlers
= &enumassoc
->IEnumAssocHandlers_iface
;