8 #include "wine/obj_storage.h"
11 #include "debugtools.h"
13 DEFAULT_DEBUG_CHANNEL(shell);
16 { ICOM_VFIELD(IStream);
24 static struct ICOM_VTABLE(IStream) rstvt;
26 /**************************************************************************
27 * IStream_ConstructorA [internal]
29 static IStream *IStream_ConstructorA(HKEY hKey, LPCSTR pszSubKey, LPCSTR pszValue, DWORD grfMode)
34 rstr = (ISHRegStream*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ISHRegStream));
36 ICOM_VTBL(rstr)=&rstvt;
39 if (!(RegOpenKeyExA (hKey, pszSubKey, 0, KEY_READ, &(rstr->hKey))))
41 if (!(RegQueryValueExA(rstr->hKey, pszValue,0,0,0,&(rstr->dwLength))))
43 /* read the binary data into the buffer */
44 if((rstr->pbBuffer = HeapAlloc(GetProcessHeap(),0,rstr->dwLength)))
46 if (!(RegQueryValueExA(rstr->hKey, pszValue,0,&dwType,rstr->pbBuffer,&(rstr->dwLength))))
48 if (dwType == REG_BINARY )
51 return (IStream*)rstr;
54 HeapFree (GetProcessHeap(),0,rstr->pbBuffer);
57 RegCloseKey(rstr->hKey);
59 HeapFree (GetProcessHeap(),0,rstr);
63 /**************************************************************************
64 * IStream_ConstructorW [internal]
66 static IStream *IStream_ConstructorW(HKEY hKey, LPCWSTR pszSubKey, LPCWSTR pszValue, DWORD grfMode)
71 rstr = (ISHRegStream*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ISHRegStream));
73 ICOM_VTBL(rstr)=&rstvt;
76 if (!(RegOpenKeyExW (hKey, pszSubKey, 0, KEY_READ, &(rstr->hKey))))
78 if (!(RegQueryValueExW(rstr->hKey, pszValue,0,0,0,&(rstr->dwLength))))
80 /* read the binary data into the buffer */
81 if((rstr->pbBuffer = HeapAlloc(GetProcessHeap(),0,rstr->dwLength)))
83 if (!(RegQueryValueExW(rstr->hKey, pszValue,0,&dwType,rstr->pbBuffer,&(rstr->dwLength))))
85 if (dwType == REG_BINARY )
88 return (IStream*)rstr;
91 HeapFree (GetProcessHeap(),0,rstr->pbBuffer);
94 RegCloseKey(rstr->hKey);
96 HeapFree (GetProcessHeap(),0,rstr);
100 /**************************************************************************
101 * IStream_fnQueryInterface
103 static HRESULT WINAPI IStream_fnQueryInterface(IStream *iface, REFIID riid, LPVOID *ppvObj)
105 ICOM_THIS(ISHRegStream, iface);
107 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
111 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
114 else if(IsEqualIID(riid, &IID_IStream)) /*IStream*/
120 IStream_AddRef((IStream*)*ppvObj);
121 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
124 TRACE("-- Interface: E_NOINTERFACE\n");
125 return E_NOINTERFACE;
128 /**************************************************************************
131 static ULONG WINAPI IStream_fnAddRef(IStream *iface)
133 ICOM_THIS(ISHRegStream, iface);
135 TRACE("(%p)->(count=%lu)\n",This, This->ref);
137 return ++(This->ref);
140 /**************************************************************************
143 static ULONG WINAPI IStream_fnRelease(IStream *iface)
145 ICOM_THIS(ISHRegStream, iface);
147 TRACE("(%p)->()\n",This);
150 { TRACE(" destroying SHReg IStream (%p)\n",This);
153 HeapFree(GetProcessHeap(),0,This->pbBuffer);
156 RegCloseKey(This->hKey);
158 HeapFree(GetProcessHeap(),0,This);
164 static HRESULT WINAPI IStream_fnRead (IStream * iface, void* pv, ULONG cb, ULONG* pcbRead)
166 ICOM_THIS(ISHRegStream, iface);
168 DWORD dwBytesToRead, dwBytesLeft;
170 TRACE("(%p)->(%p,0x%08lx,%p)\n",This, pv, cb, pcbRead);
173 return STG_E_INVALIDPOINTER;
175 dwBytesLeft = This->dwLength - This->dwPos;
177 if ( 0 >= dwBytesLeft ) /* end of buffer */
180 dwBytesToRead = ( cb > dwBytesLeft) ? dwBytesLeft : cb;
182 memmove ( pv, (This->pbBuffer) + (This->dwPos), dwBytesToRead);
184 This->dwPos += dwBytesToRead; /* adjust pointer */
187 *pcbRead = dwBytesToRead;
191 static HRESULT WINAPI IStream_fnWrite (IStream * iface, const void* pv, ULONG cb, ULONG* pcbWritten)
193 ICOM_THIS(ISHRegStream, iface);
195 TRACE("(%p)\n",This);
199 static HRESULT WINAPI IStream_fnSeek (IStream * iface, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition)
201 ICOM_THIS(ISHRegStream, iface);
203 TRACE("(%p)\n",This);
207 static HRESULT WINAPI IStream_fnSetSize (IStream * iface, ULARGE_INTEGER libNewSize)
209 ICOM_THIS(ISHRegStream, iface);
211 TRACE("(%p)\n",This);
215 static HRESULT WINAPI IStream_fnCopyTo (IStream * iface, IStream* pstm, ULARGE_INTEGER cb, ULARGE_INTEGER* pcbRead, ULARGE_INTEGER* pcbWritten)
217 ICOM_THIS(ISHRegStream, iface);
219 TRACE("(%p)\n",This);
223 static HRESULT WINAPI IStream_fnCommit (IStream * iface, DWORD grfCommitFlags)
225 ICOM_THIS(ISHRegStream, iface);
227 TRACE("(%p)\n",This);
231 static HRESULT WINAPI IStream_fnRevert (IStream * iface)
233 ICOM_THIS(ISHRegStream, iface);
235 TRACE("(%p)\n",This);
239 static HRESULT WINAPI IStream_fnLockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
241 ICOM_THIS(ISHRegStream, iface);
243 TRACE("(%p)\n",This);
247 static HRESULT WINAPI IStream_fnUnlockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
249 ICOM_THIS(ISHRegStream, iface);
251 TRACE("(%p)\n",This);
255 static HRESULT WINAPI IStream_fnStat (IStream * iface, STATSTG* pstatstg, DWORD grfStatFlag)
257 ICOM_THIS(ISHRegStream, iface);
259 TRACE("(%p)\n",This);
263 static HRESULT WINAPI IStream_fnClone (IStream * iface, IStream** ppstm)
265 ICOM_THIS(ISHRegStream, iface);
267 TRACE("(%p)\n",This);
272 static struct ICOM_VTABLE(IStream) rstvt =
274 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
275 IStream_fnQueryInterface,
285 IStream_fnLockRegion,
286 IStream_fnUnlockRegion,
292 /*************************************************************************
293 * SHOpenRegStreamA [SHLWAPI.@]
295 IStream * WINAPI SHOpenRegStreamA(
301 TRACE("(0x%08x,%s,%s,0x%08lx)\n",
302 hkey, pszSubkey, pszValue, grfMode);
304 return IStream_ConstructorA(hkey, pszSubkey, pszValue, grfMode);
307 /*************************************************************************
308 * SHOpenRegStreamW [SHLWAPI.@]
310 IStream * WINAPI SHOpenRegStreamW(
316 TRACE("(0x%08x,%s,%s,0x%08lx)\n",
317 hkey, debugstr_w(pszSubkey), debugstr_w(pszValue), grfMode);
319 return IStream_ConstructorW(hkey, pszSubkey, pszValue, grfMode);