Differentiate tracing functions between request and reply.
[wine/multimedia.git] / dlls / shell32 / regstream.c
blob2c10ac30bac4f0ed373fcc7a2fd01f03c31c3b74
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 LPSTR pszSubKey;
22 LPSTR pszValue;
23 LPBYTE pbBuffer;
24 DWORD dwLength;
25 DWORD dwPos;
26 } ISHRegStream;
28 static struct ICOM_VTABLE(IStream) rstvt;
30 /**************************************************************************
31 * IStream_Constructor()
33 IStream *IStream_Constructor(HKEY hKey, LPCSTR pszSubKey, LPCSTR pszValue, DWORD grfMode)
34 { ISHRegStream* rstr;
35 DWORD dwType;
37 rstr = (ISHRegStream*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ISHRegStream));
38 ICOM_VTBL(rstr)=&rstvt;
39 rstr->ref = 1;
41 if ( ERROR_SUCCESS == RegOpenKeyExA (hKey, pszSubKey, 0, KEY_READ, &(rstr->hKey)))
42 { if ( ERROR_SUCCESS == RegQueryValueExA(rstr->hKey, (LPSTR)pszValue,0,0,0,&(rstr->dwLength)))
44 /* read the binary data into the buffer */
45 rstr->pbBuffer = HeapAlloc(GetProcessHeap(),0,rstr->dwLength);
46 if (rstr->pbBuffer)
47 { if ( ERROR_SUCCESS == RegQueryValueExA(rstr->hKey, (LPSTR)pszValue,0,&dwType,rstr->pbBuffer,&(rstr->dwLength)))
48 { if (dwType == REG_BINARY )
49 { rstr->pszSubKey = HEAP_strdupA (GetProcessHeap(),0, pszSubKey);
50 rstr->pszValue = HEAP_strdupA (GetProcessHeap(),0, pszValue);
51 TRACE("(%p)->0x%08x,%s,%s,0x%08lx\n", rstr, hKey, pszSubKey, pszValue, grfMode);
52 shell32_ObjCount++;
53 return (IStream*)rstr;
56 HeapFree (GetProcessHeap(),0,rstr->pbBuffer);
59 RegCloseKey(rstr->hKey);
62 HeapFree (GetProcessHeap(),0,rstr);
63 return NULL;
66 /**************************************************************************
67 * IStream_fnQueryInterface
69 static HRESULT WINAPI IStream_fnQueryInterface(IStream *iface, REFIID riid, LPVOID *ppvObj)
71 ICOM_THIS(ISHRegStream, iface);
73 char xriid[50];
74 WINE_StringFromCLSID((LPCLSID)riid,xriid);
76 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,xriid,ppvObj);
78 *ppvObj = NULL;
80 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
81 { *ppvObj = This;
83 else if(IsEqualIID(riid, &IID_IStream)) /*IStream*/
84 { *ppvObj = This;
87 if(*ppvObj)
89 IStream_AddRef((IStream*)*ppvObj);
90 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
91 return S_OK;
93 TRACE("-- Interface: E_NOINTERFACE\n");
94 return E_NOINTERFACE;
97 /**************************************************************************
98 * IStream_fnAddRef
100 static ULONG WINAPI IStream_fnAddRef(IStream *iface)
102 ICOM_THIS(ISHRegStream, iface);
104 TRACE("(%p)->(count=%lu)\n",This, This->ref);
106 shell32_ObjCount++;
107 return ++(This->ref);
110 /**************************************************************************
111 * IStream_fnRelease
113 static ULONG WINAPI IStream_fnRelease(IStream *iface)
115 ICOM_THIS(ISHRegStream, iface);
117 TRACE("(%p)->()\n",This);
119 shell32_ObjCount--;
121 if (!--(This->ref))
122 { TRACE(" destroying SHReg IStream (%p)\n",This);
124 if (This->pszSubKey)
125 HeapFree(GetProcessHeap(),0,This->pszSubKey);
127 if (This->pszValue)
128 HeapFree(GetProcessHeap(),0,This->pszValue);
130 if (This->pbBuffer)
131 HeapFree(GetProcessHeap(),0,This->pbBuffer);
133 if (This->hKey)
134 RegCloseKey(This->hKey);
136 HeapFree(GetProcessHeap(),0,This);
137 return 0;
139 return This->ref;
142 HRESULT WINAPI IStream_fnRead (IStream * iface, void* pv, ULONG cb, ULONG* pcbRead)
144 ICOM_THIS(ISHRegStream, iface);
146 DWORD dwBytesToRead, dwBytesLeft;
148 TRACE("(%p)->(%p,0x%08lx,%p)\n",This, pv, cb, pcbRead);
150 if ( !pv )
151 return STG_E_INVALIDPOINTER;
153 dwBytesLeft = This->dwLength - This->dwPos;
155 if ( 0 >= dwBytesLeft ) /* end of buffer */
156 return S_FALSE;
158 dwBytesToRead = ( cb > dwBytesLeft) ? dwBytesLeft : cb;
160 memmove ( pv, (This->pbBuffer) + (This->dwPos), dwBytesToRead);
162 This->dwPos += dwBytesToRead; /* adjust pointer */
164 if (pcbRead)
165 *pcbRead = dwBytesToRead;
167 return S_OK;
169 HRESULT WINAPI IStream_fnWrite (IStream * iface, const void* pv, ULONG cb, ULONG* pcbWritten)
171 ICOM_THIS(ISHRegStream, iface);
173 TRACE("(%p)\n",This);
175 return E_NOTIMPL;
177 HRESULT WINAPI IStream_fnSeek (IStream * iface, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition)
179 ICOM_THIS(ISHRegStream, iface);
181 TRACE("(%p)\n",This);
183 return E_NOTIMPL;
185 HRESULT WINAPI IStream_fnSetSize (IStream * iface, ULARGE_INTEGER libNewSize)
187 ICOM_THIS(ISHRegStream, iface);
189 TRACE("(%p)\n",This);
191 return E_NOTIMPL;
193 HRESULT WINAPI IStream_fnCopyTo (IStream * iface, IStream* pstm, ULARGE_INTEGER cb, ULARGE_INTEGER* pcbRead, ULARGE_INTEGER* pcbWritten)
195 ICOM_THIS(ISHRegStream, iface);
197 TRACE("(%p)\n",This);
199 return E_NOTIMPL;
201 HRESULT WINAPI IStream_fnCommit (IStream * iface, DWORD grfCommitFlags)
203 ICOM_THIS(ISHRegStream, iface);
205 TRACE("(%p)\n",This);
207 return E_NOTIMPL;
209 HRESULT WINAPI IStream_fnRevert (IStream * iface)
211 ICOM_THIS(ISHRegStream, iface);
213 TRACE("(%p)\n",This);
215 return E_NOTIMPL;
217 HRESULT WINAPI IStream_fnLockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
219 ICOM_THIS(ISHRegStream, iface);
221 TRACE("(%p)\n",This);
223 return E_NOTIMPL;
225 HRESULT WINAPI IStream_fnUnlockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
227 ICOM_THIS(ISHRegStream, iface);
229 TRACE("(%p)\n",This);
231 return E_NOTIMPL;
233 HRESULT WINAPI IStream_fnStat (IStream * iface, STATSTG* pstatstg, DWORD grfStatFlag)
235 ICOM_THIS(ISHRegStream, iface);
237 TRACE("(%p)\n",This);
239 return E_NOTIMPL;
241 HRESULT WINAPI IStream_fnClone (IStream * iface, IStream** ppstm)
243 ICOM_THIS(ISHRegStream, iface);
245 TRACE("(%p)\n",This);
247 return E_NOTIMPL;
250 static struct ICOM_VTABLE(IStream) rstvt =
252 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
253 IStream_fnQueryInterface,
254 IStream_fnAddRef,
255 IStream_fnRelease,
256 IStream_fnRead,
257 IStream_fnWrite,
258 IStream_fnSeek,
259 IStream_fnSetSize,
260 IStream_fnCopyTo,
261 IStream_fnCommit,
262 IStream_fnRevert,
263 IStream_fnLockRegion,
264 IStream_fnUnlockRegion,
265 IStream_fnStat,
266 IStream_fnClone
270 /*************************************************************************
271 * OpenRegStream [SHELL32.85]
273 * NOTES
274 * exported by ordinal
276 IStream * WINAPI OpenRegStream(HKEY hkey, LPCSTR pszSubkey, LPCSTR pszValue, DWORD grfMode)
278 TRACE("(0x%08x,%s,%s,0x%08lx)\n",hkey, pszSubkey, pszValue, grfMode);
279 return IStream_Constructor(hkey, pszSubkey, pszValue, grfMode);