For a radio button even if the initial style includes WS_TABSTOP the
[wine/wine64.git] / dlls / shlwapi / regstream.c
blob528b3e083e2d177022017cb58040a01e722bcce1
1 /*
2 * SHRegOpenStream
3 */
4 #include <string.h>
6 #include "winerror.h"
7 #include "winbase.h"
8 #include "winreg.h"
9 #include "shlobj.h"
11 #include "debugtools.h"
13 DEFAULT_DEBUG_CHANNEL(shell);
15 typedef struct
16 { ICOM_VFIELD(IStream);
17 DWORD ref;
18 HKEY hKey;
19 LPBYTE pbBuffer;
20 DWORD dwLength;
21 DWORD dwPos;
22 } ISHRegStream;
24 static struct ICOM_VTABLE(IStream) rstvt;
26 /**************************************************************************
27 * IStream_ConstructorA [internal]
29 static IStream *IStream_ConstructorA(HKEY hKey, LPCSTR pszSubKey, LPCSTR pszValue, DWORD grfMode)
31 ISHRegStream* rstr;
32 DWORD dwType;
34 rstr = (ISHRegStream*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ISHRegStream));
36 ICOM_VTBL(rstr)=&rstvt;
37 rstr->ref = 1;
39 if (!(RegOpenKeyExA (hKey, pszSubKey, 0, KEY_READ, &(rstr->hKey))))
41 if (!(RegQueryValueExA(rstr->hKey, pszValue,0,0,0,&(rstr->dwLength))))
43 /* read the binary data into the buffer */
44 if((rstr->pbBuffer = HeapAlloc(GetProcessHeap(),0,rstr->dwLength)))
46 if (!(RegQueryValueExA(rstr->hKey, pszValue,0,&dwType,rstr->pbBuffer,&(rstr->dwLength))))
48 if (dwType == REG_BINARY )
50 TRACE ("%p\n", rstr);
51 return (IStream*)rstr;
54 HeapFree (GetProcessHeap(),0,rstr->pbBuffer);
57 RegCloseKey(rstr->hKey);
59 HeapFree (GetProcessHeap(),0,rstr);
60 return NULL;
63 /**************************************************************************
64 * IStream_ConstructorW [internal]
66 static IStream *IStream_ConstructorW(HKEY hKey, LPCWSTR pszSubKey, LPCWSTR pszValue, DWORD grfMode)
68 ISHRegStream* rstr;
69 DWORD dwType;
71 rstr = (ISHRegStream*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ISHRegStream));
73 ICOM_VTBL(rstr)=&rstvt;
74 rstr->ref = 1;
76 if (!(RegOpenKeyExW (hKey, pszSubKey, 0, KEY_READ, &(rstr->hKey))))
78 if (!(RegQueryValueExW(rstr->hKey, pszValue,0,0,0,&(rstr->dwLength))))
80 /* read the binary data into the buffer */
81 if((rstr->pbBuffer = HeapAlloc(GetProcessHeap(),0,rstr->dwLength)))
83 if (!(RegQueryValueExW(rstr->hKey, pszValue,0,&dwType,rstr->pbBuffer,&(rstr->dwLength))))
85 if (dwType == REG_BINARY )
87 TRACE ("%p\n", rstr);
88 return (IStream*)rstr;
91 HeapFree (GetProcessHeap(),0,rstr->pbBuffer);
94 RegCloseKey(rstr->hKey);
96 HeapFree (GetProcessHeap(),0,rstr);
97 return NULL;
100 /**************************************************************************
101 * IStream_fnQueryInterface
103 static HRESULT WINAPI IStream_fnQueryInterface(IStream *iface, REFIID riid, LPVOID *ppvObj)
105 ICOM_THIS(ISHRegStream, iface);
107 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
109 *ppvObj = NULL;
111 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
112 { *ppvObj = This;
114 else if(IsEqualIID(riid, &IID_IStream)) /*IStream*/
115 { *ppvObj = This;
118 if(*ppvObj)
120 IStream_AddRef((IStream*)*ppvObj);
121 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
122 return S_OK;
124 TRACE("-- Interface: E_NOINTERFACE\n");
125 return E_NOINTERFACE;
128 /**************************************************************************
129 * IStream_fnAddRef
131 static ULONG WINAPI IStream_fnAddRef(IStream *iface)
133 ICOM_THIS(ISHRegStream, iface);
135 TRACE("(%p)->(count=%lu)\n",This, This->ref);
137 return ++(This->ref);
140 /**************************************************************************
141 * IStream_fnRelease
143 static ULONG WINAPI IStream_fnRelease(IStream *iface)
145 ICOM_THIS(ISHRegStream, iface);
147 TRACE("(%p)->()\n",This);
149 if (!--(This->ref))
150 { TRACE(" destroying SHReg IStream (%p)\n",This);
152 if (This->pbBuffer)
153 HeapFree(GetProcessHeap(),0,This->pbBuffer);
155 if (This->hKey)
156 RegCloseKey(This->hKey);
158 HeapFree(GetProcessHeap(),0,This);
159 return 0;
161 return This->ref;
164 static HRESULT WINAPI IStream_fnRead (IStream * iface, void* pv, ULONG cb, ULONG* pcbRead)
166 ICOM_THIS(ISHRegStream, iface);
168 DWORD dwBytesToRead, dwBytesLeft;
170 TRACE("(%p)->(%p,0x%08lx,%p)\n",This, pv, cb, pcbRead);
172 if ( !pv )
173 return STG_E_INVALIDPOINTER;
175 dwBytesLeft = This->dwLength - This->dwPos;
177 if ( 0 >= dwBytesLeft ) /* end of buffer */
178 return S_FALSE;
180 dwBytesToRead = ( cb > dwBytesLeft) ? dwBytesLeft : cb;
182 memmove ( pv, (This->pbBuffer) + (This->dwPos), dwBytesToRead);
184 This->dwPos += dwBytesToRead; /* adjust pointer */
186 if (pcbRead)
187 *pcbRead = dwBytesToRead;
189 return S_OK;
191 static HRESULT WINAPI IStream_fnWrite (IStream * iface, const void* pv, ULONG cb, ULONG* pcbWritten)
193 ICOM_THIS(ISHRegStream, iface);
195 TRACE("(%p)\n",This);
197 return E_NOTIMPL;
199 static HRESULT WINAPI IStream_fnSeek (IStream * iface, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition)
201 ICOM_THIS(ISHRegStream, iface);
203 TRACE("(%p)\n",This);
205 return E_NOTIMPL;
207 static HRESULT WINAPI IStream_fnSetSize (IStream * iface, ULARGE_INTEGER libNewSize)
209 ICOM_THIS(ISHRegStream, iface);
211 TRACE("(%p)\n",This);
213 return E_NOTIMPL;
215 static HRESULT WINAPI IStream_fnCopyTo (IStream * iface, IStream* pstm, ULARGE_INTEGER cb, ULARGE_INTEGER* pcbRead, ULARGE_INTEGER* pcbWritten)
217 ICOM_THIS(ISHRegStream, iface);
219 TRACE("(%p)\n",This);
221 return E_NOTIMPL;
223 static HRESULT WINAPI IStream_fnCommit (IStream * iface, DWORD grfCommitFlags)
225 ICOM_THIS(ISHRegStream, iface);
227 TRACE("(%p)\n",This);
229 return E_NOTIMPL;
231 static HRESULT WINAPI IStream_fnRevert (IStream * iface)
233 ICOM_THIS(ISHRegStream, iface);
235 TRACE("(%p)\n",This);
237 return E_NOTIMPL;
239 static HRESULT WINAPI IStream_fnLockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
241 ICOM_THIS(ISHRegStream, iface);
243 TRACE("(%p)\n",This);
245 return E_NOTIMPL;
247 static HRESULT WINAPI IStream_fnUnlockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
249 ICOM_THIS(ISHRegStream, iface);
251 TRACE("(%p)\n",This);
253 return E_NOTIMPL;
255 static HRESULT WINAPI IStream_fnStat (IStream * iface, STATSTG* pstatstg, DWORD grfStatFlag)
257 ICOM_THIS(ISHRegStream, iface);
259 TRACE("(%p)\n",This);
261 return E_NOTIMPL;
263 static HRESULT WINAPI IStream_fnClone (IStream * iface, IStream** ppstm)
265 ICOM_THIS(ISHRegStream, iface);
267 TRACE("(%p)\n",This);
269 return E_NOTIMPL;
272 static struct ICOM_VTABLE(IStream) rstvt =
274 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
275 IStream_fnQueryInterface,
276 IStream_fnAddRef,
277 IStream_fnRelease,
278 IStream_fnRead,
279 IStream_fnWrite,
280 IStream_fnSeek,
281 IStream_fnSetSize,
282 IStream_fnCopyTo,
283 IStream_fnCommit,
284 IStream_fnRevert,
285 IStream_fnLockRegion,
286 IStream_fnUnlockRegion,
287 IStream_fnStat,
288 IStream_fnClone
292 /*************************************************************************
293 * SHOpenRegStreamA [SHLWAPI.@]
294 * SHOpenRegStream2A [SHLWAPI.@]
296 IStream * WINAPI SHOpenRegStreamA(
297 HKEY hkey,
298 LPCSTR pszSubkey,
299 LPCSTR pszValue,
300 DWORD grfMode)
302 TRACE("(0x%08x,%s,%s,0x%08lx)\n",
303 hkey, pszSubkey, pszValue, grfMode);
305 return IStream_ConstructorA(hkey, pszSubkey, pszValue, grfMode);
308 /*************************************************************************
309 * SHOpenRegStreamW [SHLWAPI.@]
310 * SHOpenRegStream2W [SHLWAPI.@]
312 IStream * WINAPI SHOpenRegStreamW(
313 HKEY hkey,
314 LPCWSTR pszSubkey,
315 LPCWSTR pszValue,
316 DWORD grfMode)
318 TRACE("(0x%08x,%s,%s,0x%08lx)\n",
319 hkey, debugstr_w(pszSubkey), debugstr_w(pszValue), grfMode);
321 return IStream_ConstructorW(hkey, pszSubkey, pszValue, grfMode);