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