typedef struct
{
- const IStreamVtbl *lpVtbl;
+ IStream IStream_iface;
LONG ref;
HKEY hKey;
LPBYTE pbBuffer;
BOOL bUnicode;
} ISHRegStream;
+static inline ISHRegStream *impl_from_IStream(IStream *iface)
+{
+ return CONTAINING_RECORD(iface, ISHRegStream, IStream_iface);
+}
+
/**************************************************************************
* IStream_fnQueryInterface
*/
static HRESULT WINAPI IStream_fnQueryInterface(IStream *iface, REFIID riid, LPVOID *ppvObj)
{
- ISHRegStream *This = (ISHRegStream *)iface;
+ ISHRegStream *This = impl_from_IStream(iface);
TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
*ppvObj = NULL;
- if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
- *ppvObj = This;
- else if(IsEqualIID(riid, &IID_IStream)) /*IStream*/
- *ppvObj = This;
+ if(IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IStream))
+ *ppvObj = &This->IStream_iface;
if(*ppvObj)
{
*/
static ULONG WINAPI IStream_fnAddRef(IStream *iface)
{
- ISHRegStream *This = (ISHRegStream *)iface;
+ ISHRegStream *This = impl_from_IStream(iface);
ULONG refCount = InterlockedIncrement(&This->ref);
TRACE("(%p)->(ref before=%u)\n",This, refCount - 1);
*/
static ULONG WINAPI IStream_fnRelease(IStream *iface)
{
- ISHRegStream *This = (ISHRegStream *)iface;
+ ISHRegStream *This = impl_from_IStream(iface);
ULONG refCount = InterlockedDecrement(&This->ref);
TRACE("(%p)->(ref before=%u)\n",This, refCount + 1);
*/
static HRESULT WINAPI IStream_fnRead (IStream * iface, void* pv, ULONG cb, ULONG* pcbRead)
{
- ISHRegStream *This = (ISHRegStream *)iface;
+ ISHRegStream *This = impl_from_IStream(iface);
DWORD dwBytesToRead;
TRACE("(%p)->(%p,0x%08x,%p)\n",This, pv, cb, pcbRead);
*/
static HRESULT WINAPI IStream_fnWrite (IStream * iface, const void* pv, ULONG cb, ULONG* pcbWritten)
{
- ISHRegStream *This = (ISHRegStream *)iface;
+ ISHRegStream *This = impl_from_IStream(iface);
DWORD newLen = This->dwPos + cb;
TRACE("(%p, %p, %d, %p)\n",This, pv, cb, pcbWritten);
*/
static HRESULT WINAPI IStream_fnSeek (IStream * iface, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition)
{
- ISHRegStream *This = (ISHRegStream *)iface;
+ ISHRegStream *This = impl_from_IStream(iface);
LARGE_INTEGER tmp;
TRACE("(%p, %s, %d %p)\n", This,
wine_dbgstr_longlong(dlibMove.QuadPart), dwOrigin, plibNewPosition);
*/
static HRESULT WINAPI IStream_fnSetSize (IStream * iface, ULARGE_INTEGER libNewSize)
{
- ISHRegStream *This = (ISHRegStream *)iface;
+ ISHRegStream *This = impl_from_IStream(iface);
DWORD newLen;
LPBYTE newBuf;
*/
static HRESULT WINAPI IStream_fnCopyTo (IStream * iface, IStream* pstm, ULARGE_INTEGER cb, ULARGE_INTEGER* pcbRead, ULARGE_INTEGER* pcbWritten)
{
- ISHRegStream *This = (ISHRegStream *)iface;
+ ISHRegStream *This = impl_from_IStream(iface);
TRACE("(%p)\n",This);
if (pcbRead)
*/
static HRESULT WINAPI IStream_fnCommit (IStream * iface, DWORD grfCommitFlags)
{
- ISHRegStream *This = (ISHRegStream *)iface;
+ ISHRegStream *This = impl_from_IStream(iface);
TRACE("(%p)\n",This);
*/
static HRESULT WINAPI IStream_fnRevert (IStream * iface)
{
- ISHRegStream *This = (ISHRegStream *)iface;
+ ISHRegStream *This = impl_from_IStream(iface);
TRACE("(%p)\n",This);
*/
static HRESULT WINAPI IStream_fnLockUnlockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
{
- ISHRegStream *This = (ISHRegStream *)iface;
+ ISHRegStream *This = impl_from_IStream(iface);
TRACE("(%p)\n",This);
*/
static HRESULT WINAPI IStream_fnStat (IStream * iface, STATSTG* pstatstg, DWORD grfStatFlag)
{
- ISHRegStream *This = (ISHRegStream *)iface;
+ ISHRegStream *This = impl_from_IStream(iface);
TRACE("(%p, %p, %d)\n",This,pstatstg,grfStatFlag);
*/
static HRESULT WINAPI IStream_fnClone (IStream * iface, IStream** ppstm)
{
- ISHRegStream *This = (ISHRegStream *)iface;
+ ISHRegStream *This = impl_from_IStream(iface);
TRACE("(%p)\n",This);
*ppstm = NULL;
*/
static ULONG WINAPI IStream_fnAddRefDummy(IStream *iface)
{
- ISHRegStream *This = (ISHRegStream *)iface;
+ ISHRegStream *This = impl_from_IStream(iface);
TRACE("(%p)\n", This);
return 2;
}
*/
static ULONG WINAPI IStream_fnReleaseDummy(IStream *iface)
{
- ISHRegStream *This = (ISHRegStream *)iface;
+ ISHRegStream *This = impl_from_IStream(iface);
TRACE("(%p)\n", This);
return 1;
}
/* Dummy registry stream object */
static ISHRegStream rsDummyRegStream =
{
- &DummyRegStreamVTable,
+ { &DummyRegStreamVTable },
1,
NULL,
NULL,
if (regStream)
{
- regStream->lpVtbl = &rstvt;
+ regStream->IStream_iface.lpVtbl = &rstvt;
regStream->ref = 1;
regStream->hKey = hKey;
regStream->pbBuffer = pbBuffer;
tmp->dwMode = dwMode;
tmp->bUnicode = FALSE;
- return (IStream *)tmp;
+ return &tmp->IStream_iface;
}
}
tmp->dwMode = dwMode;
tmp->bUnicode = TRUE;
- return (IStream *)tmp;
+ return &tmp->IStream_iface;
}
}
TRACE("(%p,%s,%s,0x%08x)\n", hkey, pszSubkey, pszValue, dwMode);
iStream = SHOpenRegStream2A(hkey, pszSubkey, pszValue, dwMode);
- return iStream ? iStream : (IStream *)&rsDummyRegStream;
+ return iStream ? iStream : &rsDummyRegStream.IStream_iface;
}
/*************************************************************************
TRACE("(%p,%s,%s,0x%08x)\n", hkey, debugstr_w(pszSubkey),
debugstr_w(pszValue), dwMode);
iStream = SHOpenRegStream2W(hkey, pszSubkey, pszValue, dwMode);
- return iStream ? iStream : (IStream *)&rsDummyRegStream;
+ return iStream ? iStream : &rsDummyRegStream.IStream_iface;
}
/*************************************************************************
*/
IStream * WINAPI SHCreateMemStream(const BYTE *lpbData, UINT dwDataLen)
{
- IStream *iStrmRet = NULL;
+ ISHRegStream *strm = NULL;
LPBYTE lpbDup;
TRACE("(%p,%d)\n", lpbData, dwDataLen);
if (lpbDup)
{
memcpy(lpbDup, lpbData, dwDataLen);
- iStrmRet = (IStream *)IStream_Create(NULL, lpbDup, dwDataLen);
+ strm = IStream_Create(NULL, lpbDup, dwDataLen);
- if (!iStrmRet)
+ if (!strm)
HeapFree(GetProcessHeap(), 0, lpbDup);
}
- return iStrmRet;
+ return &strm->IStream_iface;
}
/*************************************************************************
HRESULT WINAPI SHCreateStreamWrapper(LPBYTE lpbData, DWORD dwDataLen,
DWORD dwReserved, IStream **lppStream)
{
- IStream* lpStream;
+ ISHRegStream *strm;
if (lppStream)
*lppStream = NULL;
if(dwReserved || !lppStream)
return E_INVALIDARG;
- lpStream = (IStream *)IStream_Create(NULL, lpbData, dwDataLen);
+ strm = IStream_Create(NULL, lpbData, dwDataLen);
- if(!lpStream)
+ if(!strm)
return E_OUTOFMEMORY;
- IStream_QueryInterface(lpStream, &IID_IStream, (void**)lppStream);
- IStream_Release(lpStream);
+ IStream_QueryInterface(&strm->IStream_iface, &IID_IStream, (void**)lppStream);
+ IStream_Release(&strm->IStream_iface);
return S_OK;
}