ReactOS 0.4.15-dev-8417-gb6b82fe
utils.cpp File Reference
#include "precomp.h"
#include <shellapi.h>
#include <shlwapi.h>
#include <shlobj_undoc.h>
#include <shlguid_undoc.h>
#include <atlstr.h>
#include <shlwapi_undoc.h>
#include <strsafe.h>
Include dependency graph for utils.cpp:

Go to the source code of this file.

Classes

struct  RETRY_DATA
 

Macros

#define _ATL_NO_EXCEPTIONS
 
#define IShellFolder_GetDisplayNameOf   _disabled_IShellFolder_GetDisplayNameOf_
 
#define IShellFolder_ParseDisplayName   _disabled_IShellFolder_ParseDisplayName_
 
#define IShellFolder_CompareIDs   _disabled_IShellFolder_CompareIDs_
 
#define SHLWAPI_ISHELLFOLDER_HELPERS   /* HACK! */
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (shell)
 
EXTERN_C BOOL WINAPI IContextMenu_Invoke (_In_ IContextMenu *pContextMenu, _In_ HWND hwnd, _In_ LPCSTR lpVerb, _In_ UINT uFlags)
 
BOOL WINAPI PathFileExistsDefExtAndAttributesW (_Inout_ LPWSTR pszPath, _In_ DWORD dwWhich, _Out_opt_ LPDWORD pdwFileAttributes)
 
static BOOL SHLWAPI_IsBogusHRESULT (HRESULT hr)
 
EXTERN_C HRESULT WINAPI IShellFolder_GetDisplayNameOf (_In_ IShellFolder *psf, _In_ LPCITEMIDLIST pidl, _In_ SHGDNF uFlags, _Out_ LPSTRRET lpName, _In_ DWORD dwRetryFlags)
 
EXTERN_C HRESULT WINAPI IShellFolder_ParseDisplayName (_In_ IShellFolder *psf, _In_opt_ HWND hwndOwner, _In_opt_ LPBC pbcReserved, _In_ LPOLESTR lpszDisplayName, _Out_opt_ ULONG *pchEaten, _Out_opt_ PIDLIST_RELATIVE *ppidl, _Out_opt_ ULONG *pdwAttributes)
 
EXTERN_C HRESULT WINAPI IShellFolder_CompareIDs (_In_ IShellFolder *psf, _In_ LPARAM lParam, _In_ PCUIDLIST_RELATIVE pidl1, _In_ PCUIDLIST_RELATIVE pidl2)
 

Variables

static const RETRY_DATA g_RetryData []
 

Macro Definition Documentation

◆ _ATL_NO_EXCEPTIONS

#define _ATL_NO_EXCEPTIONS

Definition at line 8 of file utils.cpp.

◆ IShellFolder_CompareIDs

#define IShellFolder_CompareIDs   _disabled_IShellFolder_CompareIDs_

Definition at line 15 of file utils.cpp.

◆ IShellFolder_GetDisplayNameOf

#define IShellFolder_GetDisplayNameOf   _disabled_IShellFolder_GetDisplayNameOf_

Definition at line 13 of file utils.cpp.

◆ IShellFolder_ParseDisplayName

#define IShellFolder_ParseDisplayName   _disabled_IShellFolder_ParseDisplayName_

Definition at line 14 of file utils.cpp.

◆ SHLWAPI_ISHELLFOLDER_HELPERS

#define SHLWAPI_ISHELLFOLDER_HELPERS   /* HACK! */

Definition at line 31 of file utils.cpp.

Function Documentation

◆ IContextMenu_Invoke()

EXTERN_C BOOL WINAPI IContextMenu_Invoke ( _In_ IContextMenu pContextMenu,
_In_ HWND  hwnd,
_In_ LPCSTR  lpVerb,
_In_ UINT  uFlags 
)

Definition at line 45 of file utils.cpp.

50{
51 CMINVOKECOMMANDINFO info;
52 BOOL ret = FALSE;
53 INT iDefItem = 0;
54 HMENU hMenu = NULL;
55 HCURSOR hOldCursor;
56
57 TRACE("(%p, %p, %s, %u)\n", pContextMenu, hwnd, debugstr_a(lpVerb), uFlags);
58
59 if (!pContextMenu)
60 return FALSE;
61
62 hOldCursor = SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_WAIT));
63
64 ZeroMemory(&info, sizeof(info));
65 info.cbSize = sizeof(info);
66 info.hwnd = hwnd;
67 info.nShow = SW_NORMAL;
68 info.lpVerb = lpVerb;
69
70 if (IS_INTRESOURCE(lpVerb))
71 {
72 hMenu = CreatePopupMenu();
73 if (hMenu)
74 {
75 pContextMenu->QueryContextMenu(hMenu, 0, 1, MAXSHORT, uFlags | CMF_DEFAULTONLY);
76 iDefItem = GetMenuDefaultItem(hMenu, 0, 0);
77 if (iDefItem != -1)
78 info.lpVerb = MAKEINTRESOURCEA(iDefItem - 1);
79 }
80 }
81
82 if (iDefItem != -1 || info.lpVerb)
83 {
84 if (!hwnd)
85 info.fMask |= CMIC_MASK_FLAG_NO_UI;
86 ret = SUCCEEDED(pContextMenu->InvokeCommand(&info));
87 }
88
89 /* Invoking itself doesn't need the menu object, but getting the command info
90 needs the menu. */
91 if (hMenu)
92 DestroyMenu(hMenu);
93
94 SetCursor(hOldCursor);
95
96 return ret;
97}
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
UINT uFlags
Definition: api.c:59
unsigned int BOOL
Definition: ntddk_ex.h:94
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define debugstr_a
Definition: kernel32.h:31
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:63
#define TRACE(s)
Definition: solgame.cpp:4
int32_t INT
Definition: typedefs.h:58
#define MAXSHORT
Definition: umtypes.h:114
int ret
#define ZeroMemory
Definition: winbase.h:1712
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
HICON HCURSOR
Definition: windef.h:299
HMENU WINAPI CreatePopupMenu(void)
Definition: menu.c:838
UINT WINAPI GetMenuDefaultItem(_In_ HMENU hMenu, _In_ UINT fByPos, _In_ UINT gmdiFlags)
#define IS_INTRESOURCE(i)
Definition: winuser.h:580
HCURSOR WINAPI SetCursor(_In_opt_ HCURSOR)
HCURSOR WINAPI LoadCursorW(_In_opt_ HINSTANCE, _In_ LPCWSTR)
Definition: cursoricon.c:2149
#define MAKEINTRESOURCEA(i)
Definition: winuser.h:581
BOOL WINAPI DestroyMenu(_In_ HMENU)
#define IDC_WAIT
Definition: winuser.h:689
#define SW_NORMAL
Definition: winuser.h:769
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

◆ IShellFolder_CompareIDs()

EXTERN_C HRESULT WINAPI IShellFolder_CompareIDs ( _In_ IShellFolder psf,
_In_ LPARAM  lParam,
_In_ PCUIDLIST_RELATIVE  pidl1,
_In_ PCUIDLIST_RELATIVE  pidl2 
)

Definition at line 255 of file utils.cpp.

260{
261 TRACE("(%p, %p, %p, %p)\n", psf, lParam, pidl1, pidl2);
262
263 if (lParam & ~(SIZE_T)SHCIDS_COLUMNMASK)
264 {
265 /* Try as IShellFolder2 if possible */
266 HRESULT hr = psf->QueryInterface(IID_IShellFolder2, (void **)&psf);
267 if (FAILED(hr))
268 lParam &= SHCIDS_COLUMNMASK;
269 else
270 psf->Release();
271 }
272
273 return psf->CompareIDs(lParam, pidl1, pidl2);
274}
LPARAM lParam
Definition: combotst.c:139
HRESULT QueryInterface([in] REFIID riid, [out, iid_is(riid)] void **ppvObject)
nsrefcnt Release()
#define FAILED(hr)
Definition: intsafe.h:51
HRESULT hr
Definition: shlfolder.c:183
ULONG_PTR SIZE_T
Definition: typedefs.h:80

◆ IShellFolder_GetDisplayNameOf()

EXTERN_C HRESULT WINAPI IShellFolder_GetDisplayNameOf ( _In_ IShellFolder psf,
_In_ LPCITEMIDLIST  pidl,
_In_ SHGDNF  uFlags,
_Out_ LPSTRRET  lpName,
_In_ DWORD  dwRetryFlags 
)

Definition at line 167 of file utils.cpp.

173{
174 HRESULT hr;
175
176 TRACE("(%p)->(%p, 0x%lX, %p, 0x%lX)\n", psf, pidl, uFlags, lpName, dwRetryFlags);
177
178 hr = psf->GetDisplayNameOf(pidl, uFlags, lpName);
180 return hr;
181
182 dwRetryFlags |= SFGDNO_RETRYALWAYS;
183
184 if ((uFlags & SHGDN_FORPARSING) == 0)
185 dwRetryFlags |= SFGDNO_RETRYWITHFORPARSING;
186
187 // Retry with other flags to get successful results
188 for (SIZE_T iEntry = 0; iEntry < _countof(g_RetryData); ++iEntry)
189 {
190 const RETRY_DATA *pData = &g_RetryData[iEntry];
191 if (!(dwRetryFlags & pData->dwRetryFlags))
192 continue;
193
194 SHGDNF uNewFlags = ((uFlags & ~pData->uRemove) | pData->uAdd);
195 if (uNewFlags == uFlags)
196 continue;
197
198 hr = psf->GetDisplayNameOf(pidl, uNewFlags, lpName);
200 break;
201
202 uFlags = uNewFlags; // Update flags every time
203 }
204
205 return hr;
206}
static const RETRY_DATA g_RetryData[]
Definition: utils.cpp:150
static BOOL SHLWAPI_IsBogusHRESULT(HRESULT hr)
Definition: utils.cpp:138
#define _countof(array)
Definition: sndvol32.h:70
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1830
_In_ LPCSTR lpName
Definition: winbase.h:2789

◆ IShellFolder_ParseDisplayName()

EXTERN_C HRESULT WINAPI IShellFolder_ParseDisplayName ( _In_ IShellFolder psf,
_In_opt_ HWND  hwndOwner,
_In_opt_ LPBC  pbcReserved,
_In_ LPOLESTR  lpszDisplayName,
_Out_opt_ ULONG pchEaten,
_Out_opt_ PIDLIST_RELATIVE ppidl,
_Out_opt_ ULONG pdwAttributes 
)

Definition at line 215 of file utils.cpp.

223{
224 ULONG dummy1, dummy2;
225
226 TRACE("(%p)->(%p, %p, %s, %p, %p, %p)\n", psf, hwndOwner, pbcReserved,
227 debugstr_w(lpszDisplayName), pchEaten, ppidl, pdwAttributes);
228
229 if (!pdwAttributes)
230 {
231 dummy1 = 0;
232 pdwAttributes = &dummy1;
233 }
234
235 if (!pchEaten)
236 {
237 dummy2 = 0;
238 pchEaten = &dummy2;
239 }
240
241 if (ppidl)
242 *ppidl = NULL;
243
244 return psf->ParseDisplayName(hwndOwner, pbcReserved, lpszDisplayName, pchEaten,
245 ppidl, pdwAttributes);
246}
#define debugstr_w
Definition: kernel32.h:32
uint32_t ULONG
Definition: typedefs.h:59

◆ PathFileExistsDefExtAndAttributesW()

BOOL WINAPI PathFileExistsDefExtAndAttributesW ( _Inout_ LPWSTR  pszPath,
_In_ DWORD  dwWhich,
_Out_opt_ LPDWORD  pdwFileAttributes 
)

Definition at line 108 of file utils.cpp.

112{
113 TRACE("(%s, 0x%lX, %p)\n", debugstr_w(pszPath), dwWhich, pdwFileAttributes);
114
115 if (pdwFileAttributes)
116 *pdwFileAttributes = INVALID_FILE_ATTRIBUTES;
117
118 if (!pszPath)
119 return FALSE;
120
121 if (!dwWhich || (*PathFindExtensionW(pszPath) && (dwWhich & WHICH_OPTIONAL)))
122 return PathFileExistsAndAttributesW(pszPath, pdwFileAttributes);
123
124 if (!PathFileExistsDefExtW(pszPath, dwWhich))
125 {
126 if (pdwFileAttributes)
127 *pdwFileAttributes = INVALID_FILE_ATTRIBUTES;
128 return FALSE;
129 }
130
131 if (pdwFileAttributes)
132 *pdwFileAttributes = GetFileAttributesW(pszPath);
133
134 return TRUE;
135}
#define TRUE
Definition: types.h:120
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:652
LPWSTR WINAPI PathFindExtensionW(LPCWSTR lpszPath)
Definition: path.c:447
BOOL WINAPI PathFileExistsAndAttributesW(LPCWSTR lpszPath, DWORD *dwAttr)
Definition: path.c:1832
BOOL WINAPI PathFileExistsDefExtW(LPWSTR lpszPath, DWORD dwWhich)
Definition: path.c:1117
#define WHICH_OPTIONAL
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23

Referenced by START_TEST().

◆ SHLWAPI_IsBogusHRESULT()

static BOOL SHLWAPI_IsBogusHRESULT ( HRESULT  hr)
inlinestatic

Definition at line 138 of file utils.cpp.

139{
140 return (hr == E_FAIL || hr == E_INVALIDARG || hr == E_NOTIMPL);
141}
#define E_INVALIDARG
Definition: ddrawi.h:101
#define E_NOTIMPL
Definition: ddrawi.h:99
#define E_FAIL
Definition: ddrawi.h:102

Referenced by IShellFolder_GetDisplayNameOf().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( shell  )

Variable Documentation

◆ g_RetryData

const RETRY_DATA g_RetryData[]
static
Initial value:
=
{
{ SHGDN_FOREDITING, SHGDN_NORMAL, SFGDNO_RETRYALWAYS },
{ SHGDN_FORADDRESSBAR, SHGDN_NORMAL, SFGDNO_RETRYALWAYS },
{ SHGDN_NORMAL, SHGDN_FORPARSING, SFGDNO_RETRYALWAYS },
{ SHGDN_FORPARSING, SHGDN_NORMAL, SFGDNO_RETRYWITHFORPARSING },
{ SHGDN_INFOLDER, SHGDN_NORMAL, SFGDNO_RETRYALWAYS },
}

Definition at line 150 of file utils.cpp.

Referenced by IShellFolder_GetDisplayNameOf().