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