ReactOS 0.4.16-dev-983-g23ad936
utils.h
Go to the documentation of this file.
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#ifndef OPTIONAL_
11 #ifdef __cplusplus
12 #define OPTIONAL_(arg) = arg
13 #else
14 #define OPTIONAL_(arg)
15 #endif
16#endif
17
18#ifdef __cplusplus
19static inline LPWSTR
21{
22 LPWSTR Dup;
23 return SUCCEEDED(SHStrDupW(Src, &Dup)) ? Dup : NULL;
24}
25
26static inline UINT
27SHELL_ErrorBox(CMINVOKECOMMANDINFO &cmi, UINT Error)
28{
29 if (cmi.fMask & CMIC_MASK_FLAG_NO_UI)
31 return SHELL_ErrorBox(cmi.hwnd, Error);
32}
33#endif
34
35static inline BOOL
37{
38 CLSID temp;
39 return pPersist && SUCCEEDED(pPersist->GetClassID(&temp)) && IsEqualCLSID(clsid, temp);
40}
41
42static inline BOOL
44{
46}
47
48inline BOOL
50{
52 if (ret)
54 return ret;
55}
56
57inline DWORD
59{
60 if (Data)
61 return RegSetValueExW(hKey, Name, 0, Type, (LPBYTE)Data, Size);
62 else
63 return RegDeleteValueW(hKey, Name);
64}
65
66static inline DWORD
68{
69 return RegSetValueExW(hKey, Name, 0, Type, (LPBYTE)Str, (lstrlenW(Str) + 1) * sizeof(WCHAR));
70}
71
72typedef struct
73{
76} CMVERBMAP;
77
79SHELL_MapContextMenuVerbToCmdId(LPCMINVOKECOMMANDINFO pICI, const CMVERBMAP *pMap);
81SHELL_GetCommandStringImpl(SIZE_T CmdId, UINT uFlags, LPSTR Buf, UINT cchBuf, const CMVERBMAP *pMap);
82
83// SHExtractIconsW is a forward, use this function instead inside shell32
84inline HICON
86{
87 HICON hIco;
88 int r = PrivateExtractIconsW(File, Index, cx, cy, &hIco, NULL, 1, 0);
89 return r > 0 ? hIco : NULL;
90}
91
94
95static inline HRESULT
97{
98 const int id = IDI_SHELL_FOLDER;
99 return SHELL_CreateShell32DefaultExtractIcon(id > 1 ? -id : 0, riid, ppvOut);
100}
101
102static inline HRESULT
104{
105 const int id = IDI_SHELL_DOCUMENT;
106 return SHELL_CreateShell32DefaultExtractIcon(id > 1 ? -id : 0, riid, ppvOut);
107}
108
109#ifdef __cplusplus
110struct ClipboardViewerChain
111{
112 HWND m_hWndNext = HWND_BOTTOM;
113
114 void Unhook(HWND hWnd)
115 {
116 if (m_hWndNext != HWND_BOTTOM)
117 ChangeClipboardChain(hWnd, m_hWndNext);
118 m_hWndNext = HWND_BOTTOM;
119 }
120
121 void Hook(HWND hWnd)
122 {
123 if (m_hWndNext == HWND_BOTTOM)
124 m_hWndNext = SetClipboardViewer(hWnd);
125 }
126
127 LRESULT HandleChangeCBChain(WPARAM wParam, LPARAM lParam)
128 {
129 if (m_hWndNext == (HWND)wParam)
130 return (LRESULT)(m_hWndNext = (HWND)lParam);
131 else if (m_hWndNext && m_hWndNext != HWND_BOTTOM)
132 return ::SendMessageW(m_hWndNext, WM_CHANGECBCHAIN, wParam, lParam);
133 return 0;
134 }
135
136 LRESULT HandleDrawClipboard(WPARAM wParam, LPARAM lParam)
137 {
138 if (m_hWndNext && m_hWndNext != HWND_BOTTOM)
139 return ::SendMessageW(m_hWndNext, WM_DRAWCLIPBOARD, wParam, lParam);
140 return 0;
141 }
142};
143
144struct CCidaChildArrayHelper
145{
146 // Note: This just creates an array pointing to the items and has the same lifetime as the CIDA.
147 // Use _ILCopyCidaToaPidl if you need the items to outlive the CIDA!
148 explicit CCidaChildArrayHelper(const CIDA *pCida)
149 {
150 m_hr = E_OUTOFMEMORY;
151 m_array = (PCUIDLIST_RELATIVE_ARRAY)SHAlloc(pCida->cidl * sizeof(LPITEMIDLIST));
152 if (m_array)
153 {
154 m_hr = S_OK;
155 for (UINT i = 0; i < pCida->cidl; ++i)
156 *(LPITEMIDLIST*)(&m_array[i]) = (LPITEMIDLIST)HIDA_GetPIDLItem(pCida, i);
157 }
158 }
159 ~CCidaChildArrayHelper() { SHFree((LPITEMIDLIST*)m_array); }
160
161 HRESULT hr() const { return m_hr; }
162 PCUIDLIST_RELATIVE_ARRAY GetItems() const { return m_array; }
163
164 HRESULT m_hr;
166};
167#endif // __cplusplus
PRTL_UNICODE_STRING_BUFFER Path
Type
Definition: Type.h:7
HWND hWnd
Definition: settings.c:17
#define IDI_SHELL_FOLDER
Definition: treeview.c:21
BOOL Error
Definition: chkdsk.c:66
#define RegCloseKey(hKey)
Definition: registry.h:49
Definition: File.h:16
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define ERROR_SUCCESS
Definition: deptool.c:10
LPWSTR Name
Definition: desk.c:124
#define NULL
Definition: types.h:112
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4882
LONG WINAPI RegDeleteValueW(HKEY hKey, LPCWSTR lpValueName)
Definition: reg.c:2330
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
UINT uFlags
Definition: api.c:59
HANDLE HWND
Definition: compat.h:19
#define lstrlenW
Definition: compat.h:750
static const WCHAR IconIndex[]
Definition: install.c:52
HRESULT SHELL_CreateShell32DefaultExtractIcon(int IconIndex, REFIID riid, LPVOID *ppvOut)
Definition: utils.cpp:1806
static BOOL IsEqualPersistClassID(IPersist *pPersist, REFCLSID clsid)
Definition: utils.h:36
static HRESULT SHELL_CreateFallbackExtractIconForNoAssocFile(REFIID riid, LPVOID *ppvOut)
Definition: utils.h:103
HICON SHELL32_SHExtractIcon(LPCWSTR File, int Index, int cx, int cy)
Definition: utils.h:85
BOOL RegKeyExists(HKEY hKey, LPCWSTR Path)
Definition: utils.h:49
HRESULT SHELL_GetCommandStringImpl(SIZE_T CmdId, UINT uFlags, LPSTR Buf, UINT cchBuf, const CMVERBMAP *pMap)
Definition: utils.cpp:1783
static DWORD RegSetString(HKEY hKey, LPCWSTR Name, LPCWSTR Str, DWORD Type OPTIONAL_(REG_SZ))
Definition: utils.h:67
HRESULT SHELL_MapContextMenuVerbToCmdId(LPCMINVOKECOMMANDINFO pICI, const CMVERBMAP *pMap)
Definition: utils.cpp:1749
static BOOL RegValueExists(HKEY hKey, LPCWSTR Name)
Definition: utils.h:43
static HRESULT SHELL_CreateFallbackExtractIconForFolder(REFIID riid, LPVOID *ppvOut)
Definition: utils.h:96
#define OPTIONAL_(arg)
Definition: utils.h:14
DWORD RegSetOrDelete(HKEY hKey, LPCWSTR Name, DWORD Type, LPCVOID Data, DWORD Size)
Definition: utils.h:58
void WINAPI SHFree(LPVOID pv)
Definition: shellole.c:326
LPVOID WINAPI SHAlloc(SIZE_T len)
Definition: shellole.c:304
HRESULT WINAPI SHStrDupW(LPCWSTR src, LPWSTR *dest)
Definition: string.c:2018
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
FxAutoRegKey hKey
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
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
REFIID riid
Definition: atlbase.h:39
HRESULT GetClassID([out] CLSID *pClassID)
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define REG_SZ
Definition: layer.c:22
static HICON
Definition: imagelist.c:80
REFCLSID clsid
Definition: msctf.c:82
unsigned int UINT
Definition: ndis.h:50
#define MAXIMUM_ALLOWED
Definition: nt_native.h:83
_Out_opt_ int _Out_opt_ int * cy
Definition: commctrl.h:586
_Out_opt_ int * cx
Definition: commctrl.h:585
#define REFIID
Definition: guiddef.h:118
#define REFCLSID
Definition: guiddef.h:117
#define IsEqualCLSID(rclsid1, rclsid2)
Definition: guiddef.h:96
static calc_node_t temp
Definition: rpn_ieee.c:38
static PCUIDLIST_RELATIVE HIDA_GetPIDLItem(CIDA const *pida, SIZE_T i)
Definition: shellutils.h:641
#define SHELL_ErrorBox
Definition: shellutils.h:126
HRESULT hr
Definition: shlfolder.c:183
#define IDI_SHELL_DOCUMENT
Definition: shresdef.h:579
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
const PCUIDLIST_RELATIVE * PCUIDLIST_RELATIVE_ARRAY
Definition: shtypes.idl:58
Definition: shlobj.h:580
UINT cidl
Definition: shlobj.h:580
WORD CmdId
Definition: utils.h:75
LPCSTR Verb
Definition: utils.h:74
unsigned char * LPBYTE
Definition: typedefs.h:53
ULONG_PTR SIZE_T
Definition: typedefs.h:80
int ret
_In_ WDFCOLLECTION _In_ ULONG Index
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
CONST void * LPCVOID
Definition: windef.h:191
#define ERROR_INTERNAL_ERROR
Definition: winerror.h:840
UINT WINAPI PrivateExtractIconsW(_In_reads_(MAX_PATH) LPCWSTR szFileName, _In_ int nIconIndex, _In_ int cxIcon, _In_ int cyIcon, _Out_writes_opt_(nIcons) HICON *phicon, _Out_writes_opt_(nIcons) UINT *piconid, _In_ UINT nIcons, _In_ UINT flags)
#define WM_DRAWCLIPBOARD
Definition: winuser.h:1880
#define WM_CHANGECBCHAIN
Definition: winuser.h:1885
HWND WINAPI SetClipboardViewer(_In_ HWND)
BOOL WINAPI ChangeClipboardChain(_In_ HWND, _In_ HWND)
#define HWND_BOTTOM
Definition: winuser.h:1216
const char * LPCSTR
Definition: xmlstorage.h:183
char * LPSTR
Definition: xmlstorage.h:182
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185