ReactOS 0.4.15-dev-7788-g1ad9096
shelltest.cpp
Go to the documentation of this file.
1#include "shelltest.h"
2
3// + Adapted from https://blogs.msdn.microsoft.com/oldnewthing/20130503-00/?p=4463/
4// In short: We want to create an IDLIST from an item that does not exist,
5// so we have to provide WIN32_FIND_DATAW in a bind context.
6// If we don't, the FS will be queried, and we do not get a valid IDLIST for a non-existing path.
7
8CComModule gModule;
9
10class CFileSysBindData :
11 public CComCoClass<CFileSysBindData>,
12 public CComObjectRootEx<CComMultiThreadModelNoCS>,
14{
15public:
17 {
18 m_Data = *pfd;
19 return S_OK;
20 }
21
23 {
24 *pfd = m_Data;
25 return S_OK;
26 }
27
31 COM_INTERFACE_ENTRY_IID(IID_IFileSystemBindData, IFileSystemBindData)
33private:
35};
36
37static
40{
41 CComPtr<IFileSystemBindData> spfsbc(new CComObject<CFileSysBindData>());
42 WIN32_FIND_DATAW wfd = { 0 };
43 wfd.dwFileAttributes = FILE_ATTRIBUTE_NORMAL;
44 spfsbc->SetFindData(&wfd);
45 HRESULT hr = pbc->RegisterObjectParam((LPOLESTR)STR_FILE_SYS_BIND_DATA, spfsbc);
46 ok(hr == S_OK, "hr = %lx\n", hr);
47 return hr;
48}
49
50static
53{
54 CComPtr<IBindCtx> spbc;
55 HRESULT hr = CreateBindCtx(0, &spbc);
56 ok(hr == S_OK, "hr = %lx\n", hr);
57 if (SUCCEEDED(hr))
58 {
59 hr = spbc->SetBindOptions(pbo);
60 ok(hr == S_OK, "hr = %lx\n", hr);
61 }
62 *ppbc = SUCCEEDED(hr) ? spbc.Detach() : NULL;
63 return hr;
64}
65
66static HRESULT
68{
69 CComPtr<IBindCtx> spbc;
70 BIND_OPTS bo = { sizeof(bo), 0, STGM_CREATE, 0 };
71 HRESULT hr = CreateBindCtxWithOpts(&bo, &spbc);
72 ok(hr == S_OK, "hr = %lx\n", hr);
73 if (SUCCEEDED(hr))
74 {
75 hr = AddFileSysBindCtx(spbc);
76 ok(hr == S_OK, "hr = %lx\n", hr);
77 }
78 *ppbc = SUCCEEDED(hr) ? spbc.Detach() : NULL;
79 return hr;
80}
81
82VOID
84{
85 CComPtr<IBindCtx> spbc;
87 ok(hr == S_OK, "hr = %lx\n", hr);
88 if (SUCCEEDED(hr))
89 {
90 hr = SHParseDisplayName(pszPath, spbc, ppidl, 0, NULL);
91 ok(hr == S_OK, "hr = %lx\n", hr);
92 }
93}
94
95// - Adapted from https://blogs.msdn.microsoft.com/oldnewthing/20130503-00/?p=4463/
#define ok(value,...)
Definition: atltest.h:57
#define STDMETHODCALLTYPE
Definition: bdasup.h:9
WIN32_FIND_DATAW m_Data
Definition: shelltest.cpp:34
virtual HRESULT STDMETHODCALLTYPE SetFindData(const WIN32_FIND_DATAW *pfd)
Definition: shelltest.cpp:16
virtual HRESULT STDMETHODCALLTYPE GetFindData(WIN32_FIND_DATAW *pfd)
Definition: shelltest.cpp:22
#define NULL
Definition: types.h:112
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define BEGIN_COM_MAP(x)
Definition: atlcom.h:581
#define COM_INTERFACE_ENTRY_IID(iid, x)
Definition: atlcom.h:601
#define DECLARE_PROTECT_FINAL_CONSTRUCT()
Definition: atlcom.h:679
#define DECLARE_NOT_AGGREGATABLE(x)
Definition: atlcom.h:651
#define END_COM_MAP()
Definition: atlcom.h:592
static LPOLESTR
Definition: stg_prop.c:27
#define _Outptr_
Definition: ms_sal.h:427
#define _In_
Definition: ms_sal.h:308
#define STGM_CREATE
Definition: objbase.h:926
HRESULT WINAPI CreateBindCtx(DWORD reserved, LPBC *ppbc)
Definition: bindctx.c:556
HRESULT WINAPI SHParseDisplayName(LPCWSTR pszName, IBindCtx *pbc, LPITEMIDLIST *ppidl, SFGAOF sfgaoIn, SFGAOF *psfgaoOut)
Definition: pidl.c:1396
VOID PathToIDList(LPCWSTR pszPath, ITEMIDLIST **ppidl)
Definition: shelltest.cpp:83
static HRESULT CreateFileSysBindCtx(_Outptr_ IBindCtx **ppbc)
Definition: shelltest.cpp:67
CComModule gModule
Definition: shelltest.cpp:8
static HRESULT CreateBindCtxWithOpts(_In_ BIND_OPTS *pbo, _Outptr_ IBindCtx **ppbc)
Definition: shelltest.cpp:52
static HRESULT AddFileSysBindCtx(_In_ IBindCtx *pbc)
Definition: shelltest.cpp:39
HRESULT hr
Definition: shlfolder.c:183
static PIXELFORMATDESCRIPTOR pfd
Definition: ssstars.c:67
_In_opt_ SURFOBJ _In_opt_ SURFOBJ _In_ CLIPOBJ _In_opt_ XLATEOBJ _In_ RECTL _In_opt_ POINTL _In_opt_ POINTL _In_opt_ BRUSHOBJ * pbo
Definition: winddi.h:3440
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185