Yet another attempt at fixing CW_USEDEFAULT handling.
[wine.git] / dlls / shell32 / regstream.c
blob90bb6d55c30e6efddb09e4671288b2970b774e59
1 /*
2 * SHRegOpenStream
3 */
4 #include <string.h>
6 #include "wine/obj_storage.h"
8 #include "debugtools.h"
9 #include "heap.h"
10 #include "winerror.h"
11 #include "winreg.h"
13 #include "shell32_main.h"
15 DEFAULT_DEBUG_CHANNEL(shell)
17 typedef struct
18 { ICOM_VFIELD(IStream);
19 DWORD ref;
20 HKEY hKey;
21 LPBYTE pbBuffer;
22 DWORD dwLength;
23 DWORD dwPos;
24 } ISHRegStream;
26 static struct ICOM_VTABLE(IStream) rstvt;
28 /**************************************************************************
29 * IStream_ConstructorA [internal]
31 IStream *IStream_ConstructorA(HKEY hKey, LPCSTR pszSubKey, LPCSTR pszValue, DWORD grfMode)
33 ISHRegStream* rstr;
34 DWORD dwType;
36 rstr = (ISHRegStream*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ISHRegStream));
38 ICOM_VTBL(rstr)=&rstvt;
39 rstr->ref = 1;
41 if (!(RegOpenKeyExA (hKey, pszSubKey, 0, KEY_READ, &(rstr->hKey))))
43 if (!(RegQueryValueExA(rstr->hKey, pszValue,0,0,0,&(rstr->dwLength))))
45 /* read the binary data into the buffer */
46 if((rstr->pbBuffer = HeapAlloc(GetProcessHeap(),0,rstr->dwLength)))
48 if (!(RegQueryValueExA(rstr->hKey, pszValue,0,&dwType,rstr->pbBuffer,&(rstr->dwLength))))
50 if (dwType == REG_BINARY )
52 shell32_ObjCount++;
53 TRACE ("%p\n", rstr);
54 return (IStream*)rstr;
57 HeapFree (GetProcessHeap(),0,rstr->pbBuffer);
60 RegCloseKey(rstr->hKey);
62 HeapFree (GetProcessHeap(),0,rstr);
63 return NULL;
66 /**************************************************************************
67 * IStream_ConstructorW [internal]
69 IStream *IStream_ConstructorW(HKEY hKey, LPCWSTR pszSubKey, LPCWSTR pszValue, DWORD grfMode)
71 ISHRegStream* rstr;
72 DWORD dwType;
74 rstr = (ISHRegStream*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ISHRegStream));
76 ICOM_VTBL(rstr)=&rstvt;
77 rstr->ref = 1;
79 if (!(RegOpenKeyExW (hKey, pszSubKey, 0, KEY_READ, &(rstr->hKey))))
81 if (!(RegQueryValueExW(rstr->hKey, pszValue,0,0,0,&(rstr->dwLength))))
83 /* read the binary data into the buffer */
84 if((rstr->pbBuffer = HeapAlloc(GetProcessHeap(),0,rstr->dwLength)))
86 if (!(RegQueryValueExW(rstr->hKey, pszValue,0,&dwType,rstr->pbBuffer,&(rstr->dwLength))))
88 if (dwType == REG_BINARY )
90 shell32_ObjCount++;
91 TRACE ("%p\n", rstr);
92 return (IStream*)rstr;
95 HeapFree (GetProcessHeap(),0,rstr->pbBuffer);
98 RegCloseKey(rstr->hKey);
100 HeapFree (GetProcessHeap(),0,rstr);
101 return NULL;
104 /**************************************************************************
105 * IStream_fnQueryInterface
107 static HRESULT WINAPI IStream_fnQueryInterface(IStream *iface, REFIID riid, LPVOID *ppvObj)
109 ICOM_THIS(ISHRegStream, iface);
111 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
113 *ppvObj = NULL;
115 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
116 { *ppvObj = This;
118 else if(IsEqualIID(riid, &IID_IStream)) /*IStream*/
119 { *ppvObj = This;
122 if(*ppvObj)
124 IStream_AddRef((IStream*)*ppvObj);
125 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
126 return S_OK;
128 TRACE("-- Interface: E_NOINTERFACE\n");
129 return E_NOINTERFACE;
132 /**************************************************************************
133 * IStream_fnAddRef
135 static ULONG WINAPI IStream_fnAddRef(IStream *iface)
137 ICOM_THIS(ISHRegStream, iface);
139 TRACE("(%p)->(count=%lu)\n",This, This->ref);
141 shell32_ObjCount++;
142 return ++(This->ref);
145 /**************************************************************************
146 * IStream_fnRelease
148 static ULONG WINAPI IStream_fnRelease(IStream *iface)
150 ICOM_THIS(ISHRegStream, iface);
152 TRACE("(%p)->()\n",This);
154 shell32_ObjCount--;
156 if (!--(This->ref))
157 { TRACE(" destroying SHReg IStream (%p)\n",This);
159 if (This->pbBuffer)
160 HeapFree(GetProcessHeap(),0,This->pbBuffer);
162 if (This->hKey)
163 RegCloseKey(This->hKey);
165 HeapFree(GetProcessHeap(),0,This);
166 return 0;
168 return This->ref;
171 HRESULT WINAPI IStream_fnRead (IStream * iface, void* pv, ULONG cb, ULONG* pcbRead)
173 ICOM_THIS(ISHRegStream, iface);
175 DWORD dwBytesToRead, dwBytesLeft;
177 TRACE("(%p)->(%p,0x%08lx,%p)\n",This, pv, cb, pcbRead);
179 if ( !pv )
180 return STG_E_INVALIDPOINTER;
182 dwBytesLeft = This->dwLength - This->dwPos;
184 if ( 0 >= dwBytesLeft ) /* end of buffer */
185 return S_FALSE;
187 dwBytesToRead = ( cb > dwBytesLeft) ? dwBytesLeft : cb;
189 memmove ( pv, (This->pbBuffer) + (This->dwPos), dwBytesToRead);
191 This->dwPos += dwBytesToRead; /* adjust pointer */
193 if (pcbRead)
194 *pcbRead = dwBytesToRead;
196 return S_OK;
198 HRESULT WINAPI IStream_fnWrite (IStream * iface, const void* pv, ULONG cb, ULONG* pcbWritten)
200 ICOM_THIS(ISHRegStream, iface);
202 TRACE("(%p)\n",This);
204 return E_NOTIMPL;
206 HRESULT WINAPI IStream_fnSeek (IStream * iface, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition)
208 ICOM_THIS(ISHRegStream, iface);
210 TRACE("(%p)\n",This);
212 return E_NOTIMPL;
214 HRESULT WINAPI IStream_fnSetSize (IStream * iface, ULARGE_INTEGER libNewSize)
216 ICOM_THIS(ISHRegStream, iface);
218 TRACE("(%p)\n",This);
220 return E_NOTIMPL;
222 HRESULT WINAPI IStream_fnCopyTo (IStream * iface, IStream* pstm, ULARGE_INTEGER cb, ULARGE_INTEGER* pcbRead, ULARGE_INTEGER* pcbWritten)
224 ICOM_THIS(ISHRegStream, iface);
226 TRACE("(%p)\n",This);
228 return E_NOTIMPL;
230 HRESULT WINAPI IStream_fnCommit (IStream * iface, DWORD grfCommitFlags)
232 ICOM_THIS(ISHRegStream, iface);
234 TRACE("(%p)\n",This);
236 return E_NOTIMPL;
238 HRESULT WINAPI IStream_fnRevert (IStream * iface)
240 ICOM_THIS(ISHRegStream, iface);
242 TRACE("(%p)\n",This);
244 return E_NOTIMPL;
246 HRESULT WINAPI IStream_fnLockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
248 ICOM_THIS(ISHRegStream, iface);
250 TRACE("(%p)\n",This);
252 return E_NOTIMPL;
254 HRESULT WINAPI IStream_fnUnlockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
256 ICOM_THIS(ISHRegStream, iface);
258 TRACE("(%p)\n",This);
260 return E_NOTIMPL;
262 HRESULT WINAPI IStream_fnStat (IStream * iface, STATSTG* pstatstg, DWORD grfStatFlag)
264 ICOM_THIS(ISHRegStream, iface);
266 TRACE("(%p)\n",This);
268 return E_NOTIMPL;
270 HRESULT WINAPI IStream_fnClone (IStream * iface, IStream** ppstm)
272 ICOM_THIS(ISHRegStream, iface);
274 TRACE("(%p)\n",This);
276 return E_NOTIMPL;
279 static struct ICOM_VTABLE(IStream) rstvt =
281 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
282 IStream_fnQueryInterface,
283 IStream_fnAddRef,
284 IStream_fnRelease,
285 IStream_fnRead,
286 IStream_fnWrite,
287 IStream_fnSeek,
288 IStream_fnSetSize,
289 IStream_fnCopyTo,
290 IStream_fnCommit,
291 IStream_fnRevert,
292 IStream_fnLockRegion,
293 IStream_fnUnlockRegion,
294 IStream_fnStat,
295 IStream_fnClone
299 /*************************************************************************
300 * SHOpenRegStreamA [SHLWAPI.@][SHELL32.85]
302 IStream * WINAPI SHOpenRegStreamA(
303 HKEY hkey,
304 LPCSTR pszSubkey,
305 LPCSTR pszValue,
306 DWORD grfMode)
308 TRACE("(0x%08x,%s,%s,0x%08lx)\n",
309 hkey, pszSubkey, pszValue, grfMode);
311 return IStream_ConstructorA(hkey, pszSubkey, pszValue, grfMode);
314 /*************************************************************************
315 * SHOpenRegStreamW [SHLWAPI.@]
317 IStream * WINAPI SHOpenRegStreamW(
318 HKEY hkey,
319 LPCWSTR pszSubkey,
320 LPCWSTR pszValue,
321 DWORD grfMode)
323 TRACE("(0x%08x,%s,%s,0x%08lx)\n",
324 hkey, debugstr_w(pszSubkey), debugstr_w(pszValue), grfMode);
326 return IStream_ConstructorW(hkey, pszSubkey, pszValue, grfMode);