Synchronize with trunk revision 59636 (just before Alex's CreateProcess revamp).
[reactos.git] / dll / win32 / shell32 / shlfsbind.cpp
1 /*
2 * File System Bind Data object to use as parameter for the bind context to
3 * IShellFolder_ParseDisplayName
4 *
5 * Copyright 2003 Rolf Kalbermatter
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 *
21 */
22
23 #include "precomp.h"
24
25 WINE_DEFAULT_DEBUG_CHANNEL(pidl);
26
27 /***********************************************************************
28 * IFileSystemBindData implementation
29 */
30 class IFileSystemBindDataImpl :
31 public CComObjectRootEx<CComMultiThreadModelNoCS>,
32 public IFileSystemBindData
33 {
34 private:
35 WIN32_FIND_DATAW findFile;
36 public:
37 IFileSystemBindDataImpl();
38 ~IFileSystemBindDataImpl();
39
40 // *** IFileSystemBindData methods ***
41 virtual HRESULT STDMETHODCALLTYPE SetFindData(const WIN32_FIND_DATAW *pfd);
42 virtual HRESULT STDMETHODCALLTYPE GetFindData(WIN32_FIND_DATAW *pfd);
43
44 DECLARE_NOT_AGGREGATABLE(IFileSystemBindDataImpl)
45 DECLARE_PROTECT_FINAL_CONSTRUCT()
46
47 BEGIN_COM_MAP(IFileSystemBindDataImpl)
48 COM_INTERFACE_ENTRY_IID(IID_IFileSystemBindData, IFileSystemBindData)
49 END_COM_MAP()
50 };
51
52 static const WCHAR wFileSystemBindData[] = {
53 'F','i','l','e',' ','S','y','s','t','e','m',' ','B','i','n','d','D','a','t','a',0};
54
55 HRESULT WINAPI IFileSystemBindData_Constructor(const WIN32_FIND_DATAW *pfd, LPBC *ppV)
56 {
57 CComPtr<IFileSystemBindData> fileSystemBindData;
58 CComPtr<IBindCtx> bindContext;
59 BIND_OPTS bindOpts;
60 HRESULT hResult;
61
62 TRACE("%p, %p\n", pfd, ppV);
63
64 if (ppV == NULL)
65 return E_INVALIDARG;
66
67 *ppV = NULL;
68
69 hResult = IFileSystemBindDataImpl::_CreatorClass::CreateInstance(NULL, IID_IFileSystemBindData, (void **)&fileSystemBindData);
70 if (FAILED(hResult))
71 return hResult;
72 hResult = fileSystemBindData->SetFindData(pfd);
73 if (FAILED(hResult))
74 return hResult;
75
76 hResult = CreateBindCtx(0, &bindContext);
77 if (FAILED(hResult))
78 return hResult;
79 bindOpts.cbStruct = sizeof(BIND_OPTS);
80 bindOpts.grfFlags = 0;
81 bindOpts.grfMode = STGM_CREATE;
82 bindOpts.dwTickCountDeadline = 0;
83 hResult = bindContext->SetBindOptions(&bindOpts);
84 if (FAILED(hResult))
85 return hResult;
86 hResult = bindContext->RegisterObjectParam((LPOLESTR)wFileSystemBindData, fileSystemBindData);
87 if (FAILED(hResult))
88 return hResult;
89
90 *ppV = bindContext.Detach();
91
92 return S_OK;
93 }
94
95 HRESULT WINAPI FileSystemBindData_GetFindData(LPBC pbc, WIN32_FIND_DATAW *pfd)
96 {
97 CComPtr<IUnknown> pUnk;
98 CComPtr<IFileSystemBindData> pfsbd;
99 HRESULT ret;
100
101 TRACE("%p, %p\n", pbc, pfd);
102
103 if (!pfd)
104 return E_INVALIDARG;
105
106 ret = pbc->GetObjectParam((LPOLESTR)wFileSystemBindData, &pUnk);
107 if (SUCCEEDED(ret))
108 {
109 ret = pUnk->QueryInterface(IID_IFileSystemBindData, (LPVOID *)&pfsbd);
110 if (SUCCEEDED(ret))
111 ret = pfsbd->GetFindData(pfd);
112 }
113 return ret;
114 }
115
116 HRESULT WINAPI FileSystemBindData_SetFindData(LPBC pbc, const WIN32_FIND_DATAW *pfd)
117 {
118 CComPtr<IUnknown> pUnk;
119 CComPtr<IFileSystemBindData> pfsbd;
120 HRESULT ret;
121
122 TRACE("%p, %p\n", pbc, pfd);
123
124 ret = pbc->GetObjectParam((LPOLESTR)wFileSystemBindData, &pUnk);
125 if (SUCCEEDED(ret))
126 {
127 ret = pUnk->QueryInterface(IID_IFileSystemBindData, (LPVOID *)&pfsbd);
128 if (SUCCEEDED(ret))
129 ret = pfsbd->SetFindData(pfd);
130 }
131 return ret;
132 }
133
134 IFileSystemBindDataImpl::IFileSystemBindDataImpl()
135 {
136 memset(&findFile, 0, sizeof(WIN32_FIND_DATAW));
137 }
138
139 IFileSystemBindDataImpl::~IFileSystemBindDataImpl()
140 {
141 TRACE(" destroying ISFBindPidl(%p)\n", this);
142 }
143
144 HRESULT WINAPI IFileSystemBindDataImpl::GetFindData(WIN32_FIND_DATAW *pfd)
145 {
146 TRACE("(%p), %p\n", this, pfd);
147
148 if (!pfd)
149 return E_INVALIDARG;
150
151 memcpy(pfd, &findFile, sizeof(WIN32_FIND_DATAW));
152 return NOERROR;
153 }
154
155 HRESULT WINAPI IFileSystemBindDataImpl::SetFindData(const WIN32_FIND_DATAW *pfd)
156 {
157 TRACE("(%p), %p\n", this, pfd);
158
159 if (pfd)
160 memcpy(&findFile, pfd, sizeof(WIN32_FIND_DATAW));
161 else
162 memset(&findFile, 0, sizeof(WIN32_FIND_DATAW));
163 return NOERROR;
164 }