Changeset 6709 for trunk/src/shell32/memorystream.c
- Timestamp:
- Sep 15, 2001, 11:26:26 AM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/shell32/memorystream.c
r6650 r6709 1 /* $Id: memorystream.c,v 1.3 2001-09-05 13:46:56 bird Exp $ */2 1 /* 3 * 4 * 2 * this class implements a pure IStream object 3 * and can be used for many purposes 5 4 * 6 * 7 * 8 * 9 * 10 * 5 * the main reason for implementing this was 6 * a cleaner implementation of IShellLink which 7 * needs to be able to load lnk's from a IStream 8 * interface so it was obvious to capsule the file 9 * access in a IStream to. 11 10 */ 12 11 … … 37 36 static HRESULT WINAPI IStream_fnClone (IStream * iface, IStream** ppstm); 38 37 39 static ICOM_VTABLE(IStream) stvt = 40 { 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 38 static ICOM_VTABLE(IStream) stvt = 39 { 40 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE 41 IStream_fnQueryInterface, 42 IStream_fnAddRef, 43 IStream_fnRelease, 44 IStream_fnRead, 45 IStream_fnWrite, 46 IStream_fnSeek, 47 IStream_fnSetSize, 48 IStream_fnCopyTo, 49 IStream_fnCommit, 50 IStream_fnRevert, 51 IStream_fnLockRegion, 52 IStream_fnUnlockRegion, 53 IStream_fnStat, 54 IStream_fnClone 55 57 56 }; 58 57 59 typedef struct 60 { ICOM_VTABLE(IStream)*lpvtst;61 DWORDref;62 LPBYTEpImage;63 HANDLEhMapping;64 DWORDdwLength;65 DWORDdwPos;58 typedef struct 59 { ICOM_VTABLE(IStream) *lpvtst; 60 DWORD ref; 61 LPBYTE pImage; 62 HANDLE hMapping; 63 DWORD dwLength; 64 DWORD dwPos; 66 65 } ISHFileStream; 67 66 … … 73 72 HRESULT CreateStreamOnFile (LPCSTR pszFilename, IStream ** ppstm) 74 73 { 75 ISHFileStream*fstr;76 OFSTRUCTofs;77 HFILEhFile = OpenFile( pszFilename, &ofs, OF_READ );78 HRESULTret = E_FAIL;79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 end_3: 103 end_2: 104 105 106 end_1: 107 108 74 ISHFileStream* fstr; 75 OFSTRUCT ofs; 76 HFILE hFile = OpenFile( pszFilename, &ofs, OF_READ ); 77 HRESULT ret = E_FAIL; 78 79 fstr = (ISHFileStream*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ISHFileStream)); 80 fstr->lpvtst=&stvt; 81 fstr->ref = 1; 82 fstr->dwLength = GetFileSize (hFile, NULL); 83 84 shell32_ObjCount++; 85 86 if (!(fstr->hMapping = CreateFileMappingA(hFile,NULL,PAGE_READONLY|SEC_COMMIT,0,0,NULL))) 87 { 88 WARN("failed to create filemap.\n"); 89 goto end_2; 90 } 91 92 if (!(fstr->pImage = MapViewOfFile(fstr->hMapping,FILE_MAP_READ,0,0,0))) 93 { 94 WARN("failed to mmap filemap.\n"); 95 goto end_3; 96 } 97 98 ret = S_OK; 99 goto end_1; 100 101 end_3: CloseHandle(fstr->hMapping); 102 end_2: HeapFree(GetProcessHeap(), 0, fstr); 103 fstr = NULL; 104 105 end_1: _lclose(hFile); 106 (*ppstm) = (IStream*)fstr; 107 return ret; 109 108 } 110 109 … … 114 113 static HRESULT WINAPI IStream_fnQueryInterface(IStream *iface, REFIID riid, LPVOID *ppvObj) 115 114 { 116 117 118 119 120 121 122 123 124 125 126 127 128 129 { 130 IStream_AddRef((IStream*)*ppvObj); 131 132 133 134 135 115 ICOM_THIS(ISHFileStream, iface); 116 117 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj); 118 119 *ppvObj = NULL; 120 121 if(IsEqualIID(riid, &IID_IUnknown) || 122 IsEqualIID(riid, &IID_IStream)) 123 { 124 *ppvObj = This; 125 } 126 127 if(*ppvObj) 128 { 129 IStream_AddRef((IStream*)*ppvObj); 130 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj); 131 return S_OK; 132 } 133 TRACE("-- Interface: E_NOINTERFACE\n"); 134 return E_NOINTERFACE; 136 135 } 137 136 … … 141 140 static ULONG WINAPI IStream_fnAddRef(IStream *iface) 142 141 { 143 144 145 146 147 148 142 ICOM_THIS(ISHFileStream, iface); 143 144 TRACE("(%p)->(count=%lu)\n",This, This->ref); 145 146 shell32_ObjCount++; 147 return ++(This->ref); 149 148 } 150 149 … … 154 153 static ULONG WINAPI IStream_fnRelease(IStream *iface) 155 154 { 156 157 158 159 160 161 162 if (!--(This->ref)) 163 164 165 166 167 168 169 170 171 155 ICOM_THIS(ISHFileStream, iface); 156 157 TRACE("(%p)->()\n",This); 158 159 shell32_ObjCount--; 160 161 if (!--(This->ref)) 162 { TRACE(" destroying SHFileStream (%p)\n",This); 163 164 UnmapViewOfFile(This->pImage); 165 CloseHandle(This->hMapping); 166 167 HeapFree(GetProcessHeap(),0,This); 168 return 0; 169 } 170 return This->ref; 172 171 } 173 172 174 173 static HRESULT WINAPI IStream_fnRead (IStream * iface, void* pv, ULONG cb, ULONG* pcbRead) 175 174 { 176 177 178 179 180 181 182 183 184 185 186 187 if ( 0 >= dwBytesLeft )/* end of buffer */188 189 190 191 192 193 194 This->dwPos += dwBytesToRead;/* adjust pointer */195 196 197 198 199 175 ICOM_THIS(ISHFileStream, iface); 176 177 DWORD dwBytesToRead, dwBytesLeft; 178 179 TRACE("(%p)->(%p,0x%08lx,%p)\n",This, pv, cb, pcbRead); 180 181 if ( !pv ) 182 return STG_E_INVALIDPOINTER; 183 184 dwBytesLeft = This->dwLength - This->dwPos; 185 186 if ( 0 >= dwBytesLeft ) /* end of buffer */ 187 return S_FALSE; 188 189 dwBytesToRead = ( cb > dwBytesLeft) ? dwBytesLeft : cb; 190 191 memmove ( pv, (This->pImage) + (This->dwPos), dwBytesToRead); 192 193 This->dwPos += dwBytesToRead; /* adjust pointer */ 194 195 if (pcbRead) 196 *pcbRead = dwBytesToRead; 197 198 return S_OK; 200 199 } 201 200 static HRESULT WINAPI IStream_fnWrite (IStream * iface, const void* pv, ULONG cb, ULONG* pcbWritten) 202 201 { 203 204 205 206 207 202 ICOM_THIS(ISHFileStream, iface); 203 204 TRACE("(%p)\n",This); 205 206 return E_NOTIMPL; 208 207 } 209 208 static HRESULT WINAPI IStream_fnSeek (IStream * iface, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition) 210 209 { 211 212 213 214 215 210 ICOM_THIS(ISHFileStream, iface); 211 212 TRACE("(%p)\n",This); 213 214 return E_NOTIMPL; 216 215 } 217 216 static HRESULT WINAPI IStream_fnSetSize (IStream * iface, ULARGE_INTEGER libNewSize) 218 217 { 219 220 221 222 223 218 ICOM_THIS(ISHFileStream, iface); 219 220 TRACE("(%p)\n",This); 221 222 return E_NOTIMPL; 224 223 } 225 224 static HRESULT WINAPI IStream_fnCopyTo (IStream * iface, IStream* pstm, ULARGE_INTEGER cb, ULARGE_INTEGER* pcbRead, ULARGE_INTEGER* pcbWritten) 226 225 { 227 228 229 230 231 226 ICOM_THIS(ISHFileStream, iface); 227 228 TRACE("(%p)\n",This); 229 230 return E_NOTIMPL; 232 231 } 233 232 static HRESULT WINAPI IStream_fnCommit (IStream * iface, DWORD grfCommitFlags) 234 233 { 235 236 237 238 239 234 ICOM_THIS(ISHFileStream, iface); 235 236 TRACE("(%p)\n",This); 237 238 return E_NOTIMPL; 240 239 } 241 240 static HRESULT WINAPI IStream_fnRevert (IStream * iface) 242 241 { 243 244 245 246 247 242 ICOM_THIS(ISHFileStream, iface); 243 244 TRACE("(%p)\n",This); 245 246 return E_NOTIMPL; 248 247 } 249 248 static HRESULT WINAPI IStream_fnLockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType) 250 249 { 251 252 253 254 255 250 ICOM_THIS(ISHFileStream, iface); 251 252 TRACE("(%p)\n",This); 253 254 return E_NOTIMPL; 256 255 } 257 256 static HRESULT WINAPI IStream_fnUnlockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType) 258 257 { 259 260 261 262 263 258 ICOM_THIS(ISHFileStream, iface); 259 260 TRACE("(%p)\n",This); 261 262 return E_NOTIMPL; 264 263 } 265 264 static HRESULT WINAPI IStream_fnStat (IStream * iface, STATSTG* pstatstg, DWORD grfStatFlag) 266 265 { 267 268 269 270 271 266 ICOM_THIS(ISHFileStream, iface); 267 268 TRACE("(%p)\n",This); 269 270 return E_NOTIMPL; 272 271 } 273 272 static HRESULT WINAPI IStream_fnClone (IStream * iface, IStream** ppstm) 274 273 { 275 276 277 278 279 280 } 274 ICOM_THIS(ISHFileStream, iface); 275 276 TRACE("(%p)\n",This); 277 278 return E_NOTIMPL; 279 }
Note:
See TracChangeset
for help on using the changeset viewer.