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.

124 lines
3.2 KiB

  1. // NilXForm.cpp -- Implementation of the Null Transform Instance
  2. #include "stdafx.h"
  3. HRESULT CNull_TransformInstance::CreateFromILockBytes
  4. (IUnknown *pUnkOuter, ILockBytes *pLKB, ITransformInstance **ppTransformInstance)
  5. {
  6. CNull_TransformInstance *pNT = New CNull_TransformInstance(pUnkOuter);
  7. return FinishSetup(pNT? pNT->m_ImpITransformInstance.InitFromLockBytes(pLKB)
  8. : STG_E_INSUFFICIENTMEMORY,
  9. pNT, IID_ITransformInstance, (PPVOID) ppTransformInstance
  10. );
  11. }
  12. CNull_TransformInstance::CImpITransformInstance::CImpITransformInstance
  13. (CNull_TransformInstance *pBackObj, IUnknown *punkOuter)
  14. : IITTransformInstance(pBackObj, punkOuter)
  15. {
  16. m_pLKB = NULL;
  17. m_cbSpaceSize = 0;
  18. }
  19. CNull_TransformInstance::CImpITransformInstance::~CImpITransformInstance()
  20. {
  21. if (m_pLKB)
  22. {
  23. m_pLKB->Flush();
  24. m_pLKB->Release();
  25. }
  26. }
  27. HRESULT CNull_TransformInstance::CImpITransformInstance::InitFromLockBytes(ILockBytes *pLKB)
  28. {
  29. m_pLKB = pLKB;
  30. STATSTG statstg;
  31. HRESULT hr = m_pLKB->Stat(&statstg, STATFLAG_NONAME);
  32. if (SUCCEEDED(hr))
  33. m_cbSpaceSize = statstg.cbSize;
  34. return hr;
  35. }
  36. // ITransformInstance interfaces:
  37. HRESULT STDMETHODCALLTYPE CNull_TransformInstance::CImpITransformInstance::ReadAt
  38. (ULARGE_INTEGER uliOffset, void *pv, ULONG cb, ULONG *pcbRead,
  39. ImageSpan *pSpan
  40. )
  41. {
  42. HRESULT hr = m_pLKB->ReadAt((CULINT(uliOffset) + CULINT(pSpan->uliHandle)).Uli(),
  43. pv,cb, pcbRead
  44. );
  45. return hr;
  46. }
  47. HRESULT STDMETHODCALLTYPE CNull_TransformInstance::CImpITransformInstance::WriteAt
  48. (ULARGE_INTEGER ulOffset, const void *pv, ULONG cb, ULONG *pcbWritten,
  49. ImageSpan *pSpan
  50. )
  51. {
  52. RonM_ASSERT(m_pLKB);
  53. CULINT ullOffset, ullSize, ullWriteOffset, ullWriteLimit, ullReadEOS;
  54. ullOffset = pSpan->uliHandle;
  55. ullSize = pSpan->uliSize;
  56. ullReadEOS = ullOffset + ullSize;
  57. ullWriteOffset = ullOffset + ulOffset;
  58. ullWriteLimit = ullWriteOffset + cb;
  59. CSyncWith sw(g_csITFS);
  60. if (ullWriteOffset != ullReadEOS || (ullReadEOS.NonZero() && ullWriteOffset > ullReadEOS))
  61. return STG_E_INVALIDPARAMETER;
  62. if (ullWriteLimit < ullWriteOffset) // Wrapped around 64-bit address space?
  63. ullWriteLimit = 0;
  64. HRESULT hr = m_pLKB->WriteAt(ullWriteOffset.Uli(), pv,
  65. (ullWriteLimit - ullWriteOffset).Uli().LowPart,
  66. pcbWritten
  67. );
  68. ullWriteLimit = ullWriteOffset + *pcbWritten;
  69. if (m_cbSpaceSize < ullWriteLimit)
  70. m_cbSpaceSize = ullWriteLimit;
  71. CULINT ullSizeNew;
  72. ullSizeNew = ullWriteLimit - ullWriteOffset;
  73. if (SUCCEEDED(hr))
  74. pSpan->uliSize = (CULINT(pSpan->uliSize) + CULINT(*pcbWritten)).Uli();
  75. return hr;
  76. }
  77. HRESULT STDMETHODCALLTYPE CNull_TransformInstance::CImpITransformInstance::Flush()
  78. {
  79. RonM_ASSERT(m_pLKB);
  80. return m_pLKB->Flush();
  81. }
  82. HRESULT CNull_TransformInstance::CImpITransformInstance::SpaceSize(ULARGE_INTEGER *puliSize)
  83. {
  84. RonM_ASSERT(m_pLKB);
  85. *puliSize = m_cbSpaceSize.Uli();
  86. return NO_ERROR;
  87. }