Fixed make install from read-only build directory (spotted by Marcus
[wine/wine64.git] / dlls / shlwapi / regstream.c
blob1b74e431b18a74e73f407b4ae5123bc19793384e
1 /*
2 * SHRegOpenStream
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
21 #include <string.h>
23 #include "winerror.h"
24 #include "winbase.h"
25 #include "winreg.h"
26 #include "shlobj.h"
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(shell);
32 typedef struct
33 { ICOM_VFIELD(IStream);
34 DWORD ref;
35 HKEY hKey;
36 LPBYTE pbBuffer;
37 DWORD dwLength;
38 DWORD dwPos;
39 } ISHRegStream;
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)
48 ISHRegStream* rstr;
49 DWORD dwType;
51 rstr = (ISHRegStream*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ISHRegStream));
53 ICOM_VTBL(rstr)=&rstvt;
54 rstr->ref = 1;
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 )
67 TRACE ("%p\n", rstr);
68 return (IStream*)rstr;
71 HeapFree (GetProcessHeap(),0,rstr->pbBuffer);
74 RegCloseKey(rstr->hKey);
76 HeapFree (GetProcessHeap(),0,rstr);
77 return NULL;
80 /**************************************************************************
81 * IStream_ConstructorW [internal]
83 static IStream *IStream_ConstructorW(HKEY hKey, LPCWSTR pszSubKey, LPCWSTR pszValue, DWORD grfMode)
85 ISHRegStream* rstr;
86 DWORD dwType;
88 rstr = (ISHRegStream*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ISHRegStream));
90 ICOM_VTBL(rstr)=&rstvt;
91 rstr->ref = 1;
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);
114 return NULL;
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);
126 *ppvObj = NULL;
128 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
129 { *ppvObj = This;
131 else if(IsEqualIID(riid, &IID_IStream)) /*IStream*/
132 { *ppvObj = This;
135 if(*ppvObj)
137 IStream_AddRef((IStream*)*ppvObj);
138 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
139 return S_OK;
141 TRACE("-- Interface: E_NOINTERFACE\n");
142 return E_NOINTERFACE;
145 /**************************************************************************
146 * IStream_fnAddRef
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 /**************************************************************************
158 * IStream_fnRelease
160 static ULONG WINAPI IStream_fnRelease(IStream *iface)
162 ICOM_THIS(ISHRegStream, iface);
164 TRACE("(%p)->()\n",This);
166 if (!--(This->ref))
167 { TRACE(" destroying SHReg IStream (%p)\n",This);
169 if (This->pbBuffer)
170 HeapFree(GetProcessHeap(),0,This->pbBuffer);
172 if (This->hKey)
173 RegCloseKey(This->hKey);
175 HeapFree(GetProcessHeap(),0,This);
176 return 0;
178 return This->ref;
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);
189 if ( !pv )
190 return STG_E_INVALIDPOINTER;
192 dwBytesLeft = This->dwLength - This->dwPos;
194 if ( 0 >= dwBytesLeft ) /* end of buffer */
195 return S_FALSE;
197 dwBytesToRead = ( cb > dwBytesLeft) ? dwBytesLeft : cb;
199 memmove ( pv, (This->pbBuffer) + (This->dwPos), dwBytesToRead);
201 This->dwPos += dwBytesToRead; /* adjust pointer */
203 if (pcbRead)
204 *pcbRead = dwBytesToRead;
206 return S_OK;
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);
214 return E_NOTIMPL;
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);
222 return E_NOTIMPL;
224 static HRESULT WINAPI IStream_fnSetSize (IStream * iface, ULARGE_INTEGER libNewSize)
226 ICOM_THIS(ISHRegStream, iface);
228 TRACE("(%p)\n",This);
230 return E_NOTIMPL;
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);
238 return E_NOTIMPL;
240 static HRESULT WINAPI IStream_fnCommit (IStream * iface, DWORD grfCommitFlags)
242 ICOM_THIS(ISHRegStream, iface);
244 TRACE("(%p)\n",This);
246 return E_NOTIMPL;
248 static HRESULT WINAPI IStream_fnRevert (IStream * iface)
250 ICOM_THIS(ISHRegStream, iface);
252 TRACE("(%p)\n",This);
254 return E_NOTIMPL;
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);
262 return E_NOTIMPL;
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);
270 return E_NOTIMPL;
272 static HRESULT WINAPI IStream_fnStat (IStream * iface, STATSTG* pstatstg, DWORD grfStatFlag)
274 ICOM_THIS(ISHRegStream, iface);
276 TRACE("(%p)\n",This);
278 return E_NOTIMPL;
280 static HRESULT WINAPI IStream_fnClone (IStream * iface, IStream** ppstm)
282 ICOM_THIS(ISHRegStream, iface);
284 TRACE("(%p)\n",This);
286 return E_NOTIMPL;
289 static struct ICOM_VTABLE(IStream) rstvt =
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
309 /*************************************************************************
310 * SHOpenRegStreamA [SHLWAPI.@]
311 * SHOpenRegStream2A [SHLWAPI.@]
313 IStream * WINAPI SHOpenRegStreamA(
314 HKEY hkey,
315 LPCSTR pszSubkey,
316 LPCSTR pszValue,
317 DWORD grfMode)
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(
330 HKEY hkey,
331 LPCWSTR pszSubkey,
332 LPCWSTR pszValue,
333 DWORD grfMode)
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);