6 #include "wine/obj_storage.h"
8 #include "debugtools.h"
13 #include "shell32_main.h"
15 DEFAULT_DEBUG_CHANNEL(shell
)
18 { ICOM_VFIELD(IStream
);
26 static struct ICOM_VTABLE(IStream
) rstvt
;
28 /**************************************************************************
29 * IStream_ConstructorA [internal]
31 IStream
*IStream_ConstructorA(HKEY hKey
, LPCSTR pszSubKey
, LPCSTR pszValue
, DWORD grfMode
)
36 rstr
= (ISHRegStream
*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(ISHRegStream
));
38 ICOM_VTBL(rstr
)=&rstvt
;
41 if (!(RegOpenKeyExA (hKey
, pszSubKey
, 0, KEY_READ
, &(rstr
->hKey
))))
43 if (!(RegQueryValueExA(rstr
->hKey
, pszValue
,0,0,0,&(rstr
->dwLength
))))
45 /* read the binary data into the buffer */
46 if((rstr
->pbBuffer
= HeapAlloc(GetProcessHeap(),0,rstr
->dwLength
)))
48 if (!(RegQueryValueExA(rstr
->hKey
, pszValue
,0,&dwType
,rstr
->pbBuffer
,&(rstr
->dwLength
))))
50 if (dwType
== REG_BINARY
)
54 return (IStream
*)rstr
;
57 HeapFree (GetProcessHeap(),0,rstr
->pbBuffer
);
60 RegCloseKey(rstr
->hKey
);
62 HeapFree (GetProcessHeap(),0,rstr
);
66 /**************************************************************************
67 * IStream_ConstructorW [internal]
69 IStream
*IStream_ConstructorW(HKEY hKey
, LPCWSTR pszSubKey
, LPCWSTR pszValue
, DWORD grfMode
)
74 rstr
= (ISHRegStream
*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(ISHRegStream
));
76 ICOM_VTBL(rstr
)=&rstvt
;
79 if (!(RegOpenKeyExW (hKey
, pszSubKey
, 0, KEY_READ
, &(rstr
->hKey
))))
81 if (!(RegQueryValueExW(rstr
->hKey
, pszValue
,0,0,0,&(rstr
->dwLength
))))
83 /* read the binary data into the buffer */
84 if((rstr
->pbBuffer
= HeapAlloc(GetProcessHeap(),0,rstr
->dwLength
)))
86 if (!(RegQueryValueExW(rstr
->hKey
, pszValue
,0,&dwType
,rstr
->pbBuffer
,&(rstr
->dwLength
))))
88 if (dwType
== REG_BINARY
)
92 return (IStream
*)rstr
;
95 HeapFree (GetProcessHeap(),0,rstr
->pbBuffer
);
98 RegCloseKey(rstr
->hKey
);
100 HeapFree (GetProcessHeap(),0,rstr
);
104 /**************************************************************************
105 * IStream_fnQueryInterface
107 static HRESULT WINAPI
IStream_fnQueryInterface(IStream
*iface
, REFIID riid
, LPVOID
*ppvObj
)
109 ICOM_THIS(ISHRegStream
, iface
);
111 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This
,debugstr_guid(riid
),ppvObj
);
115 if(IsEqualIID(riid
, &IID_IUnknown
)) /*IUnknown*/
118 else if(IsEqualIID(riid
, &IID_IStream
)) /*IStream*/
124 IStream_AddRef((IStream
*)*ppvObj
);
125 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
128 TRACE("-- Interface: E_NOINTERFACE\n");
129 return E_NOINTERFACE
;
132 /**************************************************************************
135 static ULONG WINAPI
IStream_fnAddRef(IStream
*iface
)
137 ICOM_THIS(ISHRegStream
, iface
);
139 TRACE("(%p)->(count=%lu)\n",This
, This
->ref
);
142 return ++(This
->ref
);
145 /**************************************************************************
148 static ULONG WINAPI
IStream_fnRelease(IStream
*iface
)
150 ICOM_THIS(ISHRegStream
, iface
);
152 TRACE("(%p)->()\n",This
);
157 { TRACE(" destroying SHReg IStream (%p)\n",This
);
160 HeapFree(GetProcessHeap(),0,This
->pbBuffer
);
163 RegCloseKey(This
->hKey
);
165 HeapFree(GetProcessHeap(),0,This
);
171 HRESULT WINAPI
IStream_fnRead (IStream
* iface
, void* pv
, ULONG cb
, ULONG
* pcbRead
)
173 ICOM_THIS(ISHRegStream
, iface
);
175 DWORD dwBytesToRead
, dwBytesLeft
;
177 TRACE("(%p)->(%p,0x%08lx,%p)\n",This
, pv
, cb
, pcbRead
);
180 return STG_E_INVALIDPOINTER
;
182 dwBytesLeft
= This
->dwLength
- This
->dwPos
;
184 if ( 0 >= dwBytesLeft
) /* end of buffer */
187 dwBytesToRead
= ( cb
> dwBytesLeft
) ? dwBytesLeft
: cb
;
189 memmove ( pv
, (This
->pbBuffer
) + (This
->dwPos
), dwBytesToRead
);
191 This
->dwPos
+= dwBytesToRead
; /* adjust pointer */
194 *pcbRead
= dwBytesToRead
;
198 HRESULT WINAPI
IStream_fnWrite (IStream
* iface
, const void* pv
, ULONG cb
, ULONG
* pcbWritten
)
200 ICOM_THIS(ISHRegStream
, iface
);
202 TRACE("(%p)\n",This
);
206 HRESULT WINAPI
IStream_fnSeek (IStream
* iface
, LARGE_INTEGER dlibMove
, DWORD dwOrigin
, ULARGE_INTEGER
* plibNewPosition
)
208 ICOM_THIS(ISHRegStream
, iface
);
210 TRACE("(%p)\n",This
);
214 HRESULT WINAPI
IStream_fnSetSize (IStream
* iface
, ULARGE_INTEGER libNewSize
)
216 ICOM_THIS(ISHRegStream
, iface
);
218 TRACE("(%p)\n",This
);
222 HRESULT WINAPI
IStream_fnCopyTo (IStream
* iface
, IStream
* pstm
, ULARGE_INTEGER cb
, ULARGE_INTEGER
* pcbRead
, ULARGE_INTEGER
* pcbWritten
)
224 ICOM_THIS(ISHRegStream
, iface
);
226 TRACE("(%p)\n",This
);
230 HRESULT WINAPI
IStream_fnCommit (IStream
* iface
, DWORD grfCommitFlags
)
232 ICOM_THIS(ISHRegStream
, iface
);
234 TRACE("(%p)\n",This
);
238 HRESULT WINAPI
IStream_fnRevert (IStream
* iface
)
240 ICOM_THIS(ISHRegStream
, iface
);
242 TRACE("(%p)\n",This
);
246 HRESULT WINAPI
IStream_fnLockRegion (IStream
* iface
, ULARGE_INTEGER libOffset
, ULARGE_INTEGER cb
, DWORD dwLockType
)
248 ICOM_THIS(ISHRegStream
, iface
);
250 TRACE("(%p)\n",This
);
254 HRESULT WINAPI
IStream_fnUnlockRegion (IStream
* iface
, ULARGE_INTEGER libOffset
, ULARGE_INTEGER cb
, DWORD dwLockType
)
256 ICOM_THIS(ISHRegStream
, iface
);
258 TRACE("(%p)\n",This
);
262 HRESULT WINAPI
IStream_fnStat (IStream
* iface
, STATSTG
* pstatstg
, DWORD grfStatFlag
)
264 ICOM_THIS(ISHRegStream
, iface
);
266 TRACE("(%p)\n",This
);
270 HRESULT WINAPI
IStream_fnClone (IStream
* iface
, IStream
** ppstm
)
272 ICOM_THIS(ISHRegStream
, iface
);
274 TRACE("(%p)\n",This
);
279 static struct ICOM_VTABLE(IStream
) rstvt
=
281 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
282 IStream_fnQueryInterface
,
292 IStream_fnLockRegion
,
293 IStream_fnUnlockRegion
,
299 /*************************************************************************
300 * SHOpenRegStreamA [SHLWAPI.@][SHELL32.85]
302 IStream
* WINAPI
SHOpenRegStreamA(
308 TRACE("(0x%08x,%s,%s,0x%08lx)\n",
309 hkey
, pszSubkey
, pszValue
, grfMode
);
311 return IStream_ConstructorA(hkey
, pszSubkey
, pszValue
, grfMode
);
314 /*************************************************************************
315 * SHOpenRegStreamW [SHLWAPI.@]
317 IStream
* WINAPI
SHOpenRegStreamW(
323 TRACE("(0x%08x,%s,%s,0x%08lx)\n",
324 hkey
, debugstr_w(pszSubkey
), debugstr_w(pszValue
), grfMode
);
326 return IStream_ConstructorW(hkey
, pszSubkey
, pszValue
, grfMode
);