source: trunk/src/shlwapi/regstream.c

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

resynced with latest Wine

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