6 #include "wine/obj_storage.h"
8 #include "debugtools.h"
13 #include "shell32_main.h"
15 DEFAULT_DEBUG_CHANNEL(shell)
18 { ICOM_VTABLE(IStream)* lpvtbl;
28 static struct ICOM_VTABLE(IStream) rstvt;
30 /**************************************************************************
31 * IStream_Constructor()
33 IStream *IStream_Constructor(HKEY hKey, LPCSTR pszSubKey, LPCSTR pszValue, DWORD grfMode)
37 rstr = (ISHRegStream*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ISHRegStream));
41 if ( ERROR_SUCCESS == RegOpenKeyExA (hKey, pszSubKey, 0, KEY_READ, &(rstr->hKey)))
42 { if ( ERROR_SUCCESS == RegQueryValueExA(rstr->hKey, (LPSTR)pszValue,0,0,0,&(rstr->dwLength)))
44 /* read the binary data into the buffer */
45 rstr->pbBuffer = HeapAlloc(GetProcessHeap(),0,rstr->dwLength);
47 { if ( ERROR_SUCCESS == RegQueryValueExA(rstr->hKey, (LPSTR)pszValue,0,&dwType,rstr->pbBuffer,&(rstr->dwLength)))
48 { if (dwType == REG_BINARY )
49 { rstr->pszSubKey = HEAP_strdupA (GetProcessHeap(),0, pszSubKey);
50 rstr->pszValue = HEAP_strdupA (GetProcessHeap(),0, pszValue);
51 TRACE("(%p)->0x%08x,%s,%s,0x%08lx\n", rstr, hKey, pszSubKey, pszValue, grfMode);
53 return (IStream*)rstr;
56 HeapFree (GetProcessHeap(),0,rstr->pbBuffer);
59 RegCloseKey(rstr->hKey);
62 HeapFree (GetProcessHeap(),0,rstr);
66 /**************************************************************************
67 * IStream_fnQueryInterface
69 static HRESULT WINAPI IStream_fnQueryInterface(IStream *iface, REFIID riid, LPVOID *ppvObj)
71 ICOM_THIS(ISHRegStream, iface);
74 WINE_StringFromCLSID((LPCLSID)riid,xriid);
76 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,xriid,ppvObj);
80 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
83 else if(IsEqualIID(riid, &IID_IStream)) /*IStream*/
89 IStream_AddRef((IStream*)*ppvObj);
90 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
93 TRACE("-- Interface: E_NOINTERFACE\n");
97 /**************************************************************************
100 static ULONG WINAPI IStream_fnAddRef(IStream *iface)
102 ICOM_THIS(ISHRegStream, iface);
104 TRACE("(%p)->(count=%lu)\n",This, This->ref);
107 return ++(This->ref);
110 /**************************************************************************
113 static ULONG WINAPI IStream_fnRelease(IStream *iface)
115 ICOM_THIS(ISHRegStream, iface);
117 TRACE("(%p)->()\n",This);
122 { TRACE(" destroying SHReg IStream (%p)\n",This);
125 HeapFree(GetProcessHeap(),0,This->pszSubKey);
128 HeapFree(GetProcessHeap(),0,This->pszValue);
131 HeapFree(GetProcessHeap(),0,This->pbBuffer);
134 RegCloseKey(This->hKey);
136 HeapFree(GetProcessHeap(),0,This);
142 HRESULT WINAPI IStream_fnRead (IStream * iface, void* pv, ULONG cb, ULONG* pcbRead)
144 ICOM_THIS(ISHRegStream, iface);
146 DWORD dwBytesToRead, dwBytesLeft;
148 TRACE("(%p)->(%p,0x%08lx,%p)\n",This, pv, cb, pcbRead);
151 return STG_E_INVALIDPOINTER;
153 dwBytesLeft = This->dwLength - This->dwPos;
155 if ( 0 >= dwBytesLeft ) /* end of buffer */
158 dwBytesToRead = ( cb > dwBytesLeft) ? dwBytesLeft : cb;
160 memmove ( pv, (This->pbBuffer) + (This->dwPos), dwBytesToRead);
162 This->dwPos += dwBytesToRead; /* adjust pointer */
165 *pcbRead = dwBytesToRead;
169 HRESULT WINAPI IStream_fnWrite (IStream * iface, const void* pv, ULONG cb, ULONG* pcbWritten)
171 ICOM_THIS(ISHRegStream, iface);
173 TRACE("(%p)\n",This);
177 HRESULT WINAPI IStream_fnSeek (IStream * iface, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition)
179 ICOM_THIS(ISHRegStream, iface);
181 TRACE("(%p)\n",This);
185 HRESULT WINAPI IStream_fnSetSize (IStream * iface, ULARGE_INTEGER libNewSize)
187 ICOM_THIS(ISHRegStream, iface);
189 TRACE("(%p)\n",This);
193 HRESULT WINAPI IStream_fnCopyTo (IStream * iface, IStream* pstm, ULARGE_INTEGER cb, ULARGE_INTEGER* pcbRead, ULARGE_INTEGER* pcbWritten)
195 ICOM_THIS(ISHRegStream, iface);
197 TRACE("(%p)\n",This);
201 HRESULT WINAPI IStream_fnCommit (IStream * iface, DWORD grfCommitFlags)
203 ICOM_THIS(ISHRegStream, iface);
205 TRACE("(%p)\n",This);
209 HRESULT WINAPI IStream_fnRevert (IStream * iface)
211 ICOM_THIS(ISHRegStream, iface);
213 TRACE("(%p)\n",This);
217 HRESULT WINAPI IStream_fnLockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
219 ICOM_THIS(ISHRegStream, iface);
221 TRACE("(%p)\n",This);
225 HRESULT WINAPI IStream_fnUnlockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
227 ICOM_THIS(ISHRegStream, iface);
229 TRACE("(%p)\n",This);
233 HRESULT WINAPI IStream_fnStat (IStream * iface, STATSTG* pstatstg, DWORD grfStatFlag)
235 ICOM_THIS(ISHRegStream, iface);
237 TRACE("(%p)\n",This);
241 HRESULT WINAPI IStream_fnClone (IStream * iface, IStream** ppstm)
243 ICOM_THIS(ISHRegStream, iface);
245 TRACE("(%p)\n",This);
250 static struct ICOM_VTABLE(IStream) rstvt =
252 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
253 IStream_fnQueryInterface,
263 IStream_fnLockRegion,
264 IStream_fnUnlockRegion,
270 /*************************************************************************
271 * OpenRegStream [SHELL32.85]
274 * exported by ordinal
276 IStream * WINAPI OpenRegStream(HKEY hkey, LPCSTR pszSubkey, LPCSTR pszValue, DWORD grfMode)
278 TRACE("(0x%08x,%s,%s,0x%08lx)\n",hkey, pszSubkey, pszValue, grfMode);
279 return IStream_Constructor(hkey, pszSubkey, pszValue, grfMode);