xref: /reactos/dll/win32/shell32/utils.h (revision 84344399)
1 /*
2  * PROJECT:     shell32
3  * LICENSE:     LGPL-2.1+ (https://spdx.org/licenses/LGPL-2.1+)
4  * PURPOSE:     Utility functions
5  * COPYRIGHT:   ReactOS Team
6  */
7 
8 #pragma once
9 
10 inline BOOL
11 RegValueExists(HKEY hKey, LPCWSTR Name)
12 {
13     return RegQueryValueExW(hKey, Name, NULL, NULL, NULL, NULL) == ERROR_SUCCESS;
14 }
15 
16 inline BOOL
17 RegKeyExists(HKEY hKey, LPCWSTR Path)
18 {
19     BOOL ret = !RegOpenKeyExW(hKey, Path, 0, MAXIMUM_ALLOWED, &hKey);
20     if (ret)
21         RegCloseKey(hKey);
22     return ret;
23 }
24 
25 inline DWORD
26 RegSetOrDelete(HKEY hKey, LPCWSTR Name, DWORD Type, LPCVOID Data, DWORD Size)
27 {
28     if (Data)
29         return RegSetValueExW(hKey, Name, 0, Type, LPBYTE(Data), Size);
30     else
31         return RegDeleteValueW(hKey, Name);
32 }
33 
34 inline DWORD
35 RegSetString(HKEY hKey, LPCWSTR Name, LPCWSTR Str, DWORD Type = REG_SZ)
36 {
37     return RegSetValueExW(hKey, Name, 0, Type, LPBYTE(Str), (lstrlenW(Str) + 1) * sizeof(WCHAR));
38 }
39 
40 // SHExtractIconsW is a forward, use this function instead inside shell32
41 inline HICON
42 SHELL32_SHExtractIcon(LPCWSTR File, int Index, int cx, int cy)
43 {
44     HICON hIco;
45     int r = PrivateExtractIconsW(File, Index, cx, cy, &hIco, NULL, 1, 0);
46     return r > 0 ? hIco : NULL;
47 }
48