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.

207 lines
6.6 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // File:
  4. // utstream.h
  5. //
  6. // Contents:
  7. // Ole stream utility routines
  8. //
  9. // Classes:
  10. //
  11. // Functions:
  12. //
  13. // History:
  14. // 12/07/93 - ChrisWe - file inspection and cleanup; removed
  15. // redeclarations of ReadStringStream, and
  16. // WriteStringStream which are declared in ole2sp.h;
  17. // made default params on StSetSize explicit; removed
  18. // signatures of obsolete (non-existent) atom reading and
  19. // writing routines
  20. //
  21. //-----------------------------------------------------------------------------
  22. #ifndef _UTSTREAM_H_
  23. #define _UTSTREAM_H_
  24. // REVIEW, isn't this obsolete now, as StWrite is?
  25. FARINTERNAL_(HRESULT) StRead(IStream FAR * lpstream, LPVOID lpBuf, ULONG ulLen);
  26. #define StWrite(lpstream, lpBuf, ulLen) lpstream->Write(lpBuf, ulLen, NULL)
  27. //+----------------------------------------------------------------------------
  28. //
  29. // Function:
  30. // StSetSize, internal
  31. //
  32. // Synopsis:
  33. // Sets the size of the stream, using IStream::SetSize(). Saves
  34. // the caller having to deal with the requisite ULARGE_INTEGER
  35. // parameter, by initializing one from the [dwSize] argument.
  36. //
  37. // Arguments:
  38. // [pstm] -- the stream to set the size of
  39. // [dwSize] -- the size to set
  40. // [fRelative] -- if TRUE, indicates that the size is [dwSize]
  41. // plus the current seek position in the stream; if
  42. // FALSE, sets [dwSize] as the absolute size
  43. //
  44. // Returns:
  45. // HRESULT
  46. //
  47. // Notes:
  48. // REVIEW, this seems crocked. When would you ever call
  49. // this with [fRelative] == TRUE, and a non-zero [dwSize]?
  50. //
  51. // History:
  52. // 12/07/93 - ChrisWe - file inspection and cleanup
  53. //
  54. //-----------------------------------------------------------------------------
  55. FARINTERNAL StSetSize(LPSTREAM pstm, DWORD dwSize, BOOL fRelative);
  56. // REVIEW, are the the following functions necessary anymore?
  57. FARINTERNAL StSave10NativeData(IStorage FAR* pstgSave, HANDLE hNative,
  58. BOOL fIsOle1Interop);
  59. FARINTERNAL StRead10NativeData(IStorage FAR* pstgSave, HANDLE FAR *phNative);
  60. FARINTERNAL StSave10ItemName(IStorage FAR* pstg, LPCSTR szItemName);
  61. //+---------------------------------------------------------------------------
  62. //
  63. // Class: CStmBuf, Base class.
  64. //
  65. // Synopsis: Internal buffered Streams.
  66. //
  67. // Interfaces: CStmBuf - Constructor.
  68. // ~CStmBuf - Destructor.
  69. // Release - Release interface (used with OpenStream).
  70. //
  71. // History: 20-Feb-95 KentCe Created.
  72. //
  73. // Notes: This is a simple buffered class for internal use only.
  74. //
  75. //----------------------------------------------------------------------------
  76. class CStmBuf
  77. {
  78. public:
  79. CStmBuf();
  80. ~CStmBuf();
  81. protected:
  82. IStream * m_pStm; // Stream Interface to read/write.
  83. BYTE m_aBuffer[256]; // Small read/write buffer.
  84. PBYTE m_pBuffer; // Pointer into read/write buffer.
  85. ULONG m_cBuffer; // Count of characters in read/write buffer.
  86. };
  87. //+---------------------------------------------------------------------------
  88. //
  89. // Class: CStmBufRead
  90. //
  91. // Synopsis: Internal buffered read of Streams.
  92. //
  93. // Interfaces: Init - Defines stream to read.
  94. // OpenStream - Opens a stream for reading.
  95. // Read - Read from the stream.
  96. // ReadLong - Read a long value from the stream.
  97. // Release - Release interface (used with OpenStream).
  98. //
  99. // History: 20-Feb-95 KentCe Created.
  100. //
  101. // Notes: This is a simple buffered read class for internal use only.
  102. //
  103. //----------------------------------------------------------------------------
  104. class CStmBufRead : public CStmBuf
  105. {
  106. public:
  107. void Init(IStream * pstm);
  108. HRESULT OpenStream(IStorage * pstg, const OLECHAR * pwcsName);
  109. HRESULT Read(PVOID pBuf, ULONG cBuf);
  110. HRESULT ReadLong(LONG * plValue);
  111. void Release();
  112. private:
  113. void Reset(void);
  114. };
  115. //+---------------------------------------------------------------------------
  116. //
  117. // Class: CStmBufWrite
  118. //
  119. // Synopsis: Internal buffered write of Streams.
  120. //
  121. // Interfaces: Init - Defines stream to write.
  122. // OpenOrCreateStream - Opens/Creates a stream for writing.
  123. // CreateStream - Creates a stream for writing.
  124. // Write - Write to the stream.
  125. // WriteLong - Write a long value to the stream.
  126. // Flush - Flush buffer to the disk subsystem.
  127. // Release - Release interface.
  128. //
  129. // History: 20-Feb-95 KentCe Created.
  130. //
  131. // Notes: This is a simple buffered write class for internal use only.
  132. //
  133. //----------------------------------------------------------------------------
  134. class CStmBufWrite : public CStmBuf
  135. {
  136. public:
  137. void Init(IStream * pstm);
  138. HRESULT OpenOrCreateStream(IStorage * pstg, const OLECHAR * pwcsName);
  139. HRESULT CreateStream(IStorage * pstg, const OLECHAR * pwcsName);
  140. HRESULT Write(void const * pBuf, ULONG cBuf);
  141. HRESULT WriteLong(LONG lValue);
  142. HRESULT Flush(void);
  143. void Release();
  144. private:
  145. void Reset(void);
  146. };
  147. //
  148. // The following was moved from the ole2sp.h file to keep stream related API's
  149. // in one place.
  150. //
  151. // Utility function not in the spec; in ole2.dll.
  152. // Read and write length-prefixed strings. Open/Create stream.
  153. // ReadStringStream does allocation, returns length of
  154. // required buffer (strlen + 1 for terminating null)
  155. STDAPI ReadStringStream( CStmBufRead & StmRead, LPOLESTR FAR * ppsz );
  156. STDAPI WriteStringStream( CStmBufWrite & StmWrite, LPCOLESTR psz );
  157. STDAPI OpenOrCreateStream( IStorage FAR * pstg, const OLECHAR FAR * pwcsName,
  158. IStream FAR* FAR* ppstm);
  159. //
  160. // The following versions of StringStream are used with ANSI data
  161. //
  162. STDAPI ReadStringStreamA( CStmBufRead & StmRead, LPSTR FAR * ppsz );
  163. // read and write ole control stream (in ole2.dll)
  164. STDAPI WriteOleStg (LPSTORAGE pstg, IOleObject FAR* pOleObj,
  165. DWORD dwReserved, LPSTREAM FAR* ppstmOut);
  166. STDAPI WriteOleStgEx(LPSTORAGE pstg, IOleObject* pOleObj, DWORD dwReserved,
  167. DWORD dwGivenFlags, LPSTREAM* ppstmOut);
  168. STDAPI ReadOleStg (LPSTORAGE pstg, DWORD FAR* pdwFlags,
  169. DWORD FAR* pdwOptUpdate, DWORD FAR* pdwReserved,
  170. LPMONIKER FAR* ppmk, LPSTREAM FAR* pstmOut);
  171. STDAPI ReadM1ClassStm(LPSTREAM pstm, CLSID FAR* pclsid);
  172. STDAPI WriteM1ClassStm(LPSTREAM pstm, REFCLSID rclsid);
  173. STDAPI ReadM1ClassStmBuf(CStmBufRead & StmRead, CLSID FAR* pclsid);
  174. STDAPI WriteM1ClassStmBuf(CStmBufWrite & StmWrite, REFCLSID rclsid);
  175. #endif // _UTSTREAM_H