ole32: Add a constructor helper.

Based on a patch by Dmitry Timoshkov.

Signed-off-by: Huw Davies <huw@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Huw Davies 2020-08-11 12:49:51 +01:00 committed by Alexandre Julliard
parent fe3421ba2c
commit f946aa5b7f
1 changed files with 17 additions and 8 deletions

View File

@ -106,6 +106,22 @@ static inline HGLOBALStreamImpl *impl_from_IStream(IStream *iface)
return CONTAINING_RECORD(iface, HGLOBALStreamImpl, IStream_iface);
}
static const IStreamVtbl HGLOBALStreamImplVtbl;
static HGLOBALStreamImpl *hglobalstream_construct(void)
{
HGLOBALStreamImpl *This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
if (This)
{
This->IStream_iface.lpVtbl = &HGLOBALStreamImplVtbl;
This->ref = 1;
This->handle = NULL;
This->currentPosition.QuadPart = 0;
}
return This;
}
static HRESULT WINAPI HGLOBALStreamImpl_QueryInterface(
IStream* iface,
REFIID riid, /* [in] */
@ -615,12 +631,9 @@ HRESULT WINAPI CreateStreamOnHGlobal(
if (!ppstm)
return E_INVALIDARG;
This = HeapAlloc(GetProcessHeap(), 0, sizeof(HGLOBALStreamImpl));
This = hglobalstream_construct();
if (!This) return E_OUTOFMEMORY;
This->IStream_iface.lpVtbl = &HGLOBALStreamImplVtbl;
This->ref = 1;
This->handle = handle_create(hGlobal, fDeleteOnRelease);
if (!This->handle)
{
@ -628,10 +641,6 @@ HRESULT WINAPI CreateStreamOnHGlobal(
return E_OUTOFMEMORY;
}
/* start at the beginning */
This->currentPosition.u.HighPart = 0;
This->currentPosition.u.LowPart = 0;
*ppstm = &This->IStream_iface;
return S_OK;