143d07fe6SWhindmar Saksit /*
243d07fe6SWhindmar Saksit * PROJECT: shell32
343d07fe6SWhindmar Saksit * LICENSE: LGPL-2.1+ (https://spdx.org/licenses/LGPL-2.1+)
443d07fe6SWhindmar Saksit * PURPOSE: Utility functions
543d07fe6SWhindmar Saksit * COPYRIGHT: ReactOS Team
643d07fe6SWhindmar Saksit */
743d07fe6SWhindmar Saksit
843d07fe6SWhindmar Saksit #pragma once
943d07fe6SWhindmar Saksit
10*28399a21SWhindmar Saksit #ifdef __cplusplus
11*28399a21SWhindmar Saksit static inline LPWSTR
SHStrDupW(LPCWSTR Src)12*28399a21SWhindmar Saksit SHStrDupW(LPCWSTR Src)
13*28399a21SWhindmar Saksit {
14*28399a21SWhindmar Saksit LPWSTR Dup;
15*28399a21SWhindmar Saksit return SUCCEEDED(SHStrDupW(Src, &Dup)) ? Dup : NULL;
16*28399a21SWhindmar Saksit }
17*28399a21SWhindmar Saksit #endif
18*28399a21SWhindmar Saksit
19*28399a21SWhindmar Saksit static inline BOOL
RegValueExists(HKEY hKey,LPCWSTR Name)2043d07fe6SWhindmar Saksit RegValueExists(HKEY hKey, LPCWSTR Name)
2143d07fe6SWhindmar Saksit {
2243d07fe6SWhindmar Saksit return RegQueryValueExW(hKey, Name, NULL, NULL, NULL, NULL) == ERROR_SUCCESS;
2343d07fe6SWhindmar Saksit }
2443d07fe6SWhindmar Saksit
2543d07fe6SWhindmar Saksit inline BOOL
RegKeyExists(HKEY hKey,LPCWSTR Path)2643d07fe6SWhindmar Saksit RegKeyExists(HKEY hKey, LPCWSTR Path)
2743d07fe6SWhindmar Saksit {
2843d07fe6SWhindmar Saksit BOOL ret = !RegOpenKeyExW(hKey, Path, 0, MAXIMUM_ALLOWED, &hKey);
2943d07fe6SWhindmar Saksit if (ret)
3043d07fe6SWhindmar Saksit RegCloseKey(hKey);
3143d07fe6SWhindmar Saksit return ret;
3243d07fe6SWhindmar Saksit }
3343d07fe6SWhindmar Saksit
3443d07fe6SWhindmar Saksit inline DWORD
RegSetOrDelete(HKEY hKey,LPCWSTR Name,DWORD Type,LPCVOID Data,DWORD Size)3543d07fe6SWhindmar Saksit RegSetOrDelete(HKEY hKey, LPCWSTR Name, DWORD Type, LPCVOID Data, DWORD Size)
3643d07fe6SWhindmar Saksit {
3743d07fe6SWhindmar Saksit if (Data)
3843d07fe6SWhindmar Saksit return RegSetValueExW(hKey, Name, 0, Type, LPBYTE(Data), Size);
3943d07fe6SWhindmar Saksit else
4043d07fe6SWhindmar Saksit return RegDeleteValueW(hKey, Name);
4143d07fe6SWhindmar Saksit }
4243d07fe6SWhindmar Saksit
43*28399a21SWhindmar Saksit static inline DWORD
4443d07fe6SWhindmar Saksit RegSetString(HKEY hKey, LPCWSTR Name, LPCWSTR Str, DWORD Type = REG_SZ)
4543d07fe6SWhindmar Saksit {
4643d07fe6SWhindmar Saksit return RegSetValueExW(hKey, Name, 0, Type, LPBYTE(Str), (lstrlenW(Str) + 1) * sizeof(WCHAR));
4743d07fe6SWhindmar Saksit }
4843d07fe6SWhindmar Saksit
49*28399a21SWhindmar Saksit typedef struct {
50*28399a21SWhindmar Saksit LPCSTR Verb;
51*28399a21SWhindmar Saksit WORD CmdId;
52*28399a21SWhindmar Saksit } CMVERBMAP;
53*28399a21SWhindmar Saksit
54*28399a21SWhindmar Saksit HRESULT
55*28399a21SWhindmar Saksit SHELL_MapContextMenuVerbToCmdId(LPCMINVOKECOMMANDINFO pICI, const CMVERBMAP *pMap);
56*28399a21SWhindmar Saksit HRESULT
57*28399a21SWhindmar Saksit SHELL_GetCommandStringImpl(SIZE_T CmdId, UINT uFlags, LPSTR Buf, UINT cchBuf, const CMVERBMAP *pMap);
58*28399a21SWhindmar Saksit
5943d07fe6SWhindmar Saksit // SHExtractIconsW is a forward, use this function instead inside shell32
6043d07fe6SWhindmar Saksit inline HICON
SHELL32_SHExtractIcon(LPCWSTR File,int Index,int cx,int cy)6143d07fe6SWhindmar Saksit SHELL32_SHExtractIcon(LPCWSTR File, int Index, int cx, int cy)
6243d07fe6SWhindmar Saksit {
6343d07fe6SWhindmar Saksit HICON hIco;
6443d07fe6SWhindmar Saksit int r = PrivateExtractIconsW(File, Index, cx, cy, &hIco, NULL, 1, 0);
6543d07fe6SWhindmar Saksit return r > 0 ? hIco : NULL;
6643d07fe6SWhindmar Saksit }
67*28399a21SWhindmar Saksit
68*28399a21SWhindmar Saksit HRESULT
69*28399a21SWhindmar Saksit SHELL_CreateShell32DefaultExtractIcon(int IconIndex, REFIID riid, LPVOID *ppvOut);
70*28399a21SWhindmar Saksit
71*28399a21SWhindmar Saksit static inline HRESULT
SHELL_CreateFallbackExtractIconForFolder(REFIID riid,LPVOID * ppvOut)72*28399a21SWhindmar Saksit SHELL_CreateFallbackExtractIconForFolder(REFIID riid, LPVOID *ppvOut)
73*28399a21SWhindmar Saksit {
74*28399a21SWhindmar Saksit const int id = IDI_SHELL_FOLDER;
75*28399a21SWhindmar Saksit return SHELL_CreateShell32DefaultExtractIcon(id > 1 ? -id : 0, riid, ppvOut);
76*28399a21SWhindmar Saksit }
77*28399a21SWhindmar Saksit
78*28399a21SWhindmar Saksit static inline HRESULT
SHELL_CreateFallbackExtractIconForNoAssocFile(REFIID riid,LPVOID * ppvOut)79*28399a21SWhindmar Saksit SHELL_CreateFallbackExtractIconForNoAssocFile(REFIID riid, LPVOID *ppvOut)
80*28399a21SWhindmar Saksit {
81*28399a21SWhindmar Saksit const int id = IDI_SHELL_DOCUMENT;
82*28399a21SWhindmar Saksit return SHELL_CreateShell32DefaultExtractIcon(id > 1 ? -id : 0, riid, ppvOut);
83*28399a21SWhindmar Saksit }
84