ReactOS  0.4.15-dev-1200-gc3b3fcd
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 
8 CComModule gModule;
9 
10 class CFileSysBindData :
11  public CComCoClass<CFileSysBindData>,
12  public CComObjectRootEx<CComMultiThreadModelNoCS>,
13  public IFileSystemBindData
14 {
15 public:
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)
32  END_COM_MAP()
33 private:
35 };
36 
37 static
38 HRESULT
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 
50 static
51 HRESULT
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 
66 static 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 
82 VOID
83 PathToIDList(LPCWSTR pszPath, ITEMIDLIST** ppidl)
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/
HRESULT hr
Definition: shlfolder.c:183
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
VOID PathToIDList(LPCWSTR pszPath, ITEMIDLIST **ppidl)
Definition: shelltest.cpp:83
#define STGM_CREATE
Definition: objbase.h:925
#define _Outptr_
Definition: no_sal2.h:396
#define DECLARE_NOT_AGGREGATABLE(x)
Definition: atlcom.h:611
static LPOLESTR
Definition: stg_prop.c:27
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
CComModule gModule
Definition: shelltest.cpp:8
smooth NULL
Definition: ftsmooth.c:416
static HRESULT CreateBindCtxWithOpts(_In_ BIND_OPTS *pbo, _Outptr_ IBindCtx **ppbc)
Definition: shelltest.cpp:52
#define BEGIN_COM_MAP(x)
Definition: atlcom.h:541
static HRESULT AddFileSysBindCtx(_In_ IBindCtx *pbc)
Definition: shelltest.cpp:39
HRESULT WINAPI CreateBindCtx(DWORD reserved, LPBC *ppbc)
Definition: bindctx.c:556
_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:3433
LONG HRESULT
Definition: typedefs.h:79
#define STDMETHODCALLTYPE
Definition: bdasup.h:9
static PIXELFORMATDESCRIPTOR pfd
Definition: ssstars.c:67
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
WIN32_FIND_DATAW m_Data
Definition: shelltest.cpp:34
#define _In_
Definition: no_sal2.h:204
#define S_OK
Definition: intsafe.h:51
#define COM_INTERFACE_ENTRY_IID(iid, x)
Definition: atlcom.h:561
static HRESULT CreateFileSysBindCtx(_Outptr_ IBindCtx **ppbc)
Definition: shelltest.cpp:67
#define ok(value,...)
Definition: atltest.h:57
HRESULT WINAPI SHParseDisplayName(LPCWSTR pszName, IBindCtx *pbc, LPITEMIDLIST *ppidl, SFGAOF sfgaoIn, SFGAOF *psfgaoOut)
Definition: pidl.c:1381
#define DECLARE_PROTECT_FINAL_CONSTRUCT()
Definition: atlcom.h:639
#define END_COM_MAP()
Definition: atlcom.h:552
#define SUCCEEDED(hr)
Definition: intsafe.h:49