12 #include "debugtools.h"
14 DEFAULT_DEBUG_CHANNEL(shell);
17 { ICOM_VFIELD(IStream);
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)
35 rstr = (ISHRegStream*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ISHRegStream));
37 ICOM_VTBL(rstr)=&rstvt;
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 )
52 return (IStream*)rstr;
55 HeapFree (GetProcessHeap(),0,rstr->pbBuffer);
58 RegCloseKey(rstr->hKey);
60 HeapFree (GetProcessHeap(),0,rstr);
64 /**************************************************************************
65 * IStream_ConstructorW [internal]
67 static IStream *IStream_ConstructorW(HKEY hKey, LPCWSTR pszSubKey, LPCWSTR pszValue, DWORD grfMode)
72 rstr = (ISHRegStream*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ISHRegStream));
74 ICOM_VTBL(rstr)=&rstvt;
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 )
89 return (IStream*)rstr;
92 HeapFree (GetProcessHeap(),0,rstr->pbBuffer);
95 RegCloseKey(rstr->hKey);
97 HeapFree (GetProcessHeap(),0,rstr);
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);
112 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
115 else if(IsEqualIID(riid, &IID_IStream)) /*IStream*/
121 IStream_AddRef((IStream*)*ppvObj);
122 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
125 TRACE("-- Interface: E_NOINTERFACE\n");
126 return E_NOINTERFACE;
129 /**************************************************************************
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 /**************************************************************************
144 static ULONG WINAPI IStream_fnRelease(IStream *iface)
146 ICOM_THIS(ISHRegStream, iface);
148 TRACE("(%p)->()\n",This);
151 { TRACE(" destroying SHReg IStream (%p)\n",This);
154 HeapFree(GetProcessHeap(),0,This->pbBuffer);
157 RegCloseKey(This->hKey);
159 HeapFree(GetProcessHeap(),0,This);
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);
174 return STG_E_INVALIDPOINTER;
176 dwBytesLeft = This->dwLength - This->dwPos;
178 if ( 0 >= dwBytesLeft ) /* end of buffer */
181 dwBytesToRead = ( cb > dwBytesLeft) ? dwBytesLeft : cb;
183 memmove ( pv, (This->pbBuffer) + (This->dwPos), dwBytesToRead);
185 This->dwPos += dwBytesToRead; /* adjust pointer */
188 *pcbRead = dwBytesToRead;
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);
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);
208 static HRESULT WINAPI IStream_fnSetSize (IStream * iface, ULARGE_INTEGER libNewSize)
210 ICOM_THIS(ISHRegStream, iface);
212 TRACE("(%p)\n",This);
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);
224 static HRESULT WINAPI IStream_fnCommit (IStream * iface, DWORD grfCommitFlags)
226 ICOM_THIS(ISHRegStream, iface);
228 TRACE("(%p)\n",This);
232 static HRESULT WINAPI IStream_fnRevert (IStream * iface)
234 ICOM_THIS(ISHRegStream, iface);
236 TRACE("(%p)\n",This);
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);
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);
256 static HRESULT WINAPI IStream_fnStat (IStream * iface, STATSTG* pstatstg, DWORD grfStatFlag)
258 ICOM_THIS(ISHRegStream, iface);
260 TRACE("(%p)\n",This);
264 static HRESULT WINAPI IStream_fnClone (IStream * iface, IStream** ppstm)
266 ICOM_THIS(ISHRegStream, iface);
268 TRACE("(%p)\n",This);
273 static struct ICOM_VTABLE(IStream) rstvt =
275 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
276 IStream_fnQueryInterface,
286 IStream_fnLockRegion,
287 IStream_fnUnlockRegion,
293 /*************************************************************************
294 * SHOpenRegStreamA [SHLWAPI.@]
296 IStream * WINAPI SHOpenRegStreamA(
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(
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);