Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

169 lines
3.2 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. CMemoryStream.cpp
  5. Abstract:
  6. Minimal implementation of IStream over an array of bytes.
  7. Author:
  8. Jay Krell (a-JayK) May 2000
  9. Revision History:
  10. --*/
  11. #include "stdinc.h"
  12. #include "CMemoryStream.h"
  13. #include "SxsExceptionHandling.h"
  14. /* aka doesn't make sense aka access denied */
  15. #define NOTIMPL ASSERT_NTC(FALSE) ; return E_NOTIMPL
  16. CMemoryStream::~CMemoryStream()
  17. {
  18. ASSERT_NTC(m_cRef == 0);
  19. }
  20. ULONG __stdcall CMemoryStream::AddRef()
  21. {
  22. FN_TRACE_ADDREF(CMemoryStream, m_cRef);
  23. return ::InterlockedIncrement(&m_cRef);
  24. }
  25. ULONG __stdcall CMemoryStream::Release()
  26. {
  27. LONG cRef;
  28. FN_TRACE_RELEASE(CMemoryStream, cRef);
  29. if ((cRef = ::InterlockedDecrement(&m_cRef)) == 0)
  30. {
  31. /*delete this*/;
  32. }
  33. return cRef;
  34. }
  35. HRESULT __stdcall
  36. CMemoryStream::QueryInterface(
  37. REFIID iid,
  38. void **ppvObj
  39. )
  40. {
  41. HRESULT hr = NOERROR;
  42. FN_TRACE_HR(hr);
  43. IUnknown *punk = NULL;
  44. IUnknown **ppunk = reinterpret_cast<IUnknown **>(ppvObj);
  45. *ppunk = NULL;
  46. if (false) { }
  47. #define QI(i) else if (iid == __uuidof(i)) punk = static_cast<i *>(this);
  48. QI(IUnknown)
  49. QI(ISequentialStream)
  50. QI(IStream)
  51. #undef QI
  52. else
  53. {
  54. hr = E_NOINTERFACE;
  55. goto Exit;
  56. }
  57. AddRef();
  58. *ppunk = punk;
  59. hr = NOERROR;
  60. Exit:
  61. return hr;
  62. }
  63. HRESULT __stdcall CMemoryStream::Read(void *pv, ULONG cb32, ULONG* pcbRead)
  64. {
  65. const BYTE * const pbCurrent = m_pbCurrent; // read this once for near thread safety..
  66. __int64 cb = cb32;
  67. __int64 cbBytesRemaining = (m_pbEnd - pbCurrent);
  68. if (cb > cbBytesRemaining)
  69. cb = cbBytesRemaining;
  70. memcpy(pv, pbCurrent, static_cast<SIZE_T>(cb));
  71. m_pbCurrent = pbCurrent + cb; // write this once for near thread safety..
  72. *pcbRead = static_cast<ULONG>(cb);
  73. return NOERROR;
  74. }
  75. HRESULT __stdcall CMemoryStream::Write(void const *pv, ULONG cb, ULONG* pcbWritten)
  76. {
  77. NOTIMPL;
  78. }
  79. HRESULT __stdcall CMemoryStream::Seek(LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
  80. {
  81. NOTIMPL;
  82. }
  83. HRESULT __stdcall CMemoryStream::SetSize(ULARGE_INTEGER libNewSize)
  84. {
  85. NOTIMPL;
  86. }
  87. HRESULT __stdcall CMemoryStream::CopyTo(IStream* pstm, ULARGE_INTEGER cb, ULARGE_INTEGER *pcbRead, ULARGE_INTEGER *pcbWritten)
  88. {
  89. NOTIMPL;
  90. }
  91. HRESULT __stdcall CMemoryStream::Commit(DWORD grfCommitFlags)
  92. {
  93. NOTIMPL;
  94. }
  95. HRESULT __stdcall CMemoryStream::Revert()
  96. {
  97. NOTIMPL;
  98. }
  99. HRESULT __stdcall CMemoryStream::LockRegion(ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
  100. {
  101. NOTIMPL;
  102. }
  103. HRESULT __stdcall CMemoryStream::UnlockRegion(ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
  104. {
  105. NOTIMPL;
  106. }
  107. HRESULT __stdcall CMemoryStream::Stat(STATSTG *pstatstg, DWORD grfStatFlag)
  108. {
  109. #if 1
  110. NOTIMPL;
  111. #else
  112. we can return size, we can return access==read only
  113. #endif
  114. }
  115. HRESULT __stdcall CMemoryStream::Clone(IStream **ppIStream)
  116. {
  117. #if 1
  118. NOTIMPL;
  119. #else
  120. CMemoryStream *p;
  121. if ((p = NEW(CMemoryStream)) == NULL)
  122. {
  123. *ppIStream = NULL;
  124. return E_NOMEMORY;
  125. }
  126. p->m_pbCurrent = m_pbCurrent;
  127. p->m_pbBegin = m_pbBegin;
  128. p->m_pbEnd = m_pbEnd;
  129. p->m_cRef = 1;
  130. *ppIStream = p;
  131. return S_OK;
  132. #endif
  133. }