1 //  ----------------------------------------------------------------------------
2 //  MODULE    : OLEStream.h
3 //  LANGUAGE  : C++
4 //  AUTHOR    : Yue Zhang
5 //  DATE    : Tuesday, January 23, 1996
6 //  DESCRIPTION : This file defines an enhanced OLE stream object
7 //  COMMENT   : Enhanced OLE objects are platform independent
8 //      SCCSID            : @(#)olestrm.h 1.3 10:45:32 12 Sep 1997
9 //  ----------------------------------------------------------------------------
10 //  Copyright (c) 1999 Digital Imaging Group, Inc.
11 //  For conditions of distribution and use, see copyright notice
12 //  in Flashpix.h
13 //  ----------------------------------------------------------------------------
14 
15   #ifndef OLEStreams_h
16   #define OLEStreams_h
17 
18 //  ----------------------------------------------------------------------------
19 
20 //  Includes
21 //  --------
22 
23 #ifndef OLECommun_h
24   #include "olecomm.h"
25 #endif
26 #ifndef OLECore_h
27   #include "olecore.h"
28 #endif
29   class OLEStorage;   // to avoid include OLEStorages.h
30 
31 
32 //  Constants
33 //  ---------
34 
35 //  Class declarations
36 //  ------------------
37 
38   class OLEStream;
39 
40 //  Class definitions
41 //  -----------------
42 
43   class OLEStream : public OLECore{
44 
45   public:
46     // Create an OLEStream object from parent storage.
47         OLEStream(OLEStorage * parentStorage, LPSTREAM currentStream);
48         virtual ~OLEStream();
49 
50     // Generic OLE stream read function
51     virtual Boolean Read(void *, size_t);
52 
53     // Generic OLE stream write function
54     virtual Boolean Write( const void*, size_t );
55 
56     // Set the stream to a new position. There are 3 modes,
57     virtual Boolean Seek( const long offset = 0, const unsigned long mode = STREAM_SEEK_SET);
58 
59     // Get the position of end of the stream
60     virtual Boolean GetEndOfFile( long* endPosition);
61 
62     // Set the size of the stream
63     virtual Boolean SetSize( unsigned long );
64 
65     // Copy the stream to a new one
66     virtual Boolean CopyTo( LPSTREAM, unsigned long );
67 
68     // Save the changes made to the stream
69     virtual Boolean Commit( );
70 
71     // Discard the changes made to the stream
72     virtual Boolean Revert( );
73 
74     // This is a generic function that takes a property of the given type out of
75     // the given stream (at its current position) and puts it at the location
76     // pointed to by pData.
77     virtual DWORD ReadVT(DWORD dwType, BYTE **pData);
78 
79     // This is a generic function that takes a property of the given type out of
80     // the given stream (at its current position) and puts it at the location
81     // pointed to by variant.
82     virtual DWORD ReadVT(VARIANT * variant);
83 
84     // Reads a 2-byte WORD value with padding to 32-bit from a stream. The bytes is swapped
85     virtual DWORD ReadVT_I2(WORD *pw);
86 
87     // Reads a 2-byte WORD value without padding to 32-bit from a stream. The bytes is swapped
88     virtual DWORD   ReadVT_I2_NoPad(WORD *pw);
89 
90     // Reads a 4-byte DWORD value from a stream. The bytes is swapped
91     virtual DWORD ReadVT_I4(DWORD *pdw);
92 
93     // Reads a 32-bit IEEE floating point value from a stream. The bytes is swapped
94     virtual DWORD ReadVT_R4(float *pflt);
95 
96     // Reads a 64-bit IEEE floating point value from a stream. The bytes is swapped
97     virtual DWORD ReadVT_R8(double *pdbl);
98 
99     // Reads an 8-byte two's complement integer (scaled by 10,000) from a stream.
100     //  It's usually used for currency amounts (hence the CY type).The bytes is swapped
101     virtual DWORD ReadVT_CY(CY *pcy);
102 
103     // Reads an 8-byte integer from a stream. The bytes is swapped
104     virtual DWORD ReadVT_I8(LARGE_INTEGER *pli);
105 
106     // Reads a boolean from a stream. The bytes is swapped
107     virtual DWORD ReadVT_BOOL(BOOL *pf);
108 
109     // Reads a character string from a stream. The array is dynamically allocated,
110     // and the caller should delete it after using it.
111     virtual DWORD ReadVT_LPSTR(char **ppsz);
112 
113     // Reads a character string without padding to 32-bit from a stream. Return total bytes read. The array is
114     // dynamically allocated, and should be deleted after use.
115     virtual DWORD   ReadVT_LPSTR_NoPad(char **ppsz);
116 
117     // Reads a Unicode (16-bit) character string from a stream.
118     // The array is dynamically allocated, and the caller should delete it after
119     // using it.
120     virtual DWORD ReadVT_LPWSTR(WCHAR **ppwsz);
121 
122     // Reads a Unicode (16-bit) character string without padding to 32-bit from a stream. Return total bytes read.
123     // The array is dynamically allocated, and should be deleted after use.
124     virtual DWORD   ReadVT_LPWSTR_NoPad(WCHAR **ppwsz);
125 
126     // Reads a FILETIME structure from a stream. The bytes is swapped
127     virtual DWORD ReadVT_FILETIME(FILETIME *pft);
128 
129     // Reads a BLOB (length + raw block of data) from a stream. The BYTE array
130     // within the BLOB structure is dynamically allocated, so it should be deleted
131     // by the caller after being used.
132     virtual DWORD ReadVT_BLOB(BLOB **);
133 
134     // Reads a CLSID from a stream (which is really a DWORD, two WORDs, and 8 bytes).
135     // The bytes is swapped
136     virtual DWORD ReadVT_CLSID(CLSID *);
137     virtual DWORD ReadVT_CLSID(CLSID **);
138 
139     // Reads a VARIANT from a stream (which is really four unsigned short, and a double).
140     // The bytes is swapped
141     virtual DWORD   ReadVT_VARIANT(VARIANT *pvar);
142 
143     // FIX_DICT_PROP - added ReadDICT_ENTRIES
144     // Reads the entries for a dictionary from a stream (each of which is essentially
145     // similar to a PID and a BSTR).
146     // The bytes is swapped
147     virtual DWORD   ReadDICT_ENTRIES(DICTIONARY *pDict);
148 
149     // Reads a clipboard data structure (length + format + raw block of data)
150     // from a stream. The BYTE array within the CLIPDATA structure is dynamically
151     // allocated, so it should be deleted by the caller after being used.
152     virtual DWORD ReadVT_CF(CLIPDATA **);
153 
154     // Reads a vector data structure (cElements * length of each element), and return total bytes
155     // been read. The vector type is like VT_XX | VT_VECTOR. Right now 11 types are supported
156     // ( char, WORD, DWORD, float, double, LPSTR, LPWSTR, BLOB, CLIPDATA, CLSID, VARIANT).
157     // The vector structure is dynamically allocated, so it should be deleted
158     // by the caller after being used.
159     virtual DWORD   ReadVT_VECTOR(DWORD dwType, VECTOR **ppVector);
160 
161     // This is a generic function that writes a property of any type in pData to a stream.
162     virtual DWORD WriteVT(DWORD dwType, BYTE *pData);
163 
164     // This is a generic function that writes a property of any type to a stream.
165     virtual DWORD WriteVT(VARIANT * variant);
166 
167     // Write a 2-byte WORD value to a stream with padded to 32-bit boundary, so the actual data
168     // write to the stream is 4 bytes. The bytes are swapped.
169     virtual DWORD WriteVT_I2(WORD* pw);
170 
171     // Write a 2-byte WORD value to a stream without padded to 32-bit boundary, so the actual data
172     // write to the stream is 2 bytes. The bytes are swapped.
173     virtual DWORD   WriteVT_I2_NoPad(WORD* pw);
174 
175     // Write a 4-byte DWORD value to a stream. The bytes are swapped.
176     virtual DWORD WriteVT_I4(DWORD* pdw);
177 
178     // Write a 32-bit IEEE floating point value to a stream. The bytes are swapped
179     virtual DWORD WriteVT_R4(float* pflt);
180 
181     // Write a 64-bit IEEE floating point value to a stream. The bytes are swapped
182     virtual DWORD WriteVT_R8(double* pdbl);
183 
184     // Write a 8-byte two's complement integer (scaled by 10,000) to a stream.
185     // It's usually used for currency amounts (hence the CY type). The bytes are swapped
186     virtual DWORD WriteVT_CY(CY *pcy);
187 
188     // Write a 8-byte integer to a stream. The bytes are swapped
189     virtual DWORD WriteVT_I8(LARGE_INTEGER *pli);
190 
191     // Write a boolean to a stream. The bytes are swapped. An OLE boolean is defined to
192     // be a 2-byte WORD containing 0 (FALSE) or -1 (TRUE). It is padded to a 32-bit boundary.
193     virtual DWORD WriteVT_BOOL(BOOL* pf);
194 
195     // Writes a zero-terminated character string padded to 32-bit boundary to a stream.
196     virtual DWORD WriteVT_LPSTR(char *psz);
197 
198     // Writes a zero-terminated character string without padded to 32-bit boundary to a stream.
199     virtual DWORD   WriteVT_LPSTR_NoPad(const char *psz);
200 
201     // Writes a zero-terminated wide character string padded to 32-bit boundary to a stream.
202     virtual DWORD WriteVT_LPWSTR(WCHAR *pwsz);
203 
204     // Writes a zero-terminated wide character string without padded to 32-bit boundary to a stream.
205     virtual DWORD   WriteVT_LPWSTR_NoPad(WCHAR *pwsz);
206 
207     // Writes a FILETIME structure to a stream. The bytes is swapped
208     virtual DWORD WriteVT_FILETIME(FILETIME *pft);
209 
210     // Writes a BLOB (length + raw block of data) to a stream. The bytes is swapped
211     virtual DWORD WriteVT_BLOB(BLOB *pblob);
212 
213     // Writes a clipboard data structure (length + format + raw block of data)
214     // to a stream.
215     virtual DWORD WriteVT_CF(CLIPDATA *pclipdata);
216 
217     // Writes a CLSID to a stream (which is really a DWORD, two WORDs, and 8 bytes).
218     virtual DWORD WriteVT_CLSID(CLSID *pclsid);
219 
220     // Writes a VARIANT into a stream (which is really four WORDs, and a double). The bytes is swapped
221     virtual DWORD   WriteVT_VARIANT(VARIANT *pvar);
222 
223     // Writes a vector data structure (cElements * length of each element). The total bytes
224     // written to the disk must be padded to 32-bit and returned. The vector type is like
225     // VT_XX | VT_VECTOR. Right now 11 types are supported (char, WORD, DWORD, float, double,
226     // LPSTR, LPWSTR, BLOB, CLIPDATA, CLSID, VARIANT).
227     virtual DWORD   WriteVT_VECTOR(DWORD dwType, VECTOR *pvector);
228 
229     // FIX_DICT_PROP - added WriteDICT_ENTRIES
230     // Writes the entries for a dictionary to a stream (each of which is essentially
231     // similar to a PID and a BSTR).
232     // The bytes is swapped
233     virtual DWORD   WriteDICT_ENTRIES(DICTIONARY *pDict);
234 
235     // Returns the size of an element of the specified type
236     DWORD       SizeVT(DWORD dwType);
237 
238     // Returns a string representation of a VT type data. The returned string is dynamically
239     // allocated, so it should be deleted after use.
240     Boolean     VTtoString(VARIANT *variant, char **ppsz);
241     Boolean     VTtoString(BYTE *pData, DWORD vtType, char **ppsz);
242 
243     virtual   void  AddRef(); // Add reference to the IStream
244     virtual   void  Release();  // Release the IStream
245 
GetStream()246           LPSTREAM  GetStream() { return oleStream; } // Release the IStream
247 
248   protected:
249     Boolean     fSwapBytes;   // Swap bytes flag, swap the bytes if true
250 
251   private:
252     LPSTREAM    oleStream;    // The actual OLE stream
253     OLEStorage *  parStorage;   // Parent storage
254   };
255 
256 
257 #define ReadVT_DATE(pdbl)       ReadVT_R8(pdbl)
258 #ifndef _UNICODE
259 #define ReadVT_BSTR(pprgch)       ReadVT_LPSTR(pprgch)
260 #else
261 #define ReadVT_BSTR(pprgch)       ReadVT_LPWSTR(pprgch)
262 #endif
263 #define ReadVT_STREAM(pprgch)     ReadVT_LPSTR(pprgch)
264 #define ReadVT_STORAGE(pprgch)      ReadVT_LPSTR(pprgch)
265 #define ReadVT_STREAMED_OBJECT(pprgch)  ReadVT_STREAM(pprgch)
266 #define ReadVT_STORED_OBJECT(pprgch)  ReadVT_STORAGE(pprgch)
267 #define ReadVT_BLOB_OBJECT(pprgch)    ReadVT_STREAMED_OBJECT(pprgch)
268 
269 #define WriteVT_DATE(dbl)       WriteVT_R8(dbl)
270 #ifndef _UNICODE
271 #define WriteVT_BSTR(prgch)       WriteVT_LPSTR(prgch)
272 #else
273 #define WriteVT_BSTR(prgch)       WriteVT_LPWSTR(prgch)
274 #endif
275 #define WriteVT_STREAM(prgch)     WriteVT_LPSTR(prgch)
276 #define WriteVT_STORAGE(prgch)      WriteVT_LPSTR(prgch)
277 #define WriteVT_STREAMED_OBJECT(prgch)  WriteVT_STREAM(prgch)
278 #define WriteVT_STORED_OBJECT(prgch)  WriteVT_STORAGE(prgch)
279 #define WriteVT_BLOB_OBJECT(pprgch)   WriteVT_STREAMED_OBJECT(pprgch)
280 
281 
282 //  ----------------------------------------------------------------------------
283   #endif // OLEStreams_h
284 //  ----------------------------------------------------------------------------
285