source: trunk/src/shlwapi/regstream.c@ 8045

Last change on this file since 8045 was 7821, checked in by sandervl, 24 years ago

compile fix

File size: 7.4 KB
Line 
1/*
2 * SHRegOpenStream
3 */
4#ifdef __WIN32OS2__
5#define SHLWAPI_STREAM
6#endif
7#include <string.h>
8
9#include "winerror.h"
10#include "winbase.h"
11#include "winreg.h"
12#include "shlobj.h"
13
14#include "debugtools.h"
15
16DEFAULT_DEBUG_CHANNEL(shell);
17
18typedef struct
19{ ICOM_VFIELD(IStream);
20 DWORD ref;
21 HKEY hKey;
22 LPBYTE pbBuffer;
23 DWORD dwLength;
24 DWORD dwPos;
25} ISHRegStream;
26
27static struct ICOM_VTABLE(IStream) rstvt;
28
29/**************************************************************************
30* IStream_ConstructorA [internal]
31*/
32static IStream *IStream_ConstructorA(HKEY hKey, LPCSTR pszSubKey, LPCSTR pszValue, DWORD grfMode)
33{
34 ISHRegStream* rstr;
35 DWORD dwType;
36
37 rstr = (ISHRegStream*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ISHRegStream));
38
39 ICOM_VTBL(rstr)=&rstvt;
40 rstr->ref = 1;
41
42 if (!(RegOpenKeyExA (hKey, pszSubKey, 0, KEY_READ, &(rstr->hKey))))
43 {
44 if (!(RegQueryValueExA(rstr->hKey, pszValue,0,0,0,&(rstr->dwLength))))
45 {
46 /* read the binary data into the buffer */
47 if((rstr->pbBuffer = HeapAlloc(GetProcessHeap(),0,rstr->dwLength)))
48 {
49 if (!(RegQueryValueExA(rstr->hKey, pszValue,0,&dwType,rstr->pbBuffer,&(rstr->dwLength))))
50 {
51 if (dwType == REG_BINARY )
52 {
53 TRACE ("%p\n", rstr);
54 return (IStream*)rstr;
55 }
56 }
57 HeapFree (GetProcessHeap(),0,rstr->pbBuffer);
58 }
59 }
60 RegCloseKey(rstr->hKey);
61 }
62 HeapFree (GetProcessHeap(),0,rstr);
63 return NULL;
64}
65
66/**************************************************************************
67* IStream_ConstructorW [internal]
68*/
69static IStream *IStream_ConstructorW(HKEY hKey, LPCWSTR pszSubKey, LPCWSTR pszValue, DWORD grfMode)
70{
71 ISHRegStream* rstr;
72 DWORD dwType;
73
74 rstr = (ISHRegStream*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ISHRegStream));
75
76 ICOM_VTBL(rstr)=&rstvt;
77 rstr->ref = 1;
78
79 if (!(RegOpenKeyExW (hKey, pszSubKey, 0, KEY_READ, &(rstr->hKey))))
80 {
81 if (!(RegQueryValueExW(rstr->hKey, pszValue,0,0,0,&(rstr->dwLength))))
82 {
83 /* read the binary data into the buffer */
84 if((rstr->pbBuffer = HeapAlloc(GetProcessHeap(),0,rstr->dwLength)))
85 {
86 if (!(RegQueryValueExW(rstr->hKey, pszValue,0,&dwType,rstr->pbBuffer,&(rstr->dwLength))))
87 {
88 if (dwType == REG_BINARY )
89 {
90 TRACE ("%p\n", rstr);
91 return (IStream*)rstr;
92 }
93 }
94 HeapFree (GetProcessHeap(),0,rstr->pbBuffer);
95 }
96 }
97 RegCloseKey(rstr->hKey);
98 }
99 HeapFree (GetProcessHeap(),0,rstr);
100 return NULL;
101}
102
103/**************************************************************************
104* IStream_fnQueryInterface
105*/
106static HRESULT WINAPI IStream_fnQueryInterface(IStream *iface, REFIID riid, LPVOID *ppvObj)
107{
108 ICOM_THIS(ISHRegStream, iface);
109
110 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
111
112 *ppvObj = NULL;
113
114 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
115 { *ppvObj = This;
116 }
117 else if(IsEqualIID(riid, &IID_IStream)) /*IStream*/
118 { *ppvObj = This;
119 }
120
121 if(*ppvObj)
122 {
123 IStream_AddRef((IStream*)*ppvObj);
124 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
125 return S_OK;
126 }
127 TRACE("-- Interface: E_NOINTERFACE\n");
128 return E_NOINTERFACE;
129}
130
131/**************************************************************************
132* IStream_fnAddRef
133*/
134static ULONG WINAPI IStream_fnAddRef(IStream *iface)
135{
136 ICOM_THIS(ISHRegStream, iface);
137
138 TRACE("(%p)->(count=%lu)\n",This, This->ref);
139
140 return ++(This->ref);
141}
142
143/**************************************************************************
144* IStream_fnRelease
145*/
146static ULONG WINAPI IStream_fnRelease(IStream *iface)
147{
148 ICOM_THIS(ISHRegStream, iface);
149
150 TRACE("(%p)->()\n",This);
151
152 if (!--(This->ref))
153 { TRACE(" destroying SHReg IStream (%p)\n",This);
154
155 if (This->pbBuffer)
156 HeapFree(GetProcessHeap(),0,This->pbBuffer);
157
158 if (This->hKey)
159 RegCloseKey(This->hKey);
160
161 HeapFree(GetProcessHeap(),0,This);
162 return 0;
163 }
164 return This->ref;
165}
166
167static HRESULT WINAPI IStream_fnRead (IStream * iface, void* pv, ULONG cb, ULONG* pcbRead)
168{
169 ICOM_THIS(ISHRegStream, iface);
170
171 DWORD dwBytesToRead, dwBytesLeft;
172
173 TRACE("(%p)->(%p,0x%08lx,%p)\n",This, pv, cb, pcbRead);
174
175 if ( !pv )
176 return STG_E_INVALIDPOINTER;
177
178 dwBytesLeft = This->dwLength - This->dwPos;
179
180 if ( 0 >= dwBytesLeft ) /* end of buffer */
181 return S_FALSE;
182
183 dwBytesToRead = ( cb > dwBytesLeft) ? dwBytesLeft : cb;
184
185 memmove ( pv, (This->pbBuffer) + (This->dwPos), dwBytesToRead);
186
187 This->dwPos += dwBytesToRead; /* adjust pointer */
188
189 if (pcbRead)
190 *pcbRead = dwBytesToRead;
191
192 return S_OK;
193}
194static HRESULT WINAPI IStream_fnWrite (IStream * iface, const void* pv, ULONG cb, ULONG* pcbWritten)
195{
196 ICOM_THIS(ISHRegStream, iface);
197
198 TRACE("(%p)\n",This);
199
200 return E_NOTIMPL;
201}
202static HRESULT WINAPI IStream_fnSeek (IStream * iface, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition)
203{
204 ICOM_THIS(ISHRegStream, iface);
205
206 TRACE("(%p)\n",This);
207
208 return E_NOTIMPL;
209}
210static HRESULT WINAPI IStream_fnSetSize (IStream * iface, ULARGE_INTEGER libNewSize)
211{
212 ICOM_THIS(ISHRegStream, iface);
213
214 TRACE("(%p)\n",This);
215
216 return E_NOTIMPL;
217}
218static HRESULT WINAPI IStream_fnCopyTo (IStream * iface, IStream* pstm, ULARGE_INTEGER cb, ULARGE_INTEGER* pcbRead, ULARGE_INTEGER* pcbWritten)
219{
220 ICOM_THIS(ISHRegStream, iface);
221
222 TRACE("(%p)\n",This);
223
224 return E_NOTIMPL;
225}
226static HRESULT WINAPI IStream_fnCommit (IStream * iface, DWORD grfCommitFlags)
227{
228 ICOM_THIS(ISHRegStream, iface);
229
230 TRACE("(%p)\n",This);
231
232 return E_NOTIMPL;
233}
234static HRESULT WINAPI IStream_fnRevert (IStream * iface)
235{
236 ICOM_THIS(ISHRegStream, iface);
237
238 TRACE("(%p)\n",This);
239
240 return E_NOTIMPL;
241}
242static HRESULT WINAPI IStream_fnLockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
243{
244 ICOM_THIS(ISHRegStream, iface);
245
246 TRACE("(%p)\n",This);
247
248 return E_NOTIMPL;
249}
250static HRESULT WINAPI IStream_fnUnlockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
251{
252 ICOM_THIS(ISHRegStream, iface);
253
254 TRACE("(%p)\n",This);
255
256 return E_NOTIMPL;
257}
258static HRESULT WINAPI IStream_fnStat (IStream * iface, STATSTG* pstatstg, DWORD grfStatFlag)
259{
260 ICOM_THIS(ISHRegStream, iface);
261
262 TRACE("(%p)\n",This);
263
264 return E_NOTIMPL;
265}
266static HRESULT WINAPI IStream_fnClone (IStream * iface, IStream** ppstm)
267{
268 ICOM_THIS(ISHRegStream, iface);
269
270 TRACE("(%p)\n",This);
271
272 return E_NOTIMPL;
273}
274
275static struct ICOM_VTABLE(IStream) rstvt =
276{
277 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
278 IStream_fnQueryInterface,
279 IStream_fnAddRef,
280 IStream_fnRelease,
281 IStream_fnRead,
282 IStream_fnWrite,
283 IStream_fnSeek,
284 IStream_fnSetSize,
285 IStream_fnCopyTo,
286 IStream_fnCommit,
287 IStream_fnRevert,
288 IStream_fnLockRegion,
289 IStream_fnUnlockRegion,
290 IStream_fnStat,
291 IStream_fnClone
292
293};
294
295/*************************************************************************
296 * SHOpenRegStreamA [SHLWAPI.@]
297 * SHOpenRegStream2A [SHLWAPI.@]
298 */
299IStream * WINAPI SHOpenRegStreamA(
300 HKEY hkey,
301 LPCSTR pszSubkey,
302 LPCSTR pszValue,
303 DWORD grfMode)
304{
305 TRACE("(0x%08x,%s,%s,0x%08lx)\n",
306 hkey, pszSubkey, pszValue, grfMode);
307
308 return IStream_ConstructorA(hkey, pszSubkey, pszValue, grfMode);
309}
310
311/*************************************************************************
312 * SHOpenRegStreamW [SHLWAPI.@]
313 * SHOpenRegStream2W [SHLWAPI.@]
314 */
315IStream * WINAPI SHOpenRegStreamW(
316 HKEY hkey,
317 LPCWSTR pszSubkey,
318 LPCWSTR pszValue,
319 DWORD grfMode)
320{
321 TRACE("(0x%08x,%s,%s,0x%08lx)\n",
322 hkey, debugstr_w(pszSubkey), debugstr_w(pszValue), grfMode);
323
324 return IStream_ConstructorW(hkey, pszSubkey, pszValue, grfMode);
325}
Note: See TracBrowser for help on using the repository browser.