Leaked source code of windows server 2003
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.

228 lines
8.8 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1994.
  5. //
  6. // File: memstm.h
  7. //
  8. // Contents: memstm.h from OLE2
  9. //
  10. // History: 11-Apr-94 DrewB Copied from OLE2
  11. //
  12. //----------------------------------------------------------------------------
  13. #if !defined( _MEMSTM_H_ )
  14. #define _MEMSTM_H_
  15. // These defines shorten the class name so that the compiler doesn't
  16. // choke on really long decorated names for MarshalInterface
  17. #define CMarshalMemStm CMMS
  18. #define CMarshalMemBytes CMMB
  19. class FAR CMarshalMemStm;
  20. class FAR CMarshalMemBytes;
  21. // CMemStm is a stream implementation on top of global shared memory MEMSTM
  22. //
  23. // CMemStm
  24. // +---------+
  25. // + pvtf + Shared memory
  26. // +---------+ +--------------+
  27. // + m_pMem +-->|cb |
  28. // +---------+ |cRef |
  29. // |hGlobal |--->+--------------+
  30. // +--------------+ | Actual Data |
  31. // CMemStm MEMSTM +--------------+
  32. //
  33. struct MEMSTM { // Data in shared memory
  34. DWORD cb; // Size of hGlobal
  35. DWORD cRef; // See below
  36. HANDLE hGlobal; // The data
  37. BOOL fDeleteOnRelease;
  38. };
  39. // cRef counts all CMemStm pointers to this MEMSTM plus the number of times
  40. // a hMem handle to MEMSTM had been returned
  41. //
  42. #define STREAM_SIG (0x4d525453L)
  43. class FAR CMemStm : public IStream { // Shared emmory stream
  44. public:
  45. OLEMETHOD(QueryInterface) (REFIID iidInterface, void FAR* FAR* ppvObj);
  46. OLEMETHOD_(ULONG,AddRef) (void);
  47. OLEMETHOD_(ULONG,Release) (void);
  48. OLEMETHOD(Read) (VOID HUGEP* pv, ULONG cb, ULONG FAR* pcbRead);
  49. OLEMETHOD(Write) (VOID const HUGEP* pv, ULONG cb, ULONG FAR* pcbWritten);
  50. OLEMETHOD(Seek) (LARGE_INTEGER dlibMove,
  51. DWORD dwOrigin, ULARGE_INTEGER FAR* plibNewPosition);
  52. OLEMETHOD(SetSize) (ULARGE_INTEGER cb);
  53. OLEMETHOD(CopyTo) (IStream FAR* pstm,
  54. ULARGE_INTEGER cb, ULARGE_INTEGER FAR* pcbRead, ULARGE_INTEGER FAR* pcbWritten);
  55. OLEMETHOD(Commit) (DWORD grfCommitFlags);
  56. OLEMETHOD(Revert) (void);
  57. OLEMETHOD(LockRegion) (ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType);
  58. OLEMETHOD(UnlockRegion) (ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType);
  59. OLEMETHOD(Stat) (STATSTG FAR* pstatstg, DWORD statflag);
  60. OLEMETHOD(Clone)(IStream FAR * FAR *ppstm);
  61. OLESTATIC_(CMemStm FAR*) Create(HANDLE hMem);
  62. ctor_dtor:
  63. CMemStm() { GET_A5(); m_hMem = NULL; m_pData = NULL; m_pos = 0; m_refs = 0; }
  64. ~CMemStm() {}
  65. private:
  66. DWORD m_dwSig; // Signature indicating this is our
  67. // implementation of IStream: STREAM_SIG
  68. ULONG m_refs; // Number of references to this CmemStm
  69. ULONG m_pos; // Seek pointer for Read/Write
  70. HANDLE m_hMem; // Memory Handle passed on creation
  71. MEMSTM FAR* m_pData; // Pointer to that memroy
  72. friend HRESULT STDAPICALLTYPE GetHGlobalFromStream (LPSTREAM, HGLOBAL FAR*);
  73. friend LPSTREAM STDAPICALLTYPE CreateMemStm (DWORD, LPHANDLE);
  74. friend class CMarshalMemStm;
  75. SET_A5;
  76. };
  77. // CMemBytes is an ILockBytes implementation on top of global shared
  78. // memory MEMSTM
  79. //
  80. // CMemBytes
  81. // +---------+
  82. // + pvtf + Shared memory
  83. // +---------+ +--------------+
  84. // + m_pData +-->| cb |
  85. // +---------+ | cRef |
  86. // | hGlobal |--->+-------------+
  87. // +--------------+ | Actual data |
  88. // CMemBytes MEMSTM +-------------+
  89. //
  90. #define LOCKBYTE_SIG (0x0046574A)
  91. // cRef counts all CMemBytes pointers to this MEMSTM.
  92. // It and fDeleteOnRelease control the GlobalFree'ing of the hGlobal.
  93. class FAR CMemBytes : public ILockBytes { // Shared memory lock bytes
  94. public:
  95. OLEMETHOD(QueryInterface) (REFIID iidInterface, void FAR* FAR* ppvObj);
  96. OLEMETHOD_(ULONG,AddRef) (void);
  97. OLEMETHOD_(ULONG,Release) (void);
  98. OLEMETHOD(ReadAt) (ULARGE_INTEGER ulOffset, VOID HUGEP *pv, ULONG cb,
  99. ULONG FAR *pcbRead);
  100. OLEMETHOD(WriteAt) (ULARGE_INTEGER ulOffset, VOID const HUGEP *pv, ULONG cb,
  101. ULONG FAR *pcbWritten);
  102. OLEMETHOD(Flush) (void);
  103. OLEMETHOD(SetSize) (ULARGE_INTEGER cb);
  104. OLEMETHOD(LockRegion) (ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType);
  105. OLEMETHOD(UnlockRegion) (ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType);
  106. OLEMETHOD(Stat) (THIS_ STATSTG FAR *pstatstg, DWORD statflag);
  107. OLESTATIC_(CMemBytes FAR*) Create(HANDLE hMem);
  108. ctor_dtor:
  109. CMemBytes() { GET_A5(); m_hMem = NULL; m_pData = NULL; m_refs = 0; }
  110. ~CMemBytes() {}
  111. private:
  112. DWORD m_dwSig; // Signature indicating this is our
  113. // implementation of ILockBytes: LOCKBYTE_SIG
  114. ULONG m_refs; // Normal reference count
  115. HANDLE m_hMem; // Handle for bookeeping info (MEMSTM)
  116. MEMSTM FAR* m_pData; // Pointer to that memroy
  117. friend HRESULT STDAPICALLTYPE GetHGlobalFromILockBytes (LPLOCKBYTES, HGLOBAL FAR*);
  118. friend class CMarshalMemBytes;
  119. SET_A5;
  120. };
  121. // CMarshalMemStm can Marshal, Unmarshal CMemStm. It is impletented as
  122. // a seperate object accessible from CMemStm, CMemBytes: QueryIntreface of
  123. // IMarshal on CMemStm's IStream will return an IMarshal pointer to
  124. // CMarshalMemStm, but QueryInterface of IStream on that IMarshal will
  125. // fail.
  126. // Also QueryInterface of IUnknown on IMarshal will not return the same value
  127. // As QueryInterface of IUnkown on the original IStream.
  128. //
  129. class FAR CMarshalMemStm : public IMarshal {
  130. public:
  131. OLEMETHOD(QueryInterface) (REFIID riid, LPVOID FAR* ppvObj);
  132. OLEMETHOD_(ULONG,AddRef) (void);
  133. OLEMETHOD_(ULONG,Release) (void);
  134. OLEMETHOD(GetUnmarshalClass)(THIS_ REFIID riid, LPVOID pv,
  135. DWORD dwDestContext, LPVOID pvDestContext,
  136. DWORD mshlflags, LPCLSID pCid);
  137. OLEMETHOD(GetMarshalSizeMax)(THIS_ REFIID riid, LPVOID pv,
  138. DWORD dwDestContext, LPVOID pvDestContext,
  139. DWORD mshlflags, LPDWORD pSize);
  140. OLEMETHOD(MarshalInterface)(THIS_ IStream FAR* pStm, REFIID riid,
  141. LPVOID pv, DWORD dwDestContext, LPVOID pvDestContext,
  142. DWORD mshlflags);
  143. OLEMETHOD(UnmarshalInterface)(THIS_ IStream FAR* pStm, REFIID riid,
  144. LPVOID FAR* ppv);
  145. OLEMETHOD(ReleaseMarshalData)(THIS_ IStream FAR* pStm);
  146. OLEMETHOD(DisconnectObject)(THIS_ DWORD dwReserved);
  147. OLESTATIC_(CMarshalMemStm FAR*) Create(CMemStm FAR* pMemStm);
  148. ctor_dtor:
  149. CMarshalMemStm() { GET_A5();m_pMemStm = NULL; m_refs = 0; }
  150. ~CMarshalMemStm() {}
  151. private:
  152. ULONG m_refs; // Number of references to this CmemStm
  153. CMemStm FAR* m_pMemStm; // Pointer to object [Un]Marshalled
  154. CLSID m_clsid; // Class of object pointed by pUnk
  155. SET_A5;
  156. };
  157. // CMarshalMemBytes can Marshal, Unmarshal CMemBytes. It is impletented as
  158. // a seperate object accessible from CMemBytes, CMemBytes: QueryIntreface of
  159. // IMarshal on CMemBytes's ILocBytes will return an IMarshal pointer to
  160. // CMarshalMemBytes, but QueryInterface of ILockBytes on that IMarshal will
  161. // fail.
  162. // Also QueryInterface of IUnknown on IMarshal will not return the same value
  163. // As QueryInterface of IUnkown on the original ILockBytes.
  164. //
  165. class FAR CMarshalMemBytes : public IMarshal {
  166. public:
  167. OLEMETHOD(QueryInterface) (REFIID riid, LPVOID FAR* ppvObj);
  168. OLEMETHOD_(ULONG,AddRef) (void);
  169. OLEMETHOD_(ULONG,Release) (void);
  170. OLEMETHOD(GetUnmarshalClass)(THIS_ REFIID riid, LPVOID pv,
  171. DWORD dwDestContext, LPVOID pvDestContext,
  172. DWORD mshlflags, LPCLSID pCid);
  173. OLEMETHOD(GetMarshalSizeMax)(THIS_ REFIID riid, LPVOID pv,
  174. DWORD dwDestContext, LPVOID pvDestContext,
  175. DWORD mshlflags, LPDWORD pSize);
  176. OLEMETHOD(MarshalInterface)(THIS_ IStream FAR* pStm, REFIID riid,
  177. LPVOID pv, DWORD dwDestContext, LPVOID pvDestContext,
  178. DWORD mshlflags);
  179. OLEMETHOD(UnmarshalInterface)(THIS_ IStream FAR* pStm, REFIID riid,
  180. LPVOID FAR* ppv);
  181. OLEMETHOD(ReleaseMarshalData)(THIS_ IStream FAR* pStm);
  182. OLEMETHOD(DisconnectObject)(THIS_ DWORD dwReserved);
  183. OLESTATIC_(CMarshalMemBytes FAR*) Create(CMemBytes FAR* pMemBytes);
  184. ctor_dtor:
  185. CMarshalMemBytes() { GET_A5();m_pMemBytes = NULL; m_refs = 0; }
  186. ~CMarshalMemBytes() {}
  187. private:
  188. ULONG m_refs; // Number of references to this CMemBytes
  189. CMemBytes FAR* m_pMemBytes; // Pointer to object [Un]Marshalled
  190. CLSID m_clsid; // Class of object pointed by pUnk
  191. SET_A5;
  192. };
  193. #endif // _MemBytes_H