[PATCH 4/6] ole32: Add a constructor helper.

Huw Davies huw at codeweavers.com
Tue Aug 11 06:49:51 CDT 2020


Based on a patch by Dmitry Timoshkov.

Signed-off-by: Huw Davies <huw at codeweavers.com>
---
 dlls/ole32/hglobalstream.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/dlls/ole32/hglobalstream.c b/dlls/ole32/hglobalstream.c
index 8fd1e03913c..e715cd89500 100644
--- a/dlls/ole32/hglobalstream.c
+++ b/dlls/ole32/hglobalstream.c
@@ -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;
-- 
2.23.0




More information about the wine-devel mailing list