jscript: Throw error in to_primitive function.
[wine/testsucceed.git] / dlls / ole32 / stg_stream.c
blob9acd4145191d095698b487bf9febdcbff5f6e86b
1 /*
2 * Compound Storage (32 bit version)
3 * Stream implementation
5 * This file contains the implementation of the stream interface
6 * for streams contained in a compound storage.
8 * Copyright 1999 Francis Beaudet
9 * Copyright 1999 Thuy Nguyen
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include <assert.h>
27 #include <stdlib.h>
28 #include <stdarg.h>
29 #include <stdio.h>
30 #include <string.h>
32 #define COBJMACROS
33 #define NONAMELESSUNION
34 #define NONAMELESSSTRUCT
36 #include "windef.h"
37 #include "winbase.h"
38 #include "winerror.h"
39 #include "winternl.h"
40 #include "wine/debug.h"
42 #include "storage32.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(storage);
47 /***
48 * This is the destructor of the StgStreamImpl class.
50 * This method will clean-up all the resources used-up by the given StgStreamImpl
51 * class. The pointer passed-in to this function will be freed and will not
52 * be valid anymore.
54 static void StgStreamImpl_Destroy(StgStreamImpl* This)
56 TRACE("(%p)\n", This);
59 * Release the reference we are holding on the parent storage.
60 * IStorage_Release((IStorage*)This->parentStorage);
62 * No, don't do this. Some apps call IStorage_Release without
63 * calling IStream_Release first. If we grab a reference the
64 * file is not closed, and the app fails when it tries to
65 * reopen the file (Easy-PC, for example). Just inform the
66 * storage that we have closed the stream
69 if(This->parentStorage) {
71 StorageBaseImpl_RemoveStream(This->parentStorage, This);
75 This->parentStorage = 0;
78 * Make sure we clean-up the block chain stream objects that we were using.
80 if (This->bigBlockChain != 0)
82 BlockChainStream_Destroy(This->bigBlockChain);
83 This->bigBlockChain = 0;
86 if (This->smallBlockChain != 0)
88 SmallBlockChainStream_Destroy(This->smallBlockChain);
89 This->smallBlockChain = 0;
93 * Finally, free the memory used-up by the class.
95 HeapFree(GetProcessHeap(), 0, This);
98 /***
99 * This implements the IUnknown method QueryInterface for this
100 * class
102 static HRESULT WINAPI StgStreamImpl_QueryInterface(
103 IStream* iface,
104 REFIID riid, /* [in] */
105 void** ppvObject) /* [iid_is][out] */
107 StgStreamImpl* const This=(StgStreamImpl*)iface;
110 * Perform a sanity check on the parameters.
112 if (ppvObject==0)
113 return E_INVALIDARG;
116 * Initialize the return parameter.
118 *ppvObject = 0;
121 * Compare the riid with the interface IDs implemented by this object.
123 if (IsEqualIID(&IID_IUnknown, riid) ||
124 IsEqualIID(&IID_IPersist, riid) ||
125 IsEqualIID(&IID_IPersistStream, riid) ||
126 IsEqualIID(&IID_ISequentialStream, riid) ||
127 IsEqualIID(&IID_IStream, riid))
129 *ppvObject = This;
133 * Check that we obtained an interface.
135 if ((*ppvObject)==0)
136 return E_NOINTERFACE;
139 * Query Interface always increases the reference count by one when it is
140 * successful
142 IStream_AddRef(iface);
144 return S_OK;
147 /***
148 * This implements the IUnknown method AddRef for this
149 * class
151 static ULONG WINAPI StgStreamImpl_AddRef(
152 IStream* iface)
154 StgStreamImpl* const This=(StgStreamImpl*)iface;
155 return InterlockedIncrement(&This->ref);
158 /***
159 * This implements the IUnknown method Release for this
160 * class
162 static ULONG WINAPI StgStreamImpl_Release(
163 IStream* iface)
165 StgStreamImpl* const This=(StgStreamImpl*)iface;
167 ULONG ref;
169 ref = InterlockedDecrement(&This->ref);
172 * If the reference count goes down to 0, perform suicide.
174 if (ref==0)
176 StgStreamImpl_Destroy(This);
179 return ref;
182 /***
183 * This method will open the block chain pointed by the property
184 * that describes the stream.
185 * If the stream's size is null, no chain is opened.
187 static void StgStreamImpl_OpenBlockChain(
188 StgStreamImpl* This)
190 StgProperty curProperty;
191 BOOL readSuccessful;
194 * Make sure no old object is left over.
196 if (This->smallBlockChain != 0)
198 SmallBlockChainStream_Destroy(This->smallBlockChain);
199 This->smallBlockChain = 0;
202 if (This->bigBlockChain != 0)
204 BlockChainStream_Destroy(This->bigBlockChain);
205 This->bigBlockChain = 0;
209 * Read the information from the property.
211 readSuccessful = StorageImpl_ReadProperty(This->parentStorage->ancestorStorage,
212 This->ownerProperty,
213 &curProperty);
215 if (readSuccessful)
217 This->streamSize = curProperty.size;
220 * This code supports only streams that are <32 bits in size.
222 assert(This->streamSize.u.HighPart == 0);
224 if(curProperty.startingBlock == BLOCK_END_OF_CHAIN)
226 assert( (This->streamSize.u.HighPart == 0) && (This->streamSize.u.LowPart == 0) );
228 else
230 if ( (This->streamSize.u.HighPart == 0) &&
231 (This->streamSize.u.LowPart < LIMIT_TO_USE_SMALL_BLOCK) )
233 This->smallBlockChain = SmallBlockChainStream_Construct(
234 This->parentStorage->ancestorStorage,
235 This->ownerProperty);
237 else
239 This->bigBlockChain = BlockChainStream_Construct(
240 This->parentStorage->ancestorStorage,
241 NULL,
242 This->ownerProperty);
248 /***
249 * This method is part of the ISequentialStream interface.
251 * It reads a block of information from the stream at the current
252 * position. It then moves the current position at the end of the
253 * read block
255 * See the documentation of ISequentialStream for more info.
257 static HRESULT WINAPI StgStreamImpl_Read(
258 IStream* iface,
259 void* pv, /* [length_is][size_is][out] */
260 ULONG cb, /* [in] */
261 ULONG* pcbRead) /* [out] */
263 StgStreamImpl* const This=(StgStreamImpl*)iface;
265 ULONG bytesReadBuffer;
266 ULONG bytesToReadFromBuffer;
267 HRESULT res;
269 TRACE("(%p, %p, %d, %p)\n",
270 iface, pv, cb, pcbRead);
272 if (!This->parentStorage)
274 WARN("storage reverted\n");
275 return STG_E_REVERTED;
279 * If the caller is not interested in the number of bytes read,
280 * we use another buffer to avoid "if" statements in the code.
282 if (pcbRead==0)
283 pcbRead = &bytesReadBuffer;
286 * Using the known size of the stream, calculate the number of bytes
287 * to read from the block chain
289 bytesToReadFromBuffer = min( This->streamSize.u.LowPart - This->currentPosition.u.LowPart, cb);
292 * Depending on the type of chain that was opened when the stream was constructed,
293 * we delegate the work to the method that reads the block chains.
295 if (This->smallBlockChain!=0)
297 res = SmallBlockChainStream_ReadAt(This->smallBlockChain,
298 This->currentPosition,
299 bytesToReadFromBuffer,
301 pcbRead);
304 else if (This->bigBlockChain!=0)
306 res = BlockChainStream_ReadAt(This->bigBlockChain,
307 This->currentPosition,
308 bytesToReadFromBuffer,
310 pcbRead);
312 else
315 * Small and big block chains are both NULL. This case will happen
316 * when a stream starts with BLOCK_END_OF_CHAIN and has size zero.
319 *pcbRead = 0;
320 res = S_OK;
321 goto end;
324 if (SUCCEEDED(res))
327 * We should always be able to read the proper amount of data from the
328 * chain.
330 assert(bytesToReadFromBuffer == *pcbRead);
333 * Advance the pointer for the number of positions read.
335 This->currentPosition.u.LowPart += *pcbRead;
338 end:
339 TRACE("<-- %08x\n", res);
340 return res;
343 /***
344 * This method is part of the ISequentialStream interface.
346 * It writes a block of information to the stream at the current
347 * position. It then moves the current position at the end of the
348 * written block. If the stream is too small to fit the block,
349 * the stream is grown to fit.
351 * See the documentation of ISequentialStream for more info.
353 static HRESULT WINAPI StgStreamImpl_Write(
354 IStream* iface,
355 const void* pv, /* [size_is][in] */
356 ULONG cb, /* [in] */
357 ULONG* pcbWritten) /* [out] */
359 StgStreamImpl* const This=(StgStreamImpl*)iface;
361 ULARGE_INTEGER newSize;
362 ULONG bytesWritten = 0;
363 HRESULT res;
365 TRACE("(%p, %p, %d, %p)\n",
366 iface, pv, cb, pcbWritten);
369 * Do we have permission to write to this stream?
371 switch(STGM_ACCESS_MODE(This->grfMode))
373 case STGM_WRITE:
374 case STGM_READWRITE:
375 break;
376 default:
377 WARN("access denied by flags: 0x%x\n", STGM_ACCESS_MODE(This->grfMode));
378 return STG_E_ACCESSDENIED;
381 if (!pv)
382 return STG_E_INVALIDPOINTER;
384 if (!This->parentStorage)
386 WARN("storage reverted\n");
387 return STG_E_REVERTED;
391 * If the caller is not interested in the number of bytes written,
392 * we use another buffer to avoid "if" statements in the code.
394 if (pcbWritten == 0)
395 pcbWritten = &bytesWritten;
398 * Initialize the out parameter
400 *pcbWritten = 0;
402 if (cb == 0)
404 TRACE("<-- S_OK, written 0\n");
405 return S_OK;
407 else
409 newSize.u.HighPart = 0;
410 newSize.u.LowPart = This->currentPosition.u.LowPart + cb;
414 * Verify if we need to grow the stream
416 if (newSize.u.LowPart > This->streamSize.u.LowPart)
418 /* grow stream */
419 res = IStream_SetSize(iface, newSize);
420 if (FAILED(res))
421 return res;
425 * Depending on the type of chain that was opened when the stream was constructed,
426 * we delegate the work to the method that readwrites to the block chains.
428 if (This->smallBlockChain!=0)
430 res = SmallBlockChainStream_WriteAt(This->smallBlockChain,
431 This->currentPosition,
434 pcbWritten);
437 else if (This->bigBlockChain!=0)
439 res = BlockChainStream_WriteAt(This->bigBlockChain,
440 This->currentPosition,
443 pcbWritten);
445 else
447 /* this should never happen because the IStream_SetSize call above will
448 * make sure a big or small block chain is created */
449 assert(FALSE);
450 res = 0;
454 * Advance the position pointer for the number of positions written.
456 This->currentPosition.u.LowPart += *pcbWritten;
458 TRACE("<-- S_OK, written %u\n", *pcbWritten);
459 return res;
462 /***
463 * This method is part of the IStream interface.
465 * It will move the current stream pointer according to the parameters
466 * given.
468 * See the documentation of IStream for more info.
470 static HRESULT WINAPI StgStreamImpl_Seek(
471 IStream* iface,
472 LARGE_INTEGER dlibMove, /* [in] */
473 DWORD dwOrigin, /* [in] */
474 ULARGE_INTEGER* plibNewPosition) /* [out] */
476 StgStreamImpl* const This=(StgStreamImpl*)iface;
478 ULARGE_INTEGER newPosition;
480 TRACE("(%p, %d, %d, %p)\n",
481 iface, dlibMove.u.LowPart, dwOrigin, plibNewPosition);
484 * fail if the stream has no parent (as does windows)
487 if (!This->parentStorage)
489 WARN("storage reverted\n");
490 return STG_E_REVERTED;
494 * The caller is allowed to pass in NULL as the new position return value.
495 * If it happens, we assign it to a dynamic variable to avoid special cases
496 * in the code below.
498 if (plibNewPosition == 0)
500 plibNewPosition = &newPosition;
504 * The file pointer is moved depending on the given "function"
505 * parameter.
507 switch (dwOrigin)
509 case STREAM_SEEK_SET:
510 plibNewPosition->u.HighPart = 0;
511 plibNewPosition->u.LowPart = 0;
512 break;
513 case STREAM_SEEK_CUR:
514 *plibNewPosition = This->currentPosition;
515 break;
516 case STREAM_SEEK_END:
517 *plibNewPosition = This->streamSize;
518 break;
519 default:
520 WARN("invalid dwOrigin %d\n", dwOrigin);
521 return STG_E_INVALIDFUNCTION;
524 plibNewPosition->QuadPart = RtlLargeIntegerAdd( plibNewPosition->QuadPart, dlibMove.QuadPart );
527 * tell the caller what we calculated
529 This->currentPosition = *plibNewPosition;
531 return S_OK;
534 /***
535 * This method is part of the IStream interface.
537 * It will change the size of a stream.
539 * TODO: Switch from small blocks to big blocks and vice versa.
541 * See the documentation of IStream for more info.
543 static HRESULT WINAPI StgStreamImpl_SetSize(
544 IStream* iface,
545 ULARGE_INTEGER libNewSize) /* [in] */
547 StgStreamImpl* const This=(StgStreamImpl*)iface;
549 StgProperty curProperty;
550 BOOL Success;
552 TRACE("(%p, %d)\n", iface, libNewSize.u.LowPart);
554 if(!This->parentStorage)
556 WARN("storage reverted\n");
557 return STG_E_REVERTED;
561 * As documented.
563 if (libNewSize.u.HighPart != 0)
565 WARN("invalid value for libNewSize.u.HighPart %d\n", libNewSize.u.HighPart);
566 return STG_E_INVALIDFUNCTION;
570 * Do we have permission?
572 if (!(This->grfMode & (STGM_WRITE | STGM_READWRITE)))
574 WARN("access denied\n");
575 return STG_E_ACCESSDENIED;
578 /* In simple mode keep the stream size above the small block limit */
579 if (This->parentStorage->ancestorStorage->base.openFlags & STGM_SIMPLE)
580 libNewSize.u.LowPart = max(libNewSize.u.LowPart, LIMIT_TO_USE_SMALL_BLOCK);
582 if (This->streamSize.u.LowPart == libNewSize.u.LowPart)
583 return S_OK;
586 * This will happen if we're creating a stream
588 if ((This->smallBlockChain == 0) && (This->bigBlockChain == 0))
590 if (libNewSize.u.LowPart < LIMIT_TO_USE_SMALL_BLOCK)
592 This->smallBlockChain = SmallBlockChainStream_Construct(
593 This->parentStorage->ancestorStorage,
594 This->ownerProperty);
596 else
598 This->bigBlockChain = BlockChainStream_Construct(
599 This->parentStorage->ancestorStorage,
600 NULL,
601 This->ownerProperty);
606 * Read this stream's property to see if it's small blocks or big blocks
608 Success = StorageImpl_ReadProperty(This->parentStorage->ancestorStorage,
609 This->ownerProperty,
610 &curProperty);
612 * Determine if we have to switch from small to big blocks or vice versa
614 if ( (This->smallBlockChain!=0) &&
615 (curProperty.size.u.LowPart < LIMIT_TO_USE_SMALL_BLOCK) )
617 if (libNewSize.u.LowPart >= LIMIT_TO_USE_SMALL_BLOCK)
620 * Transform the small block chain into a big block chain
622 This->bigBlockChain = Storage32Impl_SmallBlocksToBigBlocks(
623 This->parentStorage->ancestorStorage,
624 &This->smallBlockChain);
628 if (This->smallBlockChain!=0)
630 Success = SmallBlockChainStream_SetSize(This->smallBlockChain, libNewSize);
632 else
634 Success = BlockChainStream_SetSize(This->bigBlockChain, libNewSize);
638 * Write the new information about this stream to the property
640 Success = StorageImpl_ReadProperty(This->parentStorage->ancestorStorage,
641 This->ownerProperty,
642 &curProperty);
644 curProperty.size.u.HighPart = libNewSize.u.HighPart;
645 curProperty.size.u.LowPart = libNewSize.u.LowPart;
647 if (Success)
649 StorageImpl_WriteProperty(This->parentStorage->ancestorStorage,
650 This->ownerProperty,
651 &curProperty);
654 This->streamSize = libNewSize;
656 return S_OK;
659 /***
660 * This method is part of the IStream interface.
662 * It will copy the 'cb' Bytes to 'pstm' IStream.
664 * See the documentation of IStream for more info.
666 static HRESULT WINAPI StgStreamImpl_CopyTo(
667 IStream* iface,
668 IStream* pstm, /* [unique][in] */
669 ULARGE_INTEGER cb, /* [in] */
670 ULARGE_INTEGER* pcbRead, /* [out] */
671 ULARGE_INTEGER* pcbWritten) /* [out] */
673 StgStreamImpl* const This=(StgStreamImpl*)iface;
674 HRESULT hr = S_OK;
675 BYTE tmpBuffer[128];
676 ULONG bytesRead, bytesWritten, copySize;
677 ULARGE_INTEGER totalBytesRead;
678 ULARGE_INTEGER totalBytesWritten;
680 TRACE("(%p, %p, %d, %p, %p)\n",
681 iface, pstm, cb.u.LowPart, pcbRead, pcbWritten);
684 * Sanity check
687 if (!This->parentStorage)
689 WARN("storage reverted\n");
690 return STG_E_REVERTED;
693 if ( pstm == 0 )
694 return STG_E_INVALIDPOINTER;
696 totalBytesRead.QuadPart = 0;
697 totalBytesWritten.QuadPart = 0;
699 while ( cb.QuadPart > 0 )
701 if ( cb.QuadPart >= sizeof(tmpBuffer) )
702 copySize = sizeof(tmpBuffer);
703 else
704 copySize = cb.u.LowPart;
706 IStream_Read(iface, tmpBuffer, copySize, &bytesRead);
708 totalBytesRead.QuadPart += bytesRead;
710 IStream_Write(pstm, tmpBuffer, bytesRead, &bytesWritten);
712 totalBytesWritten.QuadPart += bytesWritten;
715 * Check that read & write operations were successful
717 if (bytesRead != bytesWritten)
719 hr = STG_E_MEDIUMFULL;
720 WARN("medium full\n");
721 break;
724 if (bytesRead!=copySize)
725 cb.QuadPart = 0;
726 else
727 cb.QuadPart -= bytesRead;
730 if (pcbRead) pcbRead->QuadPart = totalBytesRead.QuadPart;
731 if (pcbWritten) pcbWritten->QuadPart = totalBytesWritten.QuadPart;
733 return hr;
736 /***
737 * This method is part of the IStream interface.
739 * For streams contained in structured storages, this method
740 * does nothing. This is what the documentation tells us.
742 * See the documentation of IStream for more info.
744 static HRESULT WINAPI StgStreamImpl_Commit(
745 IStream* iface,
746 DWORD grfCommitFlags) /* [in] */
748 StgStreamImpl* const This=(StgStreamImpl*)iface;
750 if (!This->parentStorage)
752 WARN("storage reverted\n");
753 return STG_E_REVERTED;
756 return S_OK;
759 /***
760 * This method is part of the IStream interface.
762 * For streams contained in structured storages, this method
763 * does nothing. This is what the documentation tells us.
765 * See the documentation of IStream for more info.
767 static HRESULT WINAPI StgStreamImpl_Revert(
768 IStream* iface)
770 return S_OK;
773 static HRESULT WINAPI StgStreamImpl_LockRegion(
774 IStream* iface,
775 ULARGE_INTEGER libOffset, /* [in] */
776 ULARGE_INTEGER cb, /* [in] */
777 DWORD dwLockType) /* [in] */
779 StgStreamImpl* const This=(StgStreamImpl*)iface;
781 if (!This->parentStorage)
783 WARN("storage reverted\n");
784 return STG_E_REVERTED;
787 FIXME("not implemented!\n");
788 return E_NOTIMPL;
791 static HRESULT WINAPI StgStreamImpl_UnlockRegion(
792 IStream* iface,
793 ULARGE_INTEGER libOffset, /* [in] */
794 ULARGE_INTEGER cb, /* [in] */
795 DWORD dwLockType) /* [in] */
797 StgStreamImpl* const This=(StgStreamImpl*)iface;
799 if (!This->parentStorage)
801 WARN("storage reverted\n");
802 return STG_E_REVERTED;
805 FIXME("not implemented!\n");
806 return E_NOTIMPL;
809 /***
810 * This method is part of the IStream interface.
812 * This method returns information about the current
813 * stream.
815 * See the documentation of IStream for more info.
817 static HRESULT WINAPI StgStreamImpl_Stat(
818 IStream* iface,
819 STATSTG* pstatstg, /* [out] */
820 DWORD grfStatFlag) /* [in] */
822 StgStreamImpl* const This=(StgStreamImpl*)iface;
824 StgProperty curProperty;
825 BOOL readSuccessful;
827 TRACE("%p %p %d\n", This, pstatstg, grfStatFlag);
830 * if stream has no parent, return STG_E_REVERTED
833 if (!This->parentStorage)
835 WARN("storage reverted\n");
836 return STG_E_REVERTED;
840 * Read the information from the property.
842 readSuccessful = StorageImpl_ReadProperty(This->parentStorage->ancestorStorage,
843 This->ownerProperty,
844 &curProperty);
846 if (readSuccessful)
848 StorageImpl *root = This->parentStorage->ancestorStorage;
850 StorageUtl_CopyPropertyToSTATSTG(pstatstg,
851 &curProperty,
852 grfStatFlag);
854 pstatstg->grfMode = This->grfMode;
856 /* In simple create mode cbSize is the current pos */
857 if((root->base.openFlags & STGM_SIMPLE) && root->create)
858 pstatstg->cbSize = This->currentPosition;
860 return S_OK;
863 WARN("failed to read properties\n");
864 return E_FAIL;
867 /***
868 * This method is part of the IStream interface.
870 * This method returns a clone of the interface that allows for
871 * another seek pointer
873 * See the documentation of IStream for more info.
875 * I am not totally sure what I am doing here but I presume that this
876 * should be basically as simple as creating a new stream with the same
877 * parent etc and positioning its seek cursor.
879 static HRESULT WINAPI StgStreamImpl_Clone(
880 IStream* iface,
881 IStream** ppstm) /* [out] */
883 StgStreamImpl* const This=(StgStreamImpl*)iface;
884 HRESULT hres;
885 StgStreamImpl* new_stream;
886 LARGE_INTEGER seek_pos;
888 TRACE("%p %p\n", This, ppstm);
891 * Sanity check
894 if (!This->parentStorage)
895 return STG_E_REVERTED;
897 if ( ppstm == 0 )
898 return STG_E_INVALIDPOINTER;
900 new_stream = StgStreamImpl_Construct (This->parentStorage, This->grfMode, This->ownerProperty);
902 if (!new_stream)
903 return STG_E_INSUFFICIENTMEMORY; /* Currently the only reason for new_stream=0 */
905 *ppstm = (IStream*) new_stream;
906 IStream_AddRef(*ppstm);
908 seek_pos.QuadPart = This->currentPosition.QuadPart;
910 hres=StgStreamImpl_Seek (*ppstm, seek_pos, STREAM_SEEK_SET, NULL);
912 assert (SUCCEEDED(hres));
914 return S_OK;
918 * Virtual function table for the StgStreamImpl class.
920 static const IStreamVtbl StgStreamImpl_Vtbl =
922 StgStreamImpl_QueryInterface,
923 StgStreamImpl_AddRef,
924 StgStreamImpl_Release,
925 StgStreamImpl_Read,
926 StgStreamImpl_Write,
927 StgStreamImpl_Seek,
928 StgStreamImpl_SetSize,
929 StgStreamImpl_CopyTo,
930 StgStreamImpl_Commit,
931 StgStreamImpl_Revert,
932 StgStreamImpl_LockRegion,
933 StgStreamImpl_UnlockRegion,
934 StgStreamImpl_Stat,
935 StgStreamImpl_Clone
938 /******************************************************************************
939 ** StgStreamImpl implementation
942 /***
943 * This is the constructor for the StgStreamImpl class.
945 * Params:
946 * parentStorage - Pointer to the storage that contains the stream to open
947 * ownerProperty - Index of the property that points to this stream.
949 StgStreamImpl* StgStreamImpl_Construct(
950 StorageBaseImpl* parentStorage,
951 DWORD grfMode,
952 ULONG ownerProperty)
954 StgStreamImpl* newStream;
956 newStream = HeapAlloc(GetProcessHeap(), 0, sizeof(StgStreamImpl));
958 if (newStream!=0)
961 * Set-up the virtual function table and reference count.
963 newStream->lpVtbl = &StgStreamImpl_Vtbl;
964 newStream->ref = 0;
966 newStream->parentStorage = parentStorage;
969 * We want to nail-down the reference to the storage in case the
970 * stream out-lives the storage in the client application.
972 * -- IStorage_AddRef((IStorage*)newStream->parentStorage);
974 * No, don't do this. Some apps call IStorage_Release without
975 * calling IStream_Release first. If we grab a reference the
976 * file is not closed, and the app fails when it tries to
977 * reopen the file (Easy-PC, for example)
980 newStream->grfMode = grfMode;
981 newStream->ownerProperty = ownerProperty;
984 * Start the stream at the beginning.
986 newStream->currentPosition.u.HighPart = 0;
987 newStream->currentPosition.u.LowPart = 0;
990 * Initialize the rest of the data.
992 newStream->streamSize.u.HighPart = 0;
993 newStream->streamSize.u.LowPart = 0;
994 newStream->bigBlockChain = 0;
995 newStream->smallBlockChain = 0;
998 * Read the size from the property and determine if the blocks forming
999 * this stream are large or small.
1001 StgStreamImpl_OpenBlockChain(newStream);
1003 /* add us to the storage's list of active streams */
1004 StorageBaseImpl_AddStream(parentStorage, newStream);
1007 return newStream;