home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / mfc / src / arcstrm.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-16  |  3.4 KB  |  176 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10.  
  11. #include "stdafx.h"
  12.  
  13. #ifdef AFX_CMNCTL_SEG
  14. #pragma code_seg(AFX_CMNCTL_SEG)
  15. #endif
  16.  
  17. #ifdef _DEBUG
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21.  
  22. #define new DEBUG_NEW
  23.  
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CArchiveStream
  26.  
  27. #ifndef _AFX_NO_OLE_SUPPORT
  28.  
  29. CArchiveStream::CArchiveStream(CArchive* pArchive)
  30. {
  31.     m_pArchive = pArchive;
  32. }
  33.  
  34. STDMETHODIMP_(ULONG)CArchiveStream::AddRef()
  35. {
  36.     return 1;
  37. }
  38.  
  39. STDMETHODIMP_(ULONG)CArchiveStream::Release()
  40. {
  41.     return 0;
  42. }
  43.  
  44. STDMETHODIMP CArchiveStream::QueryInterface(REFIID iid, LPVOID* ppvObj)
  45. {
  46.     if (iid == IID_IUnknown || iid == IID_IStream)
  47.     {
  48.         *ppvObj = this;
  49.         return NOERROR;
  50.     }
  51.     return E_NOINTERFACE;
  52. }
  53.  
  54. STDMETHODIMP CArchiveStream::Read(void *pv, ULONG cb, ULONG *pcbRead)
  55. {
  56.     ASSERT(m_pArchive != NULL);
  57.     ASSERT(m_pArchive->IsLoading());
  58.  
  59.     int nRead = 0;
  60.     TRY
  61.     {
  62.         nRead = m_pArchive->Read(pv, cb);
  63.     }
  64.     CATCH_ALL(e)
  65.     {
  66.         DELETE_EXCEPTION(e);
  67.         return E_UNEXPECTED;
  68.     }
  69.     END_CATCH_ALL
  70.  
  71.     if (pcbRead != NULL)
  72.         *pcbRead = nRead;
  73.     return NOERROR;
  74. }
  75.  
  76. STDMETHODIMP CArchiveStream::Write(const void *pv, ULONG cb, ULONG *pcbWritten)
  77. {
  78.     ASSERT(m_pArchive != NULL);
  79.     ASSERT(m_pArchive->IsStoring());
  80.  
  81.     int nWrite = 0;
  82.     TRY
  83.     {
  84.         m_pArchive->Write(pv, cb);
  85.         nWrite = cb;
  86.     }
  87.     CATCH_ALL(e)
  88.     {
  89.         DELETE_EXCEPTION(e);
  90.         return E_UNEXPECTED;
  91.     }
  92.     END_CATCH_ALL
  93.  
  94.     if (pcbWritten != NULL)
  95.         *pcbWritten = nWrite;
  96.     return NOERROR;
  97. }
  98.  
  99. STDMETHODIMP CArchiveStream::Seek(LARGE_INTEGER uliOffset, DWORD dwOrigin,
  100.     ULARGE_INTEGER* puliNew)
  101. {
  102.     // can't handle offsets with really large magnitude
  103.     if ((uliOffset.HighPart != 0) &&
  104.         ((uliOffset.HighPart != -1) || ((long)uliOffset.LowPart >= 0)))
  105.         return E_NOTIMPL;
  106.  
  107.     CFile* pFile = m_pArchive->GetFile();
  108.     if (pFile == NULL)
  109.         return E_NOTIMPL;
  110.     m_pArchive->Flush();
  111.  
  112.     ASSERT(STREAM_SEEK_SET == CFile::begin);
  113.     ASSERT(STREAM_SEEK_CUR == CFile::current);
  114.     ASSERT(STREAM_SEEK_END == CFile::end);
  115.     LONG lNew;
  116.     TRY
  117.     {
  118.         lNew = pFile->Seek((LONG)uliOffset.LowPart, (UINT)dwOrigin);
  119.     }
  120.     CATCH_ALL(e)
  121.     {
  122.         DELETE_EXCEPTION(e);
  123.         return E_UNEXPECTED;
  124.     }
  125.     END_CATCH_ALL
  126.  
  127.     if (puliNew != NULL)
  128.         ULISet32(*puliNew, lNew);
  129.  
  130.     return NOERROR;
  131. }
  132.  
  133. STDMETHODIMP CArchiveStream::SetSize(ULARGE_INTEGER)
  134. {
  135.     return E_NOTIMPL;
  136. }
  137.  
  138. STDMETHODIMP CArchiveStream::CopyTo(LPSTREAM, ULARGE_INTEGER, ULARGE_INTEGER*,
  139.     ULARGE_INTEGER*)
  140. {
  141.     return E_NOTIMPL;
  142. }
  143.  
  144. STDMETHODIMP CArchiveStream::Commit(DWORD)
  145. {
  146.     return E_NOTIMPL;
  147. }
  148.  
  149. STDMETHODIMP CArchiveStream::Revert()
  150. {
  151.     return E_NOTIMPL;
  152. }
  153.  
  154. STDMETHODIMP CArchiveStream::LockRegion(ULARGE_INTEGER, ULARGE_INTEGER, DWORD)
  155. {
  156.     return E_NOTIMPL;
  157. }
  158.  
  159. STDMETHODIMP CArchiveStream::UnlockRegion(ULARGE_INTEGER, ULARGE_INTEGER,
  160.     DWORD)
  161. {
  162.     return E_NOTIMPL;
  163. }
  164.  
  165. STDMETHODIMP CArchiveStream::Stat(STATSTG*, DWORD)
  166. {
  167.     return E_NOTIMPL;
  168. }
  169.  
  170. STDMETHODIMP CArchiveStream::Clone(LPSTREAM*)
  171. {
  172.     return E_NOTIMPL;
  173. }
  174.  
  175. #endif // _AFX_NO_OLE_SUPPORT
  176.