ReactOS 0.4.16-dev-257-g6aa11ac
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! */
 
#define FAILED_UNEXPECTEDLY   FAILED /* FIXME: Make shellutils.h usable without ATL */
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (shell)
 
static WORD GetVersionMajorMinor ()
 
static HRESULT SHInvokeCommandOnContextMenuInternal (_In_opt_ HWND hWnd, _In_opt_ IUnknown *pUnk, _In_ IContextMenu *pCM, _In_ UINT fCMIC, _In_ UINT fCMF, _In_opt_ LPCSTR pszVerb, _In_opt_ LPCWSTR pwszDir, _In_ bool ForceQCM)
 
EXTERN_C HRESULT WINAPI SHInvokeCommandOnContextMenuEx (_In_opt_ HWND hWnd, _In_opt_ IUnknown *pUnk, _In_ IContextMenu *pCM, _In_ UINT fCMIC, _In_ UINT fCMF, _In_opt_ LPCSTR pszVerb, _In_opt_ LPCWSTR pwszDir)
 
EXTERN_C HRESULT WINAPI SHInvokeCommandOnContextMenu (_In_opt_ HWND hWnd, _In_opt_ IUnknown *pUnk, _In_ IContextMenu *pCM, _In_ UINT fCMIC, _In_opt_ LPCSTR pszVerb)
 
EXTERN_C HRESULT WINAPI SHInvokeCommandWithFlagsAndSite (_In_opt_ HWND hWnd, _In_opt_ IUnknown *pUnk, _In_ IShellFolder *pShellFolder, _In_ LPCITEMIDLIST pidl, _In_ UINT fCMIC, _In_opt_ LPCSTR pszVerb)
 
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.

◆ FAILED_UNEXPECTEDLY

#define FAILED_UNEXPECTEDLY   FAILED /* FIXME: Make shellutils.h usable without ATL */

Definition at line 37 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

◆ GetVersionMajorMinor()

static WORD GetVersionMajorMinor ( )
inlinestatic

Definition at line 43 of file utils.cpp.

44{
47}
static const WCHAR version[]
Definition: asmname.c:66
unsigned long DWORD
Definition: ntddk_ex.h:95
#define LOBYTE(W)
Definition: jmemdos.c:487
#define HIBYTE(W)
Definition: jmemdos.c:486
DWORD WINAPI GetVersion()
Definition: redirtest.c:5
#define MAKEWORD(a, b)
Definition: typedefs.h:248

Referenced by SHInvokeCommandOnContextMenuInternal().

◆ IContextMenu_Invoke()

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

Definition at line 201 of file utils.cpp.

206{
207 TRACE("(%p, %p, %s, %u)\n", pContextMenu, hwnd, debugstr_a(lpVerb), uFlags);
209 uFlags, lpVerb, NULL, false);
210 return !FAILED_UNEXPECTEDLY(hr);
211}
#define NULL
Definition: types.h:112
UINT uFlags
Definition: api.c:59
static HRESULT SHInvokeCommandOnContextMenuInternal(_In_opt_ HWND hWnd, _In_opt_ IUnknown *pUnk, _In_ IContextMenu *pCM, _In_ UINT fCMIC, _In_ UINT fCMF, _In_opt_ LPCSTR pszVerb, _In_opt_ LPCWSTR pwszDir, _In_ bool ForceQCM)
Definition: utils.cpp:50
#define FAILED_UNEXPECTEDLY
Definition: utils.cpp:37
#define debugstr_a
Definition: kernel32.h:31
HRESULT hr
Definition: shlfolder.c:183
#define TRACE(s)
Definition: solgame.cpp:4
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023

◆ 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 369 of file utils.cpp.

374{
375 TRACE("(%p, %p, %p, %p)\n", psf, lParam, pidl1, pidl2);
376
377 if (lParam & ~(SIZE_T)SHCIDS_COLUMNMASK)
378 {
379 /* Try as IShellFolder2 if possible */
380 HRESULT hr = psf->QueryInterface(IID_IShellFolder2, (void **)&psf);
381 if (FAILED(hr))
382 lParam &= SHCIDS_COLUMNMASK;
383 else
384 psf->Release();
385 }
386
387 return psf->CompareIDs(lParam, pidl1, pidl2);
388}
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
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 281 of file utils.cpp.

287{
288 HRESULT hr;
289
290 TRACE("(%p)->(%p, 0x%lX, %p, 0x%lX)\n", psf, pidl, uFlags, lpName, dwRetryFlags);
291
292 hr = psf->GetDisplayNameOf(pidl, uFlags, lpName);
294 return hr;
295
296 dwRetryFlags |= SFGDNO_RETRYALWAYS;
297
298 if ((uFlags & SHGDN_FORPARSING) == 0)
299 dwRetryFlags |= SFGDNO_RETRYWITHFORPARSING;
300
301 // Retry with other flags to get successful results
302 for (SIZE_T iEntry = 0; iEntry < _countof(g_RetryData); ++iEntry)
303 {
304 const RETRY_DATA *pData = &g_RetryData[iEntry];
305 if (!(dwRetryFlags & pData->dwRetryFlags))
306 continue;
307
308 SHGDNF uNewFlags = ((uFlags & ~pData->uRemove) | pData->uAdd);
309 if (uNewFlags == uFlags)
310 continue;
311
312 hr = psf->GetDisplayNameOf(pidl, uNewFlags, lpName);
314 break;
315
316 uFlags = uNewFlags; // Update flags every time
317 }
318
319 return hr;
320}
static const RETRY_DATA g_RetryData[]
Definition: utils.cpp:264
static BOOL SHLWAPI_IsBogusHRESULT(HRESULT hr)
Definition: utils.cpp:252
#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:2814

◆ 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 329 of file utils.cpp.

337{
338 ULONG dummy1, dummy2;
339
340 TRACE("(%p)->(%p, %p, %s, %p, %p, %p)\n", psf, hwndOwner, pbcReserved,
341 debugstr_w(lpszDisplayName), pchEaten, ppidl, pdwAttributes);
342
343 if (!pdwAttributes)
344 {
345 dummy1 = 0;
346 pdwAttributes = &dummy1;
347 }
348
349 if (!pchEaten)
350 {
351 dummy2 = 0;
352 pchEaten = &dummy2;
353 }
354
355 if (ppidl)
356 *ppidl = NULL;
357
358 return psf->ParseDisplayName(hwndOwner, pbcReserved, lpszDisplayName, pchEaten,
359 ppidl, pdwAttributes);
360}
#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 222 of file utils.cpp.

226{
227 TRACE("(%s, 0x%lX, %p)\n", debugstr_w(pszPath), dwWhich, pdwFileAttributes);
228
229 if (pdwFileAttributes)
230 *pdwFileAttributes = INVALID_FILE_ATTRIBUTES;
231
232 if (!pszPath)
233 return FALSE;
234
235 if (!dwWhich || (*PathFindExtensionW(pszPath) && (dwWhich & WHICH_OPTIONAL)))
236 return PathFileExistsAndAttributesW(pszPath, pdwFileAttributes);
237
238 if (!PathFileExistsDefExtW(pszPath, dwWhich))
239 {
240 if (pdwFileAttributes)
241 *pdwFileAttributes = INVALID_FILE_ATTRIBUTES;
242 return FALSE;
243 }
244
245 if (pdwFileAttributes)
246 *pdwFileAttributes = GetFileAttributesW(pszPath);
247
248 return TRUE;
249}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
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().

◆ SHInvokeCommandOnContextMenu()

EXTERN_C HRESULT WINAPI SHInvokeCommandOnContextMenu ( _In_opt_ HWND  hWnd,
_In_opt_ IUnknown pUnk,
_In_ IContextMenu pCM,
_In_ UINT  fCMIC,
_In_opt_ LPCSTR  pszVerb 
)

Definition at line 155 of file utils.cpp.

161{
162 return SHInvokeCommandOnContextMenuEx(hWnd, pUnk, pCM, fCMIC, CMF_EXTENDEDVERBS, pszVerb, NULL);
163}
HWND hWnd
Definition: settings.c:17
EXTERN_C HRESULT WINAPI SHInvokeCommandOnContextMenuEx(_In_opt_ HWND hWnd, _In_opt_ IUnknown *pUnk, _In_ IContextMenu *pCM, _In_ UINT fCMIC, _In_ UINT fCMF, _In_opt_ LPCSTR pszVerb, _In_opt_ LPCWSTR pwszDir)
Definition: utils.cpp:138
static void *static void *static LPDIRECTPLAY IUnknown * pUnk
Definition: dplayx.c:30

◆ SHInvokeCommandOnContextMenuEx()

EXTERN_C HRESULT WINAPI SHInvokeCommandOnContextMenuEx ( _In_opt_ HWND  hWnd,
_In_opt_ IUnknown pUnk,
_In_ IContextMenu pCM,
_In_ UINT  fCMIC,
_In_ UINT  fCMF,
_In_opt_ LPCSTR  pszVerb,
_In_opt_ LPCWSTR  pwszDir 
)

Definition at line 138 of file utils.cpp.

146{
147 return SHInvokeCommandOnContextMenuInternal(hWnd, pUnk, pCM, fCMIC, fCMF, pszVerb, pwszDir, true);
148}

Referenced by SHInvokeCommandOnContextMenu(), and SHInvokeCommandWithFlagsAndSite().

◆ SHInvokeCommandOnContextMenuInternal()

static HRESULT SHInvokeCommandOnContextMenuInternal ( _In_opt_ HWND  hWnd,
_In_opt_ IUnknown pUnk,
_In_ IContextMenu pCM,
_In_ UINT  fCMIC,
_In_ UINT  fCMF,
_In_opt_ LPCSTR  pszVerb,
_In_opt_ LPCWSTR  pwszDir,
_In_ bool  ForceQCM 
)
static

Definition at line 50 of file utils.cpp.

59{
60 CMINVOKECOMMANDINFOEX info = { sizeof(info), fCMIC, hWnd, pszVerb };
61 INT iDefItem = 0;
62 HMENU hMenu = NULL;
63 HCURSOR hOldCursor;
64 HRESULT hr = S_OK;
65 WCHAR wideverb[MAX_PATH];
66
67 if (!pCM)
68 return E_INVALIDARG;
69
70 hOldCursor = SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_WAIT));
71 info.nShow = SW_NORMAL;
72 if (pUnk)
74
75 if (IS_INTRESOURCE(pszVerb))
76 {
77 hMenu = CreatePopupMenu();
78 if (hMenu)
79 {
80 hr = pCM->QueryContextMenu(hMenu, 0, 1, MAXSHORT, fCMF | CMF_DEFAULTONLY);
81 iDefItem = GetMenuDefaultItem(hMenu, 0, 0);
82 if (iDefItem != -1)
83 info.lpVerb = MAKEINTRESOURCEA(iDefItem - 1);
84 }
85 info.lpVerbW = MAKEINTRESOURCEW(info.lpVerb);
86 }
87 else
88 {
90 {
91 info.fMask |= CMF_OPTIMIZEFORINVOKE;
92 }
93 if (pszVerb && SHAnsiToUnicode(pszVerb, wideverb, _countof(wideverb)))
94 {
95 info.fMask |= CMIC_MASK_UNICODE;
96 info.lpVerbW = wideverb;
97 }
98 if (ForceQCM)
99 {
100 hMenu = CreatePopupMenu();
101 hr = pCM->QueryContextMenu(hMenu, 0, 1, MAXSHORT, fCMF);
102 }
103 }
104
105 SetCursor(hOldCursor);
106
107 if (!FAILED_UNEXPECTEDLY(hr) && (iDefItem != -1 || info.lpVerb))
108 {
109 if (!hWnd)
110 info.fMask |= CMIC_MASK_FLAG_NO_UI;
111
113 if (pwszDir)
114 {
115 info.fMask |= CMIC_MASK_UNICODE;
116 info.lpDirectoryW = pwszDir;
117 if (SHUnicodeToAnsi(pwszDir, dir, _countof(dir)))
118 info.lpDirectory = dir;
119 }
120
121 hr = pCM->InvokeCommand((LPCMINVOKECOMMANDINFO)&info);
122 if (FAILED_UNEXPECTEDLY(hr)) { /* Diagnostic message */ }
123 }
124
125 if (pUnk)
127 if (hMenu)
128 DestroyMenu(hMenu);
129
130 return hr;
131}
unsigned int dir
Definition: maze.c:112
#define E_INVALIDARG
Definition: ddrawi.h:101
#define MAX_PATH
Definition: compat.h:34
HRESULT WINAPI IUnknown_SetSite(IUnknown *obj, IUnknown *site)
Definition: ordinal.c:1411
DWORD WINAPI SHAnsiToUnicode(LPCSTR lpSrcStr, LPWSTR lpDstStr, int iLen)
Definition: string.c:2667
INT WINAPI SHUnicodeToAnsi(LPCWSTR lpSrcStr, LPSTR lpDstStr, INT iLen)
Definition: string.c:2791
static WORD GetVersionMajorMinor()
Definition: utils.cpp:43
#define S_OK
Definition: intsafe.h:52
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:63
#define _WIN32_WINNT_WIN7
Definition: sdkddkver.h:28
int32_t INT
Definition: typedefs.h:58
#define MAXSHORT
Definition: umtypes.h:114
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:2157
#define MAKEINTRESOURCEA(i)
Definition: winuser.h:581
BOOL WINAPI DestroyMenu(_In_ HMENU)
#define IDC_WAIT
Definition: winuser.h:689
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define SW_NORMAL
Definition: winuser.h:772
__wchar_t WCHAR
Definition: xmlstorage.h:180
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
char CHAR
Definition: xmlstorage.h:175

Referenced by IContextMenu_Invoke(), and SHInvokeCommandOnContextMenuEx().

◆ SHInvokeCommandWithFlagsAndSite()

EXTERN_C HRESULT WINAPI SHInvokeCommandWithFlagsAndSite ( _In_opt_ HWND  hWnd,
_In_opt_ IUnknown pUnk,
_In_ IShellFolder pShellFolder,
_In_ LPCITEMIDLIST  pidl,
_In_ UINT  fCMIC,
_In_opt_ LPCSTR  pszVerb 
)

Definition at line 170 of file utils.cpp.

177{
179 if (pShellFolder)
180 {
181 IContextMenu *pCM;
182 hr = pShellFolder->GetUIObjectOf(hWnd, 1, &pidl, IID_IContextMenu, NULL, (void**)&pCM);
183 if (SUCCEEDED(hr))
184 {
185 fCMIC |= CMIC_MASK_FLAG_LOG_USAGE;
186 hr = SHInvokeCommandOnContextMenuEx(hWnd, pUnk, pCM, fCMIC, 0, pszVerb, NULL);
187 pCM->Release();
188 }
189 }
190 return hr;
191}
#define SUCCEEDED(hr)
Definition: intsafe.h:50

◆ SHLWAPI_IsBogusHRESULT()

static BOOL SHLWAPI_IsBogusHRESULT ( HRESULT  hr)
inlinestatic

Definition at line 252 of file utils.cpp.

253{
254 return (hr == E_FAIL || hr == E_INVALIDARG || hr == E_NOTIMPL);
255}
#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 264 of file utils.cpp.

Referenced by IShellFolder_GetDisplayNameOf().