2 * Compound Storage (32 bit version)
3 * Storage implementation
5 * This file contains the compound file implementation
6 * of the storage interface.
8 * Copyright 1999 Francis Beaudet
9 * Copyright 1999 Sylvain St-Germain
10 * Copyright 1999 Thuy Nguyen
11 * Copyright 2005 Mike McCormack
13 * This library is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Lesser General Public
15 * License as published by the Free Software Foundation; either
16 * version 2.1 of the License, or (at your option) any later version.
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Lesser General Public License for more details.
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with this library; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
35 #define NONAMELESSUNION
36 #define NONAMELESSSTRUCT
42 #include "wine/unicode.h"
43 #include "wine/debug.h"
45 #include "storage32.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(storage);
49 #define _IPropertySetStorage_Offset ((int)(&(((StorageImpl*)0)->base.pssVtbl)))
50 #define _ICOM_THIS_From_IPropertySetStorage(class, name) \
51 class* This = (class*)(((char*)name)-_IPropertySetStorage_Offset)
53 static IPropertyStorageVtbl IPropertyStorage_Vtbl;
55 /***********************************************************************
56 * Implementation of IPropertyStorage
58 typedef struct tagPropertyStorage_impl
60 IPropertyStorageVtbl *vtbl;
63 } PropertyStorage_impl;
65 /************************************************************************
66 * IPropertyStorage_fnQueryInterface (IPropertyStorage)
68 static HRESULT WINAPI IPropertyStorage_fnQueryInterface(
69 IPropertyStorage *iface,
73 PropertyStorage_impl *This = (PropertyStorage_impl *)iface;
75 if ( (This==0) || (ppvObject==0) )
80 if (IsEqualGUID(&IID_IUnknown, riid) ||
81 IsEqualGUID(&IID_IPropertyStorage, riid))
83 IPropertyStorage_AddRef(iface);
84 *ppvObject = (IPropertyStorage*)iface;
91 /************************************************************************
92 * IPropertyStorage_fnAddRef (IPropertyStorage)
94 static ULONG WINAPI IPropertyStorage_fnAddRef(
95 IPropertyStorage *iface)
97 PropertyStorage_impl *This = (PropertyStorage_impl *)iface;
98 return InterlockedIncrement(&This->ref);
101 /************************************************************************
102 * IPropertyStorage_fnRelease (IPropertyStorage)
104 static ULONG WINAPI IPropertyStorage_fnRelease(
105 IPropertyStorage *iface)
107 PropertyStorage_impl *This = (PropertyStorage_impl *)iface;
110 ref = InterlockedDecrement(&This->ref);
113 TRACE("Destroying %p\n", This);
114 IStream_Release(This->stm);
115 HeapFree(GetProcessHeap(), 0, This);
120 /************************************************************************
121 * IPropertyStorage_fnReadMultiple (IPropertyStorage)
123 static HRESULT WINAPI IPropertyStorage_fnReadMultiple(
124 IPropertyStorage* iface,
126 const PROPSPEC rgpspec[],
127 PROPVARIANT rgpropvar[])
133 /************************************************************************
134 * IPropertyStorage_fnWriteMultiple (IPropertyStorage)
136 static HRESULT WINAPI IPropertyStorage_fnWriteMultiple(
137 IPropertyStorage* iface,
139 const PROPSPEC rgpspec[],
140 const PROPVARIANT rgpropvar[],
141 PROPID propidNameFirst)
147 /************************************************************************
148 * IPropertyStorage_fnDeleteMultiple (IPropertyStorage)
150 static HRESULT WINAPI IPropertyStorage_fnDeleteMultiple(
151 IPropertyStorage* iface,
153 const PROPSPEC rgpspec[])
159 /************************************************************************
160 * IPropertyStorage_fnReadPropertyNames (IPropertyStorage)
162 static HRESULT WINAPI IPropertyStorage_fnReadPropertyNames(
163 IPropertyStorage* iface,
165 const PROPID rgpropid[],
166 LPOLESTR rglpwstrName[])
172 /************************************************************************
173 * IPropertyStorage_fnWritePropertyNames (IPropertyStorage)
175 static HRESULT WINAPI IPropertyStorage_fnWritePropertyNames(
176 IPropertyStorage* iface,
178 const PROPID rgpropid[],
179 const LPOLESTR rglpwstrName[])
185 /************************************************************************
186 * IPropertyStorage_fnDeletePropertyNames (IPropertyStorage)
188 static HRESULT WINAPI IPropertyStorage_fnDeletePropertyNames(
189 IPropertyStorage* iface,
191 const PROPID rgpropid[])
197 /************************************************************************
198 * IPropertyStorage_fnCommit (IPropertyStorage)
200 static HRESULT WINAPI IPropertyStorage_fnCommit(
201 IPropertyStorage* iface,
202 DWORD grfCommitFlags)
208 /************************************************************************
209 * IPropertyStorage_fnRevert (IPropertyStorage)
211 static HRESULT WINAPI IPropertyStorage_fnRevert(
212 IPropertyStorage* iface)
218 /************************************************************************
219 * IPropertyStorage_fnEnum (IPropertyStorage)
221 static HRESULT WINAPI IPropertyStorage_fnEnum(
222 IPropertyStorage* iface,
223 IEnumSTATPROPSTG** ppenum)
229 /************************************************************************
230 * IPropertyStorage_fnSetTimes (IPropertyStorage)
232 static HRESULT WINAPI IPropertyStorage_fnSetTimes(
233 IPropertyStorage* iface,
234 const FILETIME* pctime,
235 const FILETIME* patime,
236 const FILETIME* pmtime)
242 /************************************************************************
243 * IPropertyStorage_fnSetClass (IPropertyStorage)
245 static HRESULT WINAPI IPropertyStorage_fnSetClass(
246 IPropertyStorage* iface,
253 /************************************************************************
254 * IPropertyStorage_fnStat (IPropertyStorage)
256 static HRESULT WINAPI IPropertyStorage_fnStat(
257 IPropertyStorage* iface,
258 STATPROPSETSTG* statpsstg)
264 /***********************************************************************
265 * PropertyStorage_Contruct
267 static HRESULT PropertyStorage_Contruct(IStream *stm, IPropertyStorage** pps)
269 PropertyStorage_impl *ps;
271 ps = HeapAlloc(GetProcessHeap(), 0, sizeof *ps);
273 return E_OUTOFMEMORY;
275 ps->vtbl = &IPropertyStorage_Vtbl;
279 *pps = (IPropertyStorage*)ps;
281 TRACE("PropertyStorage %p constructed\n", ps);
287 /***********************************************************************
288 * Implementation of IPropertySetStorage
291 static LPCWSTR format_id_to_name(REFFMTID rfmtid)
293 static const WCHAR szSummaryInfo[] = { 5,'S','u','m','m','a','r','y',
294 'I','n','f','o','r','m','a','t','i','o','n',0 };
296 if (IsEqualGUID(&FMTID_SummaryInformation, rfmtid))
297 return szSummaryInfo;
298 ERR("Unknown format id %s\n", debugstr_guid(rfmtid));
302 /************************************************************************
303 * IPropertySetStorage_fnQueryInterface (IUnknown)
305 * This method forwards to the common QueryInterface implementation
307 static HRESULT WINAPI IPropertySetStorage_fnQueryInterface(
308 IPropertySetStorage *ppstg,
312 _ICOM_THIS_From_IPropertySetStorage(StorageImpl, ppstg);
313 return StorageBaseImpl_QueryInterface( (IStorage*)This, riid, ppvObject );
316 /************************************************************************
317 * IPropertySetStorage_fnAddRef (IUnknown)
319 * This method forwards to the common AddRef implementation
321 static ULONG WINAPI IPropertySetStorage_fnAddRef(
322 IPropertySetStorage *ppstg)
324 _ICOM_THIS_From_IPropertySetStorage(StorageImpl, ppstg);
325 return StorageBaseImpl_AddRef( (IStorage*)This );
328 /************************************************************************
329 * IPropertySetStorage_fnRelease (IUnknown)
331 * This method forwards to the common Release implementation
333 static ULONG WINAPI IPropertySetStorage_fnRelease(
334 IPropertySetStorage *ppstg)
336 _ICOM_THIS_From_IPropertySetStorage(StorageImpl, ppstg);
337 return StorageBaseImpl_Release( (IStorage*)This );
340 /************************************************************************
341 * IPropertySetStorage_fnCreate (IPropertySetStorage)
343 static HRESULT WINAPI IPropertySetStorage_fnCreate(
344 IPropertySetStorage *ppstg,
349 IPropertyStorage** ppprstg)
351 _ICOM_THIS_From_IPropertySetStorage(StorageImpl, ppstg);
356 TRACE("%p %s %08lx %p\n", This, debugstr_guid(rfmtid), grfMode, ppprstg);
359 if (grfMode != (STGM_CREATE|STGM_READWRITE|STGM_SHARE_EXCLUSIVE))
360 return STG_E_INVALIDFLAG;
365 name = format_id_to_name(rfmtid);
367 return STG_E_FILENOTFOUND;
369 r = IStorage_CreateStream( (IStorage*)This, name, grfMode, 0, 0, &stm );
373 return PropertyStorage_Contruct(stm, ppprstg);
376 /************************************************************************
377 * IPropertySetStorage_fnOpen (IPropertySetStorage)
379 static HRESULT WINAPI IPropertySetStorage_fnOpen(
380 IPropertySetStorage *ppstg,
383 IPropertyStorage** ppprstg)
385 _ICOM_THIS_From_IPropertySetStorage(StorageImpl, ppstg);
390 TRACE("%p %s %08lx %p\n", This, debugstr_guid(rfmtid), grfMode, ppprstg);
393 if (grfMode != (STGM_READWRITE|STGM_SHARE_EXCLUSIVE) &&
394 grfMode != (STGM_READ|STGM_SHARE_EXCLUSIVE))
395 return STG_E_INVALIDFLAG;
400 name = format_id_to_name(rfmtid);
402 return STG_E_FILENOTFOUND;
404 r = IStorage_OpenStream((IStorage*) This, name, 0, grfMode, 0, &stm );
408 return PropertyStorage_Contruct(stm, ppprstg);
411 /************************************************************************
412 * IPropertySetStorage_fnDelete (IPropertySetStorage)
414 static HRESULT WINAPI IPropertySetStorage_fnDelete(
415 IPropertySetStorage *ppstg,
418 _ICOM_THIS_From_IPropertySetStorage(StorageImpl, ppstg);
419 IStorage *stg = NULL;
422 TRACE("%p %s\n", This, debugstr_guid(rfmtid));
427 name = format_id_to_name(rfmtid);
429 return STG_E_FILENOTFOUND;
431 stg = (IStorage*) This;
432 return IStorage_DestroyElement(stg, name);
435 /************************************************************************
436 * IPropertySetStorage_fnEnum (IPropertySetStorage)
438 static HRESULT WINAPI IPropertySetStorage_fnEnum(
439 IPropertySetStorage *ppstg,
440 IEnumSTATPROPSETSTG** ppenum)
442 _ICOM_THIS_From_IPropertySetStorage(StorageImpl, ppstg);
448 /***********************************************************************
451 IPropertySetStorageVtbl IPropertySetStorage_Vtbl =
453 IPropertySetStorage_fnQueryInterface,
454 IPropertySetStorage_fnAddRef,
455 IPropertySetStorage_fnRelease,
456 IPropertySetStorage_fnCreate,
457 IPropertySetStorage_fnOpen,
458 IPropertySetStorage_fnDelete,
459 IPropertySetStorage_fnEnum
462 static IPropertyStorageVtbl IPropertyStorage_Vtbl =
464 IPropertyStorage_fnQueryInterface,
465 IPropertyStorage_fnAddRef,
466 IPropertyStorage_fnRelease,
467 IPropertyStorage_fnReadMultiple,
468 IPropertyStorage_fnWriteMultiple,
469 IPropertyStorage_fnDeleteMultiple,
470 IPropertyStorage_fnReadPropertyNames,
471 IPropertyStorage_fnWritePropertyNames,
472 IPropertyStorage_fnDeletePropertyNames,
473 IPropertyStorage_fnCommit,
474 IPropertyStorage_fnRevert,
475 IPropertyStorage_fnEnum,
476 IPropertyStorage_fnSetTimes,
477 IPropertyStorage_fnSetClass,
478 IPropertyStorage_fnStat,