New debug scheme with explicit debug channels declaration.
[wine.git] / dlls / shell32 / regstream.c
blob5e3050cd22a0c5a3232ff1b726297f9649299213
1 /*
2 * SHRegOpenStream
3 */
4 #include <string.h>
6 #include "wine/obj_storage.h"
8 #include "debug.h"
9 #include "heap.h"
10 #include "winerror.h"
11 #include "winreg.h"
13 #include "shell.h"
14 #include "pidl.h"
15 #include "shell32_main.h"
17 DEFAULT_DEBUG_CHANNEL(shell)
19 typedef struct
20 { ICOM_VTABLE(IStream)* lpvtbl;
21 DWORD ref;
22 HKEY hKey;
23 LPSTR pszSubKey;
24 LPSTR pszValue;
25 LPBYTE pbBuffer;
26 DWORD dwLength;
27 DWORD dwPos;
28 } ISHRegStream;
30 static struct ICOM_VTABLE(IStream) rstvt;
32 /**************************************************************************
33 * IStream_Constructor()
35 IStream *IStream_Constructor(HKEY hKey, LPCSTR pszSubKey, LPCSTR pszValue, DWORD grfMode)
36 { ISHRegStream* rstr;
37 DWORD dwType;
39 rstr = (ISHRegStream*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ISHRegStream));
40 rstr->lpvtbl=&rstvt;
41 rstr->ref = 1;
43 if ( ERROR_SUCCESS == RegOpenKeyExA (hKey, pszSubKey, 0, KEY_READ, &(rstr->hKey)))
44 { if ( ERROR_SUCCESS == RegQueryValueExA(rstr->hKey, (LPSTR)pszValue,0,0,0,&(rstr->dwLength)))
46 /* read the binary data into the buffer */
47 rstr->pbBuffer = HeapAlloc(GetProcessHeap(),0,rstr->dwLength);
48 if (rstr->pbBuffer)
49 { if ( ERROR_SUCCESS == RegQueryValueExA(rstr->hKey, (LPSTR)pszValue,0,&dwType,rstr->pbBuffer,&(rstr->dwLength)))
50 { if (dwType == REG_BINARY )
51 { rstr->pszSubKey = HEAP_strdupA (GetProcessHeap(),0, pszSubKey);
52 rstr->pszValue = HEAP_strdupA (GetProcessHeap(),0, pszValue);
53 TRACE(shell,"(%p)->0x%08x,%s,%s,0x%08lx\n", rstr, hKey, pszSubKey, pszValue, grfMode);
54 shell32_ObjCount++;
55 return (IStream*)rstr;
58 HeapFree (GetProcessHeap(),0,rstr->pbBuffer);
61 RegCloseKey(rstr->hKey);
64 HeapFree (GetProcessHeap(),0,rstr);
65 return NULL;
68 /**************************************************************************
69 * IStream_fnQueryInterface
71 static HRESULT WINAPI IStream_fnQueryInterface(IStream *iface, REFIID riid, LPVOID *ppvObj)
73 ICOM_THIS(ISHRegStream, iface);
75 char xriid[50];
76 WINE_StringFromCLSID((LPCLSID)riid,xriid);
78 TRACE(shell,"(%p)->(\n\tIID:\t%s,%p)\n",This,xriid,ppvObj);
80 *ppvObj = NULL;
82 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
83 { *ppvObj = This;
85 else if(IsEqualIID(riid, &IID_IStream)) /*IStream*/
86 { *ppvObj = This;
89 if(*ppvObj)
91 IStream_AddRef((IStream*)*ppvObj);
92 TRACE(shell,"-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
93 return S_OK;
95 TRACE(shell,"-- Interface: E_NOINTERFACE\n");
96 return E_NOINTERFACE;
99 /**************************************************************************
100 * IStream_fnAddRef
102 static ULONG WINAPI IStream_fnAddRef(IStream *iface)
104 ICOM_THIS(ISHRegStream, iface);
106 TRACE(shell,"(%p)->(count=%lu)\n",This, This->ref);
108 shell32_ObjCount++;
109 return ++(This->ref);
112 /**************************************************************************
113 * IStream_fnRelease
115 static ULONG WINAPI IStream_fnRelease(IStream *iface)
117 ICOM_THIS(ISHRegStream, iface);
119 TRACE(shell,"(%p)->()\n",This);
121 shell32_ObjCount--;
123 if (!--(This->ref))
124 { TRACE(shell," destroying SHReg IStream (%p)\n",This);
126 if (This->pszSubKey)
127 HeapFree(GetProcessHeap(),0,This->pszSubKey);
129 if (This->pszValue)
130 HeapFree(GetProcessHeap(),0,This->pszValue);
132 if (This->pbBuffer)
133 HeapFree(GetProcessHeap(),0,This->pbBuffer);
135 if (This->hKey)
136 RegCloseKey(This->hKey);
138 HeapFree(GetProcessHeap(),0,This);
139 return 0;
141 return This->ref;
144 HRESULT WINAPI IStream_fnRead (IStream * iface, void* pv, ULONG cb, ULONG* pcbRead)
146 ICOM_THIS(ISHRegStream, iface);
148 DWORD dwBytesToRead, dwBytesLeft;
150 TRACE(shell,"(%p)->(%p,0x%08lx,%p)\n",This, pv, cb, pcbRead);
152 if ( !pv )
153 return STG_E_INVALIDPOINTER;
155 dwBytesLeft = This->dwLength - This->dwPos;
157 if ( 0 >= dwBytesLeft ) /* end of buffer */
158 return S_FALSE;
160 dwBytesToRead = ( cb > dwBytesLeft) ? dwBytesLeft : cb;
162 memmove ( pv, (This->pbBuffer) + (This->dwPos), dwBytesToRead);
164 This->dwPos += dwBytesToRead; /* adjust pointer */
166 if (pcbRead)
167 *pcbRead = dwBytesToRead;
169 return S_OK;
171 HRESULT WINAPI IStream_fnWrite (IStream * iface, const void* pv, ULONG cb, ULONG* pcbWritten)
173 ICOM_THIS(ISHRegStream, iface);
175 TRACE(shell,"(%p)\n",This);
177 return E_NOTIMPL;
179 HRESULT WINAPI IStream_fnSeek (IStream * iface, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition)
181 ICOM_THIS(ISHRegStream, iface);
183 TRACE(shell,"(%p)\n",This);
185 return E_NOTIMPL;
187 HRESULT WINAPI IStream_fnSetSize (IStream * iface, ULARGE_INTEGER libNewSize)
189 ICOM_THIS(ISHRegStream, iface);
191 TRACE(shell,"(%p)\n",This);
193 return E_NOTIMPL;
195 HRESULT WINAPI IStream_fnCopyTo (IStream * iface, IStream* pstm, ULARGE_INTEGER cb, ULARGE_INTEGER* pcbRead, ULARGE_INTEGER* pcbWritten)
197 ICOM_THIS(ISHRegStream, iface);
199 TRACE(shell,"(%p)\n",This);
201 return E_NOTIMPL;
203 HRESULT WINAPI IStream_fnCommit (IStream * iface, DWORD grfCommitFlags)
205 ICOM_THIS(ISHRegStream, iface);
207 TRACE(shell,"(%p)\n",This);
209 return E_NOTIMPL;
211 HRESULT WINAPI IStream_fnRevert (IStream * iface)
213 ICOM_THIS(ISHRegStream, iface);
215 TRACE(shell,"(%p)\n",This);
217 return E_NOTIMPL;
219 HRESULT WINAPI IStream_fnLockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
221 ICOM_THIS(ISHRegStream, iface);
223 TRACE(shell,"(%p)\n",This);
225 return E_NOTIMPL;
227 HRESULT WINAPI IStream_fnUnlockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
229 ICOM_THIS(ISHRegStream, iface);
231 TRACE(shell,"(%p)\n",This);
233 return E_NOTIMPL;
235 HRESULT WINAPI IStream_fnStat (IStream * iface, STATSTG* pstatstg, DWORD grfStatFlag)
237 ICOM_THIS(ISHRegStream, iface);
239 TRACE(shell,"(%p)\n",This);
241 return E_NOTIMPL;
243 HRESULT WINAPI IStream_fnClone (IStream * iface, IStream** ppstm)
245 ICOM_THIS(ISHRegStream, iface);
247 TRACE(shell,"(%p)\n",This);
249 return E_NOTIMPL;
252 static struct ICOM_VTABLE(IStream) rstvt =
254 IStream_fnQueryInterface,
255 IStream_fnAddRef,
256 IStream_fnRelease,
257 IStream_fnRead,
258 IStream_fnWrite,
259 IStream_fnSeek,
260 IStream_fnSetSize,
261 IStream_fnCopyTo,
262 IStream_fnCommit,
263 IStream_fnRevert,
264 IStream_fnLockRegion,
265 IStream_fnUnlockRegion,
266 IStream_fnStat,
267 IStream_fnClone
271 /*************************************************************************
272 * OpenRegStream [SHELL32.85]
274 * NOTES
275 * exported by ordinal
277 IStream * WINAPI OpenRegStream(HKEY hkey, LPCSTR pszSubkey, LPCSTR pszValue, DWORD grfMode)
279 TRACE(shell,"(0x%08x,%s,%s,0x%08lx)\n",hkey, pszSubkey, pszValue, grfMode);
280 return IStream_Constructor(hkey, pszSubkey, pszValue, grfMode);