Changeset 6712 for trunk/src/shlwapi/regstream.c
- Timestamp:
- Sep 15, 2001, 11:47:44 AM (24 years ago)
- File:
-
- 1 edited
-
trunk/src/shlwapi/regstream.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/shlwapi/regstream.c
r6650 r6712 1 /* $Id: regstream.c,v 1.3 2001-09-05 13:48:38 bird Exp $ */2 1 /* 3 * SHRegOpenStream2 * SHRegOpenStream 4 3 */ 5 4 #ifdef __WIN32OS2__ … … 29 28 DEFAULT_DEBUG_CHANNEL(shell); 30 29 31 typedef struct 32 { ICOM_VFIELD(IStream);33 DWORDref;34 HKEYhKey;35 LPBYTEpbBuffer;36 DWORDdwLength;37 DWORDdwPos;30 typedef struct 31 { ICOM_VFIELD(IStream); 32 DWORD ref; 33 HKEY hKey; 34 LPBYTE pbBuffer; 35 DWORD dwLength; 36 DWORD dwPos; 38 37 } ISHRegStream; 39 38 … … 41 40 42 41 /************************************************************************** 43 * IStream_ConstructorA [internal]42 * IStream_ConstructorA [internal] 44 43 */ 45 44 static IStream *IStream_ConstructorA(HKEY hKey, LPCSTR pszSubKey, LPCSTR pszValue, DWORD grfMode) 46 45 { 47 ISHRegStream*rstr;48 DWORDdwType;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]46 ISHRegStream* rstr; 47 DWORD dwType; 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] 81 80 */ 82 81 static IStream *IStream_ConstructorW(HKEY hKey, LPCWSTR pszSubKey, LPCWSTR pszValue, DWORD grfMode) 83 82 { 84 ISHRegStream*rstr;85 DWORDdwType;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;83 ISHRegStream* rstr; 84 DWORD dwType; 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; 114 113 } 115 114 … … 119 118 static HRESULT WINAPI IStream_fnQueryInterface(IStream *iface, REFIID riid, LPVOID *ppvObj) 120 119 { 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;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; 142 141 } 143 142 … … 147 146 static ULONG WINAPI IStream_fnAddRef(IStream *iface) 148 147 { 149 ICOM_THIS(ISHRegStream, iface);150 151 TRACE("(%p)->(count=%lu)\n",This, This->ref);152 153 return ++(This->ref);148 ICOM_THIS(ISHRegStream, iface); 149 150 TRACE("(%p)->(count=%lu)\n",This, This->ref); 151 152 return ++(This->ref); 154 153 } 155 154 … … 159 158 static ULONG WINAPI IStream_fnRelease(IStream *iface) 160 159 { 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;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; 178 177 } 179 178 180 179 static HRESULT WINAPI IStream_fnRead (IStream * iface, void* pv, ULONG cb, ULONG* pcbRead) 181 180 { 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;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; 206 205 } 207 206 static HRESULT WINAPI IStream_fnWrite (IStream * iface, const void* pv, ULONG cb, ULONG* pcbWritten) 208 207 { 209 ICOM_THIS(ISHRegStream, iface);210 211 TRACE("(%p)\n",This);212 213 return E_NOTIMPL;208 ICOM_THIS(ISHRegStream, iface); 209 210 TRACE("(%p)\n",This); 211 212 return E_NOTIMPL; 214 213 } 215 214 static HRESULT WINAPI IStream_fnSeek (IStream * iface, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition) 216 215 { 217 ICOM_THIS(ISHRegStream, iface);218 219 TRACE("(%p)\n",This);220 221 return E_NOTIMPL;216 ICOM_THIS(ISHRegStream, iface); 217 218 TRACE("(%p)\n",This); 219 220 return E_NOTIMPL; 222 221 } 223 222 static HRESULT WINAPI IStream_fnSetSize (IStream * iface, ULARGE_INTEGER libNewSize) 224 223 { 225 ICOM_THIS(ISHRegStream, iface);226 227 TRACE("(%p)\n",This);228 229 return E_NOTIMPL;224 ICOM_THIS(ISHRegStream, iface); 225 226 TRACE("(%p)\n",This); 227 228 return E_NOTIMPL; 230 229 } 231 230 static HRESULT WINAPI IStream_fnCopyTo (IStream * iface, IStream* pstm, ULARGE_INTEGER cb, ULARGE_INTEGER* pcbRead, ULARGE_INTEGER* pcbWritten) 232 231 { 233 ICOM_THIS(ISHRegStream, iface);234 235 TRACE("(%p)\n",This);236 237 return E_NOTIMPL;232 ICOM_THIS(ISHRegStream, iface); 233 234 TRACE("(%p)\n",This); 235 236 return E_NOTIMPL; 238 237 } 239 238 static HRESULT WINAPI IStream_fnCommit (IStream * iface, DWORD grfCommitFlags) 240 239 { 241 ICOM_THIS(ISHRegStream, iface);242 243 TRACE("(%p)\n",This);244 245 return E_NOTIMPL;240 ICOM_THIS(ISHRegStream, iface); 241 242 TRACE("(%p)\n",This); 243 244 return E_NOTIMPL; 246 245 } 247 246 static HRESULT WINAPI IStream_fnRevert (IStream * iface) 248 247 { 249 ICOM_THIS(ISHRegStream, iface);250 251 TRACE("(%p)\n",This);252 253 return E_NOTIMPL;248 ICOM_THIS(ISHRegStream, iface); 249 250 TRACE("(%p)\n",This); 251 252 return E_NOTIMPL; 254 253 } 255 254 static HRESULT WINAPI IStream_fnLockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType) 256 255 { 257 ICOM_THIS(ISHRegStream, iface);258 259 TRACE("(%p)\n",This);260 261 return E_NOTIMPL;256 ICOM_THIS(ISHRegStream, iface); 257 258 TRACE("(%p)\n",This); 259 260 return E_NOTIMPL; 262 261 } 263 262 static HRESULT WINAPI IStream_fnUnlockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType) 264 263 { 265 ICOM_THIS(ISHRegStream, iface);266 267 TRACE("(%p)\n",This);268 269 return E_NOTIMPL;264 ICOM_THIS(ISHRegStream, iface); 265 266 TRACE("(%p)\n",This); 267 268 return E_NOTIMPL; 270 269 } 271 270 static HRESULT WINAPI IStream_fnStat (IStream * iface, STATSTG* pstatstg, DWORD grfStatFlag) 272 271 { 273 ICOM_THIS(ISHRegStream, iface);274 275 TRACE("(%p)\n",This);276 277 return E_NOTIMPL;272 ICOM_THIS(ISHRegStream, iface); 273 274 TRACE("(%p)\n",This); 275 276 return E_NOTIMPL; 278 277 } 279 278 static HRESULT WINAPI IStream_fnClone (IStream * iface, IStream** ppstm) 280 279 { 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_DummyRTTIVALUE291 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_fnClone305 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_DummyRTTIVALUE 290 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_fnClone 304 306 305 }; 307 306 308 307 /************************************************************************* 309 * SHOpenRegStreamA [SHLWAPI.@]308 * SHOpenRegStreamA [SHLWAPI.@] 310 309 */ 311 310 IStream * WINAPI SHOpenRegStreamA( 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);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); 321 320 } 322 321 323 322 /************************************************************************* 324 * SHOpenRegStreamW [SHLWAPI.@]323 * SHOpenRegStreamW [SHLWAPI.@] 325 324 */ 326 325 IStream * WINAPI SHOpenRegStreamW( 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 } 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 }
Note:
See TracChangeset
for help on using the changeset viewer.
