6 #include "wine/obj_storage.h"
15 #include "shell32_main.h"
17 DEFAULT_DEBUG_CHANNEL(shell
)
20 { ICOM_VTABLE(IStream
)* lpvtbl
;
30 static struct ICOM_VTABLE(IStream
) rstvt
;
32 /**************************************************************************
33 * IStream_Constructor()
35 IStream
*IStream_Constructor(HKEY hKey
, LPCSTR pszSubKey
, LPCSTR pszValue
, DWORD grfMode
)
39 rstr
= (ISHRegStream
*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(ISHRegStream
));
43 if ( ERROR_SUCCESS
== RegOpenKeyExA (hKey
, pszSubKey
, 0, KEY_READ
, &(rstr
->hKey
)))
44 { if ( ERROR_SUCCESS
== RegQueryValueExA(rstr
->hKey
, (LPSTR
)pszValue
,0,0,0,&(rstr
->dwLength
)))
46 /* read the binary data into the buffer */
47 rstr
->pbBuffer
= HeapAlloc(GetProcessHeap(),0,rstr
->dwLength
);
49 { if ( ERROR_SUCCESS
== RegQueryValueExA(rstr
->hKey
, (LPSTR
)pszValue
,0,&dwType
,rstr
->pbBuffer
,&(rstr
->dwLength
)))
50 { if (dwType
== REG_BINARY
)
51 { rstr
->pszSubKey
= HEAP_strdupA (GetProcessHeap(),0, pszSubKey
);
52 rstr
->pszValue
= HEAP_strdupA (GetProcessHeap(),0, pszValue
);
53 TRACE(shell
,"(%p)->0x%08x,%s,%s,0x%08lx\n", rstr
, hKey
, pszSubKey
, pszValue
, grfMode
);
55 return (IStream
*)rstr
;
58 HeapFree (GetProcessHeap(),0,rstr
->pbBuffer
);
61 RegCloseKey(rstr
->hKey
);
64 HeapFree (GetProcessHeap(),0,rstr
);
68 /**************************************************************************
69 * IStream_fnQueryInterface
71 static HRESULT WINAPI
IStream_fnQueryInterface(IStream
*iface
, REFIID riid
, LPVOID
*ppvObj
)
73 ICOM_THIS(ISHRegStream
, iface
);
76 WINE_StringFromCLSID((LPCLSID
)riid
,xriid
);
78 TRACE(shell
,"(%p)->(\n\tIID:\t%s,%p)\n",This
,xriid
,ppvObj
);
82 if(IsEqualIID(riid
, &IID_IUnknown
)) /*IUnknown*/
85 else if(IsEqualIID(riid
, &IID_IStream
)) /*IStream*/
91 IStream_AddRef((IStream
*)*ppvObj
);
92 TRACE(shell
,"-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
95 TRACE(shell
,"-- Interface: E_NOINTERFACE\n");
99 /**************************************************************************
102 static ULONG WINAPI
IStream_fnAddRef(IStream
*iface
)
104 ICOM_THIS(ISHRegStream
, iface
);
106 TRACE(shell
,"(%p)->(count=%lu)\n",This
, This
->ref
);
109 return ++(This
->ref
);
112 /**************************************************************************
115 static ULONG WINAPI
IStream_fnRelease(IStream
*iface
)
117 ICOM_THIS(ISHRegStream
, iface
);
119 TRACE(shell
,"(%p)->()\n",This
);
124 { TRACE(shell
," destroying SHReg IStream (%p)\n",This
);
127 HeapFree(GetProcessHeap(),0,This
->pszSubKey
);
130 HeapFree(GetProcessHeap(),0,This
->pszValue
);
133 HeapFree(GetProcessHeap(),0,This
->pbBuffer
);
136 RegCloseKey(This
->hKey
);
138 HeapFree(GetProcessHeap(),0,This
);
144 HRESULT WINAPI
IStream_fnRead (IStream
* iface
, void* pv
, ULONG cb
, ULONG
* pcbRead
)
146 ICOM_THIS(ISHRegStream
, iface
);
148 DWORD dwBytesToRead
, dwBytesLeft
;
150 TRACE(shell
,"(%p)->(%p,0x%08lx,%p)\n",This
, pv
, cb
, pcbRead
);
153 return STG_E_INVALIDPOINTER
;
155 dwBytesLeft
= This
->dwLength
- This
->dwPos
;
157 if ( 0 >= dwBytesLeft
) /* end of buffer */
160 dwBytesToRead
= ( cb
> dwBytesLeft
) ? dwBytesLeft
: cb
;
162 memmove ( pv
, (This
->pbBuffer
) + (This
->dwPos
), dwBytesToRead
);
164 This
->dwPos
+= dwBytesToRead
; /* adjust pointer */
167 *pcbRead
= dwBytesToRead
;
171 HRESULT WINAPI
IStream_fnWrite (IStream
* iface
, const void* pv
, ULONG cb
, ULONG
* pcbWritten
)
173 ICOM_THIS(ISHRegStream
, iface
);
175 TRACE(shell
,"(%p)\n",This
);
179 HRESULT WINAPI
IStream_fnSeek (IStream
* iface
, LARGE_INTEGER dlibMove
, DWORD dwOrigin
, ULARGE_INTEGER
* plibNewPosition
)
181 ICOM_THIS(ISHRegStream
, iface
);
183 TRACE(shell
,"(%p)\n",This
);
187 HRESULT WINAPI
IStream_fnSetSize (IStream
* iface
, ULARGE_INTEGER libNewSize
)
189 ICOM_THIS(ISHRegStream
, iface
);
191 TRACE(shell
,"(%p)\n",This
);
195 HRESULT WINAPI
IStream_fnCopyTo (IStream
* iface
, IStream
* pstm
, ULARGE_INTEGER cb
, ULARGE_INTEGER
* pcbRead
, ULARGE_INTEGER
* pcbWritten
)
197 ICOM_THIS(ISHRegStream
, iface
);
199 TRACE(shell
,"(%p)\n",This
);
203 HRESULT WINAPI
IStream_fnCommit (IStream
* iface
, DWORD grfCommitFlags
)
205 ICOM_THIS(ISHRegStream
, iface
);
207 TRACE(shell
,"(%p)\n",This
);
211 HRESULT WINAPI
IStream_fnRevert (IStream
* iface
)
213 ICOM_THIS(ISHRegStream
, iface
);
215 TRACE(shell
,"(%p)\n",This
);
219 HRESULT WINAPI
IStream_fnLockRegion (IStream
* iface
, ULARGE_INTEGER libOffset
, ULARGE_INTEGER cb
, DWORD dwLockType
)
221 ICOM_THIS(ISHRegStream
, iface
);
223 TRACE(shell
,"(%p)\n",This
);
227 HRESULT WINAPI
IStream_fnUnlockRegion (IStream
* iface
, ULARGE_INTEGER libOffset
, ULARGE_INTEGER cb
, DWORD dwLockType
)
229 ICOM_THIS(ISHRegStream
, iface
);
231 TRACE(shell
,"(%p)\n",This
);
235 HRESULT WINAPI
IStream_fnStat (IStream
* iface
, STATSTG
* pstatstg
, DWORD grfStatFlag
)
237 ICOM_THIS(ISHRegStream
, iface
);
239 TRACE(shell
,"(%p)\n",This
);
243 HRESULT WINAPI
IStream_fnClone (IStream
* iface
, IStream
** ppstm
)
245 ICOM_THIS(ISHRegStream
, iface
);
247 TRACE(shell
,"(%p)\n",This
);
252 static struct ICOM_VTABLE(IStream
) rstvt
=
254 IStream_fnQueryInterface
,
264 IStream_fnLockRegion
,
265 IStream_fnUnlockRegion
,
271 /*************************************************************************
272 * OpenRegStream [SHELL32.85]
275 * exported by ordinal
277 IStream
* WINAPI
OpenRegStream(HKEY hkey
, LPCSTR pszSubkey
, LPCSTR pszValue
, DWORD grfMode
)
279 TRACE(shell
,"(0x%08x,%s,%s,0x%08lx)\n",hkey
, pszSubkey
, pszValue
, grfMode
);
280 return IStream_Constructor(hkey
, pszSubkey
, pszValue
, grfMode
);