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.

158 lines
4.5 KiB

  1. /******************************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. pfstm.h
  5. Abstract:
  6. This file contains the definitions of various stream objects
  7. Revision History:
  8. created derekm 01/19/00
  9. ******************************************************************************/
  10. #ifndef PFSTM_H
  11. #define PFSTM_H
  12. #if _MSC_VER > 1000
  13. #pragma once
  14. #endif // _MSC_VER > 1000
  15. #include "util.h"
  16. //////////////////////////////////////////////////////////////////////////////
  17. // CStreamBase
  18. class CPFStreamBase :
  19. public IStream,
  20. public CPFGenericClassBase
  21. {
  22. private:
  23. DWORD m_cRef;
  24. public:
  25. CPFStreamBase(void) { m_cRef = 0; }
  26. virtual ~CPFStreamBase(void) {}
  27. // IUnknown Interface
  28. STDMETHOD(QueryInterface)(REFIID riid, LPVOID *ppv)
  29. {
  30. if (ppv == NULL)
  31. return E_INVALIDARG;
  32. *ppv = NULL;
  33. if (riid == IID_IUnknown)
  34. *ppv = (IUnknown *)this;
  35. else if (riid == IID_IStream)
  36. *ppv = (IStream *)this;
  37. else if (riid == IID_ISequentialStream)
  38. *ppv = (ISequentialStream *)this;
  39. else
  40. return E_NOINTERFACE;
  41. this->AddRef();
  42. return NOERROR;
  43. }
  44. STDMETHOD_(ULONG, AddRef)()
  45. {
  46. return InterlockedIncrement((LONG *)&m_cRef);
  47. }
  48. STDMETHOD_(ULONG, Release)()
  49. {
  50. if (InterlockedDecrement((LONG *)&m_cRef) == 0)
  51. {
  52. delete this;
  53. return 0;
  54. }
  55. return m_cRef;
  56. }
  57. // ISequentialStream Interface
  58. STDMETHOD(Read)(void *pv, ULONG cb, LONG *pcbRead) { return E_NOTIMPL; }
  59. STDMETHOD(Write)(const void *pv, ULONG cb, ULONG *pcbWritten) { return E_NOTIMPL; }
  60. // IStream Interface
  61. STDMETHOD(Seek)(LARGE_INTEGER libMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition ) { return E_NOTIMPL; }
  62. STDMETHOD(SetSize)(ULARGE_INTEGER libNewSize) { return E_NOTIMPL; }
  63. STDMETHOD(CopyTo)(IStream *pstm, ULARGE_INTEGER cb, ULARGE_INTEGER *pcbRead, ULARGE_INTEGER *pcbWritten ) { return E_NOTIMPL; }
  64. STDMETHOD(Commit)(DWORD grfCommitFlags) { return E_NOTIMPL; }
  65. STDMETHOD(Revert)(void) { return E_NOTIMPL; }
  66. STDMETHOD(LockRegion)(ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType ) { return E_NOTIMPL; }
  67. STDMETHOD(UnlockRegion)(ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType ) { return E_NOTIMPL; }
  68. STDMETHOD(Stat)(STATSTG *pstatstg, DWORD grfStatFlag) { return E_NOTIMPL; }
  69. STDMETHOD(Clone)(IStream **ppstm) { return E_NOTIMPL; }
  70. };
  71. //////////////////////////////////////////////////////////////////////////////
  72. // CPFStreamFile
  73. class CPFStreamFile : public CPFStreamBase
  74. {
  75. private:
  76. // member data
  77. HANDLE m_hFile;
  78. DWORD m_dwAccess;
  79. public:
  80. CPFStreamFile(void);
  81. ~CPFStreamFile(void);
  82. static CPFStreamFile *CreateInstance(void) { return new CPFStreamFile; }
  83. HRESULT Open(LPCWSTR szFile, DWORD dwAccess, DWORD dwDisposition,
  84. DWORD dwSharing);
  85. HRESULT Open(HANDLE hFile, DWORD dwAccess);
  86. HRESULT Close(void);
  87. // ISequentialStream Interface
  88. STDMETHOD(Read)(void *pv, ULONG cb, ULONG *pcbRead);
  89. STDMETHOD(Write)(const void *pv, ULONG cb, ULONG *pcbWritten);
  90. // IStream Interface
  91. STDMETHOD(Seek)(LARGE_INTEGER libMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition);
  92. STDMETHOD(Stat)(STATSTG *pstatstg, DWORD grfStatFlag);
  93. STDMETHOD(Clone)(IStream **ppstm);
  94. };
  95. //////////////////////////////////////////////////////////////////////////////
  96. // CStreamMem
  97. class CPFStreamMem : public CPFStreamBase
  98. {
  99. LPVOID m_pvData;
  100. LPVOID m_pvPtr;
  101. DWORD m_cb;
  102. DWORD m_cbRead;
  103. DWORD m_cbWrite;
  104. DWORD m_cbGrow;
  105. public:
  106. CPFStreamMem(void);
  107. ~CPFStreamMem(void);
  108. static CPFStreamMem *CreateInstance(void) { return new CPFStreamMem; }
  109. HRESULT Init(DWORD cbStart = (DWORD)-1, DWORD cbGrowBy = (DWORD)-1);
  110. HRESULT InitBinBlob(LPVOID pv, DWORD cb, DWORD cbGrowBy = 0);
  111. HRESULT InitTextBlob(LPCWSTR wsz, DWORD cch, BOOL fConvertToANSI);
  112. HRESULT InitTextBlob(LPCSTR sz, DWORD cch, BOOL fConvertToWCHAR);
  113. HRESULT Clean(void);
  114. // ISequentialStream Interface
  115. STDMETHOD(Read)(void *pv, ULONG cb, ULONG *pcbRead);
  116. STDMETHOD(Write)(const void *pv, ULONG cb, ULONG *pcbWritten);
  117. // IStream Interface
  118. STDMETHOD(Seek)(LARGE_INTEGER libMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition);
  119. STDMETHOD(Stat)(STATSTG *pstatstg, DWORD grfStatFlag);
  120. STDMETHOD(Clone)(IStream **ppstm);
  121. };
  122. #endif