Repaired shared PE data sections.
[wine/multimedia.git] / dlls / shlwapi / regstream.c
blob2952ca688dee3fec9764924b6a8553312d561887
1 /*
2 * SHRegOpenStream
3 */
4 #include <string.h>
6 #include "winerror.h"
7 #include "winbase.h"
8 #include "winreg.h"
9 #include "shlobj.h"
11 #include "heap.h"
12 #include "debugtools.h"
14 DEFAULT_DEBUG_CHANNEL(shell);
16 typedef struct
17 { ICOM_VFIELD(IStream);
18 DWORD ref;
19 HKEY hKey;
20 LPBYTE pbBuffer;
21 DWORD dwLength;
22 DWORD dwPos;
23 } ISHRegStream;
25 static struct ICOM_VTABLE(IStream) rstvt;
27 /**************************************************************************
28 * IStream_ConstructorA [internal]
30 static IStream *IStream_ConstructorA(HKEY hKey, LPCSTR pszSubKey, LPCSTR pszValue, DWORD grfMode)
32 ISHRegStream* rstr;
33 DWORD dwType;
35 rstr = (ISHRegStream*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ISHRegStream));
37 ICOM_VTBL(rstr)=&rstvt;
38 rstr->ref = 1;
40 if (!(RegOpenKeyExA (hKey, pszSubKey, 0, KEY_READ, &(rstr->hKey))))
42 if (!(RegQueryValueExA(rstr->hKey, pszValue,0,0,0,&(rstr->dwLength))))
44 /* read the binary data into the buffer */
45 if((rstr->pbBuffer = HeapAlloc(GetProcessHeap(),0,rstr->dwLength)))
47 if (!(RegQueryValueExA(rstr->hKey, pszValue,0,&dwType,rstr->pbBuffer,&(rstr->dwLength))))
49 if (dwType == REG_BINARY )
51 TRACE ("%p\n", rstr);
52 return (IStream*)rstr;
55 HeapFree (GetProcessHeap(),0,rstr->pbBuffer);
58 RegCloseKey(rstr->hKey);
60 HeapFree (GetProcessHeap(),0,rstr);
61 return NULL;
64 /**************************************************************************
65 * IStream_ConstructorW [internal]
67 static IStream *IStream_ConstructorW(HKEY hKey, LPCWSTR pszSubKey, LPCWSTR pszValue, DWORD grfMode)
69 ISHRegStream* rstr;
70 DWORD dwType;
72 rstr = (ISHRegStream*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ISHRegStream));
74 ICOM_VTBL(rstr)=&rstvt;
75 rstr->ref = 1;
77 if (!(RegOpenKeyExW (hKey, pszSubKey, 0, KEY_READ, &(rstr->hKey))))
79 if (!(RegQueryValueExW(rstr->hKey, pszValue,0,0,0,&(rstr->dwLength))))
81 /* read the binary data into the buffer */
82 if((rstr->pbBuffer = HeapAlloc(GetProcessHeap(),0,rstr->dwLength)))
84 if (!(RegQueryValueExW(rstr->hKey, pszValue,0,&dwType,rstr->pbBuffer,&(rstr->dwLength))))
86 if (dwType == REG_BINARY )
88 TRACE ("%p\n", rstr);
89 return (IStream*)rstr;
92 HeapFree (GetProcessHeap(),0,rstr->pbBuffer);
95 RegCloseKey(rstr->hKey);
97 HeapFree (GetProcessHeap(),0,rstr);
98 return NULL;
101 /**************************************************************************
102 * IStream_fnQueryInterface
104 static HRESULT WINAPI IStream_fnQueryInterface(IStream *iface, REFIID riid, LPVOID *ppvObj)
106 ICOM_THIS(ISHRegStream, iface);
108 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
110 *ppvObj = NULL;
112 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
113 { *ppvObj = This;
115 else if(IsEqualIID(riid, &IID_IStream)) /*IStream*/
116 { *ppvObj = This;
119 if(*ppvObj)
121 IStream_AddRef((IStream*)*ppvObj);
122 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
123 return S_OK;
125 TRACE("-- Interface: E_NOINTERFACE\n");
126 return E_NOINTERFACE;
129 /**************************************************************************
130 * IStream_fnAddRef
132 static ULONG WINAPI IStream_fnAddRef(IStream *iface)
134 ICOM_THIS(ISHRegStream, iface);
136 TRACE("(%p)->(count=%lu)\n",This, This->ref);
138 return ++(This->ref);
141 /**************************************************************************
142 * IStream_fnRelease
144 static ULONG WINAPI IStream_fnRelease(IStream *iface)
146 ICOM_THIS(ISHRegStream, iface);
148 TRACE("(%p)->()\n",This);
150 if (!--(This->ref))
151 { TRACE(" destroying SHReg IStream (%p)\n",This);
153 if (This->pbBuffer)
154 HeapFree(GetProcessHeap(),0,This->pbBuffer);
156 if (This->hKey)
157 RegCloseKey(This->hKey);
159 HeapFree(GetProcessHeap(),0,This);
160 return 0;
162 return This->ref;
165 static HRESULT WINAPI IStream_fnRead (IStream * iface, void* pv, ULONG cb, ULONG* pcbRead)
167 ICOM_THIS(ISHRegStream, iface);
169 DWORD dwBytesToRead, dwBytesLeft;
171 TRACE("(%p)->(%p,0x%08lx,%p)\n",This, pv, cb, pcbRead);
173 if ( !pv )
174 return STG_E_INVALIDPOINTER;
176 dwBytesLeft = This->dwLength - This->dwPos;
178 if ( 0 >= dwBytesLeft ) /* end of buffer */
179 return S_FALSE;
181 dwBytesToRead = ( cb > dwBytesLeft) ? dwBytesLeft : cb;
183 memmove ( pv, (This->pbBuffer) + (This->dwPos), dwBytesToRead);
185 This->dwPos += dwBytesToRead; /* adjust pointer */
187 if (pcbRead)
188 *pcbRead = dwBytesToRead;
190 return S_OK;
192 static HRESULT WINAPI IStream_fnWrite (IStream * iface, const void* pv, ULONG cb, ULONG* pcbWritten)
194 ICOM_THIS(ISHRegStream, iface);
196 TRACE("(%p)\n",This);
198 return E_NOTIMPL;
200 static HRESULT WINAPI IStream_fnSeek (IStream * iface, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition)
202 ICOM_THIS(ISHRegStream, iface);
204 TRACE("(%p)\n",This);
206 return E_NOTIMPL;
208 static HRESULT WINAPI IStream_fnSetSize (IStream * iface, ULARGE_INTEGER libNewSize)
210 ICOM_THIS(ISHRegStream, iface);
212 TRACE("(%p)\n",This);
214 return E_NOTIMPL;
216 static HRESULT WINAPI IStream_fnCopyTo (IStream * iface, IStream* pstm, ULARGE_INTEGER cb, ULARGE_INTEGER* pcbRead, ULARGE_INTEGER* pcbWritten)
218 ICOM_THIS(ISHRegStream, iface);
220 TRACE("(%p)\n",This);
222 return E_NOTIMPL;
224 static HRESULT WINAPI IStream_fnCommit (IStream * iface, DWORD grfCommitFlags)
226 ICOM_THIS(ISHRegStream, iface);
228 TRACE("(%p)\n",This);
230 return E_NOTIMPL;
232 static HRESULT WINAPI IStream_fnRevert (IStream * iface)
234 ICOM_THIS(ISHRegStream, iface);
236 TRACE("(%p)\n",This);
238 return E_NOTIMPL;
240 static HRESULT WINAPI IStream_fnLockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
242 ICOM_THIS(ISHRegStream, iface);
244 TRACE("(%p)\n",This);
246 return E_NOTIMPL;
248 static HRESULT WINAPI IStream_fnUnlockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
250 ICOM_THIS(ISHRegStream, iface);
252 TRACE("(%p)\n",This);
254 return E_NOTIMPL;
256 static HRESULT WINAPI IStream_fnStat (IStream * iface, STATSTG* pstatstg, DWORD grfStatFlag)
258 ICOM_THIS(ISHRegStream, iface);
260 TRACE("(%p)\n",This);
262 return E_NOTIMPL;
264 static HRESULT WINAPI IStream_fnClone (IStream * iface, IStream** ppstm)
266 ICOM_THIS(ISHRegStream, iface);
268 TRACE("(%p)\n",This);
270 return E_NOTIMPL;
273 static struct ICOM_VTABLE(IStream) rstvt =
275 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
276 IStream_fnQueryInterface,
277 IStream_fnAddRef,
278 IStream_fnRelease,
279 IStream_fnRead,
280 IStream_fnWrite,
281 IStream_fnSeek,
282 IStream_fnSetSize,
283 IStream_fnCopyTo,
284 IStream_fnCommit,
285 IStream_fnRevert,
286 IStream_fnLockRegion,
287 IStream_fnUnlockRegion,
288 IStream_fnStat,
289 IStream_fnClone
293 /*************************************************************************
294 * SHOpenRegStreamA [SHLWAPI.@]
296 IStream * WINAPI SHOpenRegStreamA(
297 HKEY hkey,
298 LPCSTR pszSubkey,
299 LPCSTR pszValue,
300 DWORD grfMode)
302 TRACE("(0x%08x,%s,%s,0x%08lx)\n",
303 hkey, pszSubkey, pszValue, grfMode);
305 return IStream_ConstructorA(hkey, pszSubkey, pszValue, grfMode);
308 /*************************************************************************
309 * SHOpenRegStreamW [SHLWAPI.@]
311 IStream * WINAPI SHOpenRegStreamW(
312 HKEY hkey,
313 LPCWSTR pszSubkey,
314 LPCWSTR pszValue,
315 DWORD grfMode)
317 TRACE("(0x%08x,%s,%s,0x%08lx)\n",
318 hkey, debugstr_w(pszSubkey), debugstr_w(pszValue), grfMode);
320 return IStream_ConstructorW(hkey, pszSubkey, pszValue, grfMode);