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

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

initterm update

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