source: trunk/src/shell32/new/regstream.cpp@ 791

Last change on this file since 791 was 791, checked in by phaller, 26 years ago

Add: shell32/new - a direct port of WINE's Shell32 implmentation

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