ReactOS 0.4.17-dev-684-ga6524ef
assoc.c
Go to the documentation of this file.
1/*
2 * IQueryAssociations helper functions
3 *
4 * Copyright 2002 Jon Griffiths
5 *
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.
10 *
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.
15 *
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
19 */
20#include <stdarg.h>
21#include <assert.h>
22
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 "shlobj.h"
30#include "shlwapi.h"
31#ifdef __REACTOS__
32#include "shlwapi_undoc.h"
33#include "evalcmd.h"
34#endif
35#include "wine/unicode.h"
36#include "wine/debug.h"
37
39
40/* Default IQueryAssociations::Init() flags */
41#ifdef __REACTOS__
42#define SHLWAPI_DEF_ASSOCF (ASSOCF_INIT_BYEXENAME | ASSOCF_INIT_DEFAULTTOSTAR | \
43 ASSOCF_INIT_DEFAULTTOFOLDER | ASSOCF_INIT_NOREMAPCLSID | \
44 ASSOCF_INIT_IGNOREUNKNOWN)
45#else
46#define SHLWAPI_DEF_ASSOCF (ASSOCF_INIT_BYEXENAME|ASSOCF_INIT_DEFAULTTOSTAR| \
47 ASSOCF_INIT_DEFAULTTOFOLDER)
48#endif
49
50#ifdef __REACTOS__
51EXTERN_C ULONG WINAPI GetProcessOsVersion(void); // FIXME: Move or delete
52
54{
55 ULONG err = SHSetValueW(hKey, pszSubKey, pszName, Type, pszData, (lstrlenW(pszData) + 1) * sizeof(*pszData));
56 return HRESULT_FROM_WIN32(err);
57}
58
59/* _AssocOpenRegKey is borrowed from shell32:elements.cpp since that code is only available for NT5 targets here */
60static HRESULT
61_AssocOpenRegKey(HKEY hKey, PCWSTR lpSubKey, PHKEY phkResult, BOOL bCreate)
62{
63 *phkResult = NULL;
64 if (!hKey)
66
68 if ( bCreate )
70 phkResult, NULL);
71 else
72 error = RegOpenKeyExW(hKey, lpSubKey, 0, MAXIMUM_ALLOWED, phkResult);
73
74 if (error == ERROR_SUCCESS)
75 return S_OK;
76
78}
79
80static void AssocDeleteSubkey(HKEY hBase, LPCWSTR pszSubKey)
81{
82 HKEY hKey;
84 {
86 SHDeleteKeyW(hBase, pszSubKey);
87 }
88}
89
90static HRESULT AssocMakeVerbCommand(HKEY hVerb, LPCWSTR pszExeFallback, const ASSOCMAKEVERB *pVerb)
91{
93 WCHAR szCmd[MAX_PATH * 4];
94 LPCWSTR pszExe = pVerb->pszExe ? pVerb->pszExe : pszExeFallback;
95 LPCWSTR pszOrgArgs = pVerb->pszArgs ? pVerb->pszArgs : L"";
96 LPCWSTR pszArgs = *pszOrgArgs ? pszOrgArgs : L"\"%1\"";
97
98 if (pVerb->pszFriendlyName && *pVerb->pszFriendlyName)
100
101 lstrcpyW(szCmd, pszExe);
102 PathQuoteSpacesW(szCmd);
103 lstrcatW(szCmd, L" ");
104 lstrcatW(szCmd, pszArgs);
105 if (StrStrIW(pszExe, L"%") || StrStrIW(pszOrgArgs, L"%"))
107 return SHELL_SetRegString(hVerb, L"command", NULL, Type, szCmd);
108}
109
111{
113 if (!hClass || !pszExe || !pShell)
114 return E_INVALIDARG;
115 for (SIZE_T i = 0; i < pShell->Count; ++i)
116 {
117 HKEY hVerb;
118 WCHAR szVerbKey[sizeof("shell") + MAX_PATH];
119 const ASSOCMAKEVERB *pVerb = &pShell->pVerbs[i];
120 if (!pVerb->pszVerb)
121 continue;
122
123 PathCombineW(szVerbKey, L"shell", pVerb->pszVerb);
124 AssocDeleteSubkey(hClass, szVerbKey); // Delete possibly existing old DDE/Delegate info
125 if (FAILED(_AssocOpenRegKey(hClass, szVerbKey, &hVerb, TRUE)))
126 continue;
127 hr = AssocMakeVerbCommand(hVerb, pszExe, pVerb);
128 RegCloseKey(hVerb);
129 if (i == pShell->DefaultIndex)
130 SHELL_SetRegString(hClass, L"shell", NULL, REG_SZ, pVerb->pszVerb);
131 }
132 return hr;
133}
134
136{
137 FIXME("stub\n");
138 return E_NOTIMPL;
139}
140
142{
143 FIXME("stub\n");
144 return E_NOTIMPL;
145}
146
148{
149 return AssocMakeApplicationByKeyW(Unknown1, Unknown2, Unknown3);
150}
151
153{
154 FIXME("stub\n");
155 return E_NOTIMPL;
156}
157#endif // __REACTOS__
158
159/*************************************************************************
160 * SHLWAPI_ParamAToW
161 *
162 * Internal helper function: Convert ANSI parameter to Unicode.
163 */
164static BOOL SHLWAPI_ParamAToW(LPCSTR lpszParam, LPWSTR lpszBuff, DWORD dwLen,
165 LPWSTR* lpszOut)
166{
167#ifdef __REACTOS__
168 if (!lpszParam && LOBYTE(GetVersion()) < 6)
169 lpszParam = ""; // NT5 incorrectly converts NULL to L""
170#endif
171 if (lpszParam)
172 {
173 DWORD dwStrLen = MultiByteToWideChar(CP_ACP, 0, lpszParam, -1, NULL, 0);
174
175 if (dwStrLen < dwLen)
176 {
177 *lpszOut = lpszBuff; /* Use Buffer, it is big enough */
178 }
179 else
180 {
181 /* Create a new buffer big enough for the string */
182 *lpszOut = malloc(dwStrLen * sizeof(WCHAR));
183 if (!*lpszOut)
184 return FALSE;
185 }
186 MultiByteToWideChar(CP_ACP, 0, lpszParam, -1, *lpszOut, dwStrLen);
187 }
188 else
189 *lpszOut = NULL;
190 return TRUE;
191}
192
193/*************************************************************************
194 * AssocCreate [SHLWAPI.@]
195 *
196 * Create a new IQueryAssociations object.
197 *
198 * PARAMS
199 * clsid [I] CLSID of object
200 * refiid [I] REFIID of interface
201 * lpInterface [O] Destination for the created IQueryAssociations object
202 *
203 * RETURNS
204 * Success: S_OK. lpInterface contains the new object.
205 * Failure: An HRESULT error code indicating the error.
206 *
207#ifndef __REACTOS__ // WRONG NOTES!
208 * NOTES
209 * clsid must be equal to CLSID_QueryAssociations and
210 * refiid must be equal to IID_IQueryAssociations, IID_IUnknown or this function will fail
211#endif
212 */
213HRESULT WINAPI AssocCreate(CLSID clsid, REFIID refiid, void **lpInterface)
214{
215 TRACE("(%s,%s,%p)\n", debugstr_guid(&clsid), debugstr_guid(refiid),
216 lpInterface);
217
218 if (!lpInterface)
219 return E_INVALIDARG;
220
221#ifdef __REACTOS__
222 *(PVOID*)lpInterface = NULL;
223#else
224 *(DWORD*)lpInterface = 0;
225#endif
226
227#ifdef __REACTOS__
228 if (!IsEqualGUID(&clsid, &CLSID_QueryAssociations) &&
229 !IsEqualGUID(&clsid, &IID_IQueryAssociations))
230 {
232 return AssocCreateElement(&clsid, refiid, lpInterface);
234 }
235#else
236 if (!IsEqualGUID(&clsid, &CLSID_QueryAssociations))
238#endif
239
240 return SHCoCreateInstance( NULL, &clsid, NULL, refiid, lpInterface );
241}
242
243
245{
251};
252
253static const WCHAR unspecified_exts[] = {
254 '.','l','n','k',0,
255 '.','s','e','a','r','c','h','-','m','s',0,
256 0
257};
258
259static const WCHAR image_exts[] = {
260 '.','b','m','p',0,
261 '.','d','i','b',0,
262 '.','e','m','f',0,
263 '.','g','i','f',0,
264 '.','i','c','o',0,
265 '.','j','f','i','f',0,
266 '.','j','p','e',0,
267 '.','j','p','e','g',0,
268 '.','j','p','g',0,
269 '.','p','n','g',0,
270 '.','r','l','e',0,
271 '.','t','i','f',0,
272 '.','t','i','f','f',0,
273 '.','w','m','f',0,
274 0
275};
276
277static const WCHAR audio_exts[] = {
278 '.','a','i','f',0,
279 '.','a','i','f','c',0,
280 '.','a','i','f','f',0,
281 '.','a','u',0,
282 '.','m','3','u',0,
283 '.','m','i','d',0,
284 '.','m','i','d','i',0,
285#if _WIN32_WINNT > 0x602
286 '.','m','p','2',0,
287#endif
288 '.','m','p','3',0,
289 '.','r','m','i',0,
290 '.','s','n','d',0,
291 '.','w','a','v',0,
292 '.','w','a','x',0,
293 '.','w','m','a',0,
294 0
295};
296
297static const WCHAR video_exts[] = {
298 '.','a','s','f',0,
299 '.','a','s','x',0,
300 '.','a','v','i',0,
301 '.','d','v','r','-','m','s',0,
302 '.','I','V','F',0,
303 '.','m','1','v',0,
304#if _WIN32_WINNT <= 0x602
305 '.','m','p','2',0,
306#endif
307 '.','m','p','2','v',0,
308 '.','m','p','a',0,
309 '.','m','p','e',0,
310 '.','m','p','e','g',0,
311 '.','m','p','g',0,
312 '.','m','p','v','2',0,
313 '.','w','m',0,
314 '.','w','m','v',0,
315 '.','w','m','x',0,
316 '.','w','v','x',0,
317 0
318};
319
320static const WCHAR compressed_exts[] = {
321 '.','z','i','p',0,
322 0
323};
324
325static const WCHAR document_exts[] = {
326#if _WIN32_WINNT >= 0x600
327 '.','h','t','m',0,
328 '.','h','t','m','l',0,
329#endif
330 '.','m','h','t',0,
331 0
332};
333
334static const WCHAR system_exts[] = {
335 '.','c','p','l',0,
336 0
337};
338
339static const WCHAR application_exts[] = {
340 '.','b','a','s',0,
341 '.','b','a','t',0,
342 '.','c','m','d',0,
343 '.','c','o','m',0,
344 '.','e','x','e',0,
345 '.','h','t','a',0,
346 '.','m','s','i',0,
347 '.','p','i','f',0,
348 '.','r','e','g',0,
349 '.','s','c','r',0,
350 '.','v','b',0,
351 0
352};
353
354const WCHAR type_text[] = {'t','e','x','t',0};
355const WCHAR type_image[] = {'i','m','a','g','e',0};
356const WCHAR type_audio[] = {'a','u','d','i','o',0};
357const WCHAR type_video[] = {'v','i','d','e','o',0};
358const WCHAR type_compressed[] = {'c','o','m','p','r','e','s','s','e','d',0};
359const WCHAR type_document[] = {'d','o','c','u','m','e','n','t',0};
360const WCHAR type_system[] = {'s','y','s','t','e','m',0};
361const WCHAR type_application[] = {'a','p','p','l','i','c','a','t','i','o','n',0};
362
363#define HARDCODED_NATIVE_WMSDK (PERCEIVEDFLAG_HARDCODED | PERCEIVEDFLAG_NATIVESUPPORT | PERCEIVEDFLAG_WMSDK)
364#define HARDCODED_NATIVE_GDIPLUS (PERCEIVEDFLAG_HARDCODED | PERCEIVEDFLAG_NATIVESUPPORT | PERCEIVEDFLAG_GDIPLUS)
365#define HARDCODED_NATIVE_ZIPFLDR (PERCEIVEDFLAG_HARDCODED | PERCEIVEDFLAG_NATIVESUPPORT | PERCEIVEDFLAG_ZIPFOLDER)
366#define SOFTCODED_NATIVESUPPORT (PERCEIVEDFLAG_SOFTCODED | PERCEIVEDFLAG_NATIVESUPPORT)
367
368static const struct AssocPerceivedInfo known_types[] = {
378};
379
381{
382 UINT n;
383 for (n = 0; n < sizeof(known_types) / sizeof(known_types[0]); ++n)
384 {
385 PCWSTR Ext = known_types[n].Extensions;
386 while (Ext && *Ext)
387 {
388 if (!StrCmpIW(Ext, pszExt))
389 return &known_types[n];
390 Ext += (strlenW(Ext) + 1);
391 }
392 }
393 return NULL;
394}
395
396static const struct AssocPerceivedInfo* AssocFindByType(LPCWSTR pszType)
397{
398 UINT n;
399 for (n = 0; n < sizeof(known_types) / sizeof(known_types[0]); ++n)
400 {
401 if (known_types[n].Type)
402 {
403 if (!StrCmpIW(known_types[n].Type, pszType))
404 return &known_types[n];
405 }
406 }
407 return NULL;
408}
409
410
411/*************************************************************************
412 * AssocGetPerceivedType [SHLWAPI.@]
413 *
414 * Detect the type of a file by inspecting its extension
415 *
416 * PARAMS
417 * lpszExt [I] File extension to evaluate.
418 * lpType [O] Pointer to perceived type
419 * lpFlag [O] Pointer to perceived type flag
420 * lppszType [O] Address to pointer for perceived type text
421 *
422 * RETURNS
423 * Success: S_OK. lpType and lpFlag contain the perceived type and
424 * its information. If lppszType is not NULL, it will point
425 * to a string with perceived type text.
426 * Failure: An HRESULT error code indicating the error.
427 *
428 * NOTES
429 * lppszType is optional and it can be NULL.
430 * if lpType or lpFlag are NULL, the function will crash.
431 * if lpszExt is NULL, an error is returned.
432 */
434 INT *lpFlag, LPWSTR *lppszType)
435{
436 static const WCHAR PerceivedTypeKey[] = {'P','e','r','c','e','i','v','e','d','T','y','p','e',0};
437 static const WCHAR SystemFileAssociationsKey[] = {'S','y','s','t','e','m','F','i','l','e',
438 'A','s','s','o','c','i','a','t','i','o','n','s','\\','%','s',0};
439 const struct AssocPerceivedInfo *Info;
440
441 TRACE("(%s,%p,%p,%p)\n", debugstr_w(lpszExt), lpType, lpFlag, lppszType);
442
444 if (Info)
445 {
446 *lpType = Info->Perceived;
447 *lpFlag = Info->FlagHardcoded;
448 }
449 else
450 {
451 WCHAR Buffer[100] = { 0 };
452 DWORD Size = sizeof(Buffer);
453 if (RegGetValueW(HKEY_CLASSES_ROOT, lpszExt, PerceivedTypeKey,
455 {
457 }
458 if (!Info)
459 {
460 WCHAR KeyName[MAX_PATH] = { 0 };
461 snprintfW(KeyName, MAX_PATH, SystemFileAssociationsKey, lpszExt);
462 Size = sizeof(Buffer);
463 if (RegGetValueW(HKEY_CLASSES_ROOT, KeyName, PerceivedTypeKey,
465 {
467 }
468 }
469 if (Info)
470 {
471 *lpType = Info->Perceived;
472 *lpFlag = Info->FlagSoftcoded;
473 }
474 }
475
476 if (Info)
477 {
478 if (lppszType && Info->Type)
479 {
480 return SHStrDupW(Info->Type, lppszType);
481 }
482 return Info->Type ? S_OK : E_FAIL;
483 }
484 else
485 {
487 *lpFlag = 0;
488 }
490}
491
492/*************************************************************************
493 * AssocQueryKeyW [SHLWAPI.@]
494 *
495 * See AssocQueryKeyA.
496 */
498 LPCWSTR pszExtra, HKEY *phkeyOut)
499{
500 HRESULT hRet;
501 IQueryAssociations* lpAssoc;
502
503 TRACE("(0x%lx,%d,%s,%s,%p)\n", cfFlags, assockey, debugstr_w(pszAssoc),
504 debugstr_w(pszExtra), phkeyOut);
505
506 hRet = AssocCreate( CLSID_QueryAssociations, &IID_IQueryAssociations, (void **)&lpAssoc );
507 if (FAILED(hRet)) return hRet;
508
509#ifdef __REACTOS__
510 hRet = IQueryAssociations_Init(lpAssoc, cfFlags & SHLWAPI_DEF_ASSOCF, pszAssoc, NULL, NULL);
511#else
512 cfFlags &= SHLWAPI_DEF_ASSOCF;
513 hRet = IQueryAssociations_Init(lpAssoc, cfFlags, pszAssoc, NULL, NULL);
514#endif
515
516 if (SUCCEEDED(hRet))
517 hRet = IQueryAssociations_GetKey(lpAssoc, cfFlags, assockey, pszExtra, phkeyOut);
518
520 return hRet;
521}
522
523/*************************************************************************
524 * AssocQueryKeyA [SHLWAPI.@]
525 *
526 * Get a file association key from the registry.
527 *
528 * PARAMS
529 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
530 * assockey [I] Type of key to get
531 * pszAssoc [I] Key name to search below
532 * pszExtra [I] Extra information about the key location
533 * phkeyOut [O] Destination for the association key
534 *
535 * RETURNS
536 * Success: S_OK. phkeyOut contains the key.
537 * Failure: An HRESULT error code indicating the error.
538 */
539HRESULT WINAPI AssocQueryKeyA(ASSOCF cfFlags, ASSOCKEY assockey, LPCSTR pszAssoc,
540 LPCSTR pszExtra, HKEY *phkeyOut)
541{
542 WCHAR szAssocW[MAX_PATH], *lpszAssocW = NULL;
543 WCHAR szExtraW[MAX_PATH], *lpszExtraW = NULL;
544 HRESULT hRet = E_OUTOFMEMORY;
545
546 TRACE("(0x%lx,%d,%s,%s,%p)\n", cfFlags, assockey, debugstr_a(pszAssoc),
547 debugstr_a(pszExtra), phkeyOut);
548
549 if (SHLWAPI_ParamAToW(pszAssoc, szAssocW, MAX_PATH, &lpszAssocW) &&
550 SHLWAPI_ParamAToW(pszExtra, szExtraW, MAX_PATH, &lpszExtraW))
551 {
552 hRet = AssocQueryKeyW(cfFlags, assockey, lpszAssocW, lpszExtraW, phkeyOut);
553 }
554
555 if (lpszAssocW != szAssocW)
556 free(lpszAssocW);
557
558 if (lpszExtraW != szExtraW)
559 free(lpszExtraW);
560
561 return hRet;
562}
563
564/*************************************************************************
565 * AssocQueryStringW [SHLWAPI.@]
566 *
567 * See AssocQueryStringA.
568 */
570 LPCWSTR pszExtra, LPWSTR pszOut, DWORD *pcchOut)
571{
572 HRESULT hRet;
573 IQueryAssociations* lpAssoc;
574
575 TRACE("(0x%lx,%d,%s,%s,%p,%p)\n", cfFlags, str, debugstr_w(pszAssoc),
576 debugstr_w(pszExtra), pszOut, pcchOut);
577
578 if (!pcchOut)
579 return E_UNEXPECTED;
580
581 hRet = AssocCreate( CLSID_QueryAssociations, &IID_IQueryAssociations, (void **)&lpAssoc );
582 if (FAILED(hRet)) return hRet;
583
584 hRet = IQueryAssociations_Init(lpAssoc, cfFlags & SHLWAPI_DEF_ASSOCF,
585 pszAssoc, NULL, NULL);
586
587 if (SUCCEEDED(hRet))
588 hRet = IQueryAssociations_GetString(lpAssoc, cfFlags, str, pszExtra,
589 pszOut, pcchOut);
590
592 return hRet;
593}
594
595/*************************************************************************
596 * AssocQueryStringA [SHLWAPI.@]
597 *
598 * Get a file association string from the registry.
599 *
600 * PARAMS
601 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
602 * str [I] Type of string to get (ASSOCSTR enum from "shlwapi.h")
603 * pszAssoc [I] Key name to search below
604 * pszExtra [I] Extra information about the string location
605 * pszOut [O] Destination for the association string
606 * pcchOut [O] Length of pszOut
607 *
608 * RETURNS
609 * Success: S_OK. pszOut contains the string, pcchOut contains its length.
610 * Failure: An HRESULT error code indicating the error.
611 */
613 LPCSTR pszExtra, LPSTR pszOut, DWORD *pcchOut)
614{
615 WCHAR szAssocW[MAX_PATH], *lpszAssocW = NULL;
616 WCHAR szExtraW[MAX_PATH], *lpszExtraW = NULL;
617 HRESULT hRet = E_OUTOFMEMORY;
618
619 TRACE("(0x%lx,0x%d,%s,%s,%p,%p)\n", cfFlags, str, debugstr_a(pszAssoc),
620 debugstr_a(pszExtra), pszOut, pcchOut);
621
622 if (!pcchOut)
623 hRet = E_UNEXPECTED;
624 else if (SHLWAPI_ParamAToW(pszAssoc, szAssocW, MAX_PATH, &lpszAssocW) &&
625 SHLWAPI_ParamAToW(pszExtra, szExtraW, MAX_PATH, &lpszExtraW))
626 {
627 WCHAR szReturnW[MAX_PATH], *lpszReturnW = szReturnW;
628#ifdef __REACTOS__
629 DWORD dwLenOut = IS_INTRESOURCE(pcchOut) && LOBYTE(GetVersion()) < 6 ? PtrToUlong(pcchOut) : *pcchOut;
630#else
631 DWORD dwLenOut = *pcchOut;
632#endif
633
634 if (dwLenOut >= MAX_PATH)
635 lpszReturnW = malloc((dwLenOut + 1) * sizeof(WCHAR));
636 else
637 dwLenOut = ARRAY_SIZE(szReturnW);
638
639 if (!lpszReturnW)
640 hRet = E_OUTOFMEMORY;
641 else
642 {
643 hRet = AssocQueryStringW(cfFlags, str, lpszAssocW, lpszExtraW,
644 lpszReturnW, &dwLenOut);
645
646 if (SUCCEEDED(hRet))
647 dwLenOut = WideCharToMultiByte(CP_ACP, 0, lpszReturnW, -1,
648 pszOut, *pcchOut, NULL, NULL);
649
650#ifdef __REACTOS__
651 if (IS_INTRESOURCE(pcchOut))
652 pcchOut = &dwLenOut;
653#endif
654 *pcchOut = dwLenOut;
655 if (lpszReturnW != szReturnW)
656 free(lpszReturnW);
657 }
658 }
659
660 if (lpszAssocW != szAssocW)
661 free(lpszAssocW);
662 if (lpszExtraW != szExtraW)
663 free(lpszExtraW);
664 return hRet;
665}
666
667/*************************************************************************
668 * AssocQueryStringByKeyW [SHLWAPI.@]
669 *
670 * See AssocQueryStringByKeyA.
671 */
673 LPCWSTR pszExtra, LPWSTR pszOut,
674 DWORD *pcchOut)
675{
676 HRESULT hRet;
677 IQueryAssociations* lpAssoc;
678
679 TRACE("(0x%lx,0x%d,%p,%s,%p,%p)\n", cfFlags, str, hkAssoc,
680 debugstr_w(pszExtra), pszOut, pcchOut);
681
682 hRet = AssocCreate( CLSID_QueryAssociations, &IID_IQueryAssociations, (void **)&lpAssoc );
683 if (FAILED(hRet)) return hRet;
684
685#ifdef __REACTOS__
686 hRet = IQueryAssociations_Init(lpAssoc, cfFlags & SHLWAPI_DEF_ASSOCF, 0, hkAssoc, NULL);
687#else
688 cfFlags &= SHLWAPI_DEF_ASSOCF;
689 hRet = IQueryAssociations_Init(lpAssoc, cfFlags, 0, hkAssoc, NULL);
690#endif
691
692 if (SUCCEEDED(hRet))
693 hRet = IQueryAssociations_GetString(lpAssoc, cfFlags, str, pszExtra,
694 pszOut, pcchOut);
695
697 return hRet;
698}
699
700/*************************************************************************
701 * AssocQueryStringByKeyA [SHLWAPI.@]
702 *
703 * Get a file association string from the registry, given a starting key.
704 *
705 * PARAMS
706 * cfFlags [I] ASSOCF_ flags from "shlwapi.h"
707 * str [I] Type of string to get
708 * hkAssoc [I] Key to search below
709 * pszExtra [I] Extra information about the string location
710 * pszOut [O] Destination for the association string
711 * pcchOut [O] Length of pszOut
712 *
713 * RETURNS
714 * Success: S_OK. pszOut contains the string, pcchOut contains its length.
715 * Failure: An HRESULT error code indicating the error.
716 */
718 LPCSTR pszExtra, LPSTR pszOut,
719 DWORD *pcchOut)
720{
721 WCHAR szExtraW[MAX_PATH], *lpszExtraW = szExtraW;
722 WCHAR szReturnW[MAX_PATH], *lpszReturnW = szReturnW;
723 HRESULT hRet = E_OUTOFMEMORY;
724
725 TRACE("(0x%lx,0x%d,%p,%s,%p,%p)\n", cfFlags, str, hkAssoc,
726 debugstr_a(pszExtra), pszOut, pcchOut);
727
728 if (!pcchOut)
729 hRet = E_INVALIDARG;
730 else if (SHLWAPI_ParamAToW(pszExtra, szExtraW, MAX_PATH, &lpszExtraW))
731 {
732#ifdef __REACTOS__
733 DWORD dwLenOut = IS_INTRESOURCE(pcchOut) && LOBYTE(GetVersion()) < 6 ? PtrToUlong(pcchOut) : *pcchOut;
734#else
735 DWORD dwLenOut = *pcchOut;
736#endif
737 if (dwLenOut >= MAX_PATH)
738 lpszReturnW = malloc((dwLenOut + 1) * sizeof(WCHAR));
739
740 if (lpszReturnW)
741 {
742 hRet = AssocQueryStringByKeyW(cfFlags, str, hkAssoc, lpszExtraW,
743 lpszReturnW, &dwLenOut);
744
745 if (SUCCEEDED(hRet))
746 WideCharToMultiByte(CP_ACP,0,szReturnW,-1,pszOut,dwLenOut,0,0);
747#ifdef __REACTOS__
748 if (IS_INTRESOURCE(pcchOut))
749 pcchOut = &dwLenOut;
750#endif
751 *pcchOut = dwLenOut;
752
753 if (lpszReturnW != szReturnW)
754 free(lpszReturnW);
755 }
756 }
757
758 if (lpszExtraW != szExtraW)
759 free(lpszExtraW);
760 return hRet;
761}
762
763
764/**************************************************************************
765 * AssocIsDangerous (SHLWAPI.@)
766 *
767 * Determine if a file association is dangerous (potentially malware).
768 *
769 * PARAMS
770 * lpszAssoc [I] Name of file or file extension to check.
771 *
772 * RETURNS
773 * TRUE, if lpszAssoc may potentially be malware (executable),
774 * FALSE, Otherwise.
775 */
777{
778 FIXME("%s\n", debugstr_w(lpszAssoc));
779 return FALSE;
780}
static HRESULT SHELL_SetRegString(HKEY hKey, LPCWSTR pszSubKey, LPCWSTR pszName, UINT Type, LPCWSTR pszData)
PRTL_UNICODE_STRING_BUFFER PULONG PULONG Unknown4
Type
Definition: Type.h:7
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
void shell(int argc, const char *argv[])
Definition: cmds.c:1231
#define ARRAY_SIZE(A)
Definition: main.h:20
#define FIXME(fmt,...)
Definition: precomp.h:53
#define EXTERN_C
Definition: basetyps.h:12
#define RegCloseKey(hKey)
Definition: registry.h:49
Definition: bufpool.h:45
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES IN DWORD Unknown3
Definition: conport.c:37
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_INVALIDARG
Definition: ddrawi.h:101
#define E_NOTIMPL
Definition: ddrawi.h:99
#define E_FAIL
Definition: ddrawi.h:102
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
HRESULT hr
Definition: delayimp.cpp:582
#define ERROR_SUCCESS
Definition: deptool.c:10
static LSTATUS(WINAPI *pRegDeleteTreeW)(HKEY
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
LONG WINAPI RegCreateKeyExW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey, _In_ DWORD Reserved, _In_opt_ LPWSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_opt_ LPDWORD lpdwDisposition)
Definition: reg.c:1096
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
LSTATUS WINAPI RegGetValueW(HKEY hKey, LPCWSTR pszSubKey, LPCWSTR pszValue, DWORD dwFlags, LPDWORD pdwType, PVOID pvData, LPDWORD pcbData)
Definition: reg.c:1931
LPWSTR WINAPI StrStrIW(LPCWSTR lpszStr, LPCWSTR lpszSearch)
Definition: string.c:380
#define CP_ACP
Definition: compat.h:109
#define MAX_PATH
Definition: compat.h:34
#define lstrcpyW
Definition: compat.h:749
#define WideCharToMultiByte
Definition: compat.h:111
#define MultiByteToWideChar
Definition: compat.h:110
#define lstrlenW
Definition: compat.h:750
#define IS_INTRESOURCE(x)
Definition: loader.c:613
void WINAPI PathQuoteSpacesW(WCHAR *path)
Definition: path.c:2520
int WINAPI StrCmpIW(const WCHAR *str, const WCHAR *comp)
Definition: string.c:464
DWORD WINAPI GetVersion(void)
Definition: version.c:1458
HRESULT WINAPI SHStrDupW(const WCHAR *src, WCHAR **dest)
Definition: main.c:1692
DWORD WINAPI SHSetValueW(HKEY hkey, const WCHAR *subkey, const WCHAR *value, DWORD type, const void *data, DWORD data_len)
Definition: main.c:2292
DWORD WINAPI SHDeleteKeyW(HKEY hkey, const WCHAR *subkey)
Definition: main.c:1886
HRESULT WINAPI SHCoCreateInstance(LPCWSTR aclsid, const CLSID *clsid, LPUNKNOWN pUnkOuter, REFIID riid, LPVOID *ppv)
Definition: shellole.c:197
BOOL WINAPI AssocIsDangerous(LPCWSTR lpszAssoc)
Definition: assoc.c:776
static BOOL SHLWAPI_ParamAToW(LPCSTR lpszParam, LPWSTR lpszBuff, DWORD dwLen, LPWSTR *lpszOut)
Definition: assoc.c:164
#define SHLWAPI_DEF_ASSOCF
Definition: assoc.c:46
#define HARDCODED_NATIVE_ZIPFLDR
Definition: assoc.c:365
#define SOFTCODED_NATIVESUPPORT
Definition: assoc.c:366
static const WCHAR system_exts[]
Definition: assoc.c:334
HRESULT WINAPI AssocQueryKeyW(ASSOCF cfFlags, ASSOCKEY assockey, LPCWSTR pszAssoc, LPCWSTR pszExtra, HKEY *phkeyOut)
Definition: assoc.c:497
HRESULT WINAPI AssocQueryKeyA(ASSOCF cfFlags, ASSOCKEY assockey, LPCSTR pszAssoc, LPCSTR pszExtra, HKEY *phkeyOut)
Definition: assoc.c:539
HRESULT WINAPI AssocCreate(CLSID clsid, REFIID refiid, void **lpInterface)
Definition: assoc.c:213
const WCHAR type_compressed[]
Definition: assoc.c:358
HRESULT WINAPI AssocQueryStringA(ASSOCF cfFlags, ASSOCSTR str, LPCSTR pszAssoc, LPCSTR pszExtra, LPSTR pszOut, DWORD *pcchOut)
Definition: assoc.c:612
static const WCHAR document_exts[]
Definition: assoc.c:325
const WCHAR type_document[]
Definition: assoc.c:359
const WCHAR type_video[]
Definition: assoc.c:357
const WCHAR type_image[]
Definition: assoc.c:355
HRESULT WINAPI AssocQueryStringByKeyW(ASSOCF cfFlags, ASSOCSTR str, HKEY hkAssoc, LPCWSTR pszExtra, LPWSTR pszOut, DWORD *pcchOut)
Definition: assoc.c:672
static const WCHAR audio_exts[]
Definition: assoc.c:277
HRESULT WINAPI AssocGetPerceivedType(LPCWSTR lpszExt, PERCEIVED *lpType, INT *lpFlag, LPWSTR *lppszType)
Definition: assoc.c:433
const WCHAR type_system[]
Definition: assoc.c:360
static const struct AssocPerceivedInfo known_types[]
Definition: assoc.c:368
static const struct AssocPerceivedInfo * AssocFindByType(LPCWSTR pszType)
Definition: assoc.c:396
const WCHAR type_text[]
Definition: assoc.c:354
HRESULT WINAPI AssocQueryStringW(ASSOCF cfFlags, ASSOCSTR str, LPCWSTR pszAssoc, LPCWSTR pszExtra, LPWSTR pszOut, DWORD *pcchOut)
Definition: assoc.c:569
#define HARDCODED_NATIVE_WMSDK
Definition: assoc.c:363
HRESULT WINAPI AssocQueryStringByKeyA(ASSOCF cfFlags, ASSOCSTR str, HKEY hkAssoc, LPCSTR pszExtra, LPSTR pszOut, DWORD *pcchOut)
Definition: assoc.c:717
const WCHAR type_application[]
Definition: assoc.c:361
static const struct AssocPerceivedInfo * AssocFindByBuiltinExtension(LPCWSTR pszExt)
Definition: assoc.c:380
static const WCHAR application_exts[]
Definition: assoc.c:339
static const WCHAR image_exts[]
Definition: assoc.c:259
#define HARDCODED_NATIVE_GDIPLUS
Definition: assoc.c:364
static const WCHAR video_exts[]
Definition: assoc.c:297
static const WCHAR compressed_exts[]
Definition: assoc.c:320
static const WCHAR unspecified_exts[]
Definition: assoc.c:253
const WCHAR type_audio[]
Definition: assoc.c:356
EXTERN_C ULONG WINAPI GetProcessOsVersion(void)
Definition: utils.cpp:1257
#define L(x)
Definition: resources.c:13
#define PtrToUlong(u)
Definition: config.h:107
static HRESULT _AssocOpenRegKey(HKEY hKey, PCWSTR lpSubKey, PHKEY phkResult, BOOL bCreate)
Definition: elements.cpp:229
EXTERN_C HRESULT WINAPI AssocCreateElement(_In_ REFCLSID rclsid, _In_ REFIID riid, _Outptr_ PVOID *ppvObj)
Definition: elements.cpp:1612
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
GLdouble n
Definition: glext.h:7729
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned int UINT
Definition: sysinfo.c:13
@ Unknown
Definition: i8042prt.h:114
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
#define LOBYTE(W)
Definition: jmemdos.c:487
#define debugstr_guid
Definition: kernel32.h:35
#define debugstr_a
Definition: kernel32.h:31
#define debugstr_w
Definition: kernel32.h:32
#define REG_SZ
Definition: layer.c:22
LPWSTR WINAPI lstrcatW(LPWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:274
#define error(str)
Definition: mkdosfs.c:1605
static struct proto Ext[]
Definition: mkg3states.c:72
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
const CLSID * clsid
Definition: msctf.cpp:50
#define REG_EXPAND_SZ
Definition: nt_native.h:1497
#define MAXIMUM_ALLOWED
Definition: nt_native.h:83
#define PathCombineW
Definition: pathcch.h:318
short WCHAR
Definition: pedump.c:58
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define REFIID
Definition: guiddef.h:118
#define IQueryAssociations_GetKey(p, a, b, c, d)
Definition: shlwapi.h:990
ASSOCSTR
Definition: shlwapi.h:885
#define PERCEIVEDFLAG_HARDCODED
Definition: shtypes.idl:187
#define IQueryAssociations_Release(p)
Definition: shlwapi.h:987
#define IQueryAssociations_Init(p, a, b, c, d)
Definition: shlwapi.h:988
ASSOCKEY
Definition: shlwapi.h:918
_In_opt_ LPCSTR pszSubKey
Definition: shlwapi.h:783
DWORD ASSOCF
Definition: shlwapi.h:967
#define IQueryAssociations_GetString(p, a, b, c, d, e)
Definition: shlwapi.h:989
#define PERCEIVEDFLAG_SOFTCODED
Definition: shtypes.idl:186
#define err(...)
const WCHAR * str
#define _WIN32_WINNT_VISTA
Definition: sdkddkver.h:25
_In_ int _In_ BOOL bCreate
Definition: shlobj.h:1536
HRESULT WINAPI AssocMakeShell(SIZE_T Unknown, _In_ HKEY hClass, _In_ LPCWSTR pszExe, _In_ const ASSOCMAKESHELL *pAMS)
HRESULT WINAPI AssocMakeApplicationByKeyA(SIZE_T Unknown1, SIZE_T Unknown2, SIZE_T Unknown3)
HRESULT WINAPI AssocCopyVerbs(HKEY hSrc, HKEY hDst)
HRESULT WINAPI AssocMakeProgid(SIZE_T Unknown1, SIZE_T Unknown2, SIZE_T Unknown3, SIZE_T Unknown4)
HRESULT WINAPI AssocMakeApplicationByKeyW(SIZE_T Unknown1, SIZE_T Unknown2, SIZE_T Unknown3)
enum tagPERCEIVED PERCEIVED
@ PERCEIVED_TYPE_TEXT
Definition: shtypes.idl:173
@ PERCEIVED_TYPE_COMPRESSED
Definition: shtypes.idl:177
@ PERCEIVED_TYPE_SYSTEM
Definition: shtypes.idl:179
@ PERCEIVED_TYPE_DOCUMENT
Definition: shtypes.idl:178
@ PERCEIVED_TYPE_UNSPECIFIED
Definition: shtypes.idl:170
@ PERCEIVED_TYPE_VIDEO
Definition: shtypes.idl:176
@ PERCEIVED_TYPE_IMAGE
Definition: shtypes.idl:174
@ PERCEIVED_TYPE_AUDIO
Definition: shtypes.idl:175
@ PERCEIVED_TYPE_APPLICATION
Definition: shtypes.idl:180
#define TRACE(s)
Definition: solgame.cpp:4
PERCEIVED Perceived
Definition: assoc.c:247
PCWSTR Extensions
Definition: assoc.c:250
ASSOCMAKEVERB * pVerbs
LPCWSTR pszFriendlyName
const char * LPCSTR
Definition: typedefs.h:52
const uint16_t * PCWSTR
Definition: typedefs.h:57
const uint16_t * LPCWSTR
Definition: typedefs.h:57
uint16_t * LPWSTR
Definition: typedefs.h:56
ULONG_PTR SIZE_T
Definition: typedefs.h:80
char * LPSTR
Definition: typedefs.h:51
int32_t INT
Definition: typedefs.h:58
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
Definition: wdfchildlist.h:690
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4539
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2705
#define WINAPI
Definition: msvc.h:6
#define strlenW(s)
Definition: unicode.h:28
#define snprintfW
Definition: unicode.h:60
static HRESULT HRESULT_FROM_WIN32(unsigned int x)
Definition: winerror.h:210
#define ERROR_NO_ASSOCIATION
Definition: winerror.h:1001
#define E_UNEXPECTED
Definition: winerror.h:3528
#define CLASS_E_CLASSNOTAVAILABLE
Definition: winerror.h:3772
#define RRF_RT_REG_SZ
Definition: winreg.h:58
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10