home *** CD-ROM | disk | FTP | other *** search
/ Supercompiler 1997 / SUPERCOMPILER97.iso / MS_VC.50 / VC / MFC / SRC / ARCSTRM.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-30  |  3.7 KB  |  182 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1997 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. // private definitions of IIDs to avoid linking with uuid.lib
  30. static const IID _IID_IUnknown =
  31.     { 0x00000000, 0x0000, 0x0000, { 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 } };
  32. static const IID _IID_IStream =
  33.     { 0x0000000C, 0x0000, 0x0000, { 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 } };
  34.  
  35. CArchiveStream::CArchiveStream(CArchive* pArchive)
  36. {
  37.     m_pArchive = pArchive;
  38. }
  39.  
  40. STDMETHODIMP_(ULONG)CArchiveStream::AddRef()
  41. {
  42.     return 1;
  43. }
  44.  
  45. STDMETHODIMP_(ULONG)CArchiveStream::Release()
  46. {
  47.     return 0;
  48. }
  49.  
  50. STDMETHODIMP CArchiveStream::QueryInterface(REFIID iid, LPVOID* ppvObj)
  51. {
  52.     if (iid == _IID_IUnknown || iid == _IID_IStream)
  53.     {
  54.         *ppvObj = this;
  55.         return NOERROR;
  56.     }
  57.     return E_NOINTERFACE;
  58. }
  59.  
  60. STDMETHODIMP CArchiveStream::Read(void *pv, ULONG cb, ULONG *pcbRead)
  61. {
  62.     ASSERT(m_pArchive != NULL);
  63.     ASSERT(m_pArchive->IsLoading());
  64.  
  65.     int nRead = 0;
  66.     TRY
  67.     {
  68.         nRead = m_pArchive->Read(pv, cb);
  69.     }
  70.     CATCH_ALL(e)
  71.     {
  72.         DELETE_EXCEPTION(e);
  73.         return E_UNEXPECTED;
  74.     }
  75.     END_CATCH_ALL
  76.  
  77.     if (pcbRead != NULL)
  78.         *pcbRead = nRead;
  79.     return NOERROR;
  80. }
  81.  
  82. STDMETHODIMP CArchiveStream::Write(const void *pv, ULONG cb, ULONG *pcbWritten)
  83. {
  84.     ASSERT(m_pArchive != NULL);
  85.     ASSERT(m_pArchive->IsStoring());
  86.  
  87.     int nWrite = 0;
  88.     TRY
  89.     {
  90.         m_pArchive->Write(pv, cb);
  91.         nWrite = cb;
  92.     }
  93.     CATCH_ALL(e)
  94.     {
  95.         DELETE_EXCEPTION(e);
  96.         return E_UNEXPECTED;
  97.     }
  98.     END_CATCH_ALL
  99.  
  100.     if (pcbWritten != NULL)
  101.         *pcbWritten = nWrite;
  102.     return NOERROR;
  103. }
  104.  
  105. STDMETHODIMP CArchiveStream::Seek(LARGE_INTEGER uliOffset, DWORD dwOrigin,
  106.     ULARGE_INTEGER* puliNew)
  107. {
  108.     // can't handle offsets with really large magnitude
  109.     if ((uliOffset.HighPart != 0) &&
  110.         ((uliOffset.HighPart != -1) || ((long)uliOffset.LowPart >= 0)))
  111.         return E_NOTIMPL;
  112.  
  113.     CFile* pFile = m_pArchive->GetFile();
  114.     if (pFile == NULL)
  115.         return E_NOTIMPL;
  116.     m_pArchive->Flush();
  117.  
  118.     ASSERT(STREAM_SEEK_SET == CFile::begin);
  119.     ASSERT(STREAM_SEEK_CUR == CFile::current);
  120.     ASSERT(STREAM_SEEK_END == CFile::end);
  121.     LONG lNew;
  122.     TRY
  123.     {
  124.         lNew = pFile->Seek((LONG)uliOffset.LowPart, (UINT)dwOrigin);
  125.     }
  126.     CATCH_ALL(e)
  127.     {
  128.         DELETE_EXCEPTION(e);
  129.         return E_UNEXPECTED;
  130.     }
  131.     END_CATCH_ALL
  132.  
  133.     if (puliNew != NULL)
  134.         ULISet32(*puliNew, lNew);
  135.  
  136.     return NOERROR;
  137. }
  138.  
  139. STDMETHODIMP CArchiveStream::SetSize(ULARGE_INTEGER)
  140. {
  141.     return E_NOTIMPL;
  142. }
  143.  
  144. STDMETHODIMP CArchiveStream::CopyTo(LPSTREAM, ULARGE_INTEGER, ULARGE_INTEGER*,
  145.     ULARGE_INTEGER*)
  146. {
  147.     return E_NOTIMPL;
  148. }
  149.  
  150. STDMETHODIMP CArchiveStream::Commit(DWORD)
  151. {
  152.     return E_NOTIMPL;
  153. }
  154.  
  155. STDMETHODIMP CArchiveStream::Revert()
  156. {
  157.     return E_NOTIMPL;
  158. }
  159.  
  160. STDMETHODIMP CArchiveStream::LockRegion(ULARGE_INTEGER, ULARGE_INTEGER, DWORD)
  161. {
  162.     return E_NOTIMPL;
  163. }
  164.  
  165. STDMETHODIMP CArchiveStream::UnlockRegion(ULARGE_INTEGER, ULARGE_INTEGER,
  166.     DWORD)
  167. {
  168.     return E_NOTIMPL;
  169. }
  170.  
  171. STDMETHODIMP CArchiveStream::Stat(STATSTG*, DWORD)
  172. {
  173.     return E_NOTIMPL;
  174. }
  175.  
  176. STDMETHODIMP CArchiveStream::Clone(LPSTREAM*)
  177. {
  178.     return E_NOTIMPL;
  179. }
  180.  
  181. #endif // _AFX_NO_OLE_SUPPORT
  182.