source: trunk/src/ole32/hglobalstream.c

Last change on this file was 21916, checked in by dmik, 14 years ago

Merge branch gcc-kmk to trunk.

File size: 21.1 KB
RevLine 
[5602]1/*
2 * HGLOBAL Stream implementation
3 *
4 * This file contains the implementation of the stream interface
5 * for streams contained supported by an HGLOBAL pointer.
6 *
7 * Copyright 1999 Francis Beaudet
[8441]8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
[5602]22 */
[7926]23
24#include "config.h"
25
[5602]26#include <assert.h>
27#include <stdlib.h>
28#include <stdio.h>
29#include <string.h>
30
[7926]31#include "windef.h"
32#include "objbase.h"
33#include "ole2.h"
[5602]34#include "winbase.h"
35#include "winerror.h"
[9400]36#include "winternl.h"
[7926]37
[8441]38#include "wine/debug.h"
[5602]39
[8441]40WINE_DEFAULT_DEBUG_CHANNEL(storage);
[5602]41
42/****************************************************************************
43 * HGLOBALStreamImpl definition.
44 *
45 * This class imlements the IStream inteface and represents a stream
46 * supported by an HGLOBAL pointer.
47 */
48struct HGLOBALStreamImpl
49{
50 ICOM_VFIELD(IStream); /* Needs to be the first item in the stuct
[6711]51 * since we want to cast this in a IStream pointer */
[8620]52
[5602]53 /*
54 * Reference count
55 */
[6711]56 ULONG ref;
[5602]57
58 /*
59 * Support for the stream
60 */
61 HGLOBAL supportHandle;
62
63 /*
64 * This flag is TRUE if the HGLOBAL is destroyed when the stream
65 * is finally released.
66 */
67 BOOL deleteOnRelease;
68
69 /*
70 * Helper variable that contains the size of the stream
71 */
72 ULARGE_INTEGER streamSize;
73
74 /*
75 * This is the current position of the cursor in the stream
76 */
77 ULARGE_INTEGER currentPosition;
78};
79
80typedef struct HGLOBALStreamImpl HGLOBALStreamImpl;
81
82/*
83 * Method definition for the StgStreamImpl class.
84 */
85HGLOBALStreamImpl* HGLOBALStreamImpl_Construct(
[6711]86 HGLOBAL hGlobal,
87 BOOL fDeleteOnRelease);
[5602]88
89void HGLOBALStreamImpl_Destroy(
90 HGLOBALStreamImpl* This);
91
92void HGLOBALStreamImpl_OpenBlockChain(
93 HGLOBALStreamImpl* This);
94
95HRESULT WINAPI HGLOBALStreamImpl_QueryInterface(
[6711]96 IStream* iface,
[8620]97 REFIID riid, /* [in] */
98 void** ppvObject); /* [iid_is][out] */
99
[5602]100ULONG WINAPI HGLOBALStreamImpl_AddRef(
[6711]101 IStream* iface);
[8620]102
[5602]103ULONG WINAPI HGLOBALStreamImpl_Release(
[6711]104 IStream* iface);
[8620]105
106HRESULT WINAPI HGLOBALStreamImpl_Read(
[6711]107 IStream* iface,
108 void* pv, /* [length_is][size_is][out] */
[8620]109 ULONG cb, /* [in] */
110 ULONG* pcbRead); /* [out] */
111
[5602]112HRESULT WINAPI HGLOBALStreamImpl_Write(
[6711]113 IStream* iface,
[8620]114 const void* pv, /* [size_is][in] */
115 ULONG cb, /* [in] */
116 ULONG* pcbWritten); /* [out] */
117
118HRESULT WINAPI HGLOBALStreamImpl_Seek(
[6711]119 IStream* iface,
[8620]120 LARGE_INTEGER dlibMove, /* [in] */
121 DWORD dwOrigin, /* [in] */
[6711]122 ULARGE_INTEGER* plibNewPosition); /* [out] */
[8620]123
124HRESULT WINAPI HGLOBALStreamImpl_SetSize(
[6711]125 IStream* iface,
[8620]126 ULARGE_INTEGER libNewSize); /* [in] */
127
128HRESULT WINAPI HGLOBALStreamImpl_CopyTo(
[6711]129 IStream* iface,
[8620]130 IStream* pstm, /* [unique][in] */
131 ULARGE_INTEGER cb, /* [in] */
132 ULARGE_INTEGER* pcbRead, /* [out] */
133 ULARGE_INTEGER* pcbWritten); /* [out] */
[5602]134
[8620]135HRESULT WINAPI HGLOBALStreamImpl_Commit(
[6711]136 IStream* iface,
[8620]137 DWORD grfCommitFlags); /* [in] */
138
139HRESULT WINAPI HGLOBALStreamImpl_Revert(
[6711]140 IStream* iface);
[8620]141
142HRESULT WINAPI HGLOBALStreamImpl_LockRegion(
[6711]143 IStream* iface,
[8620]144 ULARGE_INTEGER libOffset, /* [in] */
145 ULARGE_INTEGER cb, /* [in] */
146 DWORD dwLockType); /* [in] */
147
148HRESULT WINAPI HGLOBALStreamImpl_UnlockRegion(
[6711]149 IStream* iface,
[8620]150 ULARGE_INTEGER libOffset, /* [in] */
151 ULARGE_INTEGER cb, /* [in] */
152 DWORD dwLockType); /* [in] */
153
154HRESULT WINAPI HGLOBALStreamImpl_Stat(
[6711]155 IStream* iface,
156 STATSTG* pstatstg, /* [out] */
[8620]157 DWORD grfStatFlag); /* [in] */
158
159HRESULT WINAPI HGLOBALStreamImpl_Clone(
[6711]160 IStream* iface,
[8620]161 IStream** ppstm); /* [out] */
[5602]162
163
164/*
165 * Virtual function table for the HGLOBALStreamImpl class.
166 */
167static ICOM_VTABLE(IStream) HGLOBALStreamImpl_Vtbl =
168{
169 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
170 HGLOBALStreamImpl_QueryInterface,
171 HGLOBALStreamImpl_AddRef,
172 HGLOBALStreamImpl_Release,
173 HGLOBALStreamImpl_Read,
174 HGLOBALStreamImpl_Write,
175 HGLOBALStreamImpl_Seek,
176 HGLOBALStreamImpl_SetSize,
177 HGLOBALStreamImpl_CopyTo,
178 HGLOBALStreamImpl_Commit,
179 HGLOBALStreamImpl_Revert,
180 HGLOBALStreamImpl_LockRegion,
181 HGLOBALStreamImpl_UnlockRegion,
182 HGLOBALStreamImpl_Stat,
183 HGLOBALStreamImpl_Clone
184};
185
186/***********************************************************************
187 * CreateStreamOnHGlobal [OLE32.61]
188 */
189HRESULT WINAPI CreateStreamOnHGlobal(
[8620]190 HGLOBAL hGlobal,
191 BOOL fDeleteOnRelease,
[6711]192 LPSTREAM* ppstm)
[5602]193{
194 HGLOBALStreamImpl* newStream;
195
196 newStream = HGLOBALStreamImpl_Construct(hGlobal,
[6711]197 fDeleteOnRelease);
[5602]198
199 if (newStream!=NULL)
200 {
[8620]201 return IUnknown_QueryInterface((IUnknown*)newStream,
[6711]202 &IID_IStream,
203 (void**)ppstm);
[5602]204 }
205
206 return E_OUTOFMEMORY;
207}
208
209/***********************************************************************
210 * GetHGlobalFromStream [OLE32.71]
211 */
212HRESULT WINAPI GetHGlobalFromStream(IStream* pstm, HGLOBAL* phglobal)
213{
214 HGLOBALStreamImpl* pStream;
215
216 if (pstm == NULL)
217 return E_INVALIDARG;
218
219 pStream = (HGLOBALStreamImpl*) pstm;
220
221 /*
222 * Verify that the stream object was created with CreateStreamOnHGlobal.
223 */
224 if (ICOM_VTBL(pStream) == &HGLOBALStreamImpl_Vtbl)
225 *phglobal = pStream->supportHandle;
226 else
227 {
228 *phglobal = 0;
229 return E_INVALIDARG;
230 }
231
232 return S_OK;
233}
234
235/******************************************************************************
236** HGLOBALStreamImpl implementation
237*/
238
239/***
240 * This is the constructor for the HGLOBALStreamImpl class.
241 *
242 * Params:
243 * hGlobal - Handle that will support the stream. can be NULL.
[8620]244 * fDeleteOnRelease - Flag set to TRUE if the HGLOBAL will be released
[5602]245 * when the IStream object is destroyed.
246 */
247HGLOBALStreamImpl* HGLOBALStreamImpl_Construct(
[6711]248 HGLOBAL hGlobal,
249 BOOL fDeleteOnRelease)
[5602]250{
251 HGLOBALStreamImpl* newStream;
252
253 newStream = HeapAlloc(GetProcessHeap(), 0, sizeof(HGLOBALStreamImpl));
[8620]254
[5602]255 if (newStream!=0)
256 {
257 /*
258 * Set-up the virtual function table and reference count.
259 */
260 ICOM_VTBL(newStream) = &HGLOBALStreamImpl_Vtbl;
261 newStream->ref = 0;
[8620]262
[5602]263 /*
264 * Initialize the support.
265 */
266 newStream->supportHandle = hGlobal;
267 newStream->deleteOnRelease = fDeleteOnRelease;
268
269 /*
270 * This method will allocate a handle if one is not supplied.
271 */
272 if (!newStream->supportHandle)
273 {
274 newStream->supportHandle = GlobalAlloc(GMEM_MOVEABLE | GMEM_NODISCARD |
[6711]275 GMEM_SHARE, 0);
[5602]276 }
[8620]277
[5602]278 /*
[7926]279 * Start the stream at the beginning.
[5602]280 */
[21916]281 newStream->currentPosition.DUMMYSTRUCTNAME_DOT HighPart = 0;
282 newStream->currentPosition.DUMMYSTRUCTNAME_DOT LowPart = 0;
[8620]283
[5602]284 /*
285 * Initialize the size of the stream to the size of the handle.
286 */
[21916]287 newStream->streamSize.DUMMYSTRUCTNAME_DOT HighPart = 0;
288 newStream->streamSize.DUMMYSTRUCTNAME_DOT LowPart = GlobalSize(newStream->supportHandle);
[5602]289 }
[8620]290
[5602]291 return newStream;
292}
293
294/***
295 * This is the destructor of the HGLOBALStreamImpl class.
296 *
[8620]297 * This method will clean-up all the resources used-up by the given HGLOBALStreamImpl
[5602]298 * class. The pointer passed-in to this function will be freed and will not
299 * be valid anymore.
300 */
301void HGLOBALStreamImpl_Destroy(HGLOBALStreamImpl* This)
302{
303 TRACE("(%p)\n", This);
304
305 /*
306 * Release the HGlobal if the constructor asked for that.
307 */
308 if (This->deleteOnRelease)
309 {
310 GlobalFree(This->supportHandle);
311 This->supportHandle=0;
312 }
313
314 /*
315 * Finally, free the memory used-up by the class.
316 */
[8620]317 HeapFree(GetProcessHeap(), 0, This);
[5602]318}
319
320/***
321 * This implements the IUnknown method QueryInterface for this
322 * class
323 */
324HRESULT WINAPI HGLOBALStreamImpl_QueryInterface(
[6711]325 IStream* iface,
[8620]326 REFIID riid, /* [in] */
327 void** ppvObject) /* [iid_is][out] */
[5602]328{
329 HGLOBALStreamImpl* const This=(HGLOBALStreamImpl*)iface;
330
331 /*
332 * Perform a sanity check on the parameters.
333 */
334 if (ppvObject==0)
335 return E_INVALIDARG;
[8620]336
[5602]337 /*
338 * Initialize the return parameter.
339 */
340 *ppvObject = 0;
[8620]341
[5602]342 /*
343 * Compare the riid with the interface IDs implemented by this object.
344 */
[8620]345 if (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) == 0)
[5602]346 {
347 *ppvObject = (IStream*)This;
348 }
[8620]349 else if (memcmp(&IID_IStream, riid, sizeof(IID_IStream)) == 0)
[5602]350 {
351 *ppvObject = (IStream*)This;
352 }
[8620]353
[5602]354 /*
355 * Check that we obtained an interface.
356 */
357 if ((*ppvObject)==0)
358 return E_NOINTERFACE;
[8620]359
[5602]360 /*
361 * Query Interface always increases the reference count by one when it is
362 * successful
363 */
364 HGLOBALStreamImpl_AddRef(iface);
[8620]365
366 return S_OK;
[5602]367}
368
369/***
370 * This implements the IUnknown method AddRef for this
371 * class
372 */
373ULONG WINAPI HGLOBALStreamImpl_AddRef(
[6711]374 IStream* iface)
[5602]375{
376 HGLOBALStreamImpl* const This=(HGLOBALStreamImpl*)iface;
377
378 This->ref++;
[8620]379
[5602]380 return This->ref;
381}
382
383/***
384 * This implements the IUnknown method Release for this
385 * class
386 */
387ULONG WINAPI HGLOBALStreamImpl_Release(
[6711]388 IStream* iface)
[5602]389{
390 HGLOBALStreamImpl* const This=(HGLOBALStreamImpl*)iface;
391
392 ULONG newRef;
[8620]393
[5602]394 This->ref--;
[8620]395
[5602]396 newRef = This->ref;
[8620]397
[5602]398 /*
399 * If the reference count goes down to 0, perform suicide.
400 */
401 if (newRef==0)
402 {
403 HGLOBALStreamImpl_Destroy(This);
404 }
[8620]405
[5602]406 return newRef;
407}
408
409/***
410 * This method is part of the ISequentialStream interface.
411 *
412 * If reads a block of information from the stream at the current
413 * position. It then moves the current position at the end of the
414 * read block
415 *
416 * See the documentation of ISequentialStream for more info.
417 */
[8620]418HRESULT WINAPI HGLOBALStreamImpl_Read(
[6711]419 IStream* iface,
420 void* pv, /* [length_is][size_is][out] */
[8620]421 ULONG cb, /* [in] */
422 ULONG* pcbRead) /* [out] */
[5602]423{
424 HGLOBALStreamImpl* const This=(HGLOBALStreamImpl*)iface;
425
426 void* supportBuffer;
427 ULONG bytesReadBuffer;
428 ULONG bytesToReadFromBuffer;
429
430 TRACE("(%p, %p, %ld, %p)\n", iface,
[6711]431 pv, cb, pcbRead);
[8620]432
433 /*
[5602]434 * If the caller is not interested in the nubmer of bytes read,
435 * we use another buffer to avoid "if" statements in the code.
436 */
437 if (pcbRead==0)
438 pcbRead = &bytesReadBuffer;
[8620]439
[5602]440 /*
441 * Using the known size of the stream, calculate the number of bytes
442 * to read from the block chain
443 */
[21916]444 bytesToReadFromBuffer = min( This->streamSize.DUMMYSTRUCTNAME_DOT LowPart - This->currentPosition.DUMMYSTRUCTNAME_DOT LowPart, cb);
[5602]445
446 /*
447 * Lock the buffer in position and copy the data.
448 */
449 supportBuffer = GlobalLock(This->supportHandle);
450
[21916]451 memcpy(pv, (char *) supportBuffer+This->currentPosition.DUMMYSTRUCTNAME_DOT LowPart, bytesToReadFromBuffer);
[5602]452
453 /*
454 * Move the current position to the new position
455 */
[21916]456 This->currentPosition.DUMMYSTRUCTNAME_DOT LowPart+=bytesToReadFromBuffer;
[5602]457
458 /*
459 * Return the number of bytes read.
460 */
461 *pcbRead = bytesToReadFromBuffer;
462
463 /*
464 * Cleanup
465 */
466 GlobalUnlock(This->supportHandle);
[8620]467
[5602]468 /*
469 * The function returns S_OK if the buffer was filled completely
470 * it returns S_FALSE if the end of the stream is reached before the
471 * buffer is filled
472 */
473 if(*pcbRead == cb)
474 return S_OK;
[8620]475
[5602]476 return S_FALSE;
477}
[8620]478
[5602]479/***
480 * This method is part of the ISequentialStream interface.
481 *
482 * It writes a block of information to the stream at the current
483 * position. It then moves the current position at the end of the
484 * written block. If the stream is too small to fit the block,
485 * the stream is grown to fit.
486 *
487 * See the documentation of ISequentialStream for more info.
488 */
489HRESULT WINAPI HGLOBALStreamImpl_Write(
[6711]490 IStream* iface,
[8620]491 const void* pv, /* [size_is][in] */
492 ULONG cb, /* [in] */
493 ULONG* pcbWritten) /* [out] */
[5602]494{
495 HGLOBALStreamImpl* const This=(HGLOBALStreamImpl*)iface;
496
497 void* supportBuffer;
498 ULARGE_INTEGER newSize;
499 ULONG bytesWritten = 0;
500
501 TRACE("(%p, %p, %ld, %p)\n", iface,
[6711]502 pv, cb, pcbWritten);
[8620]503
[5602]504 /*
505 * If the caller is not interested in the number of bytes written,
506 * we use another buffer to avoid "if" statements in the code.
507 */
508 if (pcbWritten == 0)
509 pcbWritten = &bytesWritten;
[8620]510
[5602]511 if (cb == 0)
512 {
513 return S_OK;
514 }
515 else
516 {
[21916]517 newSize.DUMMYSTRUCTNAME_DOT HighPart = 0;
518 newSize.DUMMYSTRUCTNAME_DOT LowPart = This->currentPosition.DUMMYSTRUCTNAME_DOT LowPart + cb;
[5602]519 }
[8620]520
[5602]521 /*
522 * Verify if we need to grow the stream
523 */
[21916]524 if (newSize.DUMMYSTRUCTNAME_DOT LowPart > This->streamSize.DUMMYSTRUCTNAME_DOT LowPart)
[5602]525 {
526 /* grow stream */
527 IStream_SetSize(iface, newSize);
528 }
[8620]529
[5602]530 /*
531 * Lock the buffer in position and copy the data.
532 */
533 supportBuffer = GlobalLock(This->supportHandle);
534
[21916]535 memcpy((char *) supportBuffer+This->currentPosition.DUMMYSTRUCTNAME_DOT LowPart, pv, cb);
[5602]536
537 /*
538 * Move the current position to the new position
539 */
[21916]540 This->currentPosition.DUMMYSTRUCTNAME_DOT LowPart+=cb;
[5602]541
542 /*
543 * Return the number of bytes read.
544 */
545 *pcbWritten = cb;
546
547 /*
548 * Cleanup
549 */
550 GlobalUnlock(This->supportHandle);
[8620]551
[5602]552 return S_OK;
553}
554
555/***
556 * This method is part of the IStream interface.
557 *
558 * It will move the current stream pointer according to the parameters
559 * given.
560 *
561 * See the documentation of IStream for more info.
[8620]562 */
563HRESULT WINAPI HGLOBALStreamImpl_Seek(
[6711]564 IStream* iface,
[8620]565 LARGE_INTEGER dlibMove, /* [in] */
566 DWORD dwOrigin, /* [in] */
[6711]567 ULARGE_INTEGER* plibNewPosition) /* [out] */
[5602]568{
569 HGLOBALStreamImpl* const This=(HGLOBALStreamImpl*)iface;
570
571 ULARGE_INTEGER newPosition;
572
573 TRACE("(%p, %ld, %ld, %p)\n", iface,
[21916]574 dlibMove.DUMMYSTRUCTNAME_DOT LowPart, dwOrigin, plibNewPosition);
[5602]575
[8620]576 /*
[5602]577 * The file pointer is moved depending on the given "function"
578 * parameter.
579 */
580 switch (dwOrigin)
581 {
582 case STREAM_SEEK_SET:
[21916]583 newPosition.DUMMYSTRUCTNAME_DOT HighPart = 0;
584 newPosition.DUMMYSTRUCTNAME_DOT LowPart = 0;
[5602]585 break;
586 case STREAM_SEEK_CUR:
[9400]587 newPosition = This->currentPosition;
[5602]588 break;
589 case STREAM_SEEK_END:
[9400]590 newPosition = This->streamSize;
[5602]591 break;
592 default:
593 return STG_E_INVALIDFUNCTION;
594 }
595
596 /*
597 * Move the actual file pointer
598 * If the file pointer ends-up after the end of the stream, the next Write operation will
599 * make the file larger. This is how it is documented.
600 */
[9400]601#ifdef __WIN32OS2__
602 *(LARGE_INTEGER *)&newPosition = RtlpLargeIntegerAdd( (LARGE_INTEGER *)&newPosition, &dlibMove );
603#else
604 newPosition.QuadPart = RtlLargeIntegerAdd(newPosition.QuadPart, dlibMove.QuadPart);
605#endif
606 if (newPosition.QuadPart < 0) return STG_E_INVALIDFUNCTION;
[8620]607
[9400]608 if (plibNewPosition) *plibNewPosition = newPosition;
609 This->currentPosition = newPosition;
610
[5602]611 return S_OK;
612}
613
614/***
615 * This method is part of the IStream interface.
616 *
617 * It will change the size of a stream.
618 *
619 * TODO: Switch from small blocks to big blocks and vice versa.
620 *
621 * See the documentation of IStream for more info.
622 */
[8620]623HRESULT WINAPI HGLOBALStreamImpl_SetSize(
[6711]624 IStream* iface,
[8620]625 ULARGE_INTEGER libNewSize) /* [in] */
[5602]626{
627 HGLOBALStreamImpl* const This=(HGLOBALStreamImpl*)iface;
628
[21916]629 TRACE("(%p, %ld)\n", iface, libNewSize.DUMMYSTRUCTNAME_DOT LowPart);
[5602]630
631 /*
632 * As documented.
633 */
[21916]634 if (libNewSize.DUMMYSTRUCTNAME_DOT HighPart != 0)
[5602]635 return STG_E_INVALIDFUNCTION;
[8620]636
[21916]637 if (This->streamSize.DUMMYSTRUCTNAME_DOT LowPart == libNewSize.DUMMYSTRUCTNAME_DOT LowPart)
[5602]638 return S_OK;
639
640 /*
641 * Re allocate the HGlobal to fit the new size of the stream.
642 */
[8620]643 This->supportHandle = GlobalReAlloc(This->supportHandle,
[21916]644 libNewSize.DUMMYSTRUCTNAME_DOT LowPart,
[6711]645 0);
[5602]646
[21916]647 This->streamSize.DUMMYSTRUCTNAME_DOT LowPart = libNewSize.DUMMYSTRUCTNAME_DOT LowPart;
[8620]648
[5602]649 return S_OK;
650}
[8620]651
[5602]652/***
653 * This method is part of the IStream interface.
654 *
655 * It will copy the 'cb' Bytes to 'pstm' IStream.
656 *
657 * See the documentation of IStream for more info.
658 */
[8620]659HRESULT WINAPI HGLOBALStreamImpl_CopyTo(
[6711]660 IStream* iface,
[8620]661 IStream* pstm, /* [unique][in] */
662 ULARGE_INTEGER cb, /* [in] */
663 ULARGE_INTEGER* pcbRead, /* [out] */
664 ULARGE_INTEGER* pcbWritten) /* [out] */
[5602]665{
666 HRESULT hr = S_OK;
667 BYTE tmpBuffer[128];
668 ULONG bytesRead, bytesWritten, copySize;
669 ULARGE_INTEGER totalBytesRead;
670 ULARGE_INTEGER totalBytesWritten;
671
[8620]672 TRACE("(%p, %p, %ld, %p, %p)\n", iface, pstm,
[21916]673 cb.DUMMYSTRUCTNAME_DOT LowPart, pcbRead, pcbWritten);
[5602]674
675 /*
676 * Sanity check
677 */
678 if ( pstm == 0 )
679 return STG_E_INVALIDPOINTER;
680
[21916]681 totalBytesRead.DUMMYSTRUCTNAME_DOT LowPart = totalBytesRead.DUMMYSTRUCTNAME_DOT HighPart = 0;
682 totalBytesWritten.DUMMYSTRUCTNAME_DOT LowPart = totalBytesWritten.DUMMYSTRUCTNAME_DOT HighPart = 0;
[5602]683
684 /*
685 * use stack to store data temporarly
686 * there is surely more performant way of doing it, for now this basic
687 * implementation will do the job
688 */
[21916]689 while ( cb.DUMMYSTRUCTNAME_DOT LowPart > 0 )
[5602]690 {
[21916]691 if ( cb.DUMMYSTRUCTNAME_DOT LowPart >= 128 )
[5602]692 copySize = 128;
693 else
[21916]694 copySize = cb.DUMMYSTRUCTNAME_DOT LowPart;
[8620]695
[5602]696 IStream_Read(iface, tmpBuffer, copySize, &bytesRead);
697
[21916]698 totalBytesRead.DUMMYSTRUCTNAME_DOT LowPart += bytesRead;
[8620]699
[5602]700 IStream_Write(pstm, tmpBuffer, bytesRead, &bytesWritten);
701
[21916]702 totalBytesWritten.DUMMYSTRUCTNAME_DOT LowPart += bytesWritten;
[5602]703
704 /*
705 * Check that read & write operations were succesfull
706 */
707 if (bytesRead != bytesWritten)
708 {
709 hr = STG_E_MEDIUMFULL;
710 break;
711 }
[8620]712
[5602]713 if (bytesRead!=copySize)
[21916]714 cb.DUMMYSTRUCTNAME_DOT LowPart = 0;
[5602]715 else
[21916]716 cb.DUMMYSTRUCTNAME_DOT LowPart -= bytesRead;
[5602]717 }
718
719 /*
720 * Update number of bytes read and written
721 */
722 if (pcbRead)
723 {
[21916]724 pcbRead->DUMMYSTRUCTNAME_DOT LowPart = totalBytesRead.DUMMYSTRUCTNAME_DOT LowPart;
725 pcbRead->DUMMYSTRUCTNAME_DOT HighPart = totalBytesRead.DUMMYSTRUCTNAME_DOT HighPart;
[5602]726 }
727
728 if (pcbWritten)
729 {
[21916]730 pcbWritten->DUMMYSTRUCTNAME_DOT LowPart = totalBytesWritten.DUMMYSTRUCTNAME_DOT LowPart;
731 pcbWritten->DUMMYSTRUCTNAME_DOT HighPart = totalBytesWritten.DUMMYSTRUCTNAME_DOT HighPart;
[5602]732 }
733 return hr;
734}
735
736/***
737 * This method is part of the IStream interface.
738 *
[8620]739 * For streams supported by HGLOBALS, this function does nothing.
[5602]740 * This is what the documentation tells us.
741 *
742 * See the documentation of IStream for more info.
[8620]743 */
744HRESULT WINAPI HGLOBALStreamImpl_Commit(
[6711]745 IStream* iface,
[8620]746 DWORD grfCommitFlags) /* [in] */
[5602]747{
748 return S_OK;
749}
750
751/***
752 * This method is part of the IStream interface.
753 *
[8620]754 * For streams supported by HGLOBALS, this function does nothing.
[5602]755 * This is what the documentation tells us.
756 *
757 * See the documentation of IStream for more info.
[8620]758 */
759HRESULT WINAPI HGLOBALStreamImpl_Revert(
[6711]760 IStream* iface)
[5602]761{
762 return S_OK;
763}
764
765/***
766 * This method is part of the IStream interface.
767 *
[8620]768 * For streams supported by HGLOBALS, this function does nothing.
[5602]769 * This is what the documentation tells us.
770 *
771 * See the documentation of IStream for more info.
[8620]772 */
773HRESULT WINAPI HGLOBALStreamImpl_LockRegion(
[6711]774 IStream* iface,
[8620]775 ULARGE_INTEGER libOffset, /* [in] */
776 ULARGE_INTEGER cb, /* [in] */
777 DWORD dwLockType) /* [in] */
[5602]778{
779 return S_OK;
780}
781
782/*
783 * This method is part of the IStream interface.
784 *
[8620]785 * For streams supported by HGLOBALS, this function does nothing.
[5602]786 * This is what the documentation tells us.
787 *
788 * See the documentation of IStream for more info.
[8620]789 */
790HRESULT WINAPI HGLOBALStreamImpl_UnlockRegion(
[6711]791 IStream* iface,
[8620]792 ULARGE_INTEGER libOffset, /* [in] */
793 ULARGE_INTEGER cb, /* [in] */
794 DWORD dwLockType) /* [in] */
[5602]795{
796 return S_OK;
797}
798
799/***
800 * This method is part of the IStream interface.
801 *
802 * This method returns information about the current
803 * stream.
804 *
805 * See the documentation of IStream for more info.
[8620]806 */
807HRESULT WINAPI HGLOBALStreamImpl_Stat(
[6711]808 IStream* iface,
809 STATSTG* pstatstg, /* [out] */
[8620]810 DWORD grfStatFlag) /* [in] */
[5602]811{
812 HGLOBALStreamImpl* const This=(HGLOBALStreamImpl*)iface;
813
814 memset(pstatstg, 0, sizeof(STATSTG));
815
816 pstatstg->pwcsName = NULL;
817 pstatstg->type = STGTY_STREAM;
818 pstatstg->cbSize = This->streamSize;
819
820 return S_OK;
821}
[8620]822
823HRESULT WINAPI HGLOBALStreamImpl_Clone(
[6711]824 IStream* iface,
[8620]825 IStream** ppstm) /* [out] */
[5602]826{
[9400]827 ULARGE_INTEGER dummy;
828 LARGE_INTEGER offset;
829 HRESULT hr;
830 HGLOBALStreamImpl* const This=(HGLOBALStreamImpl*)iface;
831 TRACE(" Cloning %p (deleteOnRelease=%d seek position=%ld)\n",iface,This->deleteOnRelease,(long)This->currentPosition.QuadPart);
832 hr=CreateStreamOnHGlobal(This->supportHandle, FALSE, ppstm);
833 if(FAILED(hr))
834 return hr;
835 offset.QuadPart=(LONGLONG)This->currentPosition.QuadPart;
836 HGLOBALStreamImpl_Seek(*ppstm,offset,STREAM_SEEK_SET,&dummy);
837 return S_OK;
[5602]838}
Note: See TracBrowser for help on using the repository browser.