ReactOS 0.4.17-dev-683-g0dafdc5
CQueryAssociations.cpp File Reference
#include "precomp.h"
#include <shlwapi_undoc.h>
#include "evalcmd/elements.h"
#include <evalcmd.h>
Include dependency graph for CQueryAssociations.cpp:

Go to the source code of this file.

Classes

struct  ClassesRegKey
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (shell)
 
static HRESULT SHRegDuplicateHKey (HKEY hKey, HKEY *phKey)
 
static HRESULT SH32_AssocCreateElement (_In_ REFCLSID rclsid, _In_ REFIID riid, _Outptr_ PVOID *ppv)
 
static HRESULT AssocCreateElementInternal (REFCLSID rclsid, IQuerySource *pQS, REFIID riid, PVOID *ppv)
 
static HRESULT AssocCreateElementOnKeyInternal (_In_ REFCLSID rclsid, _In_ HKEY hKey, _In_opt_ PCWSTR pszSubKey, _In_ REFIID riid, _Outptr_ PVOID *ppv, _In_ BYTE Major)
 
static HRESULT SH32_AssocCreateElementOnKey (_In_ REFCLSID rclsid, _In_ HKEY hKey, _In_opt_ PCWSTR pszSubKey, _In_ REFIID riid, _Outptr_ PVOID *ppv)
 
static HRESULT SH32_QueryAssocElementString (_In_ REFCLSID rclsid, _In_ UINT Query, _In_ HKEY hKey, _In_opt_ PCWSTR pszSubKey, _In_ PCWSTR pszExtra, _Out_ PWSTR *ppszValue)
 
template<class T >
static HRESULT GetKeyFromObjectWithQuerySource (T &Obj, HKEY *phKey)
 
EXTERN_C HRESULT SHELL32_AssocGetFSDirectoryDescription (PWSTR Buf, UINT cchBuf)
 
static HRESULT GetExtensionDefaultDescription (PCWSTR DotExt, PWSTR Buf, UINT cchBuf)
 
static HRESULT SHELL32_AssocGetExtensionDescription (PCWSTR DotExt, PWSTR Buf, UINT cchBuf)
 
EXTERN_C HRESULT SHELL32_AssocGetFileDescription (PCWSTR Name, PWSTR Buf, UINT cchBuf)
 
static HRESULT OpenShellVerbKey (HKEY hClass, LPCWSTR pszVerb, HKEY *phKey)
 
static HRESULT OpenClassWithShellExecKey (ASSOCF fA, HKEY hClass, LPCWSTR pszVerb, HKEY *phKey)
 
static HRESULT GetClassKeyName (ASSOCF fA, PCWSTR pszSource, HKEY hSource, LPWSTR pszClass, UINT cchMax)
 
static HRESULT OpenClassKey (ASSOCF fA, PCWSTR pszSource, HKEY hCR, HKEY hSource, HKEY *phKey)
 
static HRESULT OpenClassKey (ASSOCF fA, const WCHAR *const pszSource, HKEY *phKey)
 

Function Documentation

◆ AssocCreateElementInternal()

static HRESULT AssocCreateElementInternal ( REFCLSID  rclsid,
IQuerySource *  pQS,
REFIID  riid,
PVOID ppv 
)
static

Definition at line 34 of file CQueryAssociations.cpp.

35{
36 HRESULT hr;
37 C_ASSERT(&IID_IObjectWithQuerySource == &IID_IObjectWithQuerySourceOld);
39 if (FAILED(hr = SH32_AssocCreateElement(rclsid, IID_PPV_ARG(IObjectWithQuerySource, &pOWQS))))
40 return hr;
41 return (SUCCEEDED(hr = pOWQS->SetSource(pQS))) ? pOWQS->QueryInterface(riid, ppv) : hr;
42}
static HRESULT SH32_AssocCreateElement(_In_ REFCLSID rclsid, _In_ REFIID riid, _Outptr_ PVOID *ppv)
HRESULT hr
Definition: delayimp.cpp:582
REFIID riid
Definition: atlbase.h:39
REFIID LPVOID * ppv
Definition: atlbase.h:39
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
#define C_ASSERT(e)
Definition: intsafe.h:73
#define IID_IObjectWithQuerySourceOld
#define IID_PPV_ARG(Itype, ppType)

Referenced by AssocCreateElementOnKeyInternal().

◆ AssocCreateElementOnKeyInternal()

static HRESULT AssocCreateElementOnKeyInternal ( _In_ REFCLSID  rclsid,
_In_ HKEY  hKey,
_In_opt_ PCWSTR  pszSubKey,
_In_ REFIID  riid,
_Outptr_ PVOID ppv,
_In_ BYTE  Major 
)
static

Definition at line 44 of file CQueryAssociations.cpp.

46{
48 REFIID riidQS = Major > 5 ? IID_IQuerySource : IID_IQuerySourceOld;
49 HRESULT hr = QuerySourceCreateFromKey(hKey, pszSubKey, false, riidQS, (void**)&pQSO);
50 if (FAILED(hr))
51 return hr;
52 return AssocCreateElementInternal(rclsid, (IQuerySource*)static_cast<IUnknown*>(pQSO), riid, ppv);
53}
static HRESULT AssocCreateElementInternal(REFCLSID rclsid, IQuerySource *pQS, REFIID riid, PVOID *ppv)
FxAutoRegKey hKey
#define REFIID
Definition: guiddef.h:118
_In_opt_ LPCSTR pszSubKey
Definition: shlwapi.h:783
EXTERN_C HRESULT WINAPI QuerySourceCreateFromKey(_In_ HKEY hKey, _In_opt_ PCWSTR lpSubKey, _In_ BOOL bCreate, _In_ REFIID riid, _Outptr_ PVOID *ppv)
Definition: querysrc.cpp:577

Referenced by SH32_AssocCreateElementOnKey().

◆ GetClassKeyName()

static HRESULT GetClassKeyName ( ASSOCF  fA,
PCWSTR  pszSource,
HKEY  hSource,
LPWSTR  pszClass,
UINT  cchMax 
)
inlinestatic

Definition at line 198 of file CQueryAssociations.cpp.

199{
200 PCWSTR pszSubKey = *pszSource == L'{' ? L"ProgID" : NULL;
201 return SHELL_RegGetString(hSource, pszSubKey, NULL, pszClass, cchMax);
202}
UINT cchMax
#define NULL
Definition: types.h:112
#define L(x)
Definition: resources.c:13
static HRESULT SHELL_RegGetString(HKEY hKey, PCWSTR pszPath, PCWSTR pszName, PWSTR pszOut, DWORD cchMax)
Definition: shellutils.h:141
const uint16_t * PCWSTR
Definition: typedefs.h:57

Referenced by OpenClassKey().

◆ GetExtensionDefaultDescription()

static HRESULT GetExtensionDefaultDescription ( PCWSTR  DotExt,
PWSTR  Buf,
UINT  cchBuf 
)
static

Definition at line 108 of file CQueryAssociations.cpp.

109{
110 static WCHAR fmt[33] = {};
111 if (!*fmt)
113 return StringCchPrintfW(Buf, cchBuf, fmt, DotExt);
114}
#define shell32_hInstance
#define IDS_ANY_FILE
Definition: resource.h:5
short WCHAR
Definition: pedump.c:58
_In_ UINT cchBuf
Definition: shlwapi.h:378
#define LoadStringW
Definition: utils.h:64
#define _countof(array)
Definition: sndvol32.h:70
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
Definition: dsound.c:943

Referenced by SHELL32_AssocGetExtensionDescription().

◆ GetKeyFromObjectWithQuerySource()

template<class T >
static HRESULT GetKeyFromObjectWithQuerySource ( T Obj,
HKEY phKey 
)
static

Definition at line 82 of file CQueryAssociations.cpp.

83{
84 HRESULT hr;
85 C_ASSERT(&IID_IObjectWithQuerySource == &IID_IObjectWithQuerySourceOld);
87 if (FAILED(hr = Obj.QueryInterface(IID_PPV_ARG(IObjectWithQuerySource, &pOWQS))))
88 return hr;
91 if (SUCCEEDED(hr = pOWQS->GetSource(IID_PPV_ARG(IObjectWithRegistryKeyOld, &pOWRKO))))
92 hr = pOWRKO->GetKey(phKey);
93#if DLL_EXPORT_VERSION >= _WIN32_WINNT_VISTA
94 else if (SUCCEEDED(hr = pOWQS->GetSource(IID_PPV_ARG(IObjectWithRegistryKey, &pOWRK))))
95 hr = pOWRK->GetKey(MAXIMUM_ALLOWED, phKey);
96#endif
97 return hr;
98}
#define MAXIMUM_ALLOWED
Definition: nt_native.h:83

Referenced by CQueryAssociations::GetKey().

◆ OpenClassKey() [1/2]

static HRESULT OpenClassKey ( ASSOCF  fA,
const WCHAR *const  pszSource,
HKEY phKey 
)
static

Definition at line 241 of file CQueryAssociations.cpp.

242{
243 // TODO: Handle the FileExts key and ASSOCF_NOUSERSETTINGS?
244 PCWSTR pszSourcePath = pszSource;
245 WCHAR buf[100];
246 if (*pszSource == L'{')
247 {
248 HRESULT hr = StringCchPrintfW(buf, _countof(buf), L"CLSID\\%s", pszSource);
249 if (FAILED(hr))
250 return hr;
251 pszSourcePath = buf;
252 }
253 ClassesRegKey cr;
254 if (HRESULT hr = cr.Initialize(fA, pszSource))
255 return hr;
256 HKEY hSourceKey;
257 LONG err = RegOpenKeyExW(cr.hKey, pszSourcePath, 0, KEY_READ, &hSourceKey);
258 if (err)
259 return HResultFromWin32(err);
260 HRESULT hr = OpenClassKey(fA, pszSource, cr.hKey, hSourceKey, phKey);
261 RegCloseKey(hSourceKey);
262 return hr;
263}
static HRESULT OpenClassKey(ASSOCF fA, PCWSTR pszSource, HKEY hCR, HKEY hSource, HKEY *phKey)
#define RegCloseKey(hKey)
Definition: registry.h:49
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define HResultFromWin32
Definition: loader.cpp:14
#define KEY_READ
Definition: nt_native.h:1026
long LONG
Definition: pedump.c:60
#define err(...)
HRESULT Initialize(ASSOCF fA, PCWSTR pszSource)

◆ OpenClassKey() [2/2]

static HRESULT OpenClassKey ( ASSOCF  fA,
PCWSTR  pszSource,
HKEY  hCR,
HKEY  hSource,
HKEY phKey 
)
static

Definition at line 204 of file CQueryAssociations.cpp.

205{
206 WCHAR szBuf[MAX_PATH];
207 HRESULT hr = E_FAIL;
208 if (*pszSource == L'.' || (*pszSource == L'{' && !(fA & ASSOCF_INIT_NOREMAPCLSID)))
209 {
210 hr = GetClassKeyName(fA, pszSource, hSource, szBuf, _countof(szBuf));
211 if (FAILED(hr) && *pszSource == L'.')
212 return hr; // .ext can only have its ProgId in another location
213 }
214
216 if (SUCCEEDED(hr))
218 else
219 hr = SHRegDuplicateHKey(hSource, &hClassKey);
220
221 if (FAILED(hr))
222 return hr;
223
224 // Check for CurVer redirection
225 if (SUCCEEDED(SHELL_RegGetString(hClassKey, L"CurVer", NULL, szBuf, _countof(szBuf))))
226 {
227 if (RegOpenKeyExW(hCR, szBuf, 0, KEY_READ, phKey) == ERROR_SUCCESS)
228 {
229 if (RegKeyExists(*phKey, L"shell")) // Does it look like a valid ProgId?
230 {
232 return S_OK;
233 }
234 RegCloseKey(*phKey);
235 }
236 }
237 *phKey = hClassKey;
238 return hr;
239}
static HRESULT GetClassKeyName(ASSOCF fA, PCWSTR pszSource, HKEY hSource, LPWSTR pszClass, UINT cchMax)
static HRESULT SHRegDuplicateHKey(HKEY hKey, HKEY *phKey)
HKEY hClassKey
Definition: umpnpmgr.c:45
#define E_FAIL
Definition: ddrawi.h:102
#define ERROR_SUCCESS
Definition: deptool.c:10
#define MAX_PATH
Definition: compat.h:34
BOOL RegKeyExists(HKEY hKey, LPCWSTR Path)
Definition: utils.h:49
#define S_OK
Definition: intsafe.h:52
@ ASSOCF_INIT_NOREMAPCLSID
Definition: shlwapi.h:859

Referenced by CQueryAssociations::Init(), and OpenClassKey().

◆ OpenClassWithShellExecKey()

static HRESULT OpenClassWithShellExecKey ( ASSOCF  fA,
HKEY  hClass,
LPCWSTR  pszVerb,
HKEY phKey 
)
static

Definition at line 186 of file CQueryAssociations.cpp.

187{
188 if (fA & ASSOCF_VERIFY)
189 {
190 HRESULT hr = OpenShellVerbKey(hClass, pszVerb, phKey);
191 if (FAILED(hr))
193 RegCloseKey(*phKey);
194 }
195 return SHRegDuplicateHKey(hClass, phKey);
196}
static HRESULT OpenShellVerbKey(HKEY hClass, LPCWSTR pszVerb, HKEY *phKey)
@ ASSOCF_VERIFY
Definition: shlwapi.h:866
static HRESULT HRESULT_FROM_WIN32(unsigned int x)
Definition: winerror.h:210
#define ERROR_NO_ASSOCIATION
Definition: winerror.h:1001

Referenced by CQueryAssociations::GetKey().

◆ OpenShellVerbKey()

static HRESULT OpenShellVerbKey ( HKEY  hClass,
LPCWSTR  pszVerb,
HKEY phKey 
)
static

Definition at line 173 of file CQueryAssociations.cpp.

174{
175 const SIZE_T cchPrefix = sizeof("shell\\") - 1;
176 WCHAR szPath[cchPrefix + MAX_PATH];
177 if (FAILED(StringCchPrintfW(szPath, _countof(szPath), L"shell\\%s", pszVerb ? pszVerb : L"")))
178 return E_FAIL;
179
180 if (!pszVerb && !HCR_GetDefaultVerbW(hClass, NULL, szPath + cchPrefix, _countof(szPath) - cchPrefix))
182
183 return HResultFromWin32(RegOpenKeyExW(hClass, szPath, 0, KEY_READ, phKey));
184}
LPCWSTR szPath
Definition: env.c:37
BOOL HCR_GetDefaultVerbW(HKEY hkeyClass, LPCWSTR szVerb, LPWSTR szDest, DWORD len)
Definition: classes.c:152
ULONG_PTR SIZE_T
Definition: typedefs.h:80

Referenced by OpenClassWithShellExecKey().

◆ SH32_AssocCreateElement()

static HRESULT SH32_AssocCreateElement ( _In_ REFCLSID  rclsid,
_In_ REFIID  riid,
_Outptr_ PVOID ppv 
)
inlinestatic

Definition at line 25 of file CQueryAssociations.cpp.

26{
27#if DLL_EXPORT_VERSION >= _WIN32_WINNT_VISTA
28 return AssocCreateElement(rclsid, riid, ppv);
29#else
30 return AssocCreate(rclsid, riid, ppv);
31#endif
32}
HRESULT WINAPI AssocCreate(CLSID clsid, REFIID refiid, void **lpInterface)
Definition: assoc.c:213
EXTERN_C HRESULT WINAPI AssocCreateElement(_In_ REFCLSID rclsid, _In_ REFIID riid, _Outptr_ PVOID *ppvObj)
Definition: elements.cpp:1612

Referenced by AssocCreateElementInternal(), and CQueryAssociations::GetKey().

◆ SH32_AssocCreateElementOnKey()

static HRESULT SH32_AssocCreateElementOnKey ( _In_ REFCLSID  rclsid,
_In_ HKEY  hKey,
_In_opt_ PCWSTR  pszSubKey,
_In_ REFIID  riid,
_Outptr_ PVOID ppv 
)
static

Definition at line 55 of file CQueryAssociations.cpp.

57{
58#if DLL_EXPORT_VERSION >= _WIN32_WINNT_VISTA
60 if (SUCCEEDED(hr))
61 return hr;
62#endif
64}
static HRESULT AssocCreateElementOnKeyInternal(_In_ REFCLSID rclsid, _In_ HKEY hKey, _In_opt_ PCWSTR pszSubKey, _In_ REFIID riid, _Outptr_ PVOID *ppv, _In_ BYTE Major)

Referenced by SH32_QueryAssocElementString().

◆ SH32_QueryAssocElementString()

static HRESULT SH32_QueryAssocElementString ( _In_ REFCLSID  rclsid,
_In_ UINT  Query,
_In_ HKEY  hKey,
_In_opt_ PCWSTR  pszSubKey,
_In_ PCWSTR  pszExtra,
_Out_ PWSTR ppszValue 
)
static

Definition at line 66 of file CQueryAssociations.cpp.

68{
69#if SHELL32_CAssocElement_Version >= _WIN32_WINNT_VISTA
71 REFIID riid = IID_IAssociationElement;
72#else
74 REFIID riid = IID_IAssociationElementOld;
75#endif
76 HRESULT hr = SH32_AssocCreateElementOnKey(rclsid, hKey, pszSubKey, riid, (void**)&pAE);
77 if (FAILED(hr))
78 return hr;
79 return pAE->QueryString(Query, pszExtra, ppszValue);
80}
static HRESULT SH32_AssocCreateElementOnKey(_In_ REFCLSID rclsid, _In_ HKEY hKey, _In_opt_ PCWSTR pszSubKey, _In_ REFIID riid, _Outptr_ PVOID *ppv)
BOOL Query(LPCTSTR *ServiceArgs, DWORD ArgCount, BOOL bExtended)
Definition: query.c:292

Referenced by CQueryAssociations::GetCommand().

◆ SHELL32_AssocGetExtensionDescription()

static HRESULT SHELL32_AssocGetExtensionDescription ( PCWSTR  DotExt,
PWSTR  Buf,
UINT  cchBuf 
)
static

Definition at line 116 of file CQueryAssociations.cpp.

117{
118 HRESULT hr;
119 if (!DotExt[0] || (!DotExt[1] && DotExt[0] == '.'))
120 {
122 StrTrimW(Buf, L" -"); // Remove the empty %s so we are left with "File"
123 return hr;
124 }
125 HKEY hKey;
127 {
128 DWORD err = RegLoadMUIStringW(hKey, L"FriendlyTypeName", Buf, cchBuf, NULL, 0, NULL);
129 if (err && hr == S_OK) // ProgId default value fallback (but not if we only have a .ext key)
130 {
131 DWORD cb = cchBuf * sizeof(*Buf);
133 }
135 if (!err)
136 return err;
137 }
138 // No information in the registry, default to "UPPERCASEEXT File"
139 WCHAR ext[MAX_PATH + 33];
141 DotExt = ext;
142 return GetExtensionDefaultDescription(DotExt, Buf, cchBuf);
143}
static HRESULT GetExtensionDefaultDescription(PCWSTR DotExt, PWSTR Buf, UINT cchBuf)
LONG RegLoadMUIStringW(IN HKEY hKey, IN LPCWSTR pszValue OPTIONAL, OUT LPWSTR pszOutBuf, IN DWORD cbOutBuf, OUT LPDWORD pcbData OPTIONAL, IN DWORD Flags, IN LPCWSTR pszDirectory OPTIONAL)
Definition: muireg.c:53
#define TRUE
Definition: types.h:120
LSTATUS WINAPI RegGetValueW(HKEY hKey, LPCWSTR pszSubKey, LPCWSTR pszValue, DWORD dwFlags, LPDWORD pdwType, PVOID pvData, LPDWORD pcbData)
Definition: reg.c:1931
static const WCHAR *const ext[]
Definition: module.c:53
INT WINAPI LCMapStringW(LCID lcid, DWORD flags, LPCWSTR src, INT srclen, LPWSTR dst, INT dstlen)
Definition: locale.c:3808
BOOL WINAPI StrTrimW(WCHAR *str, const WCHAR *trim)
Definition: string.c:804
static MonoProfilerRuntimeShutdownBeginCallback cb
Definition: metahost.c:118
unsigned long DWORD
Definition: ntddk_ex.h:95
#define LOCALE_USER_DEFAULT
HRESULT HCR_GetProgIdKeyOfExtension(PCWSTR szExtension, PHKEY phKey, BOOL AllowFallback)
Definition: classes.c:55
#define LCMAP_UPPERCASE
Definition: winnls.h:202
#define RRF_RT_REG_SZ
Definition: winreg.h:58

Referenced by SHELL32_AssocGetFileDescription().

◆ SHELL32_AssocGetFileDescription()

EXTERN_C HRESULT SHELL32_AssocGetFileDescription ( PCWSTR  Name,
PWSTR  Buf,
UINT  cchBuf 
)

Definition at line 145 of file CQueryAssociations.cpp.

146{
148}
static HRESULT SHELL32_AssocGetExtensionDescription(PCWSTR DotExt, PWSTR Buf, UINT cchBuf)
LPWSTR Name
Definition: desk.c:124
LPWSTR WINAPI PathFindExtensionW(const WCHAR *path)
Definition: path.c:1250

Referenced by GetItemDescription(), and SHGetFileInfoW().

◆ SHELL32_AssocGetFSDirectoryDescription()

EXTERN_C HRESULT SHELL32_AssocGetFSDirectoryDescription ( PWSTR  Buf,
UINT  cchBuf 
)

Definition at line 100 of file CQueryAssociations.cpp.

101{
102 static WCHAR cache[33] = {};
103 if (!*cache)
105 return StringCchCopyW(Buf, cchBuf, cache);
106}
#define IDS_DIRECTORY
Definition: shresdef.h:158
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
Definition: cache.c:49

Referenced by GetItemDescription(), and SHGetFileInfoW().

◆ SHRegDuplicateHKey()

static HRESULT SHRegDuplicateHKey ( HKEY  hKey,
HKEY phKey 
)
inlinestatic

Definition at line 19 of file CQueryAssociations.cpp.

20{
21 hKey = *phKey = ::SHRegDuplicateHKey(hKey);
23}
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

Referenced by OpenClassKey(), OpenClassWithShellExecKey(), and SHRegDuplicateHKey().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( shell  )