ReactOS 0.4.15-dev-7961-gdcf9eb0
GetDisplayNameOf.cpp File Reference
#include <ntstatus.h>
#include <windef.h>
#include <ntndk.h>
#include <atlbase.h>
#include <atlcom.h>
#include <shellapi.h>
#include <shlobj.h>
#include <shlwapi.h>
#include <shellutils.h>
#include <versionhelpers.h>
#include "wine/test.h"
Include dependency graph for GetDisplayNameOf.cpp:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 

Functions

static HRESULT GetDisplayName (CComPtr< IShellFolder > &spFolder, LPCITEMIDLIST pidlRelative, SHGDNF uFlags, WCHAR Buf[MAX_PATH])
 
static HRESULT Initialize (CComPtr< IShellFolder > &spFolder, WCHAR FolderName[MAX_PATH])
 
static void Test_GetDisplayNameOf (CComPtr< IShellFolder > &spFolder, const WCHAR *FolderName)
 
 START_TEST (GetDisplayNameOf)
 

Variables

static const CLSID CLSID_FontExt = { 0xBD84B380, 0x8CA2, 0x1069, { 0xAB, 0x1D, 0x08, 0x00, 0x09, 0x48, 0xF5, 0x34 } }
 
static BOOL g_bFontFolderWithShellView = FALSE
 
static BOOL g_bVistaWorkaround = FALSE
 

Macro Definition Documentation

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 9 of file GetDisplayNameOf.cpp.

Function Documentation

◆ GetDisplayName()

static HRESULT GetDisplayName ( CComPtr< IShellFolder > &  spFolder,
LPCITEMIDLIST  pidlRelative,
SHGDNF  uFlags,
WCHAR  Buf[MAX_PATH] 
)
static

Definition at line 25 of file GetDisplayNameOf.cpp.

26{
27 STRRET strret;
28 HRESULT hr = spFolder->GetDisplayNameOf(pidlRelative, uFlags, &strret);
29 ok_hex(hr, S_OK);
30 if (FAILED(hr))
31 return hr;
32
33 hr = StrRetToBufW(&strret, pidlRelative, Buf, MAX_PATH);
34 ok_hex(hr, S_OK);
35 return hr;
36}
#define ok_hex(expression, result)
Definition: atltest.h:94
UINT uFlags
Definition: api.c:59
#define MAX_PATH
Definition: compat.h:34
HRESULT WINAPI StrRetToBufW(LPSTRRET src, const ITEMIDLIST *pidl, LPWSTR dest, UINT len)
Definition: string.c:1530
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51
HRESULT hr
Definition: shlfolder.c:183

Referenced by Initialize(), and Test_GetDisplayNameOf().

◆ Initialize()

static HRESULT Initialize ( CComPtr< IShellFolder > &  spFolder,
WCHAR  FolderName[MAX_PATH] 
)
static

Definition at line 38 of file GetDisplayNameOf.cpp.

39{
40 WCHAR Path[MAX_PATH] = {0};
42 ok_hex(hr, S_OK);
43 if (FAILED(hr))
44 return hr;
45
46 CComPtr<IShellFolder> desktopFolder;
47 hr = SHGetDesktopFolder(&desktopFolder);
48 ok_hex(hr, S_OK);
49 if (FAILED(hr))
50 return hr;
51
52 CComHeapPtr<ITEMIDLIST> pidl;
53 hr = desktopFolder->ParseDisplayName(NULL, NULL, Path, NULL, &pidl, NULL);
54 ok_hex(hr, S_OK);
55 if (FAILED(hr))
56 return hr;
57
58 hr = desktopFolder->BindToObject(pidl, NULL, IID_PPV_ARG(IShellFolder, &spFolder));
59 ok_hex(hr, S_OK);
60 if (FAILED(hr))
61 return hr;
62
63
64 CComPtr<IShellFolder> psfParent;
65 LPCITEMIDLIST pidlRelative = NULL;
66 hr = SHBindToParent(pidl, IID_PPV_ARG(IShellFolder, &psfParent), &pidlRelative);
67 ok_hex(hr, S_OK);
68 if (FAILED(hr))
69 return hr;
70
71 return GetDisplayName(psfParent, pidlRelative, SHGDN_NORMAL, FolderName);
72}
HRESULT WINAPI SHGetDesktopFolder(IShellFolder **psf)
PRTL_UNICODE_STRING_BUFFER Path
#define NULL
Definition: types.h:112
HRESULT WINAPI SHGetFolderPathW(HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwFlags, LPWSTR pszPath)
Definition: shellpath.c:2589
static HRESULT GetDisplayName(CComPtr< IShellFolder > &spFolder, LPCITEMIDLIST pidlRelative, SHGDNF uFlags, WCHAR Buf[MAX_PATH])
HRESULT WINAPI SHBindToParent(LPCITEMIDLIST pidl, REFIID riid, LPVOID *ppv, LPCITEMIDLIST *ppidlLast)
Definition: pidl.c:1361
#define CSIDL_FONTS
Definition: shlobj.h:2177
const ITEMIDLIST UNALIGNED * LPCITEMIDLIST
Definition: shtypes.idl:42
#define IID_PPV_ARG(Itype, ppType)
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ START_TEST()

START_TEST ( GetDisplayNameOf  )

Definition at line 172 of file GetDisplayNameOf.cpp.

173{
175
176 // Detect if this is an old (2k3) style fontext, or a new one.
177 // The old one has an IShellView, the new one an IShellFolder
178 {
179 CComPtr<IShellView> spView;
180 HRESULT hr = CoCreateInstance(CLSID_FontExt, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IShellView, &spView));
182 }
183
185
186 trace("Has shellview: %d, Vista: %d\n", g_bFontFolderWithShellView, g_bVistaWorkaround);
187 {
188 CComPtr<IShellFolder> spFolder;
189 WCHAR FolderName[MAX_PATH];
190 HRESULT hr = Initialize(spFolder, FolderName);
191 if (SUCCEEDED(hr))
192 {
193 Test_GetDisplayNameOf(spFolder, FolderName);
194 }
195 }
196
198}
#define trace
Definition: atltest.h:70
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3325
HRESULT WINAPI DECLSPEC_HOTPATCH CoInitializeEx(LPVOID lpReserved, DWORD dwCoInit)
Definition: compobj.c:2002
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:2067
static void Test_GetDisplayNameOf(CComPtr< IShellFolder > &spFolder, const WCHAR *FolderName)
static BOOL g_bVistaWorkaround
static const CLSID CLSID_FontExt
static BOOL g_bFontFolderWithShellView
#define SUCCEEDED(hr)
Definition: intsafe.h:50
@ COINIT_APARTMENTTHREADED
Definition: objbase.h:278
VERSIONHELPERAPI IsWindows7OrGreater()
VERSIONHELPERAPI IsWindowsVistaOrGreater()
static void Initialize()
Definition: xlate.c:212

◆ Test_GetDisplayNameOf()

static void Test_GetDisplayNameOf ( CComPtr< IShellFolder > &  spFolder,
const WCHAR FolderName 
)
static

Definition at line 74 of file GetDisplayNameOf.cpp.

75{
76 CComPtr<IEnumIDList> fontsEnum;
77 HRESULT hr = spFolder->EnumObjects(NULL, SHCONTF_NONFOLDERS, &fontsEnum);
78
79 ok_hex(hr, S_OK);
80 if (FAILED(hr))
81 return;
82
83 CComHeapPtr<ITEMIDLIST> fontPidl;
84
85 // Get the first item from the folder
86 ULONG fetched = 0;
87 hr = fontsEnum->Next(1, &fontPidl, &fetched);
88 ok_hex(hr, S_OK);
89 if (FAILED(hr))
90 return;
91
92
93 WCHAR Buf[MAX_PATH], *Ptr;
94 if (FAILED(GetDisplayName(spFolder, fontPidl, SHGDN_FORPARSING, Buf)))
95 return;
96
97 // On 2k3 where this is not a custom IShellFolder, it will return something like:
98 // Same for Vista??
99 // 'C:\\WINDOWS\\Fonts\\arial.ttf'
100 // On 7+ this results is:
101 // 'C:\\Windows\\Fonts\\System Bold'
102 BOOL bRelative = PathIsRelativeW(Buf);
104 trace("Path: %s\n", wine_dbgstr_w(Buf));
105 ok(bRelative == FALSE, "Path not absolute? (%s)\n", wine_dbgstr_w(Buf));
106 ok(Ptr != (Buf + wcslen(Buf)), "Did not find a separator in '%s'!\n", wine_dbgstr_w(Buf));
107
108 // Expected 'arial.ttf' (2k3), 'Arial' (Vista) or 'System Bold' (7+), 'System \0388\03bd\03c4\03bf\03bd\03b7 \03b3\03c1\03b1\03c6\03ae' in greek
109 if (FAILED(GetDisplayName(spFolder, fontPidl, SHGDN_INFOLDER, Buf)))
110 return;
111
112 bRelative = PathIsRelativeW(Buf);
114 trace("Path: %s\n", wine_dbgstr_w(Buf));
115 ok(bRelative != FALSE, "Path not relative? (%s)\n", wine_dbgstr_w(Buf));
116 ok(Ptr == (Buf + wcslen(Buf)), "Found a separator in '%s'!\n", wine_dbgstr_w(Buf));
117
118 // Expected 'arial.ttf' (2k3) or 'Arial' (Vista), 'System Bold' (7+), 'System \0388\03bd\03c4\03bf\03bd\03b7 \03b3\03c1\03b1\03c6\03ae' in greek
119 if (FAILED(GetDisplayName(spFolder, fontPidl, SHGDN_NORMAL, Buf)))
120 return;
121
122 bRelative = PathIsRelativeW(Buf);
124 trace("Path: %s\n", wine_dbgstr_w(Buf));
125 ok(bRelative != FALSE, "Path not relative? (%s)\n", wine_dbgstr_w(Buf));
126 ok(Ptr == (Buf + wcslen(Buf)), "Found a separator in '%s'!\n", wine_dbgstr_w(Buf));
127
128 // Expected 'arial.ttf' (2k3), 'C:\\WINDOWS\\Fonts\\arial.ttf' (Vista), 'System Bold' (7+)
129 if (FAILED(GetDisplayName(spFolder, fontPidl, SHGDN_INFOLDER | SHGDN_FORPARSING, Buf)))
130 return;
131
132 bRelative = PathIsRelativeW(Buf);
134 trace("Path: %s\n", wine_dbgstr_w(Buf));
136 {
137 // Vista is the odd one here
138 ok(bRelative == FALSE, "Path not absolute? (%s)\n", wine_dbgstr_w(Buf));
139 ok(Ptr != (Buf + wcslen(Buf)), "Did not find a separator in '%s'!\n", wine_dbgstr_w(Buf));
140 }
141 else
142 {
143 ok(bRelative != FALSE, "Path not relative? (%s)\n", wine_dbgstr_w(Buf));
144 ok(Ptr == (Buf + wcslen(Buf)), "Found a separator in '%s'!\n", wine_dbgstr_w(Buf));
145 }
146
147 // Expected 'arial.ttf' (2k3), 'Arial' (Vista) or 'Fonts\\System Bold' (7+), 'Fonts\\System \0388\03bd\03c4\03bf\03bd\03b7 \03b3\03c1\03b1\03c6\03ae' in greek
148 if (FAILED(GetDisplayName(spFolder, fontPidl, SHGDN_FORADDRESSBAR, Buf)))
149 return;
150
151 bRelative = PathIsRelativeW(Buf);
153 trace("Path: %s\n", wine_dbgstr_w(Buf));
154 ok(bRelative != FALSE, "Path not relative? (%s)\n", wine_dbgstr_w(Buf));
155
156 // 2k3 does not have a custom IShellFolder, so there this weird behavior does not exist:
157 // (And vista's version is ???)
159 {
160 ok(Ptr == (Buf + wcslen(Buf)), "Found a separator in '%s'!\n", wine_dbgstr_w(Buf));
161 }
162 else
163 {
164 // For some reason, there is 'Fonts\\' in front of the fontname...
165 ok(Ptr != (Buf + wcslen(Buf)), "Did not find a separator in '%s'!\n", wine_dbgstr_w(Buf));
166 ok(!_wcsnicmp(FolderName, Buf, wcslen(FolderName)), "Result (%s) does not start with fonts folder (%s)\n",
167 wine_dbgstr_w(Buf), wine_dbgstr_w(FolderName));
168 }
169}
#define ok(value,...)
Definition: atltest.h:57
#define FALSE
Definition: types.h:117
LPWSTR WINAPI PathFindNextComponentW(LPCWSTR lpszPath)
Definition: path.c:2579
BOOL WINAPI PathIsRelativeW(LPCWSTR lpszPath)
Definition: path.c:1579
unsigned int BOOL
Definition: ntddk_ex.h:94
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define wine_dbgstr_w
Definition: kernel32.h:34
_Check_return_ _CRTIMP int __cdecl _wcsnicmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
uint32_t ULONG
Definition: typedefs.h:59

Referenced by START_TEST().

Variable Documentation

◆ CLSID_FontExt

const CLSID CLSID_FontExt = { 0xBD84B380, 0x8CA2, 0x1069, { 0xAB, 0x1D, 0x08, 0x00, 0x09, 0x48, 0xF5, 0x34 } }
static

Definition at line 21 of file GetDisplayNameOf.cpp.

Referenced by START_TEST().

◆ g_bFontFolderWithShellView

BOOL g_bFontFolderWithShellView = FALSE
static

Definition at line 22 of file GetDisplayNameOf.cpp.

Referenced by START_TEST(), and Test_GetDisplayNameOf().

◆ g_bVistaWorkaround

BOOL g_bVistaWorkaround = FALSE
static

Definition at line 23 of file GetDisplayNameOf.cpp.

Referenced by START_TEST(), and Test_GetDisplayNameOf().