Changeset 6711 for trunk/src/ole32/hglobalstream.c
- Timestamp:
- Sep 15, 2001, 11:32:00 AM (24 years ago)
- File:
-
- 1 edited
-
trunk/src/ole32/hglobalstream.c (modified) (47 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/ole32/hglobalstream.c
r6648 r6711 1 /* $Id: hglobalstream.c,v 1.2 2001-09-05 13:17:09 bird Exp $ */2 1 /* 3 2 * HGLOBAL Stream implementation … … 30 29 { 31 30 ICOM_VFIELD(IStream); /* Needs to be the first item in the stuct 32 * since we want to cast this in a IStream pointer */33 31 * since we want to cast this in a IStream pointer */ 32 34 33 /* 35 34 * Reference count 36 35 */ 37 ULONG ref;36 ULONG ref; 38 37 39 38 /* … … 65 64 */ 66 65 HGLOBALStreamImpl* HGLOBALStreamImpl_Construct( 67 HGLOBAL hGlobal,68 BOOL fDeleteOnRelease);66 HGLOBAL hGlobal, 67 BOOL fDeleteOnRelease); 69 68 70 69 void HGLOBALStreamImpl_Destroy( … … 75 74 76 75 HRESULT WINAPI HGLOBALStreamImpl_QueryInterface( 77 IStream* iface,78 REFIID riid, /* [in] */ 79 void** ppvObject); /* [iid_is][out] */ 80 76 IStream* iface, 77 REFIID riid, /* [in] */ 78 void** ppvObject); /* [iid_is][out] */ 79 81 80 ULONG WINAPI HGLOBALStreamImpl_AddRef( 82 IStream* iface);83 81 IStream* iface); 82 84 83 ULONG WINAPI HGLOBALStreamImpl_Release( 85 IStream* iface);86 87 HRESULT WINAPI HGLOBALStreamImpl_Read( 88 IStream* iface,89 void* pv, /* [length_is][size_is][out] */90 ULONG cb, /* [in] */ 91 ULONG* pcbRead); /* [out] */ 92 84 IStream* iface); 85 86 HRESULT WINAPI HGLOBALStreamImpl_Read( 87 IStream* iface, 88 void* pv, /* [length_is][size_is][out] */ 89 ULONG cb, /* [in] */ 90 ULONG* pcbRead); /* [out] */ 91 93 92 HRESULT WINAPI HGLOBALStreamImpl_Write( 94 IStream* iface,95 const void* pv, /* [size_is][in] */ 96 ULONG cb, /* [in] */ 97 ULONG* pcbWritten); /* [out] */ 98 99 HRESULT WINAPI HGLOBALStreamImpl_Seek( 100 IStream* iface,101 LARGE_INTEGER dlibMove, /* [in] */ 102 DWORD dwOrigin, /* [in] */ 103 ULARGE_INTEGER* plibNewPosition); /* [out] */104 105 HRESULT WINAPI HGLOBALStreamImpl_SetSize( 106 IStream* iface,107 ULARGE_INTEGER libNewSize); /* [in] */ 108 109 HRESULT WINAPI HGLOBALStreamImpl_CopyTo( 110 IStream* iface,111 IStream* pstm, /* [unique][in] */ 112 ULARGE_INTEGER cb, /* [in] */ 113 ULARGE_INTEGER* pcbRead, /* [out] */ 114 ULARGE_INTEGER* pcbWritten); /* [out] */ 115 116 HRESULT WINAPI HGLOBALStreamImpl_Commit( 117 IStream* iface,118 DWORD grfCommitFlags); /* [in] */ 119 120 HRESULT WINAPI HGLOBALStreamImpl_Revert( 121 IStream* iface);122 123 HRESULT WINAPI HGLOBALStreamImpl_LockRegion( 124 IStream* iface,125 ULARGE_INTEGER libOffset, /* [in] */ 126 ULARGE_INTEGER cb, /* [in] */ 127 DWORD dwLockType); /* [in] */ 128 129 HRESULT WINAPI HGLOBALStreamImpl_UnlockRegion( 130 IStream* iface,131 ULARGE_INTEGER libOffset, /* [in] */ 132 ULARGE_INTEGER cb, /* [in] */ 133 DWORD dwLockType); /* [in] */ 134 135 HRESULT WINAPI HGLOBALStreamImpl_Stat( 136 IStream* iface,137 STATSTG* pstatstg, /* [out] */138 DWORD grfStatFlag); /* [in] */ 139 140 HRESULT WINAPI HGLOBALStreamImpl_Clone( 141 IStream* iface,142 IStream** ppstm); /* [out] */ 93 IStream* iface, 94 const void* pv, /* [size_is][in] */ 95 ULONG cb, /* [in] */ 96 ULONG* pcbWritten); /* [out] */ 97 98 HRESULT WINAPI HGLOBALStreamImpl_Seek( 99 IStream* iface, 100 LARGE_INTEGER dlibMove, /* [in] */ 101 DWORD dwOrigin, /* [in] */ 102 ULARGE_INTEGER* plibNewPosition); /* [out] */ 103 104 HRESULT WINAPI HGLOBALStreamImpl_SetSize( 105 IStream* iface, 106 ULARGE_INTEGER libNewSize); /* [in] */ 107 108 HRESULT WINAPI HGLOBALStreamImpl_CopyTo( 109 IStream* iface, 110 IStream* pstm, /* [unique][in] */ 111 ULARGE_INTEGER cb, /* [in] */ 112 ULARGE_INTEGER* pcbRead, /* [out] */ 113 ULARGE_INTEGER* pcbWritten); /* [out] */ 114 115 HRESULT WINAPI HGLOBALStreamImpl_Commit( 116 IStream* iface, 117 DWORD grfCommitFlags); /* [in] */ 118 119 HRESULT WINAPI HGLOBALStreamImpl_Revert( 120 IStream* iface); 121 122 HRESULT WINAPI HGLOBALStreamImpl_LockRegion( 123 IStream* iface, 124 ULARGE_INTEGER libOffset, /* [in] */ 125 ULARGE_INTEGER cb, /* [in] */ 126 DWORD dwLockType); /* [in] */ 127 128 HRESULT WINAPI HGLOBALStreamImpl_UnlockRegion( 129 IStream* iface, 130 ULARGE_INTEGER libOffset, /* [in] */ 131 ULARGE_INTEGER cb, /* [in] */ 132 DWORD dwLockType); /* [in] */ 133 134 HRESULT WINAPI HGLOBALStreamImpl_Stat( 135 IStream* iface, 136 STATSTG* pstatstg, /* [out] */ 137 DWORD grfStatFlag); /* [in] */ 138 139 HRESULT WINAPI HGLOBALStreamImpl_Clone( 140 IStream* iface, 141 IStream** ppstm); /* [out] */ 143 142 144 143 … … 169 168 */ 170 169 HRESULT WINAPI CreateStreamOnHGlobal( 171 HGLOBAL hGlobal, 172 BOOL fDeleteOnRelease, 173 LPSTREAM* ppstm)170 HGLOBAL hGlobal, 171 BOOL fDeleteOnRelease, 172 LPSTREAM* ppstm) 174 173 { 175 174 HGLOBALStreamImpl* newStream; 176 175 177 176 newStream = HGLOBALStreamImpl_Construct(hGlobal, 178 fDeleteOnRelease);177 fDeleteOnRelease); 179 178 180 179 if (newStream!=NULL) 181 180 { 182 return IUnknown_QueryInterface((IUnknown*)newStream, 183 &IID_IStream,184 (void**)ppstm);181 return IUnknown_QueryInterface((IUnknown*)newStream, 182 &IID_IStream, 183 (void**)ppstm); 185 184 } 186 185 … … 223 222 * Params: 224 223 * hGlobal - Handle that will support the stream. can be NULL. 225 * fDeleteOnRelease - Flag set to TRUE if the HGLOBAL will be released 224 * fDeleteOnRelease - Flag set to TRUE if the HGLOBAL will be released 226 225 * when the IStream object is destroyed. 227 226 */ 228 227 HGLOBALStreamImpl* HGLOBALStreamImpl_Construct( 229 HGLOBAL hGlobal,230 BOOL fDeleteOnRelease)228 HGLOBAL hGlobal, 229 BOOL fDeleteOnRelease) 231 230 { 232 231 HGLOBALStreamImpl* newStream; 233 232 234 233 newStream = HeapAlloc(GetProcessHeap(), 0, sizeof(HGLOBALStreamImpl)); 235 234 236 235 if (newStream!=0) 237 236 { … … 241 240 ICOM_VTBL(newStream) = &HGLOBALStreamImpl_Vtbl; 242 241 newStream->ref = 0; 243 242 244 243 /* 245 244 * Initialize the support. … … 254 253 { 255 254 newStream->supportHandle = GlobalAlloc(GMEM_MOVEABLE | GMEM_NODISCARD | 256 GMEM_SHARE, 0);255 GMEM_SHARE, 0); 257 256 } 258 257 259 258 /* 260 259 * Start the stream at the begining. … … 262 261 newStream->currentPosition.s.HighPart = 0; 263 262 newStream->currentPosition.s.LowPart = 0; 264 263 265 264 /* 266 265 * Initialize the size of the stream to the size of the handle. … … 269 268 newStream->streamSize.s.LowPart = GlobalSize(newStream->supportHandle); 270 269 } 271 270 272 271 return newStream; 273 272 } … … 276 275 * This is the destructor of the HGLOBALStreamImpl class. 277 276 * 278 * This method will clean-up all the resources used-up by the given HGLOBALStreamImpl 277 * This method will clean-up all the resources used-up by the given HGLOBALStreamImpl 279 278 * class. The pointer passed-in to this function will be freed and will not 280 279 * be valid anymore. … … 296 295 * Finally, free the memory used-up by the class. 297 296 */ 298 HeapFree(GetProcessHeap(), 0, This); 297 HeapFree(GetProcessHeap(), 0, This); 299 298 } 300 299 … … 304 303 */ 305 304 HRESULT WINAPI HGLOBALStreamImpl_QueryInterface( 306 IStream* iface,307 REFIID riid, /* [in] */ 308 void** ppvObject) /* [iid_is][out] */ 305 IStream* iface, 306 REFIID riid, /* [in] */ 307 void** ppvObject) /* [iid_is][out] */ 309 308 { 310 309 HGLOBALStreamImpl* const This=(HGLOBALStreamImpl*)iface; … … 315 314 if (ppvObject==0) 316 315 return E_INVALIDARG; 317 316 318 317 /* 319 318 * Initialize the return parameter. 320 319 */ 321 320 *ppvObject = 0; 322 321 323 322 /* 324 323 * Compare the riid with the interface IDs implemented by this object. 325 324 */ 326 if (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) == 0) 325 if (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) == 0) 327 326 { 328 327 *ppvObject = (IStream*)This; 329 328 } 330 else if (memcmp(&IID_IStream, riid, sizeof(IID_IStream)) == 0) 329 else if (memcmp(&IID_IStream, riid, sizeof(IID_IStream)) == 0) 331 330 { 332 331 *ppvObject = (IStream*)This; 333 332 } 334 333 335 334 /* 336 335 * Check that we obtained an interface. … … 338 337 if ((*ppvObject)==0) 339 338 return E_NOINTERFACE; 340 339 341 340 /* 342 341 * Query Interface always increases the reference count by one when it is … … 344 343 */ 345 344 HGLOBALStreamImpl_AddRef(iface); 346 345 347 346 return S_OK;; 348 347 } … … 353 352 */ 354 353 ULONG WINAPI HGLOBALStreamImpl_AddRef( 355 IStream* iface)354 IStream* iface) 356 355 { 357 356 HGLOBALStreamImpl* const This=(HGLOBALStreamImpl*)iface; 358 357 359 358 This->ref++; 360 359 361 360 return This->ref; 362 361 } … … 367 366 */ 368 367 ULONG WINAPI HGLOBALStreamImpl_Release( 369 IStream* iface)368 IStream* iface) 370 369 { 371 370 HGLOBALStreamImpl* const This=(HGLOBALStreamImpl*)iface; 372 371 373 372 ULONG newRef; 374 373 375 374 This->ref--; 376 375 377 376 newRef = This->ref; 378 377 379 378 /* 380 379 * If the reference count goes down to 0, perform suicide. … … 384 383 HGLOBALStreamImpl_Destroy(This); 385 384 } 386 385 387 386 return newRef; 388 387 } … … 397 396 * See the documentation of ISequentialStream for more info. 398 397 */ 399 HRESULT WINAPI HGLOBALStreamImpl_Read( 400 IStream* iface,401 void* pv, /* [length_is][size_is][out] */402 ULONG cb, /* [in] */ 403 ULONG* pcbRead) /* [out] */ 398 HRESULT WINAPI HGLOBALStreamImpl_Read( 399 IStream* iface, 400 void* pv, /* [length_is][size_is][out] */ 401 ULONG cb, /* [in] */ 402 ULONG* pcbRead) /* [out] */ 404 403 { 405 404 HGLOBALStreamImpl* const This=(HGLOBALStreamImpl*)iface; … … 410 409 411 410 TRACE("(%p, %p, %ld, %p)\n", iface, 412 pv, cb, pcbRead);413 414 /* 411 pv, cb, pcbRead); 412 413 /* 415 414 * If the caller is not interested in the nubmer of bytes read, 416 415 * we use another buffer to avoid "if" statements in the code. … … 418 417 if (pcbRead==0) 419 418 pcbRead = &bytesReadBuffer; 420 419 421 420 /* 422 421 * Using the known size of the stream, calculate the number of bytes … … 446 445 */ 447 446 GlobalUnlock(This->supportHandle); 448 447 449 448 /* 450 449 * The function returns S_OK if the buffer was filled completely … … 454 453 if(*pcbRead == cb) 455 454 return S_OK; 456 455 457 456 return S_FALSE; 458 457 } 459 458 460 459 /*** 461 460 * This method is part of the ISequentialStream interface. … … 469 468 */ 470 469 HRESULT WINAPI HGLOBALStreamImpl_Write( 471 IStream* iface,472 const void* pv, /* [size_is][in] */ 473 ULONG cb, /* [in] */ 474 ULONG* pcbWritten) /* [out] */ 470 IStream* iface, 471 const void* pv, /* [size_is][in] */ 472 ULONG cb, /* [in] */ 473 ULONG* pcbWritten) /* [out] */ 475 474 { 476 475 HGLOBALStreamImpl* const This=(HGLOBALStreamImpl*)iface; … … 481 480 482 481 TRACE("(%p, %p, %ld, %p)\n", iface, 483 pv, cb, pcbWritten);484 482 pv, cb, pcbWritten); 483 485 484 /* 486 485 * If the caller is not interested in the number of bytes written, … … 489 488 if (pcbWritten == 0) 490 489 pcbWritten = &bytesWritten; 491 490 492 491 if (cb == 0) 493 492 { … … 499 498 newSize.s.LowPart = This->currentPosition.s.LowPart + cb; 500 499 } 501 500 502 501 /* 503 502 * Verify if we need to grow the stream … … 508 507 IStream_SetSize(iface, newSize); 509 508 } 510 509 511 510 /* 512 511 * Lock the buffer in position and copy the data. … … 514 513 supportBuffer = GlobalLock(This->supportHandle); 515 514 516 memcpy((char *) supportBuffer+This->currentPosition.s.LowPart, pv, cb); 515 memcpy((char *) supportBuffer+This->currentPosition.s.LowPart, pv, cb); 517 516 518 517 /* … … 530 529 */ 531 530 GlobalUnlock(This->supportHandle); 532 531 533 532 return S_OK; 534 533 } … … 541 540 * 542 541 * See the documentation of IStream for more info. 543 */ 544 HRESULT WINAPI HGLOBALStreamImpl_Seek( 545 IStream* iface,546 LARGE_INTEGER dlibMove, /* [in] */ 547 DWORD dwOrigin, /* [in] */ 548 ULARGE_INTEGER* plibNewPosition) /* [out] */542 */ 543 HRESULT WINAPI HGLOBALStreamImpl_Seek( 544 IStream* iface, 545 LARGE_INTEGER dlibMove, /* [in] */ 546 DWORD dwOrigin, /* [in] */ 547 ULARGE_INTEGER* plibNewPosition) /* [out] */ 549 548 { 550 549 HGLOBALStreamImpl* const This=(HGLOBALStreamImpl*)iface; … … 553 552 554 553 TRACE("(%p, %ld, %ld, %p)\n", iface, 555 dlibMove.s.LowPart, dwOrigin, plibNewPosition);556 557 /* 554 dlibMove.s.LowPart, dwOrigin, plibNewPosition); 555 556 /* 558 557 * The caller is allowed to pass in NULL as the new position return value. 559 558 * If it happens, we assign it to a dynamic variable to avoid special cases … … 609 608 plibNewPosition->s.LowPart += dlibMove.s.LowPart; 610 609 This->currentPosition = *plibNewPosition; 611 610 612 611 return S_OK; 613 612 } … … 622 621 * See the documentation of IStream for more info. 623 622 */ 624 HRESULT WINAPI HGLOBALStreamImpl_SetSize( 625 IStream* iface,626 ULARGE_INTEGER libNewSize) /* [in] */ 623 HRESULT WINAPI HGLOBALStreamImpl_SetSize( 624 IStream* iface, 625 ULARGE_INTEGER libNewSize) /* [in] */ 627 626 { 628 627 HGLOBALStreamImpl* const This=(HGLOBALStreamImpl*)iface; … … 635 634 if (libNewSize.s.HighPart != 0) 636 635 return STG_E_INVALIDFUNCTION; 637 636 638 637 if (This->streamSize.s.LowPart == libNewSize.s.LowPart) 639 638 return S_OK; … … 642 641 * Re allocate the HGlobal to fit the new size of the stream. 643 642 */ 644 This->supportHandle = GlobalReAlloc(This->supportHandle, 645 libNewSize.s.LowPart,646 0);643 This->supportHandle = GlobalReAlloc(This->supportHandle, 644 libNewSize.s.LowPart, 645 0); 647 646 648 647 This->streamSize.s.LowPart = libNewSize.s.LowPart; 649 648 650 649 return S_OK; 651 650 } 652 651 653 652 /*** 654 653 * This method is part of the IStream interface. … … 658 657 * See the documentation of IStream for more info. 659 658 */ 660 HRESULT WINAPI HGLOBALStreamImpl_CopyTo( 661 IStream* iface,662 IStream* pstm, /* [unique][in] */ 663 ULARGE_INTEGER cb, /* [in] */ 664 ULARGE_INTEGER* pcbRead, /* [out] */ 665 ULARGE_INTEGER* pcbWritten) /* [out] */ 659 HRESULT WINAPI HGLOBALStreamImpl_CopyTo( 660 IStream* iface, 661 IStream* pstm, /* [unique][in] */ 662 ULARGE_INTEGER cb, /* [in] */ 663 ULARGE_INTEGER* pcbRead, /* [out] */ 664 ULARGE_INTEGER* pcbWritten) /* [out] */ 666 665 { 667 666 HRESULT hr = S_OK; … … 671 670 ULARGE_INTEGER totalBytesWritten; 672 671 673 TRACE("(%p, %p, %ld, %p, %p)\n", iface, pstm, 674 cb.s.LowPart, pcbRead, pcbWritten);672 TRACE("(%p, %p, %ld, %p, %p)\n", iface, pstm, 673 cb.s.LowPart, pcbRead, pcbWritten); 675 674 676 675 /* … … 694 693 else 695 694 copySize = cb.s.LowPart; 696 695 697 696 IStream_Read(iface, tmpBuffer, copySize, &bytesRead); 698 697 699 698 totalBytesRead.s.LowPart += bytesRead; 700 699 701 700 IStream_Write(pstm, tmpBuffer, bytesRead, &bytesWritten); 702 701 … … 711 710 break; 712 711 } 713 712 714 713 if (bytesRead!=copySize) 715 714 cb.s.LowPart = 0; … … 738 737 * This method is part of the IStream interface. 739 738 * 740 * For streams supported by HGLOBALS, this function does nothing. 739 * For streams supported by HGLOBALS, this function does nothing. 741 740 * This is what the documentation tells us. 742 741 * 743 742 * See the documentation of IStream for more info. 744 */ 745 HRESULT WINAPI HGLOBALStreamImpl_Commit( 746 IStream* iface,747 DWORD grfCommitFlags) /* [in] */ 743 */ 744 HRESULT WINAPI HGLOBALStreamImpl_Commit( 745 IStream* iface, 746 DWORD grfCommitFlags) /* [in] */ 748 747 { 749 748 return S_OK; … … 753 752 * This method is part of the IStream interface. 754 753 * 755 * For streams supported by HGLOBALS, this function does nothing. 754 * For streams supported by HGLOBALS, this function does nothing. 756 755 * This is what the documentation tells us. 757 756 * 758 757 * See the documentation of IStream for more info. 759 */ 760 HRESULT WINAPI HGLOBALStreamImpl_Revert( 761 IStream* iface)758 */ 759 HRESULT WINAPI HGLOBALStreamImpl_Revert( 760 IStream* iface) 762 761 { 763 762 return S_OK; … … 767 766 * This method is part of the IStream interface. 768 767 * 769 * For streams supported by HGLOBALS, this function does nothing. 768 * For streams supported by HGLOBALS, this function does nothing. 770 769 * This is what the documentation tells us. 771 770 * 772 771 * See the documentation of IStream for more info. 773 */ 774 HRESULT WINAPI HGLOBALStreamImpl_LockRegion( 775 IStream* iface,776 ULARGE_INTEGER libOffset, /* [in] */ 777 ULARGE_INTEGER cb, /* [in] */ 778 DWORD dwLockType) /* [in] */ 772 */ 773 HRESULT WINAPI HGLOBALStreamImpl_LockRegion( 774 IStream* iface, 775 ULARGE_INTEGER libOffset, /* [in] */ 776 ULARGE_INTEGER cb, /* [in] */ 777 DWORD dwLockType) /* [in] */ 779 778 { 780 779 return S_OK; … … 784 783 * This method is part of the IStream interface. 785 784 * 786 * For streams supported by HGLOBALS, this function does nothing. 785 * For streams supported by HGLOBALS, this function does nothing. 787 786 * This is what the documentation tells us. 788 787 * 789 788 * See the documentation of IStream for more info. 790 */ 791 HRESULT WINAPI HGLOBALStreamImpl_UnlockRegion( 792 IStream* iface,793 ULARGE_INTEGER libOffset, /* [in] */ 794 ULARGE_INTEGER cb, /* [in] */ 795 DWORD dwLockType) /* [in] */ 789 */ 790 HRESULT WINAPI HGLOBALStreamImpl_UnlockRegion( 791 IStream* iface, 792 ULARGE_INTEGER libOffset, /* [in] */ 793 ULARGE_INTEGER cb, /* [in] */ 794 DWORD dwLockType) /* [in] */ 796 795 { 797 796 return S_OK; … … 805 804 * 806 805 * See the documentation of IStream for more info. 807 */ 808 HRESULT WINAPI HGLOBALStreamImpl_Stat( 809 IStream* iface,810 STATSTG* pstatstg, /* [out] */811 DWORD grfStatFlag) /* [in] */ 806 */ 807 HRESULT WINAPI HGLOBALStreamImpl_Stat( 808 IStream* iface, 809 STATSTG* pstatstg, /* [out] */ 810 DWORD grfStatFlag) /* [in] */ 812 811 { 813 812 HGLOBALStreamImpl* const This=(HGLOBALStreamImpl*)iface; … … 821 820 return S_OK; 822 821 } 823 824 HRESULT WINAPI HGLOBALStreamImpl_Clone( 825 IStream* iface,826 IStream** ppstm) /* [out] */ 822 823 HRESULT WINAPI HGLOBALStreamImpl_Clone( 824 IStream* iface, 825 IStream** ppstm) /* [out] */ 827 826 { 828 827 FIXME("not implemented!\n");
Note:
See TracChangeset
for help on using the changeset viewer.
