push 30c3afdf8e27eb453070f5cf144ec76e9777c0a8
[wine/hacks.git] / dlls / shlwapi / assoc.c
blob0d8baa0a9ee25a2c2d6fe96115c94ea98d9c5db2
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>
21 #include <assert.h>
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 "wine/unicode.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(shell);
35 /**************************************************************************
36 * IQueryAssociations {SHLWAPI}
38 * DESCRIPTION
39 * This object provides a layer of abstraction over the system registry in
40 * order to simplify the process of parsing associations between files.
41 * Associations in this context means the registry entries that link (for
42 * example) the extension of a file with its description, list of
43 * applications to open the file with, and actions that can be performed on it
44 * (the shell displays such information in the context menu of explorer
45 * when you right-click on a file).
47 * HELPERS
48 * You can use this object transparently by calling the helper functions
49 * AssocQueryKeyA(), AssocQueryStringA() and AssocQueryStringByKeyA(). These
50 * create an IQueryAssociations object, perform the requested actions
51 * and then dispose of the object. Alternatively, you can create an instance
52 * of the object using AssocCreate() and call the following methods on it:
54 * METHODS
57 /* Default IQueryAssociations::Init() flags */
58 #define SHLWAPI_DEF_ASSOCF (ASSOCF_INIT_BYEXENAME|ASSOCF_INIT_DEFAULTTOSTAR| \
59 ASSOCF_INIT_DEFAULTTOFOLDER)
61 typedef struct
63 const IQueryAssociationsVtbl *lpVtbl;
64 LONG ref;
65 HKEY hkeySource;
66 HKEY hkeyProgID;
67 } IQueryAssociationsImpl;
69 static const IQueryAssociationsVtbl IQueryAssociations_vtbl;
71 /**************************************************************************
72 * IQueryAssociations_Constructor [internal]
74 * Construct a new IQueryAssociations object.
76 static IQueryAssociations* IQueryAssociations_Constructor(void)
78 IQueryAssociationsImpl* iface;
80 iface = HeapAlloc(GetProcessHeap(),0,sizeof(IQueryAssociationsImpl));
81 iface->lpVtbl = &IQueryAssociations_vtbl;
82 iface->ref = 1;
83 iface->hkeySource = NULL;
84 iface->hkeyProgID = NULL;
86 TRACE("Returning IQueryAssociations* %p\n", iface);
87 return (IQueryAssociations*)iface;
90 /*************************************************************************
91 * SHLWAPI_ParamAToW
93 * Internal helper function: Convert ASCII parameter to Unicode.
95 static BOOL SHLWAPI_ParamAToW(LPCSTR lpszParam, LPWSTR lpszBuff, DWORD dwLen,
96 LPWSTR* lpszOut)
98 if (lpszParam)
100 DWORD dwStrLen = MultiByteToWideChar(CP_ACP, 0, lpszParam, -1, NULL, 0);
102 if (dwStrLen < dwLen)
104 *lpszOut = lpszBuff; /* Use Buffer, it is big enough */
106 else
108 /* Create a new buffer big enough for the string */
109 *lpszOut = HeapAlloc(GetProcessHeap(), 0,
110 dwStrLen * sizeof(WCHAR));
111 if (!*lpszOut)
112 return FALSE;
114 MultiByteToWideChar(CP_ACP, 0, lpszParam, -1, *lpszOut, dwStrLen);
116 else
117 *lpszOut = NULL;
118 return TRUE;
121 /*************************************************************************
122 * AssocCreate [SHLWAPI.@]
124 * Create a new IQueryAssociations object.
126 * PARAMS
127 * clsid [I] CLSID of object
128 * refiid [I] REFIID of interface
129 * lpInterface [O] Destination for the created IQueryAssociations object
131 * RETURNS
132 * Success: S_OK. lpInterface contains the new object.
133 * Failure: An HRESULT error code indicating the error.
135 * NOTES
136 * refiid must be equal to IID_IQueryAssociations, or this function will fail.
138 HRESULT WINAPI AssocCreate(CLSID clsid, REFIID refiid, void **lpInterface)
140 HRESULT hRet;
141 IQueryAssociations* lpAssoc;
143 TRACE("(%s,%s,%p)\n", debugstr_guid(&clsid), debugstr_guid(refiid),
144 lpInterface);
146 if (!lpInterface)
147 return E_INVALIDARG;
149 *(DWORD*)lpInterface = 0;
151 if (!IsEqualGUID(&clsid, &IID_IQueryAssociations))
152 return E_NOTIMPL;
154 lpAssoc = IQueryAssociations_Constructor();
156 if (!lpAssoc)
157 return E_OUTOFMEMORY;
159 hRet = IQueryAssociations_QueryInterface(lpAssoc, refiid, lpInterface);
160 IQueryAssociations_Release(lpAssoc);
161 return hRet;
164 /*************************************************************************
165 * AssocQueryKeyW [SHLWAPI.@]
167 * See AssocQueryKeyA.
169 HRESULT WINAPI AssocQueryKeyW(ASSOCF cfFlags, ASSOCKEY assockey, LPCWSTR pszAssoc,
170 LPCWSTR pszExtra, HKEY *phkeyOut)
172 HRESULT hRet;
173 IQueryAssociations* lpAssoc;
175 TRACE("(0x%8x,0x%8x,%s,%s,%p)\n", cfFlags, assockey, debugstr_w(pszAssoc),
176 debugstr_w(pszExtra), phkeyOut);
178 lpAssoc = IQueryAssociations_Constructor();
180 if (!lpAssoc)
181 return E_OUTOFMEMORY;
183 cfFlags &= SHLWAPI_DEF_ASSOCF;
184 hRet = IQueryAssociations_Init(lpAssoc, cfFlags, pszAssoc, NULL, NULL);
186 if (SUCCEEDED(hRet))
187 hRet = IQueryAssociations_GetKey(lpAssoc, cfFlags, assockey, pszExtra, phkeyOut);
189 IQueryAssociations_Release(lpAssoc);
190 return hRet;
193 /*************************************************************************
194 * AssocQueryKeyA [SHLWAPI.@]
196 * Get a file association key from the registry.
198 * PARAMS
199 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
200 * assockey [I] Type of key to get
201 * pszAssoc [I] Key name to search below
202 * pszExtra [I] Extra information about the key location
203 * phkeyOut [O] Destination for the association key
205 * RETURNS
206 * Success: S_OK. phkeyOut contains the key.
207 * Failure: An HRESULT error code indicating the error.
209 HRESULT WINAPI AssocQueryKeyA(ASSOCF cfFlags, ASSOCKEY assockey, LPCSTR pszAssoc,
210 LPCSTR pszExtra, HKEY *phkeyOut)
212 WCHAR szAssocW[MAX_PATH], *lpszAssocW = NULL;
213 WCHAR szExtraW[MAX_PATH], *lpszExtraW = NULL;
214 HRESULT hRet = E_OUTOFMEMORY;
216 TRACE("(0x%8x,0x%8x,%s,%s,%p)\n", cfFlags, assockey, debugstr_a(pszAssoc),
217 debugstr_a(pszExtra), phkeyOut);
219 if (SHLWAPI_ParamAToW(pszAssoc, szAssocW, MAX_PATH, &lpszAssocW) &&
220 SHLWAPI_ParamAToW(pszExtra, szExtraW, MAX_PATH, &lpszExtraW))
222 hRet = AssocQueryKeyW(cfFlags, assockey, lpszAssocW, lpszExtraW, phkeyOut);
225 if (lpszAssocW != szAssocW)
226 HeapFree(GetProcessHeap(), 0, lpszAssocW);
228 if (lpszExtraW != szExtraW)
229 HeapFree(GetProcessHeap(), 0, lpszExtraW);
231 return hRet;
234 /*************************************************************************
235 * AssocQueryStringW [SHLWAPI.@]
237 * See AssocQueryStringA.
239 HRESULT WINAPI AssocQueryStringW(ASSOCF cfFlags, ASSOCSTR str, LPCWSTR pszAssoc,
240 LPCWSTR pszExtra, LPWSTR pszOut, DWORD *pcchOut)
242 HRESULT hRet;
243 IQueryAssociations* lpAssoc;
245 TRACE("(0x%8x,0x%8x,%s,%s,%p,%p)\n", cfFlags, str, debugstr_w(pszAssoc),
246 debugstr_w(pszExtra), pszOut, pcchOut);
248 if (!pcchOut)
249 return E_UNEXPECTED;
251 lpAssoc = IQueryAssociations_Constructor();
253 if (!lpAssoc)
254 return E_OUTOFMEMORY;
256 hRet = IQueryAssociations_Init(lpAssoc, cfFlags & SHLWAPI_DEF_ASSOCF,
257 pszAssoc, NULL, NULL);
259 if (SUCCEEDED(hRet))
260 hRet = IQueryAssociations_GetString(lpAssoc, cfFlags, str, pszExtra,
261 pszOut, pcchOut);
263 IQueryAssociations_Release(lpAssoc);
264 return hRet;
267 /*************************************************************************
268 * AssocQueryStringA [SHLWAPI.@]
270 * Get a file association string from the registry.
272 * PARAMS
273 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
274 * str [I] Type of string to get (ASSOCSTR enum from "shlwapi.h")
275 * pszAssoc [I] Key name to search below
276 * pszExtra [I] Extra information about the string location
277 * pszOut [O] Destination for the association string
278 * pcchOut [O] Length of pszOut
280 * RETURNS
281 * Success: S_OK. pszOut contains the string, pcchOut contains its length.
282 * Failure: An HRESULT error code indicating the error.
284 HRESULT WINAPI AssocQueryStringA(ASSOCF cfFlags, ASSOCSTR str, LPCSTR pszAssoc,
285 LPCSTR pszExtra, LPSTR pszOut, DWORD *pcchOut)
287 WCHAR szAssocW[MAX_PATH], *lpszAssocW = NULL;
288 WCHAR szExtraW[MAX_PATH], *lpszExtraW = NULL;
289 HRESULT hRet = E_OUTOFMEMORY;
291 TRACE("(0x%8x,0x%8x,%s,%s,%p,%p)\n", cfFlags, str, debugstr_a(pszAssoc),
292 debugstr_a(pszExtra), pszOut, pcchOut);
294 if (!pcchOut)
295 hRet = E_UNEXPECTED;
296 else if (SHLWAPI_ParamAToW(pszAssoc, szAssocW, MAX_PATH, &lpszAssocW) &&
297 SHLWAPI_ParamAToW(pszExtra, szExtraW, MAX_PATH, &lpszExtraW))
299 WCHAR szReturnW[MAX_PATH], *lpszReturnW = szReturnW;
300 DWORD dwLenOut = *pcchOut;
302 if (dwLenOut >= MAX_PATH)
303 lpszReturnW = HeapAlloc(GetProcessHeap(), 0,
304 (dwLenOut + 1) * sizeof(WCHAR));
306 if (!lpszReturnW)
307 hRet = E_OUTOFMEMORY;
308 else
310 hRet = AssocQueryStringW(cfFlags, str, lpszAssocW, lpszExtraW,
311 lpszReturnW, &dwLenOut);
313 if (SUCCEEDED(hRet))
314 WideCharToMultiByte(CP_ACP,0,szReturnW,-1,pszOut,dwLenOut,0,0);
315 *pcchOut = dwLenOut;
317 if (lpszReturnW != szReturnW)
318 HeapFree(GetProcessHeap(), 0, lpszReturnW);
322 if (lpszAssocW != szAssocW)
323 HeapFree(GetProcessHeap(), 0, lpszAssocW);
324 if (lpszExtraW != szExtraW)
325 HeapFree(GetProcessHeap(), 0, lpszExtraW);
326 return hRet;
329 /*************************************************************************
330 * AssocQueryStringByKeyW [SHLWAPI.@]
332 * See AssocQueryStringByKeyA.
334 HRESULT WINAPI AssocQueryStringByKeyW(ASSOCF cfFlags, ASSOCSTR str, HKEY hkAssoc,
335 LPCWSTR pszExtra, LPWSTR pszOut,
336 DWORD *pcchOut)
338 HRESULT hRet;
339 IQueryAssociations* lpAssoc;
341 TRACE("(0x%8x,0x%8x,%p,%s,%p,%p)\n", cfFlags, str, hkAssoc,
342 debugstr_w(pszExtra), pszOut, pcchOut);
344 lpAssoc = IQueryAssociations_Constructor();
346 if (!lpAssoc)
347 return E_OUTOFMEMORY;
349 cfFlags &= SHLWAPI_DEF_ASSOCF;
350 hRet = IQueryAssociations_Init(lpAssoc, cfFlags, 0, hkAssoc, NULL);
352 if (SUCCEEDED(hRet))
353 hRet = IQueryAssociations_GetString(lpAssoc, cfFlags, str, pszExtra,
354 pszOut, pcchOut);
356 IQueryAssociations_Release(lpAssoc);
357 return hRet;
360 /*************************************************************************
361 * AssocQueryStringByKeyA [SHLWAPI.@]
363 * Get a file association string from the registry, given a starting key.
365 * PARAMS
366 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
367 * str [I] Type of string to get
368 * hkAssoc [I] Key to search below
369 * pszExtra [I] Extra information about the string location
370 * pszOut [O] Destination for the association string
371 * pcchOut [O] Length of pszOut
373 * RETURNS
374 * Success: S_OK. pszOut contains the string, pcchOut contains its length.
375 * Failure: An HRESULT error code indicating the error.
377 HRESULT WINAPI AssocQueryStringByKeyA(ASSOCF cfFlags, ASSOCSTR str, HKEY hkAssoc,
378 LPCSTR pszExtra, LPSTR pszOut,
379 DWORD *pcchOut)
381 WCHAR szExtraW[MAX_PATH], *lpszExtraW = szExtraW;
382 WCHAR szReturnW[MAX_PATH], *lpszReturnW = szReturnW;
383 HRESULT hRet = E_OUTOFMEMORY;
385 TRACE("(0x%8x,0x%8x,%p,%s,%p,%p)\n", cfFlags, str, hkAssoc,
386 debugstr_a(pszExtra), pszOut, pcchOut);
388 if (!pcchOut)
389 hRet = E_INVALIDARG;
390 else if (SHLWAPI_ParamAToW(pszExtra, szExtraW, MAX_PATH, &lpszExtraW))
392 DWORD dwLenOut = *pcchOut;
393 if (dwLenOut >= MAX_PATH)
394 lpszReturnW = HeapAlloc(GetProcessHeap(), 0,
395 (dwLenOut + 1) * sizeof(WCHAR));
397 if (lpszReturnW)
399 hRet = AssocQueryStringByKeyW(cfFlags, str, hkAssoc, lpszExtraW,
400 lpszReturnW, &dwLenOut);
402 if (SUCCEEDED(hRet))
403 WideCharToMultiByte(CP_ACP,0,szReturnW,-1,pszOut,dwLenOut,0,0);
404 *pcchOut = dwLenOut;
406 if (lpszReturnW != szReturnW)
407 HeapFree(GetProcessHeap(), 0, lpszReturnW);
411 if (lpszExtraW != szExtraW)
412 HeapFree(GetProcessHeap(), 0, lpszExtraW);
413 return hRet;
417 /**************************************************************************
418 * AssocIsDangerous (SHLWAPI.@)
420 * Determine if a file association is dangerous (potentially malware).
422 * PARAMS
423 * lpszAssoc [I] Name of file or file extension to check.
425 * RETURNS
426 * TRUE, if lpszAssoc may potentially be malware (executable),
427 * FALSE, Otherwise.
429 BOOL WINAPI AssocIsDangerous(LPCWSTR lpszAssoc)
431 FIXME("%s\n", debugstr_w(lpszAssoc));
432 return FALSE;
435 /**************************************************************************
436 * IQueryAssociations_QueryInterface {SHLWAPI}
438 * See IUnknown_QueryInterface.
440 static HRESULT WINAPI IQueryAssociations_fnQueryInterface(
441 IQueryAssociations* iface,
442 REFIID riid,
443 LPVOID *ppvObj)
445 IQueryAssociationsImpl *This = (IQueryAssociationsImpl *)iface;
447 TRACE("(%p,%s,%p)\n",This, debugstr_guid(riid), ppvObj);
449 *ppvObj = NULL;
451 if (IsEqualIID(riid, &IID_IUnknown) ||
452 IsEqualIID(riid, &IID_IQueryAssociations))
454 *ppvObj = (IQueryAssociations*)This;
456 IQueryAssociations_AddRef((IQueryAssociations*)*ppvObj);
457 TRACE("Returning IQueryAssociations (%p)\n", *ppvObj);
458 return S_OK;
460 TRACE("Returning E_NOINTERFACE\n");
461 return E_NOINTERFACE;
464 /**************************************************************************
465 * IQueryAssociations_AddRef {SHLWAPI}
467 * See IUnknown_AddRef.
469 static ULONG WINAPI IQueryAssociations_fnAddRef(IQueryAssociations *iface)
471 IQueryAssociationsImpl *This = (IQueryAssociationsImpl *)iface;
472 ULONG refCount = InterlockedIncrement(&This->ref);
474 TRACE("(%p)->(ref before=%u)\n",This, refCount - 1);
476 return refCount;
479 /**************************************************************************
480 * IQueryAssociations_Release {SHLWAPI}
482 * See IUnknown_Release.
484 static ULONG WINAPI IQueryAssociations_fnRelease(IQueryAssociations *iface)
486 IQueryAssociationsImpl *This = (IQueryAssociationsImpl *)iface;
487 ULONG refCount = InterlockedDecrement(&This->ref);
489 TRACE("(%p)->(ref before=%u)\n",This, refCount + 1);
491 if (!refCount)
493 TRACE("Destroying IQueryAssociations (%p)\n", This);
494 RegCloseKey(This->hkeySource);
495 RegCloseKey(This->hkeyProgID);
496 HeapFree(GetProcessHeap(), 0, This);
499 return refCount;
502 /**************************************************************************
503 * IQueryAssociations_Init {SHLWAPI}
505 * Initialise an IQueryAssociations object.
507 * PARAMS
508 * iface [I] IQueryAssociations interface to initialise
509 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
510 * pszAssoc [I] String for the root key name, or NULL if hkeyProgid is given
511 * hkeyProgid [I] Handle for the root key, or NULL if pszAssoc is given
512 * hWnd [I] Reserved, must be NULL.
514 * RETURNS
515 * Success: S_OK. iface is initialised with the parameters given.
516 * Failure: An HRESULT error code indicating the error.
518 static HRESULT WINAPI IQueryAssociations_fnInit(
519 IQueryAssociations *iface,
520 ASSOCF cfFlags,
521 LPCWSTR pszAssoc,
522 HKEY hkeyProgid,
523 HWND hWnd)
525 static const WCHAR szProgID[] = {'P','r','o','g','I','D',0};
526 IQueryAssociationsImpl *This = (IQueryAssociationsImpl *)iface;
527 LONG ret;
529 TRACE("(%p)->(%d,%s,%p,%p)\n", iface,
530 cfFlags,
531 debugstr_w(pszAssoc),
532 hkeyProgid,
533 hWnd);
534 if (hWnd != NULL)
535 FIXME("hwnd != NULL not supported\n");
536 if (cfFlags != 0)
537 FIXME("unsupported flags: %x\n", cfFlags);
538 if (pszAssoc != NULL)
540 ret = RegOpenKeyExW(HKEY_CLASSES_ROOT,
541 pszAssoc,
543 KEY_READ,
544 &This->hkeySource);
545 if (ret != ERROR_SUCCESS)
546 return E_FAIL;
547 /* if this is not a prog id */
548 if ((*pszAssoc == '.') || (*pszAssoc == '{'))
550 RegOpenKeyExW(This->hkeySource,
551 szProgID,
553 KEY_READ,
554 &This->hkeyProgID);
556 else
557 This->hkeyProgID = This->hkeySource;
558 return S_OK;
560 else if (hkeyProgid != NULL)
562 This->hkeyProgID = hkeyProgid;
563 return S_OK;
565 else
566 return E_INVALIDARG;
569 static HRESULT ASSOC_GetValue(HKEY hkey, WCHAR ** pszText)
571 DWORD len;
572 LONG ret;
574 assert(pszText);
575 ret = RegQueryValueExW(hkey, NULL, 0, NULL, NULL, &len);
576 if (ret != ERROR_SUCCESS)
577 return HRESULT_FROM_WIN32(ret);
578 if (!len)
579 return E_FAIL;
580 *pszText = HeapAlloc(GetProcessHeap(), 0, len);
581 if (!*pszText)
582 return E_OUTOFMEMORY;
583 ret = RegQueryValueExW(hkey, NULL, 0, NULL, (LPBYTE)*pszText,
584 &len);
585 if (ret != ERROR_SUCCESS)
587 HeapFree(GetProcessHeap(), 0, *pszText);
588 return HRESULT_FROM_WIN32(ret);
590 return S_OK;
593 /**************************************************************************
594 * IQueryAssociations_GetString {SHLWAPI}
596 * Get a file association string from the registry.
598 * PARAMS
599 * iface [I] IQueryAssociations interface to query
600 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
601 * str [I] Type of string to get (ASSOCSTR enum from "shlwapi.h")
602 * pszExtra [I] Extra information about the string location
603 * pszOut [O] Destination for the association string
604 * pcchOut [I/O] Length of pszOut
606 * RETURNS
607 * Success: S_OK. pszOut contains the string, pcchOut contains its length.
608 * Failure: An HRESULT error code indicating the error.
610 static HRESULT WINAPI IQueryAssociations_fnGetString(
611 IQueryAssociations *iface,
612 ASSOCF cfFlags,
613 ASSOCSTR str,
614 LPCWSTR pszExtra,
615 LPWSTR pszOut,
616 DWORD *pcchOut)
618 IQueryAssociationsImpl *This = (IQueryAssociationsImpl *)iface;
619 const ASSOCF cfUnimplemented = ~(0);
620 DWORD len;
621 HKEY hkeyCommand;
622 HKEY hkeyFile;
623 HKEY hkeyShell;
624 HKEY hkeyVerb;
625 HRESULT hr;
626 LONG ret;
627 WCHAR path[MAX_PATH];
628 WCHAR * pszCommand;
629 WCHAR * pszEnd;
630 WCHAR * pszExtraFromReg;
631 WCHAR * pszFileType;
632 WCHAR * pszStart;
633 static const WCHAR commandW[] = { 'c','o','m','m','a','n','d',0 };
634 static const WCHAR shellW[] = { 's','h','e','l','l',0 };
636 TRACE("(%p,0x%8x,0x%8x,%s,%p,%p)\n", This, cfFlags, str,
637 debugstr_w(pszExtra), pszOut, pcchOut);
639 if (cfFlags & cfUnimplemented)
640 FIXME("%08x: unimplemented flags!\n", cfFlags & cfUnimplemented);
642 if (!pcchOut)
643 return E_UNEXPECTED;
645 switch (str)
647 case ASSOCSTR_EXECUTABLE:
649 hr = ASSOC_GetValue(This->hkeySource, &pszFileType);
650 if (FAILED(hr))
651 return hr;
652 ret = RegOpenKeyExW(HKEY_CLASSES_ROOT, pszFileType, 0, KEY_READ,
653 &hkeyFile);
654 HeapFree(GetProcessHeap(), 0, pszFileType);
655 if (ret != ERROR_SUCCESS)
656 return HRESULT_FROM_WIN32(ret);
658 ret = RegOpenKeyExW(hkeyFile, shellW, 0, KEY_READ, &hkeyShell);
659 RegCloseKey(hkeyFile);
660 if (ret != ERROR_SUCCESS)
661 return HRESULT_FROM_WIN32(ret);
663 if (!pszExtra)
665 hr = ASSOC_GetValue(hkeyShell, &pszExtraFromReg);
666 if (FAILED(hr))
668 RegCloseKey(hkeyShell);
669 return hr;
673 ret = RegOpenKeyExW(hkeyShell, pszExtra ? pszExtra : pszExtraFromReg,
674 0, KEY_READ, &hkeyVerb);
675 HeapFree(GetProcessHeap(), 0, pszExtraFromReg);
676 RegCloseKey(hkeyShell);
677 if (ret != ERROR_SUCCESS)
678 return HRESULT_FROM_WIN32(ret);
680 ret = RegOpenKeyExW(hkeyVerb, commandW, 0, KEY_READ, &hkeyCommand);
681 RegCloseKey(hkeyVerb);
682 if (ret != ERROR_SUCCESS)
683 return HRESULT_FROM_WIN32(ret);
684 hr = ASSOC_GetValue(hkeyCommand, &pszCommand);
685 RegCloseKey(hkeyCommand);
686 if (FAILED(hr))
687 return hr;
689 /* cleanup pszCommand */
690 if (pszCommand[0] == '"')
692 pszStart = pszCommand + 1;
693 pszEnd = strchrW(pszStart, '"');
695 else
697 pszStart = pszCommand;
698 pszEnd = strchrW(pszStart, ' ');
700 if (pszEnd)
701 *pszEnd = 0;
703 len = SearchPathW(NULL, pszStart, NULL, MAX_PATH, path, NULL);
704 HeapFree(GetProcessHeap(), 0, pszCommand);
705 if (!len)
706 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
708 len++;
709 if (pszOut)
711 if (*pcchOut < len)
713 *pcchOut = len;
714 return E_POINTER;
716 *pcchOut = len;
717 lstrcpynW(pszOut, path, len);
718 return S_OK;
720 else
722 *pcchOut = len;
723 return S_FALSE;
725 break;
728 default:
729 FIXME("assocstr %d unimplemented!\n", str);
730 return E_NOTIMPL;
734 /**************************************************************************
735 * IQueryAssociations_GetKey {SHLWAPI}
737 * Get a file association key from the registry.
739 * PARAMS
740 * iface [I] IQueryAssociations interface to query
741 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
742 * assockey [I] Type of key to get (ASSOCKEY enum from "shlwapi.h")
743 * pszExtra [I] Extra information about the key location
744 * phkeyOut [O] Destination for the association key
746 * RETURNS
747 * Success: S_OK. phkeyOut contains a handle to the key.
748 * Failure: An HRESULT error code indicating the error.
750 static HRESULT WINAPI IQueryAssociations_fnGetKey(
751 IQueryAssociations *iface,
752 ASSOCF cfFlags,
753 ASSOCKEY assockey,
754 LPCWSTR pszExtra,
755 HKEY *phkeyOut)
757 IQueryAssociationsImpl *This = (IQueryAssociationsImpl *)iface;
759 FIXME("(%p,0x%8x,0x%8x,%s,%p)-stub!\n", This, cfFlags, assockey,
760 debugstr_w(pszExtra), phkeyOut);
761 return E_NOTIMPL;
764 /**************************************************************************
765 * IQueryAssociations_GetData {SHLWAPI}
767 * Get the data for a file association key from the registry.
769 * PARAMS
770 * iface [I] IQueryAssociations interface to query
771 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
772 * assocdata [I] Type of data to get (ASSOCDATA enum from "shlwapi.h")
773 * pszExtra [I] Extra information about the data location
774 * pvOut [O] Destination for the association key
775 * pcbOut [I/O] Size of pvOut
777 * RETURNS
778 * Success: S_OK. pszOut contains the data, pcbOut contains its length.
779 * Failure: An HRESULT error code indicating the error.
781 static HRESULT WINAPI IQueryAssociations_fnGetData(
782 IQueryAssociations *iface,
783 ASSOCF cfFlags,
784 ASSOCDATA assocdata,
785 LPCWSTR pszExtra,
786 LPVOID pvOut,
787 DWORD *pcbOut)
789 IQueryAssociationsImpl *This = (IQueryAssociationsImpl *)iface;
791 FIXME("(%p,0x%8x,0x%8x,%s,%p,%p)-stub!\n", This, cfFlags, assocdata,
792 debugstr_w(pszExtra), pvOut, pcbOut);
793 return E_NOTIMPL;
796 /**************************************************************************
797 * IQueryAssociations_GetEnum {SHLWAPI}
799 * Not yet implemented in native Win32.
801 * PARAMS
802 * iface [I] IQueryAssociations interface to query
803 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
804 * assocenum [I] Type of enum to get (ASSOCENUM enum from "shlwapi.h")
805 * pszExtra [I] Extra information about the enum location
806 * riid [I] REFIID to look for
807 * ppvOut [O] Destination for the interface.
809 * RETURNS
810 * Success: S_OK.
811 * Failure: An HRESULT error code indicating the error.
813 * NOTES
814 * Presumably this function returns an enumerator object.
816 static HRESULT WINAPI IQueryAssociations_fnGetEnum(
817 IQueryAssociations *iface,
818 ASSOCF cfFlags,
819 ASSOCENUM assocenum,
820 LPCWSTR pszExtra,
821 REFIID riid,
822 LPVOID *ppvOut)
824 IQueryAssociationsImpl *This = (IQueryAssociationsImpl *)iface;
826 FIXME("(%p,0x%8x,0x%8x,%s,%s,%p)-stub!\n", This, cfFlags, assocenum,
827 debugstr_w(pszExtra), debugstr_guid(riid), ppvOut);
828 return E_NOTIMPL;
831 static const IQueryAssociationsVtbl IQueryAssociations_vtbl =
833 IQueryAssociations_fnQueryInterface,
834 IQueryAssociations_fnAddRef,
835 IQueryAssociations_fnRelease,
836 IQueryAssociations_fnInit,
837 IQueryAssociations_fnGetString,
838 IQueryAssociations_fnGetKey,
839 IQueryAssociations_fnGetData,
840 IQueryAssociations_fnGetEnum