DOSFS_ToDosFCBFormat: fail if extension longer than 3 characters.
[wine/gsoc-2012-control.git] / dlls / shell32 / regstream.c
blobabae9b8f3da83ea3ee4045627e579bea628852e9
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 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
75 *ppvObj = NULL;
77 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
78 { *ppvObj = This;
80 else if(IsEqualIID(riid, &IID_IStream)) /*IStream*/
81 { *ppvObj = This;
84 if(*ppvObj)
86 IStream_AddRef((IStream*)*ppvObj);
87 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
88 return S_OK;
90 TRACE("-- Interface: E_NOINTERFACE\n");
91 return E_NOINTERFACE;
94 /**************************************************************************
95 * IStream_fnAddRef
97 static ULONG WINAPI IStream_fnAddRef(IStream *iface)
99 ICOM_THIS(ISHRegStream, iface);
101 TRACE("(%p)->(count=%lu)\n",This, This->ref);
103 shell32_ObjCount++;
104 return ++(This->ref);
107 /**************************************************************************
108 * IStream_fnRelease
110 static ULONG WINAPI IStream_fnRelease(IStream *iface)
112 ICOM_THIS(ISHRegStream, iface);
114 TRACE("(%p)->()\n",This);
116 shell32_ObjCount--;
118 if (!--(This->ref))
119 { TRACE(" destroying SHReg IStream (%p)\n",This);
121 if (This->pszSubKey)
122 HeapFree(GetProcessHeap(),0,This->pszSubKey);
124 if (This->pszValue)
125 HeapFree(GetProcessHeap(),0,This->pszValue);
127 if (This->pbBuffer)
128 HeapFree(GetProcessHeap(),0,This->pbBuffer);
130 if (This->hKey)
131 RegCloseKey(This->hKey);
133 HeapFree(GetProcessHeap(),0,This);
134 return 0;
136 return This->ref;
139 HRESULT WINAPI IStream_fnRead (IStream * iface, void* pv, ULONG cb, ULONG* pcbRead)
141 ICOM_THIS(ISHRegStream, iface);
143 DWORD dwBytesToRead, dwBytesLeft;
145 TRACE("(%p)->(%p,0x%08lx,%p)\n",This, pv, cb, pcbRead);
147 if ( !pv )
148 return STG_E_INVALIDPOINTER;
150 dwBytesLeft = This->dwLength - This->dwPos;
152 if ( 0 >= dwBytesLeft ) /* end of buffer */
153 return S_FALSE;
155 dwBytesToRead = ( cb > dwBytesLeft) ? dwBytesLeft : cb;
157 memmove ( pv, (This->pbBuffer) + (This->dwPos), dwBytesToRead);
159 This->dwPos += dwBytesToRead; /* adjust pointer */
161 if (pcbRead)
162 *pcbRead = dwBytesToRead;
164 return S_OK;
166 HRESULT WINAPI IStream_fnWrite (IStream * iface, const void* pv, ULONG cb, ULONG* pcbWritten)
168 ICOM_THIS(ISHRegStream, iface);
170 TRACE("(%p)\n",This);
172 return E_NOTIMPL;
174 HRESULT WINAPI IStream_fnSeek (IStream * iface, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition)
176 ICOM_THIS(ISHRegStream, iface);
178 TRACE("(%p)\n",This);
180 return E_NOTIMPL;
182 HRESULT WINAPI IStream_fnSetSize (IStream * iface, ULARGE_INTEGER libNewSize)
184 ICOM_THIS(ISHRegStream, iface);
186 TRACE("(%p)\n",This);
188 return E_NOTIMPL;
190 HRESULT WINAPI IStream_fnCopyTo (IStream * iface, IStream* pstm, ULARGE_INTEGER cb, ULARGE_INTEGER* pcbRead, ULARGE_INTEGER* pcbWritten)
192 ICOM_THIS(ISHRegStream, iface);
194 TRACE("(%p)\n",This);
196 return E_NOTIMPL;
198 HRESULT WINAPI IStream_fnCommit (IStream * iface, DWORD grfCommitFlags)
200 ICOM_THIS(ISHRegStream, iface);
202 TRACE("(%p)\n",This);
204 return E_NOTIMPL;
206 HRESULT WINAPI IStream_fnRevert (IStream * iface)
208 ICOM_THIS(ISHRegStream, iface);
210 TRACE("(%p)\n",This);
212 return E_NOTIMPL;
214 HRESULT WINAPI IStream_fnLockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
216 ICOM_THIS(ISHRegStream, iface);
218 TRACE("(%p)\n",This);
220 return E_NOTIMPL;
222 HRESULT WINAPI IStream_fnUnlockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
224 ICOM_THIS(ISHRegStream, iface);
226 TRACE("(%p)\n",This);
228 return E_NOTIMPL;
230 HRESULT WINAPI IStream_fnStat (IStream * iface, STATSTG* pstatstg, DWORD grfStatFlag)
232 ICOM_THIS(ISHRegStream, iface);
234 TRACE("(%p)\n",This);
236 return E_NOTIMPL;
238 HRESULT WINAPI IStream_fnClone (IStream * iface, IStream** ppstm)
240 ICOM_THIS(ISHRegStream, iface);
242 TRACE("(%p)\n",This);
244 return E_NOTIMPL;
247 static struct ICOM_VTABLE(IStream) rstvt =
249 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
250 IStream_fnQueryInterface,
251 IStream_fnAddRef,
252 IStream_fnRelease,
253 IStream_fnRead,
254 IStream_fnWrite,
255 IStream_fnSeek,
256 IStream_fnSetSize,
257 IStream_fnCopyTo,
258 IStream_fnCommit,
259 IStream_fnRevert,
260 IStream_fnLockRegion,
261 IStream_fnUnlockRegion,
262 IStream_fnStat,
263 IStream_fnClone
267 /*************************************************************************
268 * OpenRegStream [SHELL32.85]
270 * NOTES
271 * exported by ordinal
273 IStream * WINAPI OpenRegStream(HKEY hkey, LPCSTR pszSubkey, LPCSTR pszValue, DWORD grfMode)
275 TRACE("(0x%08x,%s,%s,0x%08lx)\n",hkey, pszSubkey, pszValue, grfMode);
276 return IStream_Constructor(hkey, pszSubkey, pszValue, grfMode);