source: trunk/src/shell32/memorystream.cpp@ 1398

Last change on this file since 1398 was 1398, checked in by phaller, 26 years ago

Fix: debug info

File size: 9.1 KB
Line 
1/* $Id: memorystream.cpp,v 1.3 1999-10-22 12:18:46 phaller Exp $ */
2
3/*
4 * Win32 SHELL32 for OS/2
5 *
6 * Copyright 1999 Patrick Haller (haller@zebra.fh-weingarten.de)
7 * Project Odin Software License can be found in LICENSE.TXT
8 *
9 * this class implements a pure IStream object
10 * and can be used for many purposes
11 *
12 * the main reason for implementing this was
13 * a cleaner implementation of IShellLink which
14 * needs to be able to load lnk's from a IStream
15 * interface so it was obvious to capsule the file
16 * access in a IStream to.
17 */
18
19
20/*****************************************************************************
21 * Includes *
22 *****************************************************************************/
23
24#include <odin.h>
25#include <odinwrap.h>
26#include <os2sel.h>
27
28#include <string.h>
29
30#define ICOM_CINTERFACE 1
31#define CINTERFACE 1
32
33#include "wine/obj_storage.h"
34#include "heap.h"
35#include "winerror.h"
36#include "debugtools.h"
37#include "shell32_main.h"
38
39#include <misc.h>
40
41
42ODINDEBUGCHANNEL(SHELL32-MEMORYSTREAM)
43
44
45/*****************************************************************************
46 * Local Prototypes *
47 *****************************************************************************/
48
49static HRESULT WINAPI IStream_fnQueryInterface(IStream *iface, REFIID riid, LPVOID *ppvObj);
50static ULONG WINAPI IStream_fnAddRef(IStream *iface);
51static ULONG WINAPI IStream_fnRelease(IStream *iface);
52static HRESULT WINAPI IStream_fnRead (IStream * iface, void* pv, ULONG cb, ULONG* pcbRead);
53static HRESULT WINAPI IStream_fnWrite (IStream * iface, const void* pv, ULONG cb, ULONG* pcbWritten);
54static HRESULT WINAPI IStream_fnSeek (IStream * iface, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition);
55static HRESULT WINAPI IStream_fnSetSize (IStream * iface, ULARGE_INTEGER libNewSize);
56static HRESULT WINAPI IStream_fnCopyTo (IStream * iface, IStream* pstm, ULARGE_INTEGER cb, ULARGE_INTEGER* pcbRead, ULARGE_INTEGER* pcbWritten);
57static HRESULT WINAPI IStream_fnCommit (IStream * iface, DWORD grfCommitFlags);
58static HRESULT WINAPI IStream_fnRevert (IStream * iface);
59static HRESULT WINAPI IStream_fnLockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType);
60static HRESULT WINAPI IStream_fnUnlockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType);
61static HRESULT WINAPI IStream_fnStat (IStream * iface, STATSTG* pstatstg, DWORD grfStatFlag);
62static HRESULT WINAPI IStream_fnClone (IStream * iface, IStream** ppstm);
63
64static ICOM_VTABLE(IStream) stvt =
65{
66 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
67 IStream_fnQueryInterface,
68 IStream_fnAddRef,
69 IStream_fnRelease,
70 IStream_fnRead,
71 IStream_fnWrite,
72 IStream_fnSeek,
73 IStream_fnSetSize,
74 IStream_fnCopyTo,
75 IStream_fnCommit,
76 IStream_fnRevert,
77 IStream_fnLockRegion,
78 IStream_fnUnlockRegion,
79 IStream_fnStat,
80 IStream_fnClone
81
82};
83
84typedef struct
85{ ICOM_VTABLE(IStream) *lpvtst;
86 DWORD ref;
87 LPBYTE pImage;
88 HANDLE hMapping;
89 DWORD dwLength;
90 DWORD dwPos;
91} ISHFileStream;
92
93/**************************************************************************
94 * CreateStreamOnFile()
95 *
96 * similar to CreateStreamOnHGlobal
97 */
98HRESULT CreateStreamOnFile (LPCSTR pszFilename, IStream ** ppstm)
99{
100 ISHFileStream* fstr;
101 OFSTRUCT ofs;
102 HFILE hFile = OpenFile( pszFilename, &ofs, OF_READ );
103 HRESULT ret = E_FAIL;
104
105 dprintf(("SHELL32:MemoryStream CreateStreamOnFile(%s,%08xh)\n",
106 pszFilename,
107 ppstm));
108
109 fstr = (ISHFileStream*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ISHFileStream));
110 fstr->lpvtst=&stvt;
111 fstr->ref = 1;
112 fstr->dwLength = GetFileSize (hFile, NULL);
113
114 shell32_ObjCount++;
115
116 if (!(fstr->hMapping = CreateFileMappingA(hFile,NULL,PAGE_READONLY|SEC_COMMIT,0,0,NULL)))
117 {
118 dprintf(("failed to create filemap.\n"));
119 goto end_2;
120 }
121
122 if (!(fstr->pImage = (BYTE*)MapViewOfFile(fstr->hMapping,FILE_MAP_READ,0,0,0)))
123 {
124 dprintf(("failed to mmap filemap.\n"));
125 goto end_3;
126 }
127
128 ret = S_OK;
129 goto end_1;
130
131end_3: CloseHandle(fstr->hMapping);
132end_2: HeapFree(GetProcessHeap(), 0, fstr);
133 fstr = NULL;
134
135end_1: _lclose(hFile);
136 (*ppstm) = (IStream*)fstr;
137 return ret;
138}
139
140/**************************************************************************
141* IStream_fnQueryInterface
142*/
143static HRESULT WINAPI IStream_fnQueryInterface(IStream *iface, REFIID riid, LPVOID *ppvObj)
144{
145 ICOM_THIS(ISHFileStream, iface);
146
147 char xriid[50];
148 WINE_StringFromCLSID((LPCLSID)riid,xriid);
149
150 dprintf(("SHELL32:MemoryStream IStream_fnQueryInterface(%p)->(\n\tIID:\t%s,%p)\n",
151 This,xriid,ppvObj));
152
153 *ppvObj = NULL;
154
155 if(IsEqualIID(riid, &IID_IUnknown) ||
156 IsEqualIID(riid, &IID_IStream))
157 {
158 *ppvObj = This;
159 }
160
161 if(*ppvObj)
162 {
163 IStream_AddRef((IStream*)*ppvObj);
164 dprintf(("Interface: (%p)->(%p)\n",ppvObj,*ppvObj));
165 return S_OK;
166 }
167 dprintf(("-- Interface: E_NOINTERFACE\n"));
168 return E_NOINTERFACE;
169}
170
171/**************************************************************************
172* IStream_fnAddRef
173*/
174static ULONG WINAPI IStream_fnAddRef(IStream *iface)
175{
176 ICOM_THIS(ISHFileStream, iface);
177
178 dprintf(("SHELL32:MemoryStream IStream_fnAddRef (%p)->(count=%lu)\n",
179 This, This->ref));
180
181 shell32_ObjCount++;
182 return ++(This->ref);
183}
184
185/**************************************************************************
186* IStream_fnRelease
187*/
188static ULONG WINAPI IStream_fnRelease(IStream *iface)
189{
190 ICOM_THIS(ISHFileStream, iface);
191
192 dprintf(("SHELL32:MemoryStream IStream_fnRelease(%p)->()\n",
193 This));
194
195 shell32_ObjCount--;
196
197 if (!--(This->ref))
198 { dprintf((" destroying SHFileStream (%p)\n",This));
199
200 UnmapViewOfFile(This->pImage);
201 CloseHandle(This->hMapping);
202
203 HeapFree(GetProcessHeap(),0,This);
204 return 0;
205 }
206 return This->ref;
207}
208
209static HRESULT WINAPI IStream_fnRead (IStream * iface, void* pv, ULONG cb, ULONG* pcbRead)
210{
211 DWORD dwBytesToRead, dwBytesLeft;
212
213 ICOM_THIS(ISHFileStream, iface);
214
215 dprintf(("SHELL32:MemoryStream IStream_fnRead(%p)->(%p,%p,%p)\n",
216 This, pv, cb, pcbRead));
217
218 if ( !pv )
219 return STG_E_INVALIDPOINTER;
220
221 dwBytesLeft = This->dwLength - This->dwPos;
222
223 if ( 0 >= dwBytesLeft ) /* end of buffer */
224 return S_FALSE;
225
226 dwBytesToRead = ( cb > dwBytesLeft) ? dwBytesLeft : cb;
227
228 memmove ( pv, (This->pImage) + (This->dwPos), dwBytesToRead);
229
230 This->dwPos += dwBytesToRead; /* adjust pointer */
231
232 if (pcbRead)
233 *pcbRead = dwBytesToRead;
234
235 return S_OK;
236}
237static HRESULT WINAPI IStream_fnWrite (IStream * iface, const void* pv, ULONG cb, ULONG* pcbWritten)
238{
239 ICOM_THIS(ISHFileStream, iface);
240
241 dprintf(("SHELL32:MemoryStream IStream_fnWrite (%p) not implemented\n",This));
242
243 return E_NOTIMPL;
244}
245static HRESULT WINAPI IStream_fnSeek (IStream * iface, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition)
246{
247 ICOM_THIS(ISHFileStream, iface);
248
249 dprintf(("SHELL32:MemoryStream IStream_fnSeek (%p) not implemented\n",This));
250
251 return E_NOTIMPL;
252}
253static HRESULT WINAPI IStream_fnSetSize (IStream * iface, ULARGE_INTEGER libNewSize)
254{
255 ICOM_THIS(ISHFileStream, iface);
256
257 dprintf(("SHELL32:MemoryStream IStream_fnSetSize (%p) not implemented\n",This));
258
259 return E_NOTIMPL;
260}
261static HRESULT WINAPI IStream_fnCopyTo (IStream * iface, IStream* pstm, ULARGE_INTEGER cb, ULARGE_INTEGER* pcbRead, ULARGE_INTEGER* pcbWritten)
262{
263 ICOM_THIS(ISHFileStream, iface);
264
265 dprintf(("SHELL32:MemoryStream IStream_fnCopyTo (%p) not implemented\n",This));
266
267 return E_NOTIMPL;
268}
269static HRESULT WINAPI IStream_fnCommit (IStream * iface, DWORD grfCommitFlags)
270{
271 ICOM_THIS(ISHFileStream, iface);
272
273 dprintf(("SHELL32:MemoryStream IStream_fnCommit (%p) not implemented\n",This));
274
275 return E_NOTIMPL;
276}
277static HRESULT WINAPI IStream_fnRevert (IStream * iface)
278{
279 ICOM_THIS(ISHFileStream, iface);
280
281 dprintf(("SHELL32:MemoryStream IStream_fnRevert (%p) not implemented\n",This));
282
283 return E_NOTIMPL;
284}
285static HRESULT WINAPI IStream_fnLockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
286{
287 ICOM_THIS(ISHFileStream, iface);
288
289 dprintf(("SHELL32:MemoryStream IStream_fnLockRegion (%p) not implemented\n",This));
290
291 return E_NOTIMPL;
292}
293static HRESULT WINAPI IStream_fnUnlockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
294{
295 ICOM_THIS(ISHFileStream, iface);
296
297 dprintf(("SHELL32:MemoryStream IStream_fnUnlockRegoin (%p) not implemented.\n",This));
298
299 return E_NOTIMPL;
300}
301static HRESULT WINAPI IStream_fnStat (IStream * iface, STATSTG* pstatstg, DWORD grfStatFlag)
302{
303 ICOM_THIS(ISHFileStream, iface);
304
305 dprintf(("SHELL32:MemoryStream IStream_fnStat (%p) not implemented.\n",This));
306
307 return E_NOTIMPL;
308}
309static HRESULT WINAPI IStream_fnClone (IStream * iface, IStream** ppstm)
310{
311 ICOM_THIS(ISHFileStream, iface);
312
313 dprintf(("SHELL32:MemoryStream IStream_fnClone (%p) not implemented.\n",This));
314
315 return E_NOTIMPL;
316}
Note: See TracBrowser for help on using the repository browser.