6 #include "wine/obj_storage.h"
8 #include "debugtools.h"
13 #include "shell32_main.h"
15 DEFAULT_DEBUG_CHANNEL(shell
)
18 { ICOM_VFIELD(IStream
);
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
));
38 ICOM_VTBL(rstr
)=&rstvt
;
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
);
73 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This
,debugstr_guid(riid
),ppvObj
);
77 if(IsEqualIID(riid
, &IID_IUnknown
)) /*IUnknown*/
80 else if(IsEqualIID(riid
, &IID_IStream
)) /*IStream*/
86 IStream_AddRef((IStream
*)*ppvObj
);
87 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
90 TRACE("-- Interface: E_NOINTERFACE\n");
94 /**************************************************************************
97 static ULONG WINAPI
IStream_fnAddRef(IStream
*iface
)
99 ICOM_THIS(ISHRegStream
, iface
);
101 TRACE("(%p)->(count=%lu)\n",This
, This
->ref
);
104 return ++(This
->ref
);
107 /**************************************************************************
110 static ULONG WINAPI
IStream_fnRelease(IStream
*iface
)
112 ICOM_THIS(ISHRegStream
, iface
);
114 TRACE("(%p)->()\n",This
);
119 { TRACE(" destroying SHReg IStream (%p)\n",This
);
122 HeapFree(GetProcessHeap(),0,This
->pszSubKey
);
125 HeapFree(GetProcessHeap(),0,This
->pszValue
);
128 HeapFree(GetProcessHeap(),0,This
->pbBuffer
);
131 RegCloseKey(This
->hKey
);
133 HeapFree(GetProcessHeap(),0,This
);
139 HRESULT WINAPI
IStream_fnRead (IStream
* iface
, void* pv
, ULONG cb
, ULONG
* pcbRead
)
141 ICOM_THIS(ISHRegStream
, iface
);
143 DWORD dwBytesToRead
, dwBytesLeft
;
145 TRACE("(%p)->(%p,0x%08lx,%p)\n",This
, pv
, cb
, pcbRead
);
148 return STG_E_INVALIDPOINTER
;
150 dwBytesLeft
= This
->dwLength
- This
->dwPos
;
152 if ( 0 >= dwBytesLeft
) /* end of buffer */
155 dwBytesToRead
= ( cb
> dwBytesLeft
) ? dwBytesLeft
: cb
;
157 memmove ( pv
, (This
->pbBuffer
) + (This
->dwPos
), dwBytesToRead
);
159 This
->dwPos
+= dwBytesToRead
; /* adjust pointer */
162 *pcbRead
= dwBytesToRead
;
166 HRESULT WINAPI
IStream_fnWrite (IStream
* iface
, const void* pv
, ULONG cb
, ULONG
* pcbWritten
)
168 ICOM_THIS(ISHRegStream
, iface
);
170 TRACE("(%p)\n",This
);
174 HRESULT WINAPI
IStream_fnSeek (IStream
* iface
, LARGE_INTEGER dlibMove
, DWORD dwOrigin
, ULARGE_INTEGER
* plibNewPosition
)
176 ICOM_THIS(ISHRegStream
, iface
);
178 TRACE("(%p)\n",This
);
182 HRESULT WINAPI
IStream_fnSetSize (IStream
* iface
, ULARGE_INTEGER libNewSize
)
184 ICOM_THIS(ISHRegStream
, iface
);
186 TRACE("(%p)\n",This
);
190 HRESULT WINAPI
IStream_fnCopyTo (IStream
* iface
, IStream
* pstm
, ULARGE_INTEGER cb
, ULARGE_INTEGER
* pcbRead
, ULARGE_INTEGER
* pcbWritten
)
192 ICOM_THIS(ISHRegStream
, iface
);
194 TRACE("(%p)\n",This
);
198 HRESULT WINAPI
IStream_fnCommit (IStream
* iface
, DWORD grfCommitFlags
)
200 ICOM_THIS(ISHRegStream
, iface
);
202 TRACE("(%p)\n",This
);
206 HRESULT WINAPI
IStream_fnRevert (IStream
* iface
)
208 ICOM_THIS(ISHRegStream
, iface
);
210 TRACE("(%p)\n",This
);
214 HRESULT WINAPI
IStream_fnLockRegion (IStream
* iface
, ULARGE_INTEGER libOffset
, ULARGE_INTEGER cb
, DWORD dwLockType
)
216 ICOM_THIS(ISHRegStream
, iface
);
218 TRACE("(%p)\n",This
);
222 HRESULT WINAPI
IStream_fnUnlockRegion (IStream
* iface
, ULARGE_INTEGER libOffset
, ULARGE_INTEGER cb
, DWORD dwLockType
)
224 ICOM_THIS(ISHRegStream
, iface
);
226 TRACE("(%p)\n",This
);
230 HRESULT WINAPI
IStream_fnStat (IStream
* iface
, STATSTG
* pstatstg
, DWORD grfStatFlag
)
232 ICOM_THIS(ISHRegStream
, iface
);
234 TRACE("(%p)\n",This
);
238 HRESULT WINAPI
IStream_fnClone (IStream
* iface
, IStream
** ppstm
)
240 ICOM_THIS(ISHRegStream
, iface
);
242 TRACE("(%p)\n",This
);
247 static struct ICOM_VTABLE(IStream
) rstvt
=
249 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
250 IStream_fnQueryInterface
,
260 IStream_fnLockRegion
,
261 IStream_fnUnlockRegion
,
267 /*************************************************************************
268 * OpenRegStream [SHELL32.85]
271 * exported by ordinal
273 IStream
* WINAPI
OpenRegStream(HKEY hkey
, LPCSTR pszSubkey
, LPCSTR pszValue
, DWORD grfMode
)
275 TRACE("(0x%08x,%s,%s,0x%08lx)\n",hkey
, pszSubkey
, pszValue
, grfMode
);
276 return IStream_Constructor(hkey
, pszSubkey
, pszValue
, grfMode
);