dpnet/tests: Add a trailing '\n' to some ok() calls.
[wine.git] / dlls / shell32 / assoc.c
blobb0d815abb490b1c34be1522f741869e2cee15ae4
1 /*
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
20 #include <stdarg.h>
22 #define COBJMACROS
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winnls.h"
26 #include "winreg.h"
27 #include "objbase.h"
28 #include "shlguid.h"
29 #include "shlwapi.h"
30 #include "shobjidl.h"
31 #include "shell32_main.h"
32 #include "ver.h"
33 #include "wine/unicode.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(shell);
38 /**************************************************************************
39 * IQueryAssociations
41 * DESCRIPTION
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).
50 * HELPERS
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:
57 * METHODS
60 typedef struct
62 IQueryAssociations IQueryAssociations_iface;
63 LONG ref;
64 HKEY hkeySource;
65 HKEY hkeyProgID;
66 } IQueryAssociationsImpl;
68 typedef struct
70 IApplicationAssociationRegistration IApplicationAssociationRegistration_iface;
71 LONG ref;
72 } IApplicationAssociationRegistrationImpl;
75 static inline IQueryAssociationsImpl *impl_from_IQueryAssociations(IQueryAssociations *iface)
77 return CONTAINING_RECORD(iface, IQueryAssociationsImpl, IQueryAssociations_iface);
80 /**************************************************************************
81 * IQueryAssociations_QueryInterface
83 * See IUnknown_QueryInterface.
85 static HRESULT WINAPI IQueryAssociations_fnQueryInterface(
86 IQueryAssociations* iface,
87 REFIID riid,
88 LPVOID *ppvObj)
90 IQueryAssociationsImpl *This = impl_from_IQueryAssociations(iface);
92 TRACE("(%p,%s,%p)\n",This, debugstr_guid(riid), ppvObj);
94 if (ppvObj == NULL)
95 return E_POINTER;
97 *ppvObj = NULL;
99 if (IsEqualIID(riid, &IID_IUnknown) ||
100 IsEqualIID(riid, &IID_IQueryAssociations))
102 *ppvObj = &This->IQueryAssociations_iface;
104 IQueryAssociations_AddRef((IQueryAssociations*)*ppvObj);
105 TRACE("Returning IQueryAssociations (%p)\n", *ppvObj);
106 return S_OK;
108 TRACE("Returning E_NOINTERFACE\n");
109 return E_NOINTERFACE;
112 /**************************************************************************
113 * IQueryAssociations_AddRef
115 * See IUnknown_AddRef.
117 static ULONG WINAPI IQueryAssociations_fnAddRef(IQueryAssociations *iface)
119 IQueryAssociationsImpl *This = impl_from_IQueryAssociations(iface);
120 ULONG refCount = InterlockedIncrement(&This->ref);
122 TRACE("(%p)->(ref before=%u)\n",This, refCount - 1);
124 return refCount;
127 /**************************************************************************
128 * IQueryAssociations_Release
130 * See IUnknown_Release.
132 static ULONG WINAPI IQueryAssociations_fnRelease(IQueryAssociations *iface)
134 IQueryAssociationsImpl *This = impl_from_IQueryAssociations(iface);
135 ULONG refCount = InterlockedDecrement(&This->ref);
137 TRACE("(%p)->(ref before=%u)\n",This, refCount + 1);
139 if (!refCount)
141 TRACE("Destroying IQueryAssociations (%p)\n", This);
142 RegCloseKey(This->hkeySource);
143 RegCloseKey(This->hkeyProgID);
144 SHFree(This);
147 return refCount;
150 /**************************************************************************
151 * IQueryAssociations_Init
153 * Initialise an IQueryAssociations object.
155 * PARAMS
156 * iface [I] IQueryAssociations interface to initialise
157 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
158 * pszAssoc [I] String for the root key name, or NULL if hkeyProgid is given
159 * hkeyProgid [I] Handle for the root key, or NULL if pszAssoc is given
160 * hWnd [I] Reserved, must be NULL.
162 * RETURNS
163 * Success: S_OK. iface is initialised with the parameters given.
164 * Failure: An HRESULT error code indicating the error.
166 static HRESULT WINAPI IQueryAssociations_fnInit(
167 IQueryAssociations *iface,
168 ASSOCF cfFlags,
169 LPCWSTR pszAssoc,
170 HKEY hkeyProgid,
171 HWND hWnd)
173 static const WCHAR szProgID[] = {'P','r','o','g','I','D',0};
174 IQueryAssociationsImpl *This = impl_from_IQueryAssociations(iface);
175 LONG ret;
177 TRACE("(%p)->(%d,%s,%p,%p)\n", iface,
178 cfFlags,
179 debugstr_w(pszAssoc),
180 hkeyProgid,
181 hWnd);
182 if (hWnd != NULL)
183 FIXME("hwnd != NULL not supported\n");
184 if (cfFlags != 0)
185 FIXME("unsupported flags: %x\n", cfFlags);
187 RegCloseKey(This->hkeySource);
188 RegCloseKey(This->hkeyProgID);
189 This->hkeySource = This->hkeyProgID = NULL;
190 if (pszAssoc != NULL)
192 ret = RegOpenKeyExW(HKEY_CLASSES_ROOT,
193 pszAssoc,
195 KEY_READ,
196 &This->hkeySource);
197 if (ret)
198 return S_OK;
199 /* if this is not a prog id */
200 if ((*pszAssoc == '.') || (*pszAssoc == '{'))
202 RegOpenKeyExW(This->hkeySource,
203 szProgID,
205 KEY_READ,
206 &This->hkeyProgID);
208 else
209 This->hkeyProgID = This->hkeySource;
210 return S_OK;
212 else if (hkeyProgid != NULL)
214 This->hkeyProgID = hkeyProgid;
215 return S_OK;
217 else
218 return E_INVALIDARG;
221 static HRESULT ASSOC_GetValue(HKEY hkey, const WCHAR *name, void **data, DWORD *data_size)
223 DWORD size;
224 LONG ret;
226 ret = RegQueryValueExW(hkey, name, 0, NULL, NULL, &size);
227 if (ret != ERROR_SUCCESS)
228 return HRESULT_FROM_WIN32(ret);
229 if (!size)
230 return E_FAIL;
231 *data = HeapAlloc(GetProcessHeap(), 0, size);
232 if (!*data)
233 return E_OUTOFMEMORY;
234 ret = RegQueryValueExW(hkey, name, 0, NULL, (LPBYTE)*data, &size);
235 if (ret != ERROR_SUCCESS)
237 HeapFree(GetProcessHeap(), 0, *data);
238 return HRESULT_FROM_WIN32(ret);
240 if(data_size)
241 *data_size = size;
242 return S_OK;
245 static HRESULT ASSOC_GetCommand(IQueryAssociationsImpl *This, const WCHAR *extra, WCHAR **command)
247 HKEY hkeyCommand;
248 HKEY hkeyShell;
249 HKEY hkeyVerb;
250 HRESULT hr;
251 LONG ret;
252 WCHAR *extra_from_reg = NULL;
253 WCHAR *filetype;
254 static const WCHAR commandW[] = { 'c','o','m','m','a','n','d',0 };
255 static const WCHAR shellW[] = { 's','h','e','l','l',0 };
257 /* When looking for file extension it's possible to have a default value
258 that points to another key that contains 'shell/<verb>/command' subtree. */
259 hr = ASSOC_GetValue(This->hkeySource, NULL, (void**)&filetype, NULL);
260 if (hr == S_OK)
262 HKEY hkeyFile;
264 ret = RegOpenKeyExW(HKEY_CLASSES_ROOT, filetype, 0, KEY_READ, &hkeyFile);
265 HeapFree(GetProcessHeap(), 0, filetype);
267 if (ret == ERROR_SUCCESS)
269 ret = RegOpenKeyExW(hkeyFile, shellW, 0, KEY_READ, &hkeyShell);
270 RegCloseKey(hkeyFile);
272 else
273 ret = RegOpenKeyExW(This->hkeySource, shellW, 0, KEY_READ, &hkeyShell);
275 else
276 ret = RegOpenKeyExW(This->hkeySource, shellW, 0, KEY_READ, &hkeyShell);
278 if (ret) return HRESULT_FROM_WIN32(ret);
280 if (!extra)
282 /* check for default verb */
283 hr = ASSOC_GetValue(hkeyShell, NULL, (void**)&extra_from_reg, NULL);
284 if (FAILED(hr))
286 /* no default verb, try first subkey */
287 DWORD max_subkey_len;
289 ret = RegQueryInfoKeyW(hkeyShell, NULL, NULL, NULL, NULL, &max_subkey_len, NULL, NULL, NULL, NULL, NULL, NULL);
290 if (ret)
292 RegCloseKey(hkeyShell);
293 return HRESULT_FROM_WIN32(ret);
296 max_subkey_len++;
297 extra_from_reg = HeapAlloc(GetProcessHeap(), 0, max_subkey_len * sizeof(WCHAR));
298 if (!extra_from_reg)
300 RegCloseKey(hkeyShell);
301 return E_OUTOFMEMORY;
304 ret = RegEnumKeyExW(hkeyShell, 0, extra_from_reg, &max_subkey_len, NULL, NULL, NULL, NULL);
305 if (ret)
307 HeapFree(GetProcessHeap(), 0, extra_from_reg);
308 RegCloseKey(hkeyShell);
309 return HRESULT_FROM_WIN32(ret);
312 extra = extra_from_reg;
315 /* open verb subkey */
316 ret = RegOpenKeyExW(hkeyShell, extra, 0, KEY_READ, &hkeyVerb);
317 HeapFree(GetProcessHeap(), 0, extra_from_reg);
318 RegCloseKey(hkeyShell);
319 if (ret) return HRESULT_FROM_WIN32(ret);
321 /* open command subkey */
322 ret = RegOpenKeyExW(hkeyVerb, commandW, 0, KEY_READ, &hkeyCommand);
323 RegCloseKey(hkeyVerb);
324 if (ret) return HRESULT_FROM_WIN32(ret);
326 hr = ASSOC_GetValue(hkeyCommand, NULL, (void**)command, NULL);
327 RegCloseKey(hkeyCommand);
328 return hr;
331 static HRESULT ASSOC_GetExecutable(IQueryAssociationsImpl *This,
332 LPCWSTR pszExtra, LPWSTR path,
333 DWORD pathlen, DWORD *len)
335 WCHAR *pszCommand;
336 WCHAR *pszStart;
337 WCHAR *pszEnd;
338 HRESULT hr;
340 hr = ASSOC_GetCommand(This, pszExtra, &pszCommand);
341 if (FAILED(hr))
342 return hr;
344 /* cleanup pszCommand */
345 if (pszCommand[0] == '"')
347 pszStart = pszCommand + 1;
348 pszEnd = strchrW(pszStart, '"');
349 if (pszEnd)
350 *pszEnd = 0;
351 *len = SearchPathW(NULL, pszStart, NULL, pathlen, path, NULL);
353 else
355 pszStart = pszCommand;
356 for (pszEnd = pszStart; (pszEnd = strchrW(pszEnd, ' ')); pszEnd++)
358 WCHAR c = *pszEnd;
359 *pszEnd = 0;
360 if ((*len = SearchPathW(NULL, pszStart, NULL, pathlen, path, NULL)))
361 break;
362 *pszEnd = c;
364 if (!pszEnd)
365 *len = SearchPathW(NULL, pszStart, NULL, pathlen, path, NULL);
368 HeapFree(GetProcessHeap(), 0, pszCommand);
369 if (!*len)
370 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
371 return S_OK;
374 static HRESULT ASSOC_ReturnData(void *out, DWORD *outlen, const void *data,
375 DWORD datalen)
377 if (out)
379 if (*outlen < datalen)
381 *outlen = datalen;
382 return E_POINTER;
384 *outlen = datalen;
385 memcpy(out, data, datalen);
386 return S_OK;
388 else
390 *outlen = datalen;
391 return S_FALSE;
395 static HRESULT ASSOC_ReturnString(ASSOCF flags, LPWSTR out, DWORD *outlen, LPCWSTR data, DWORD datalen)
397 HRESULT hr = S_OK;
398 DWORD len;
400 TRACE("flags=0x%08x, data=%s\n", flags, debugstr_w(data));
402 if (!out)
404 *outlen = datalen;
405 return S_FALSE;
408 if (*outlen < datalen)
410 if (flags & ASSOCF_NOTRUNCATE)
412 len = 0;
413 if (*outlen > 0) out[0] = 0;
414 hr = E_POINTER;
416 else
418 len = min(*outlen, datalen);
419 hr = E_NOT_SUFFICIENT_BUFFER;
421 *outlen = datalen;
423 else
424 len = datalen;
426 if (len)
427 memcpy(out, data, len*sizeof(WCHAR));
429 return hr;
432 /**************************************************************************
433 * IQueryAssociations_GetString
435 * Get a file association string from the registry.
437 * PARAMS
438 * iface [I] IQueryAssociations interface to query
439 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
440 * str [I] Type of string to get (ASSOCSTR enum from "shlwapi.h")
441 * pszExtra [I] Extra information about the string location
442 * pszOut [O] Destination for the association string
443 * pcchOut [I/O] Length of pszOut
445 * RETURNS
446 * Success: S_OK. pszOut contains the string, pcchOut contains its length.
447 * Failure: An HRESULT error code indicating the error.
449 static HRESULT WINAPI IQueryAssociations_fnGetString(
450 IQueryAssociations *iface,
451 ASSOCF flags,
452 ASSOCSTR str,
453 LPCWSTR pszExtra,
454 LPWSTR pszOut,
455 DWORD *pcchOut)
457 IQueryAssociationsImpl *This = impl_from_IQueryAssociations(iface);
458 const ASSOCF unimplemented_flags = ~ASSOCF_NOTRUNCATE;
459 DWORD len = 0;
460 HRESULT hr;
461 WCHAR path[MAX_PATH];
463 TRACE("(%p)->(0x%08x, %u, %s, %p, %p)\n", This, flags, str, debugstr_w(pszExtra), pszOut, pcchOut);
465 if (flags & unimplemented_flags)
466 FIXME("%08x: unimplemented flags\n", flags & unimplemented_flags);
468 if (!pcchOut)
469 return E_UNEXPECTED;
471 if (!This->hkeySource && !This->hkeyProgID)
472 return HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION);
474 switch (str)
476 case ASSOCSTR_COMMAND:
478 WCHAR *command;
479 hr = ASSOC_GetCommand(This, pszExtra, &command);
480 if (SUCCEEDED(hr))
482 hr = ASSOC_ReturnString(flags, pszOut, pcchOut, command, strlenW(command) + 1);
483 HeapFree(GetProcessHeap(), 0, command);
485 return hr;
488 case ASSOCSTR_EXECUTABLE:
490 hr = ASSOC_GetExecutable(This, pszExtra, path, MAX_PATH, &len);
491 if (FAILED(hr))
492 return hr;
493 len++;
494 return ASSOC_ReturnString(flags, pszOut, pcchOut, path, len);
497 case ASSOCSTR_FRIENDLYDOCNAME:
499 WCHAR *pszFileType;
500 DWORD ret;
501 DWORD size;
503 hr = ASSOC_GetValue(This->hkeySource, NULL, (void**)&pszFileType, NULL);
504 if (FAILED(hr))
505 return hr;
506 size = 0;
507 ret = RegGetValueW(HKEY_CLASSES_ROOT, pszFileType, NULL, RRF_RT_REG_SZ, NULL, NULL, &size);
508 if (ret == ERROR_SUCCESS)
510 WCHAR *docName = HeapAlloc(GetProcessHeap(), 0, size);
511 if (docName)
513 ret = RegGetValueW(HKEY_CLASSES_ROOT, pszFileType, NULL, RRF_RT_REG_SZ, NULL, docName, &size);
514 if (ret == ERROR_SUCCESS)
515 hr = ASSOC_ReturnString(flags, pszOut, pcchOut, docName, strlenW(docName) + 1);
516 else
517 hr = HRESULT_FROM_WIN32(ret);
518 HeapFree(GetProcessHeap(), 0, docName);
520 else
521 hr = E_OUTOFMEMORY;
523 else
524 hr = HRESULT_FROM_WIN32(ret);
525 HeapFree(GetProcessHeap(), 0, pszFileType);
526 return hr;
529 case ASSOCSTR_FRIENDLYAPPNAME:
531 PVOID verinfoW = NULL;
532 DWORD size, retval = 0;
533 UINT flen;
534 WCHAR *bufW;
535 static const WCHAR translationW[] = {
536 '\\','V','a','r','F','i','l','e','I','n','f','o',
537 '\\','T','r','a','n','s','l','a','t','i','o','n',0
539 static const WCHAR fileDescFmtW[] = {
540 '\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o',
541 '\\','%','0','4','x','%','0','4','x',
542 '\\','F','i','l','e','D','e','s','c','r','i','p','t','i','o','n',0
544 WCHAR fileDescW[41];
546 hr = ASSOC_GetExecutable(This, pszExtra, path, MAX_PATH, &len);
547 if (FAILED(hr))
548 return hr;
550 retval = GetFileVersionInfoSizeW(path, &size);
551 if (!retval)
552 goto get_friendly_name_fail;
553 verinfoW = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, retval);
554 if (!verinfoW)
555 return E_OUTOFMEMORY;
556 if (!GetFileVersionInfoW(path, 0, retval, verinfoW))
557 goto get_friendly_name_fail;
558 if (VerQueryValueW(verinfoW, translationW, (LPVOID *)&bufW, &flen))
560 UINT i;
561 DWORD *langCodeDesc = (DWORD *)bufW;
562 for (i = 0; i < flen / sizeof(DWORD); i++)
564 sprintfW(fileDescW, fileDescFmtW, LOWORD(langCodeDesc[i]),
565 HIWORD(langCodeDesc[i]));
566 if (VerQueryValueW(verinfoW, fileDescW, (LPVOID *)&bufW, &flen))
568 /* Does strlenW(bufW) == 0 mean we use the filename? */
569 len = strlenW(bufW) + 1;
570 TRACE("found FileDescription: %s\n", debugstr_w(bufW));
571 hr = ASSOC_ReturnString(flags, pszOut, pcchOut, bufW, len);
572 HeapFree(GetProcessHeap(), 0, verinfoW);
573 return hr;
577 get_friendly_name_fail:
578 PathRemoveExtensionW(path);
579 PathStripPathW(path);
580 TRACE("using filename: %s\n", debugstr_w(path));
581 hr = ASSOC_ReturnString(flags, pszOut, pcchOut, path, strlenW(path) + 1);
582 HeapFree(GetProcessHeap(), 0, verinfoW);
583 return hr;
586 case ASSOCSTR_CONTENTTYPE:
588 static const WCHAR Content_TypeW[] = {'C','o','n','t','e','n','t',' ','T','y','p','e',0};
589 WCHAR *contentType;
590 DWORD ret;
591 DWORD size;
593 size = 0;
594 ret = RegGetValueW(This->hkeySource, NULL, Content_TypeW, RRF_RT_REG_SZ, NULL, NULL, &size);
595 if (ret != ERROR_SUCCESS)
596 return HRESULT_FROM_WIN32(ret);
597 contentType = HeapAlloc(GetProcessHeap(), 0, size);
598 if (contentType != NULL)
600 ret = RegGetValueW(This->hkeySource, NULL, Content_TypeW, RRF_RT_REG_SZ, NULL, contentType, &size);
601 if (ret == ERROR_SUCCESS)
602 hr = ASSOC_ReturnString(flags, pszOut, pcchOut, contentType, strlenW(contentType) + 1);
603 else
604 hr = HRESULT_FROM_WIN32(ret);
605 HeapFree(GetProcessHeap(), 0, contentType);
607 else
608 hr = E_OUTOFMEMORY;
609 return hr;
612 case ASSOCSTR_DEFAULTICON:
614 static const WCHAR DefaultIconW[] = {'D','e','f','a','u','l','t','I','c','o','n',0};
615 WCHAR *pszFileType;
616 DWORD ret;
617 DWORD size;
618 HKEY hkeyFile;
620 hr = ASSOC_GetValue(This->hkeySource, NULL, (void**)&pszFileType, NULL);
621 if (FAILED(hr))
622 return hr;
623 ret = RegOpenKeyExW(HKEY_CLASSES_ROOT, pszFileType, 0, KEY_READ, &hkeyFile);
624 if (ret == ERROR_SUCCESS)
626 size = 0;
627 ret = RegGetValueW(hkeyFile, DefaultIconW, NULL, RRF_RT_REG_SZ, NULL, NULL, &size);
628 if (ret == ERROR_SUCCESS)
630 WCHAR *icon = HeapAlloc(GetProcessHeap(), 0, size);
631 if (icon)
633 ret = RegGetValueW(hkeyFile, DefaultIconW, NULL, RRF_RT_REG_SZ, NULL, icon, &size);
634 if (ret == ERROR_SUCCESS)
635 hr = ASSOC_ReturnString(flags, pszOut, pcchOut, icon, strlenW(icon) + 1);
636 else
637 hr = HRESULT_FROM_WIN32(ret);
638 HeapFree(GetProcessHeap(), 0, icon);
640 else
641 hr = E_OUTOFMEMORY;
643 else
644 hr = HRESULT_FROM_WIN32(ret);
645 RegCloseKey(hkeyFile);
647 else
648 hr = HRESULT_FROM_WIN32(ret);
649 HeapFree(GetProcessHeap(), 0, pszFileType);
650 return hr;
652 case ASSOCSTR_SHELLEXTENSION:
654 static const WCHAR shellexW[] = {'S','h','e','l','l','E','x','\\',0};
655 WCHAR keypath[sizeof(shellexW) / sizeof(shellexW[0]) + 39], guid[39];
656 CLSID clsid;
657 HKEY hkey;
658 DWORD size;
659 LONG ret;
661 hr = CLSIDFromString(pszExtra, &clsid);
662 if (FAILED(hr)) return hr;
664 strcpyW(keypath, shellexW);
665 strcatW(keypath, pszExtra);
666 ret = RegOpenKeyExW(This->hkeySource, keypath, 0, KEY_READ, &hkey);
667 if (ret) return HRESULT_FROM_WIN32(ret);
669 size = sizeof(guid);
670 ret = RegGetValueW(hkey, NULL, NULL, RRF_RT_REG_SZ, NULL, guid, &size);
671 RegCloseKey(hkey);
672 if (ret) return HRESULT_FROM_WIN32(ret);
674 return ASSOC_ReturnString(flags, pszOut, pcchOut, guid, size / sizeof(WCHAR));
677 default:
678 FIXME("assocstr %d unimplemented!\n", str);
679 return E_NOTIMPL;
683 /**************************************************************************
684 * IQueryAssociations_GetKey
686 * Get a file association key from the registry.
688 * PARAMS
689 * iface [I] IQueryAssociations interface to query
690 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
691 * assockey [I] Type of key to get (ASSOCKEY enum from "shlwapi.h")
692 * pszExtra [I] Extra information about the key location
693 * phkeyOut [O] Destination for the association key
695 * RETURNS
696 * Success: S_OK. phkeyOut contains a handle to the key.
697 * Failure: An HRESULT error code indicating the error.
699 static HRESULT WINAPI IQueryAssociations_fnGetKey(
700 IQueryAssociations *iface,
701 ASSOCF cfFlags,
702 ASSOCKEY assockey,
703 LPCWSTR pszExtra,
704 HKEY *phkeyOut)
706 IQueryAssociationsImpl *This = impl_from_IQueryAssociations(iface);
708 FIXME("(%p,0x%8x,0x%8x,%s,%p)-stub!\n", This, cfFlags, assockey,
709 debugstr_w(pszExtra), phkeyOut);
710 return E_NOTIMPL;
713 /**************************************************************************
714 * IQueryAssociations_GetData
716 * Get the data for a file association key from the registry.
718 * PARAMS
719 * iface [I] IQueryAssociations interface to query
720 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
721 * assocdata [I] Type of data to get (ASSOCDATA enum from "shlwapi.h")
722 * pszExtra [I] Extra information about the data location
723 * pvOut [O] Destination for the association key
724 * pcbOut [I/O] Size of pvOut
726 * RETURNS
727 * Success: S_OK. pszOut contains the data, pcbOut contains its length.
728 * Failure: An HRESULT error code indicating the error.
730 static HRESULT WINAPI IQueryAssociations_fnGetData(IQueryAssociations *iface,
731 ASSOCF cfFlags, ASSOCDATA assocdata, LPCWSTR pszExtra, LPVOID pvOut,
732 DWORD *pcbOut)
734 static const WCHAR edit_flags[] = {'E','d','i','t','F','l','a','g','s',0};
736 IQueryAssociationsImpl *This = impl_from_IQueryAssociations(iface);
737 void *data;
738 DWORD size;
739 HRESULT hres;
741 TRACE("(%p,0x%8x,0x%8x,%s,%p,%p)\n", This, cfFlags, assocdata,
742 debugstr_w(pszExtra), pvOut, pcbOut);
744 if(cfFlags)
745 FIXME("Unsupported flags: %x\n", cfFlags);
747 switch(assocdata) {
748 case ASSOCDATA_EDITFLAGS:
749 if(!This->hkeyProgID)
750 return HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION);
752 hres = ASSOC_GetValue(This->hkeyProgID, edit_flags, &data, &size);
753 if(FAILED(hres) || !pcbOut)
754 return hres;
756 hres = ASSOC_ReturnData(pvOut, pcbOut, data, size);
757 HeapFree(GetProcessHeap(), 0, data);
758 return hres;
759 default:
760 FIXME("Unsupported ASSOCDATA value: %d\n", assocdata);
761 return E_NOTIMPL;
765 /**************************************************************************
766 * IQueryAssociations_GetEnum
768 * Not yet implemented in native Win32.
770 * PARAMS
771 * iface [I] IQueryAssociations interface to query
772 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
773 * assocenum [I] Type of enum to get (ASSOCENUM enum from "shlwapi.h")
774 * pszExtra [I] Extra information about the enum location
775 * riid [I] REFIID to look for
776 * ppvOut [O] Destination for the interface.
778 * RETURNS
779 * Success: S_OK.
780 * Failure: An HRESULT error code indicating the error.
782 * NOTES
783 * Presumably this function returns an enumerator object.
785 static HRESULT WINAPI IQueryAssociations_fnGetEnum(
786 IQueryAssociations *iface,
787 ASSOCF cfFlags,
788 ASSOCENUM assocenum,
789 LPCWSTR pszExtra,
790 REFIID riid,
791 LPVOID *ppvOut)
793 IQueryAssociationsImpl *This = impl_from_IQueryAssociations(iface);
795 FIXME("(%p,0x%8x,0x%8x,%s,%s,%p)-stub!\n", This, cfFlags, assocenum,
796 debugstr_w(pszExtra), debugstr_guid(riid), ppvOut);
797 return E_NOTIMPL;
800 static const IQueryAssociationsVtbl IQueryAssociations_vtbl =
802 IQueryAssociations_fnQueryInterface,
803 IQueryAssociations_fnAddRef,
804 IQueryAssociations_fnRelease,
805 IQueryAssociations_fnInit,
806 IQueryAssociations_fnGetString,
807 IQueryAssociations_fnGetKey,
808 IQueryAssociations_fnGetData,
809 IQueryAssociations_fnGetEnum
812 /**************************************************************************
813 * IApplicationAssociationRegistration implementation
815 static inline IApplicationAssociationRegistrationImpl *impl_from_IApplicationAssociationRegistration(IApplicationAssociationRegistration *iface)
817 return CONTAINING_RECORD(iface, IApplicationAssociationRegistrationImpl, IApplicationAssociationRegistration_iface);
820 static HRESULT WINAPI ApplicationAssociationRegistration_QueryInterface(
821 IApplicationAssociationRegistration* iface, REFIID riid, LPVOID *ppv)
823 IApplicationAssociationRegistrationImpl *This = impl_from_IApplicationAssociationRegistration(iface);
825 TRACE("(%p, %s, %p)\n",This, debugstr_guid(riid), ppv);
827 if (ppv == NULL)
828 return E_POINTER;
830 if (IsEqualGUID(&IID_IUnknown, riid) ||
831 IsEqualGUID(&IID_IApplicationAssociationRegistration, riid)) {
832 *ppv = &This->IApplicationAssociationRegistration_iface;
833 IUnknown_AddRef((IUnknown*)*ppv);
834 TRACE("returning IApplicationAssociationRegistration: %p\n", *ppv);
835 return S_OK;
838 *ppv = NULL;
839 FIXME("(%p)->(%s %p) interface not supported\n", This, debugstr_guid(riid), ppv);
840 return E_NOINTERFACE;
843 static ULONG WINAPI ApplicationAssociationRegistration_AddRef(IApplicationAssociationRegistration *iface)
845 IApplicationAssociationRegistrationImpl *This = impl_from_IApplicationAssociationRegistration(iface);
846 ULONG ref = InterlockedIncrement(&This->ref);
848 TRACE("(%p) ref=%d\n", This, ref);
849 return ref;
852 static ULONG WINAPI ApplicationAssociationRegistration_Release(IApplicationAssociationRegistration *iface)
854 IApplicationAssociationRegistrationImpl *This = impl_from_IApplicationAssociationRegistration(iface);
855 ULONG ref = InterlockedDecrement(&This->ref);
857 TRACE("(%p) ref=%d\n", This, ref);
859 if (!ref) {
860 SHFree(This);
862 return ref;
865 static HRESULT WINAPI ApplicationAssociationRegistration_QueryCurrentDefault(IApplicationAssociationRegistration* This, LPCWSTR query,
866 ASSOCIATIONTYPE type, ASSOCIATIONLEVEL level, LPWSTR *association)
868 FIXME("(%p)->(%s, %d, %d, %p)\n", This, debugstr_w(query), type, level, association);
869 return E_NOTIMPL;
872 static HRESULT WINAPI ApplicationAssociationRegistration_QueryAppIsDefault(IApplicationAssociationRegistration* This, LPCWSTR query,
873 ASSOCIATIONTYPE type, ASSOCIATIONLEVEL level, LPCWSTR appname, BOOL *is_default)
875 FIXME("(%p)->(%s, %d, %d, %s, %p)\n", This, debugstr_w(query), type, level, debugstr_w(appname), is_default);
876 return E_NOTIMPL;
879 static HRESULT WINAPI ApplicationAssociationRegistration_QueryAppIsDefaultAll(IApplicationAssociationRegistration* This, ASSOCIATIONLEVEL level,
880 LPCWSTR appname, BOOL *is_default)
882 FIXME("(%p)->(%d, %s, %p)\n", This, level, debugstr_w(appname), is_default);
883 return E_NOTIMPL;
886 static HRESULT WINAPI ApplicationAssociationRegistration_SetAppAsDefault(IApplicationAssociationRegistration* This, LPCWSTR appname,
887 LPCWSTR set, ASSOCIATIONTYPE set_type)
889 FIXME("(%p)->(%s, %s, %d)\n", This, debugstr_w(appname), debugstr_w(set), set_type);
890 return E_NOTIMPL;
893 static HRESULT WINAPI ApplicationAssociationRegistration_SetAppAsDefaultAll(IApplicationAssociationRegistration* This, LPCWSTR appname)
895 FIXME("(%p)->(%s)\n", This, debugstr_w(appname));
896 return E_NOTIMPL;
900 static HRESULT WINAPI ApplicationAssociationRegistration_ClearUserAssociations(IApplicationAssociationRegistration* This)
902 FIXME("(%p)\n", This);
903 return E_NOTIMPL;
907 static const IApplicationAssociationRegistrationVtbl IApplicationAssociationRegistration_vtbl =
909 ApplicationAssociationRegistration_QueryInterface,
910 ApplicationAssociationRegistration_AddRef,
911 ApplicationAssociationRegistration_Release,
912 ApplicationAssociationRegistration_QueryCurrentDefault,
913 ApplicationAssociationRegistration_QueryAppIsDefault,
914 ApplicationAssociationRegistration_QueryAppIsDefaultAll,
915 ApplicationAssociationRegistration_SetAppAsDefault,
916 ApplicationAssociationRegistration_SetAppAsDefaultAll,
917 ApplicationAssociationRegistration_ClearUserAssociations
920 /**************************************************************************
921 * IQueryAssociations_Constructor [internal]
923 * Construct a new IQueryAssociations object.
925 HRESULT WINAPI QueryAssociations_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppOutput)
927 IQueryAssociationsImpl* this;
928 HRESULT ret;
930 if (pUnkOuter) return CLASS_E_NOAGGREGATION;
932 if (!(this = SHAlloc(sizeof(*this)))) return E_OUTOFMEMORY;
933 this->IQueryAssociations_iface.lpVtbl = &IQueryAssociations_vtbl;
934 this->ref = 0;
935 this->hkeySource = 0;
936 this->hkeyProgID = 0;
937 if (FAILED(ret = IQueryAssociations_QueryInterface(&this->IQueryAssociations_iface, riid, ppOutput))) SHFree( this );
938 TRACE("returning %p\n", *ppOutput);
939 return ret;
942 /**************************************************************************
943 * ApplicationAssociationRegistration_Constructor [internal]
945 * Construct a IApplicationAssociationRegistration object.
947 HRESULT WINAPI ApplicationAssociationRegistration_Constructor(IUnknown *outer, REFIID riid, LPVOID *ppv)
949 IApplicationAssociationRegistrationImpl *This;
950 HRESULT hr;
952 if (outer)
953 return CLASS_E_NOAGGREGATION;
955 if (!(This = SHAlloc(sizeof(*This))))
956 return E_OUTOFMEMORY;
958 This->IApplicationAssociationRegistration_iface.lpVtbl = &IApplicationAssociationRegistration_vtbl;
959 This->ref = 0;
961 hr = IApplicationAssociationRegistration_QueryInterface(&This->IApplicationAssociationRegistration_iface, riid, ppv);
962 if (FAILED(hr))
963 SHFree(This);
965 TRACE("returning 0x%x with %p\n", hr, *ppv);
966 return hr;