4 * Copyright 1999 Juergen Schmied
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
33 { ICOM_VFIELD(IStream
);
41 static struct ICOM_VTABLE(IStream
) rstvt
;
43 /**************************************************************************
44 * IStream_ConstructorA [internal]
46 static IStream
*IStream_ConstructorA(HKEY hKey
, LPCSTR pszSubKey
, LPCSTR pszValue
, DWORD grfMode
)
51 rstr
= (ISHRegStream
*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(ISHRegStream
));
53 ICOM_VTBL(rstr
)=&rstvt
;
56 if (!(RegOpenKeyExA (hKey
, pszSubKey
, 0, KEY_READ
, &(rstr
->hKey
))))
58 if (!(RegQueryValueExA(rstr
->hKey
, pszValue
,0,0,0,&(rstr
->dwLength
))))
60 /* read the binary data into the buffer */
61 if((rstr
->pbBuffer
= HeapAlloc(GetProcessHeap(),0,rstr
->dwLength
)))
63 if (!(RegQueryValueExA(rstr
->hKey
, pszValue
,0,&dwType
,rstr
->pbBuffer
,&(rstr
->dwLength
))))
65 if (dwType
== REG_BINARY
)
68 return (IStream
*)rstr
;
71 HeapFree (GetProcessHeap(),0,rstr
->pbBuffer
);
74 RegCloseKey(rstr
->hKey
);
76 HeapFree (GetProcessHeap(),0,rstr
);
80 /**************************************************************************
81 * IStream_ConstructorW [internal]
83 static IStream
*IStream_ConstructorW(HKEY hKey
, LPCWSTR pszSubKey
, LPCWSTR pszValue
, DWORD grfMode
)
88 rstr
= (ISHRegStream
*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(ISHRegStream
));
90 ICOM_VTBL(rstr
)=&rstvt
;
93 if (!(RegOpenKeyExW (hKey
, pszSubKey
, 0, KEY_READ
, &(rstr
->hKey
))))
95 if (!(RegQueryValueExW(rstr
->hKey
, pszValue
,0,0,0,&(rstr
->dwLength
))))
97 /* read the binary data into the buffer */
98 if((rstr
->pbBuffer
= HeapAlloc(GetProcessHeap(),0,rstr
->dwLength
)))
100 if (!(RegQueryValueExW(rstr
->hKey
, pszValue
,0,&dwType
,rstr
->pbBuffer
,&(rstr
->dwLength
))))
102 if (dwType
== REG_BINARY
)
104 TRACE ("%p\n", rstr
);
105 return (IStream
*)rstr
;
108 HeapFree (GetProcessHeap(),0,rstr
->pbBuffer
);
111 RegCloseKey(rstr
->hKey
);
113 HeapFree (GetProcessHeap(),0,rstr
);
117 /**************************************************************************
118 * IStream_fnQueryInterface
120 static HRESULT WINAPI
IStream_fnQueryInterface(IStream
*iface
, REFIID riid
, LPVOID
*ppvObj
)
122 ICOM_THIS(ISHRegStream
, iface
);
124 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This
,debugstr_guid(riid
),ppvObj
);
128 if(IsEqualIID(riid
, &IID_IUnknown
)) /*IUnknown*/
131 else if(IsEqualIID(riid
, &IID_IStream
)) /*IStream*/
137 IStream_AddRef((IStream
*)*ppvObj
);
138 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
141 TRACE("-- Interface: E_NOINTERFACE\n");
142 return E_NOINTERFACE
;
145 /**************************************************************************
148 static ULONG WINAPI
IStream_fnAddRef(IStream
*iface
)
150 ICOM_THIS(ISHRegStream
, iface
);
152 TRACE("(%p)->(count=%lu)\n",This
, This
->ref
);
154 return ++(This
->ref
);
157 /**************************************************************************
160 static ULONG WINAPI
IStream_fnRelease(IStream
*iface
)
162 ICOM_THIS(ISHRegStream
, iface
);
164 TRACE("(%p)->()\n",This
);
167 { TRACE(" destroying SHReg IStream (%p)\n",This
);
170 HeapFree(GetProcessHeap(),0,This
->pbBuffer
);
173 RegCloseKey(This
->hKey
);
175 HeapFree(GetProcessHeap(),0,This
);
181 static HRESULT WINAPI
IStream_fnRead (IStream
* iface
, void* pv
, ULONG cb
, ULONG
* pcbRead
)
183 ICOM_THIS(ISHRegStream
, iface
);
185 DWORD dwBytesToRead
, dwBytesLeft
;
187 TRACE("(%p)->(%p,0x%08lx,%p)\n",This
, pv
, cb
, pcbRead
);
190 return STG_E_INVALIDPOINTER
;
192 dwBytesLeft
= This
->dwLength
- This
->dwPos
;
194 if ( 0 >= dwBytesLeft
) /* end of buffer */
197 dwBytesToRead
= ( cb
> dwBytesLeft
) ? dwBytesLeft
: cb
;
199 memmove ( pv
, (This
->pbBuffer
) + (This
->dwPos
), dwBytesToRead
);
201 This
->dwPos
+= dwBytesToRead
; /* adjust pointer */
204 *pcbRead
= dwBytesToRead
;
208 static HRESULT WINAPI
IStream_fnWrite (IStream
* iface
, const void* pv
, ULONG cb
, ULONG
* pcbWritten
)
210 ICOM_THIS(ISHRegStream
, iface
);
212 TRACE("(%p)\n",This
);
216 static HRESULT WINAPI
IStream_fnSeek (IStream
* iface
, LARGE_INTEGER dlibMove
, DWORD dwOrigin
, ULARGE_INTEGER
* plibNewPosition
)
218 ICOM_THIS(ISHRegStream
, iface
);
220 TRACE("(%p)\n",This
);
224 static HRESULT WINAPI
IStream_fnSetSize (IStream
* iface
, ULARGE_INTEGER libNewSize
)
226 ICOM_THIS(ISHRegStream
, iface
);
228 TRACE("(%p)\n",This
);
232 static HRESULT WINAPI
IStream_fnCopyTo (IStream
* iface
, IStream
* pstm
, ULARGE_INTEGER cb
, ULARGE_INTEGER
* pcbRead
, ULARGE_INTEGER
* pcbWritten
)
234 ICOM_THIS(ISHRegStream
, iface
);
236 TRACE("(%p)\n",This
);
240 static HRESULT WINAPI
IStream_fnCommit (IStream
* iface
, DWORD grfCommitFlags
)
242 ICOM_THIS(ISHRegStream
, iface
);
244 TRACE("(%p)\n",This
);
248 static HRESULT WINAPI
IStream_fnRevert (IStream
* iface
)
250 ICOM_THIS(ISHRegStream
, iface
);
252 TRACE("(%p)\n",This
);
256 static HRESULT WINAPI
IStream_fnLockRegion (IStream
* iface
, ULARGE_INTEGER libOffset
, ULARGE_INTEGER cb
, DWORD dwLockType
)
258 ICOM_THIS(ISHRegStream
, iface
);
260 TRACE("(%p)\n",This
);
264 static HRESULT WINAPI
IStream_fnUnlockRegion (IStream
* iface
, ULARGE_INTEGER libOffset
, ULARGE_INTEGER cb
, DWORD dwLockType
)
266 ICOM_THIS(ISHRegStream
, iface
);
268 TRACE("(%p)\n",This
);
272 static HRESULT WINAPI
IStream_fnStat (IStream
* iface
, STATSTG
* pstatstg
, DWORD grfStatFlag
)
274 ICOM_THIS(ISHRegStream
, iface
);
276 TRACE("(%p)\n",This
);
280 static HRESULT WINAPI
IStream_fnClone (IStream
* iface
, IStream
** ppstm
)
282 ICOM_THIS(ISHRegStream
, iface
);
284 TRACE("(%p)\n",This
);
289 static struct ICOM_VTABLE(IStream
) rstvt
=
291 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
292 IStream_fnQueryInterface
,
302 IStream_fnLockRegion
,
303 IStream_fnUnlockRegion
,
309 /*************************************************************************
310 * SHOpenRegStreamA [SHLWAPI.@]
311 * SHOpenRegStream2A [SHLWAPI.@]
313 IStream
* WINAPI
SHOpenRegStreamA(
319 TRACE("(0x%08x,%s,%s,0x%08lx)\n",
320 hkey
, pszSubkey
, pszValue
, grfMode
);
322 return IStream_ConstructorA(hkey
, pszSubkey
, pszValue
, grfMode
);
325 /*************************************************************************
326 * SHOpenRegStreamW [SHLWAPI.@]
327 * SHOpenRegStream2W [SHLWAPI.@]
329 IStream
* WINAPI
SHOpenRegStreamW(
335 TRACE("(0x%08x,%s,%s,0x%08lx)\n",
336 hkey
, debugstr_w(pszSubkey
), debugstr_w(pszValue
), grfMode
);
338 return IStream_ConstructorW(hkey
, pszSubkey
, pszValue
, grfMode
);