ReactOS 0.4.17-dev-258-gb1f0478
AssocQueryKey.c File Reference
#include <apitest.h>
#include <windef.h>
#include <shlwapi.h>
#include <pseh/pseh2.h>
Include dependency graph for AssocQueryKey.c:

Go to the source code of this file.

Classes

struct  _MY_KEY_NAME_INFORMATION
 

Typedefs

typedef enum _MY_KEY_INFORMATION_CLASS MY_KEY_INFORMATION_CLASS
 
typedef struct _MY_KEY_NAME_INFORMATION MY_KEY_NAME_INFORMATION
 
typedef struct _MY_KEY_NAME_INFORMATIONPMY_KEY_NAME_INFORMATION
 
typedef NTSTATUS(__stdcallFN_NtQueryKey) (HANDLE, MY_KEY_INFORMATION_CLASS, PVOID, ULONG, PULONG)
 

Enumerations

enum  _MY_KEY_INFORMATION_CLASS { MyKeyBasicInformation = 0 , MyKeyNodeInformation = 1 , MyKeyFullInformation = 2 , MyKeyNameInformation = 3 }
 

Functions

static BOOL InitNtQueryKey (VOID)
 
static LPWSTR GetKeyPath (HKEY hKey)
 
static void TEST_AssocKeys (void)
 
static void TEST_AssocF_Flags (void)
 
static void TEST_PszAssoc (void)
 
static void TEST_InvalidArgs (void)
 
static void TEST_ByExeName (void)
 
static void TEST_ShellExecClass (void)
 
 START_TEST (AssocQueryKey)
 

Variables

static FN_NtQueryKey g_NtQueryKey = NULL
 

Typedef Documentation

◆ FN_NtQueryKey

Definition at line 28 of file AssocQueryKey.c.

◆ MY_KEY_INFORMATION_CLASS

◆ MY_KEY_NAME_INFORMATION

◆ PMY_KEY_NAME_INFORMATION

Enumeration Type Documentation

◆ _MY_KEY_INFORMATION_CLASS

Enumerator
MyKeyBasicInformation 
MyKeyNodeInformation 
MyKeyFullInformation 
MyKeyNameInformation 

Definition at line 13 of file AssocQueryKey.c.

14{
@ MyKeyNodeInformation
Definition: AssocQueryKey.c:16
@ MyKeyNameInformation
Definition: AssocQueryKey.c:18
@ MyKeyBasicInformation
Definition: AssocQueryKey.c:15
@ MyKeyFullInformation
Definition: AssocQueryKey.c:17
enum _MY_KEY_INFORMATION_CLASS MY_KEY_INFORMATION_CLASS

Function Documentation

◆ GetKeyPath()

static LPWSTR GetKeyPath ( HKEY  hKey)
static

Definition at line 40 of file AssocQueryKey.c.

41{
42 if (!g_NtQueryKey || !hKey)
43 return NULL;
44
45 ULONG needed = 0;
47
48 if (!needed)
49 return NULL;
50
51 SIZE_T cb = needed + sizeof(WCHAR);
52 PBYTE buf = (PBYTE)_alloca(cb);
54
55 ULONG returned = 0;
57
58 if (status < 0)
59 return NULL;
60
62 return StrDupW(info->Name); // needs LocalFree
63}
static FN_NtQueryKey g_NtQueryKey
Definition: AssocQueryKey.c:29
struct _MY_KEY_NAME_INFORMATION * PMY_KEY_NAME_INFORMATION
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
WCHAR *WINAPI StrDupW(const WCHAR *str)
Definition: string.c:313
static MonoProfilerRuntimeShutdownBeginCallback cb
Definition: metahost.c:118
FxAutoRegKey hKey
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define ZeroMemory
Definition: minwinbase.h:31
BYTE * PBYTE
Definition: pedump.c:66
short WCHAR
Definition: pedump.c:58
Definition: ps.c:97
ULONG_PTR SIZE_T
Definition: typedefs.h:80
uint32_t ULONG
Definition: typedefs.h:59

Referenced by TEST_AssocF_Flags(), TEST_AssocKeys(), TEST_ByExeName(), TEST_PszAssoc(), and TEST_ShellExecClass().

◆ InitNtQueryKey()

static BOOL InitNtQueryKey ( VOID  )
static

Definition at line 31 of file AssocQueryKey.c.

32{
33 HMODULE hNTDLL = GetModuleHandleW(L"ntdll.dll");
34 if (!hNTDLL) return FALSE;
35 g_NtQueryKey = (FN_NtQueryKey)GetProcAddress(hNTDLL, "NtQueryKey");
36 return g_NtQueryKey != NULL;
37}
NTSTATUS(__stdcall * FN_NtQueryKey)(HANDLE, MY_KEY_INFORMATION_CLASS, PVOID, ULONG, PULONG)
Definition: AssocQueryKey.c:28
#define FALSE
Definition: types.h:117
#define GetProcAddress(x, y)
Definition: compat.h:753
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
#define L(x)
Definition: resources.c:13

Referenced by START_TEST().

◆ START_TEST()

START_TEST ( AssocQueryKey  )

Definition at line 385 of file AssocQueryKey.c.

386{
387 if (!InitNtQueryKey())
388 {
389 skip("NtQueryKey not found\n");
390 return;
391 }
392
393 HRESULT hrCoInit = CoInitialize(NULL);
394
401
402 if (SUCCEEDED(hrCoInit))
404}
static BOOL InitNtQueryKey(VOID)
Definition: AssocQueryKey.c:31
static void TEST_ByExeName(void)
static void TEST_ShellExecClass(void)
static void TEST_PszAssoc(void)
static void TEST_AssocKeys(void)
Definition: AssocQueryKey.c:66
static void TEST_AssocF_Flags(void)
static void TEST_InvalidArgs(void)
#define skip(...)
Definition: atltest.h:64
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: combase.c:2842
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:531
#define SUCCEEDED(hr)
Definition: intsafe.h:50

◆ TEST_AssocF_Flags()

static void TEST_AssocF_Flags ( void  )
static

Definition at line 131 of file AssocQueryKey.c.

132{
133 const ASSOCF cases[] =
134 {
148 };
149
150 for (size_t i = 0; i < _countof(cases); ++i)
151 {
152 HKEY hKey = NULL;
153 HRESULT hr = AssocQueryKeyW(cases[i], ASSOCKEY_CLASS, L".reg", NULL, &hKey);
154 ok_hr(hr, S_OK);
155
157 if (hKey)
159
160 ok(path &&
161 (StrStrIW(path, L"\\REGISTRY\\MACHINE\\") || StrStrIW(path, L"\\REGISTRY\\USER\\")),
162 "path was %s\n", wine_dbgstr_w(path));
164 }
165}
#define ok_hr(status, expected)
Definition: ACListISF.cpp:31
static LPWSTR GetKeyPath(HKEY hKey)
Definition: AssocQueryKey.c:40
#define ok(value,...)
Definition: atltest.h:57
#define RegCloseKey(hKey)
Definition: registry.h:49
HRESULT hr
Definition: delayimp.cpp:582
LPWSTR WINAPI StrStrIW(LPCWSTR lpszStr, LPCWSTR lpszSearch)
Definition: string.c:380
HRESULT WINAPI AssocQueryKeyW(ASSOCF cfFlags, ASSOCKEY assockey, LPCWSTR pszAssoc, LPCWSTR pszExtra, HKEY *phkeyOut)
Definition: assoc.c:369
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
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
#define S_OK
Definition: intsafe.h:52
#define wine_dbgstr_w
Definition: kernel32.h:34
@ ASSOCF_REMAPRUNDLL
Definition: shlwapi.h:867
@ ASSOCF_NOFIXUPS
Definition: shlwapi.h:868
@ ASSOCF_INIT_DEFAULTTOSTAR
Definition: shlwapi.h:862
@ ASSOCF_INIT_DEFAULTTOFOLDER
Definition: shlwapi.h:863
@ ASSOCF_IGNOREBASECLASS
Definition: shlwapi.h:869
@ ASSOCF_INIT_NOREMAPCLSID
Definition: shlwapi.h:859
@ ASSOCF_VERIFY
Definition: shlwapi.h:866
@ ASSOCF_INIT_IGNOREUNKNOWN
Definition: shlwapi.h:870
@ ASSOCF_NOUSERSETTINGS
Definition: shlwapi.h:864
@ ASSOCF_NONE
Definition: shlwapi.h:858
@ ASSOCF_NOTRUNCATE
Definition: shlwapi.h:865
@ ASSOCKEY_CLASS
Definition: shlwapi.h:921
DWORD ASSOCF
Definition: shlwapi.h:967
#define _countof(array)
Definition: sndvol32.h:70
uint16_t * LPWSTR
Definition: typedefs.h:56

Referenced by START_TEST().

◆ TEST_AssocKeys()

static void TEST_AssocKeys ( void  )
static

Definition at line 66 of file AssocQueryKey.c.

67{
68 {
69 HKEY hKey = NULL;
71 ok_hr(hr, S_OK);
72
74 if (hKey)
76
77 ok(path &&
78 (StrStrIW(path, L"\\REGISTRY\\MACHINE\\") || StrStrIW(path, L"\\REGISTRY\\USER\\")) &&
79 StrStrIW(path, L"regfile"),
80 "path was %s\n", wine_dbgstr_w(path));
82 }
83
84 {
85 HKEY hKey = NULL;
87 ok_hr(hr, S_OK);
88
90 if (hKey)
92
94 L"\\REGISTRY\\MACHINE\\SOFTWARE\\Classes\\Applications\\regedit.exe"),
95 "path was %s\n", wine_dbgstr_w(path));
97 }
98
99 {
100 HKEY hKey = NULL;
102 ok_hr(hr, S_OK);
103
105 if (hKey)
107
108 ok(path &&
109 (StrStrIW(path, L"\\REGISTRY\\MACHINE\\") || StrStrIW(path, L"\\REGISTRY\\USER\\")) &&
110 StrStrIW(path, L"Classes\\regfile"),
111 "path was %s\n", wine_dbgstr_w(path));
113 }
114
115 {
116 HKEY hKey = NULL;
118 ok_hr(hr, S_OK);
119
121 if (hKey)
123
124 ok(path && !_wcsicmp(path, L"\\REGISTRY\\MACHINE\\SOFTWARE\\Classes\\exefile"),
125 "path was %s\n", wine_dbgstr_w(path));
127 }
128}
_ACRTIMP int __cdecl _wcsicmp(const wchar_t *, const wchar_t *)
Definition: wcs.c:159
@ ASSOCKEY_SHELLEXECCLASS
Definition: shlwapi.h:919
@ ASSOCKEY_APP
Definition: shlwapi.h:920

Referenced by START_TEST().

◆ TEST_ByExeName()

static void TEST_ByExeName ( void  )
static

Definition at line 314 of file AssocQueryKey.c.

315{
316 WCHAR notepadPath[MAX_PATH];
317 GetSystemDirectoryW(notepadPath, MAX_PATH);
318 lstrcatW(notepadPath, L"\\notepad.exe");
319
320 // Full path
321 {
322 HKEY hKey = NULL;
324
326 if (hKey)
328
329 ok_hr(hr, S_OK);
330
331 ok(path &&
332 !_wcsicmp(path, L"\\REGISTRY\\MACHINE\\SOFTWARE\\Classes\\Applications\\notepad.exe"),
333 "path was %s\n", wine_dbgstr_w(path));
335 }
336
337 // Short name
338 {
339 HKEY hKey = NULL;
341 L"regedit.exe", NULL, &hKey);
343 if (hKey)
345 ok_hr(hr, S_OK);
346
347 ok(path &&
348 !_wcsicmp(path, L"\\REGISTRY\\MACHINE\\SOFTWARE\\Classes\\Applications\\regedit.exe"),
349 "path was %s\n", wine_dbgstr_w(path));
351 }
352
353 // Non existent
354 {
355 HKEY hKey = NULL;
357 L"__ghost__.exe", NULL, &hKey);
358 ok(hKey == NULL, "hKey was not NULL\n");
359 if (hKey)
361 ok(FAILED(hr), "hr was 0x%08lX\n", hr);
362 }
363}
#define MAX_PATH
Definition: compat.h:34
UINT WINAPI GetSystemDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2232
#define FAILED(hr)
Definition: intsafe.h:51
LPWSTR WINAPI lstrcatW(LPWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:274
@ ASSOCF_OPEN_BYEXENAME
Definition: shlwapi.h:861
@ ASSOCF_INIT_BYEXENAME
Definition: shlwapi.h:860

Referenced by START_TEST().

◆ TEST_InvalidArgs()

static void TEST_InvalidArgs ( void  )
static

Definition at line 232 of file AssocQueryKey.c.

233{
234 // phkeyOut == NULL
235 {
236 BOOL threw = FALSE;
238
240 {
242 }
244 {
245 hr = 0xDEADFACE;
246 threw = TRUE;
247 }
248 _SEH2_END;
249
250 ok_hr(hr, 0xDEADFACE);
251 ok_int(threw, TRUE);
252 }
253
254 // pszAssoc == NULL
255 {
256 BOOL threw = FALSE;
258 HKEY hKey = NULL;
259
261 {
263 }
265 {
266 hr = 0xDEADFACE;
267 threw = TRUE;
268 }
269 _SEH2_END;
270
271 ok(hKey == NULL, "hKey was not NULL\n");
272 if (hKey)
274
276 ok_int(threw, FALSE);
277 }
278
279 // pszAssoc == ""
280 {
281 HKEY hKey = NULL;
283 if (hKey)
286 }
287
288 // Invalid ASSOCKEY value
289 {
290 HKEY hKey = NULL;
291 BOOL threw = FALSE;
293
295 {
296 hr = AssocQueryKeyW(ASSOCF_NONE, (ASSOCKEY)0xFFFF, L".txt", NULL, &hKey);
297 }
299 {
300 hr = 0xDEADFACE;
301 threw = TRUE;
302 }
303 _SEH2_END;
304
305 ok(hKey == NULL, "hKey was not NULL\n");
306 if (hKey)
308
310 ok_int(threw, FALSE);
311 }
312}
#define ok_int(expression, result)
Definition: atltest.h:134
#define TRUE
Definition: types.h:120
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
unsigned int BOOL
Definition: ntddk_ex.h:94
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:90
ASSOCKEY
Definition: shlwapi.h:918
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:104
#define _SEH2_END
Definition: pseh2_64.h:194
#define _SEH2_TRY
Definition: pseh2_64.h:93
static HRESULT HRESULT_FROM_WIN32(unsigned int x)
Definition: winerror.h:210
#define E_UNEXPECTED
Definition: winerror.h:3528

Referenced by START_TEST().

◆ TEST_PszAssoc()

static void TEST_PszAssoc ( void  )
static

Definition at line 168 of file AssocQueryKey.c.

169{
170 const wchar_t* exts[] =
171 {
172 L".txt", L".htm", L".reg", L".xml", L".png", L".jpg", L".zip"
173 };
174
175 for (size_t i = 0; i < _countof(exts); ++i)
176 {
177 HKEY hKey = NULL;
179 ok_hr(hr, S_OK);
180
182 if (hKey)
184
185 ok(path &&
186 (StrStrIW(path, L"\\REGISTRY\\MACHINE\\") || StrStrIW(path, L"\\REGISTRY\\USER\\")),
187 "path was %s\n", wine_dbgstr_w(path));
189 }
190
191 // Direct ProgID
192 {
193 HKEY hKey = NULL;
195 ok_hr(hr, S_OK);
196
198 if (hKey)
200
201 ok(path &&
202 (StrStrIW(path, L"\\REGISTRY\\MACHINE\\") || StrStrIW(path, L"\\REGISTRY\\USER\\")) &&
203 StrStrIW(path, L"regfile"),
204 "path was %s\n", wine_dbgstr_w(path));
206 }
207 {
208 HKEY hKey = NULL;
210 ok_hr(hr, S_OK);
211
213 if (hKey)
215
216 ok(path && !_wcsicmp(path, L"\\REGISTRY\\MACHINE\\SOFTWARE\\Classes\\exefile"),
217 "path was %s\n", wine_dbgstr_w(path));
219 }
220
221 // ProgID: InternetShortcut
222 {
223 HKEY hKey = NULL;
224 HRESULT hr = AssocQueryKeyW(ASSOCF_NONE, ASSOCKEY_CLASS, L"InternetShortcut", NULL, &hKey);
225 ok_hr(hr, S_OK);
226 if (hKey)
228 }
229}
static const struct encodedExtensions exts[]
Definition: encode.c:2738

Referenced by START_TEST().

◆ TEST_ShellExecClass()

static void TEST_ShellExecClass ( void  )
static

Definition at line 366 of file AssocQueryKey.c.

367{
368 static const LPCWSTR cases[] = { L".txt", L".htm", L".html", L"txtfile" };
369 for (size_t i = 0; i < _countof(cases); ++i)
370 {
371 HKEY hKey = NULL;
373 ok_hr(hr, S_OK);
374
376 if (hKey)
378
379 ok(path && StrStrIW(path, L"\\REGISTRY\\MACHINE\\SOFTWARE\\Classes\\"),
380 "path was %s\n", wine_dbgstr_w(path));
382 }
383}
const uint16_t * LPCWSTR
Definition: typedefs.h:57

Referenced by START_TEST().

Variable Documentation

◆ g_NtQueryKey

FN_NtQueryKey g_NtQueryKey = NULL
static

Definition at line 29 of file AssocQueryKey.c.

Referenced by GetKeyPath(), and InitNtQueryKey().