Changeset 6650 for trunk/src/shlwapi/regstream.c
- Timestamp:
- Sep 5, 2001, 3:54:53 PM (24 years ago)
- File:
-
- 1 edited
-
trunk/src/shlwapi/regstream.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/shlwapi/regstream.c
r6375 r6650 1 /* $Id: regstream.c,v 1.3 2001-09-05 13:48:38 bird Exp $ */ 1 2 /* 2 * SHRegOpenStream3 * SHRegOpenStream 3 4 */ 4 5 #ifdef __WIN32OS2__ … … 28 29 DEFAULT_DEBUG_CHANNEL(shell); 29 30 30 typedef struct 31 { ICOM_VFIELD(IStream);32 DWORDref;33 HKEYhKey;34 LPBYTEpbBuffer;35 DWORDdwLength;36 DWORDdwPos;31 typedef struct 32 { ICOM_VFIELD(IStream); 33 DWORD ref; 34 HKEY hKey; 35 LPBYTE pbBuffer; 36 DWORD dwLength; 37 DWORD dwPos; 37 38 } ISHRegStream; 38 39 … … 40 41 41 42 /************************************************************************** 42 * IStream_ConstructorA [internal]43 * IStream_ConstructorA [internal] 43 44 */ 44 45 static IStream *IStream_ConstructorA(HKEY hKey, LPCSTR pszSubKey, LPCSTR pszValue, DWORD grfMode) 45 46 { 46 ISHRegStream*rstr;47 DWORDdwType;48 49 rstr = (ISHRegStream*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ISHRegStream));50 51 ICOM_VTBL(rstr)=&rstvt;52 rstr->ref = 1;53 54 if (!(RegOpenKeyExA (hKey, pszSubKey, 0, KEY_READ, &(rstr->hKey))))55 {56 if (!(RegQueryValueExA(rstr->hKey, pszValue,0,0,0,&(rstr->dwLength))))57 { 58 /* read the binary data into the buffer */59 if((rstr->pbBuffer = HeapAlloc(GetProcessHeap(),0,rstr->dwLength)))60 {61 if (!(RegQueryValueExA(rstr->hKey, pszValue,0,&dwType,rstr->pbBuffer,&(rstr->dwLength))))62 {63 if (dwType == REG_BINARY )64 {65 TRACE ("%p\n", rstr);66 return (IStream*)rstr;67 }68 }69 HeapFree (GetProcessHeap(),0,rstr->pbBuffer);70 }71 }72 RegCloseKey(rstr->hKey);73 }74 HeapFree (GetProcessHeap(),0,rstr);75 return NULL;76 } 77 78 /************************************************************************** 79 * IStream_ConstructorW [internal]47 ISHRegStream* rstr; 48 DWORD dwType; 49 50 rstr = (ISHRegStream*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ISHRegStream)); 51 52 ICOM_VTBL(rstr)=&rstvt; 53 rstr->ref = 1; 54 55 if (!(RegOpenKeyExA (hKey, pszSubKey, 0, KEY_READ, &(rstr->hKey)))) 56 { 57 if (!(RegQueryValueExA(rstr->hKey, pszValue,0,0,0,&(rstr->dwLength)))) 58 { 59 /* read the binary data into the buffer */ 60 if((rstr->pbBuffer = HeapAlloc(GetProcessHeap(),0,rstr->dwLength))) 61 { 62 if (!(RegQueryValueExA(rstr->hKey, pszValue,0,&dwType,rstr->pbBuffer,&(rstr->dwLength)))) 63 { 64 if (dwType == REG_BINARY ) 65 { 66 TRACE ("%p\n", rstr); 67 return (IStream*)rstr; 68 } 69 } 70 HeapFree (GetProcessHeap(),0,rstr->pbBuffer); 71 } 72 } 73 RegCloseKey(rstr->hKey); 74 } 75 HeapFree (GetProcessHeap(),0,rstr); 76 return NULL; 77 } 78 79 /************************************************************************** 80 * IStream_ConstructorW [internal] 80 81 */ 81 82 static IStream *IStream_ConstructorW(HKEY hKey, LPCWSTR pszSubKey, LPCWSTR pszValue, DWORD grfMode) 82 83 { 83 ISHRegStream*rstr;84 DWORDdwType;85 86 rstr = (ISHRegStream*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ISHRegStream));87 88 ICOM_VTBL(rstr)=&rstvt;89 rstr->ref = 1;90 91 if (!(RegOpenKeyExW (hKey, pszSubKey, 0, KEY_READ, &(rstr->hKey))))92 {93 if (!(RegQueryValueExW(rstr->hKey, pszValue,0,0,0,&(rstr->dwLength))))94 { 95 /* read the binary data into the buffer */96 if((rstr->pbBuffer = HeapAlloc(GetProcessHeap(),0,rstr->dwLength)))97 {98 if (!(RegQueryValueExW(rstr->hKey, pszValue,0,&dwType,rstr->pbBuffer,&(rstr->dwLength))))99 {100 if (dwType == REG_BINARY )101 {102 TRACE ("%p\n", rstr);103 return (IStream*)rstr;104 }105 }106 HeapFree (GetProcessHeap(),0,rstr->pbBuffer);107 }108 }109 RegCloseKey(rstr->hKey);110 }111 HeapFree (GetProcessHeap(),0,rstr);112 return NULL;84 ISHRegStream* rstr; 85 DWORD dwType; 86 87 rstr = (ISHRegStream*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ISHRegStream)); 88 89 ICOM_VTBL(rstr)=&rstvt; 90 rstr->ref = 1; 91 92 if (!(RegOpenKeyExW (hKey, pszSubKey, 0, KEY_READ, &(rstr->hKey)))) 93 { 94 if (!(RegQueryValueExW(rstr->hKey, pszValue,0,0,0,&(rstr->dwLength)))) 95 { 96 /* read the binary data into the buffer */ 97 if((rstr->pbBuffer = HeapAlloc(GetProcessHeap(),0,rstr->dwLength))) 98 { 99 if (!(RegQueryValueExW(rstr->hKey, pszValue,0,&dwType,rstr->pbBuffer,&(rstr->dwLength)))) 100 { 101 if (dwType == REG_BINARY ) 102 { 103 TRACE ("%p\n", rstr); 104 return (IStream*)rstr; 105 } 106 } 107 HeapFree (GetProcessHeap(),0,rstr->pbBuffer); 108 } 109 } 110 RegCloseKey(rstr->hKey); 111 } 112 HeapFree (GetProcessHeap(),0,rstr); 113 return NULL; 113 114 } 114 115 … … 118 119 static HRESULT WINAPI IStream_fnQueryInterface(IStream *iface, REFIID riid, LPVOID *ppvObj) 119 120 { 120 ICOM_THIS(ISHRegStream, iface);121 122 //// TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);123 124 *ppvObj = NULL;125 126 if(IsEqualIID(riid, &IID_IUnknown))/*IUnknown*/127 { *ppvObj = This; 128 }129 else if(IsEqualIID(riid, &IID_IStream))/*IStream*/130 { *ppvObj = This;131 } 132 133 if(*ppvObj)134 { 135 IStream_AddRef((IStream*)*ppvObj); 136 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);137 return S_OK;138 }139 TRACE("-- Interface: E_NOINTERFACE\n");140 return E_NOINTERFACE;121 ICOM_THIS(ISHRegStream, iface); 122 123 //// TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj); 124 125 *ppvObj = NULL; 126 127 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/ 128 { *ppvObj = This; 129 } 130 else if(IsEqualIID(riid, &IID_IStream)) /*IStream*/ 131 { *ppvObj = This; 132 } 133 134 if(*ppvObj) 135 { 136 IStream_AddRef((IStream*)*ppvObj); 137 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj); 138 return S_OK; 139 } 140 TRACE("-- Interface: E_NOINTERFACE\n"); 141 return E_NOINTERFACE; 141 142 } 142 143 … … 146 147 static ULONG WINAPI IStream_fnAddRef(IStream *iface) 147 148 { 148 ICOM_THIS(ISHRegStream, iface);149 150 TRACE("(%p)->(count=%lu)\n",This, This->ref);151 152 return ++(This->ref);149 ICOM_THIS(ISHRegStream, iface); 150 151 TRACE("(%p)->(count=%lu)\n",This, This->ref); 152 153 return ++(This->ref); 153 154 } 154 155 … … 158 159 static ULONG WINAPI IStream_fnRelease(IStream *iface) 159 160 { 160 ICOM_THIS(ISHRegStream, iface);161 162 TRACE("(%p)->()\n",This);163 164 if (!--(This->ref)) 165 { TRACE(" destroying SHReg IStream (%p)\n",This);166 167 if (This->pbBuffer)168 HeapFree(GetProcessHeap(),0,This->pbBuffer);169 170 if (This->hKey)171 RegCloseKey(This->hKey);172 173 HeapFree(GetProcessHeap(),0,This);174 return 0;175 }176 return This->ref;161 ICOM_THIS(ISHRegStream, iface); 162 163 TRACE("(%p)->()\n",This); 164 165 if (!--(This->ref)) 166 { TRACE(" destroying SHReg IStream (%p)\n",This); 167 168 if (This->pbBuffer) 169 HeapFree(GetProcessHeap(),0,This->pbBuffer); 170 171 if (This->hKey) 172 RegCloseKey(This->hKey); 173 174 HeapFree(GetProcessHeap(),0,This); 175 return 0; 176 } 177 return This->ref; 177 178 } 178 179 179 180 static HRESULT WINAPI IStream_fnRead (IStream * iface, void* pv, ULONG cb, ULONG* pcbRead) 180 181 { 181 ICOM_THIS(ISHRegStream, iface);182 183 DWORD dwBytesToRead, dwBytesLeft;184 185 TRACE("(%p)->(%p,0x%08lx,%p)\n",This, pv, cb, pcbRead);186 187 if ( !pv )188 return STG_E_INVALIDPOINTER;189 190 dwBytesLeft = This->dwLength - This->dwPos;191 192 if ( 0 >= dwBytesLeft )/* end of buffer */193 return S_FALSE;194 195 dwBytesToRead = ( cb > dwBytesLeft) ? dwBytesLeft : cb;196 197 memmove ( pv, (This->pbBuffer) + (This->dwPos), dwBytesToRead);198 199 This->dwPos += dwBytesToRead;/* adjust pointer */200 201 if (pcbRead)202 *pcbRead = dwBytesToRead;203 204 return S_OK;182 ICOM_THIS(ISHRegStream, iface); 183 184 DWORD dwBytesToRead, dwBytesLeft; 185 186 TRACE("(%p)->(%p,0x%08lx,%p)\n",This, pv, cb, pcbRead); 187 188 if ( !pv ) 189 return STG_E_INVALIDPOINTER; 190 191 dwBytesLeft = This->dwLength - This->dwPos; 192 193 if ( 0 >= dwBytesLeft ) /* end of buffer */ 194 return S_FALSE; 195 196 dwBytesToRead = ( cb > dwBytesLeft) ? dwBytesLeft : cb; 197 198 memmove ( pv, (This->pbBuffer) + (This->dwPos), dwBytesToRead); 199 200 This->dwPos += dwBytesToRead; /* adjust pointer */ 201 202 if (pcbRead) 203 *pcbRead = dwBytesToRead; 204 205 return S_OK; 205 206 } 206 207 static HRESULT WINAPI IStream_fnWrite (IStream * iface, const void* pv, ULONG cb, ULONG* pcbWritten) 207 208 { 208 ICOM_THIS(ISHRegStream, iface);209 210 TRACE("(%p)\n",This);211 212 return E_NOTIMPL;209 ICOM_THIS(ISHRegStream, iface); 210 211 TRACE("(%p)\n",This); 212 213 return E_NOTIMPL; 213 214 } 214 215 static HRESULT WINAPI IStream_fnSeek (IStream * iface, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition) 215 216 { 216 ICOM_THIS(ISHRegStream, iface);217 218 TRACE("(%p)\n",This);219 220 return E_NOTIMPL;217 ICOM_THIS(ISHRegStream, iface); 218 219 TRACE("(%p)\n",This); 220 221 return E_NOTIMPL; 221 222 } 222 223 static HRESULT WINAPI IStream_fnSetSize (IStream * iface, ULARGE_INTEGER libNewSize) 223 224 { 224 ICOM_THIS(ISHRegStream, iface);225 226 TRACE("(%p)\n",This);227 228 return E_NOTIMPL;225 ICOM_THIS(ISHRegStream, iface); 226 227 TRACE("(%p)\n",This); 228 229 return E_NOTIMPL; 229 230 } 230 231 static HRESULT WINAPI IStream_fnCopyTo (IStream * iface, IStream* pstm, ULARGE_INTEGER cb, ULARGE_INTEGER* pcbRead, ULARGE_INTEGER* pcbWritten) 231 232 { 232 ICOM_THIS(ISHRegStream, iface);233 234 TRACE("(%p)\n",This);235 236 return E_NOTIMPL;233 ICOM_THIS(ISHRegStream, iface); 234 235 TRACE("(%p)\n",This); 236 237 return E_NOTIMPL; 237 238 } 238 239 static HRESULT WINAPI IStream_fnCommit (IStream * iface, DWORD grfCommitFlags) 239 240 { 240 ICOM_THIS(ISHRegStream, iface);241 242 TRACE("(%p)\n",This);243 244 return E_NOTIMPL;241 ICOM_THIS(ISHRegStream, iface); 242 243 TRACE("(%p)\n",This); 244 245 return E_NOTIMPL; 245 246 } 246 247 static HRESULT WINAPI IStream_fnRevert (IStream * iface) 247 248 { 248 ICOM_THIS(ISHRegStream, iface);249 250 TRACE("(%p)\n",This);251 252 return E_NOTIMPL;249 ICOM_THIS(ISHRegStream, iface); 250 251 TRACE("(%p)\n",This); 252 253 return E_NOTIMPL; 253 254 } 254 255 static HRESULT WINAPI IStream_fnLockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType) 255 256 { 256 ICOM_THIS(ISHRegStream, iface);257 258 TRACE("(%p)\n",This);259 260 return E_NOTIMPL;257 ICOM_THIS(ISHRegStream, iface); 258 259 TRACE("(%p)\n",This); 260 261 return E_NOTIMPL; 261 262 } 262 263 static HRESULT WINAPI IStream_fnUnlockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType) 263 264 { 264 ICOM_THIS(ISHRegStream, iface);265 266 TRACE("(%p)\n",This);267 268 return E_NOTIMPL;265 ICOM_THIS(ISHRegStream, iface); 266 267 TRACE("(%p)\n",This); 268 269 return E_NOTIMPL; 269 270 } 270 271 static HRESULT WINAPI IStream_fnStat (IStream * iface, STATSTG* pstatstg, DWORD grfStatFlag) 271 272 { 272 ICOM_THIS(ISHRegStream, iface);273 274 TRACE("(%p)\n",This);275 276 return E_NOTIMPL;273 ICOM_THIS(ISHRegStream, iface); 274 275 TRACE("(%p)\n",This); 276 277 return E_NOTIMPL; 277 278 } 278 279 static HRESULT WINAPI IStream_fnClone (IStream * iface, IStream** ppstm) 279 280 { 280 ICOM_THIS(ISHRegStream, iface);281 282 TRACE("(%p)\n",This);283 284 return E_NOTIMPL;285 } 286 287 static struct ICOM_VTABLE(IStream) rstvt = 288 { 289 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE290 IStream_fnQueryInterface,291 IStream_fnAddRef,292 IStream_fnRelease,293 IStream_fnRead,294 IStream_fnWrite,295 IStream_fnSeek,296 IStream_fnSetSize,297 IStream_fnCopyTo,298 IStream_fnCommit,299 IStream_fnRevert,300 IStream_fnLockRegion,301 IStream_fnUnlockRegion,302 IStream_fnStat,303 IStream_fnClone304 281 ICOM_THIS(ISHRegStream, iface); 282 283 TRACE("(%p)\n",This); 284 285 return E_NOTIMPL; 286 } 287 288 static struct ICOM_VTABLE(IStream) rstvt = 289 { 290 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE 291 IStream_fnQueryInterface, 292 IStream_fnAddRef, 293 IStream_fnRelease, 294 IStream_fnRead, 295 IStream_fnWrite, 296 IStream_fnSeek, 297 IStream_fnSetSize, 298 IStream_fnCopyTo, 299 IStream_fnCommit, 300 IStream_fnRevert, 301 IStream_fnLockRegion, 302 IStream_fnUnlockRegion, 303 IStream_fnStat, 304 IStream_fnClone 305 305 306 }; 306 307 307 308 /************************************************************************* 308 * SHOpenRegStreamA [SHLWAPI.@]309 * SHOpenRegStreamA [SHLWAPI.@] 309 310 */ 310 311 IStream * WINAPI SHOpenRegStreamA( 311 HKEY hkey,312 LPCSTR pszSubkey,313 LPCSTR pszValue,314 DWORD grfMode)315 { 316 TRACE("(0x%08x,%s,%s,0x%08lx)\n",317 hkey, pszSubkey, pszValue, grfMode);318 319 return IStream_ConstructorA(hkey, pszSubkey, pszValue, grfMode);312 HKEY hkey, 313 LPCSTR pszSubkey, 314 LPCSTR pszValue, 315 DWORD grfMode) 316 { 317 TRACE("(0x%08x,%s,%s,0x%08lx)\n", 318 hkey, pszSubkey, pszValue, grfMode); 319 320 return IStream_ConstructorA(hkey, pszSubkey, pszValue, grfMode); 320 321 } 321 322 322 323 /************************************************************************* 323 * SHOpenRegStreamW [SHLWAPI.@]324 * SHOpenRegStreamW [SHLWAPI.@] 324 325 */ 325 326 IStream * WINAPI SHOpenRegStreamW( 326 HKEY hkey,327 LPCWSTR pszSubkey,328 LPCWSTR pszValue,329 DWORD grfMode)330 { 331 TRACE("(0x%08x,%s,%s,0x%08lx)\n",332 hkey, debugstr_w(pszSubkey), debugstr_w(pszValue), grfMode);333 334 return IStream_ConstructorW(hkey, pszSubkey, pszValue, grfMode);335 } 327 HKEY hkey, 328 LPCWSTR pszSubkey, 329 LPCWSTR pszValue, 330 DWORD grfMode) 331 { 332 TRACE("(0x%08x,%s,%s,0x%08lx)\n", 333 hkey, debugstr_w(pszSubkey), debugstr_w(pszValue), grfMode); 334 335 return IStream_ConstructorW(hkey, pszSubkey, pszValue, grfMode); 336 }
Note:
See TracChangeset
for help on using the changeset viewer.
