Nikolay Sivov : ole32: Add a helper to create antimoniker of specific order.
Alexandre Julliard
julliard at winehq.org
Wed Jan 29 16:24:08 CST 2020
Module: wine
Branch: master
Commit: 2a93a8ada88c4be0e8057b8a20e509aa9d3a9951
URL: https://source.winehq.org/git/wine.git/?a=commit;h=2a93a8ada88c4be0e8057b8a20e509aa9d3a9951
Author: Nikolay Sivov <nsivov at codeweavers.com>
Date: Wed Jan 29 16:57:02 2020 +0300
ole32: Add a helper to create antimoniker of specific order.
Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/ole32/antimoniker.c | 77 ++++++++++++++++++------------------------------
1 file changed, 29 insertions(+), 48 deletions(-)
diff --git a/dlls/ole32/antimoniker.c b/dlls/ole32/antimoniker.c
index 5bce4fc5da..93d6ab9d56 100644
--- a/dlls/ole32/antimoniker.c
+++ b/dlls/ole32/antimoniker.c
@@ -30,6 +30,7 @@
#include "winerror.h"
#include "objbase.h"
#include "wine/debug.h"
+#include "wine/heap.h"
#include "moniker.h"
WINE_DEFAULT_DEBUG_CHANNEL(ole);
@@ -38,7 +39,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(ole);
typedef struct AntiMonikerImpl{
IMoniker IMoniker_iface;
IROTData IROTData_iface;
- LONG ref;
+ LONG refcount;
IUnknown *pMarshal; /* custom marshaler */
DWORD count;
} AntiMonikerImpl;
@@ -103,37 +104,33 @@ AntiMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject)
/******************************************************************************
* AntiMoniker_AddRef
******************************************************************************/
-static ULONG WINAPI
-AntiMonikerImpl_AddRef(IMoniker* iface)
+static ULONG WINAPI AntiMonikerImpl_AddRef(IMoniker *iface)
{
- AntiMonikerImpl *This = impl_from_IMoniker(iface);
+ AntiMonikerImpl *moniker = impl_from_IMoniker(iface);
+ ULONG refcount = InterlockedIncrement(&moniker->refcount);
- TRACE("(%p)\n",This);
+ TRACE("%p, refcount %u.\n", iface, refcount);
- return InterlockedIncrement(&This->ref);
+ return refcount;
}
/******************************************************************************
* AntiMoniker_Release
******************************************************************************/
-static ULONG WINAPI
-AntiMonikerImpl_Release(IMoniker* iface)
+static ULONG WINAPI AntiMonikerImpl_Release(IMoniker *iface)
{
- AntiMonikerImpl *This = impl_from_IMoniker(iface);
- ULONG ref;
-
- TRACE("(%p)\n",This);
+ AntiMonikerImpl *moniker = impl_from_IMoniker(iface);
+ ULONG refcount = InterlockedDecrement(&moniker->refcount);
- ref = InterlockedDecrement(&This->ref);
+ TRACE("%p, refcount %u.\n", iface, refcount);
- /* destroy the object if there are no more references to it */
- if (ref == 0)
+ if (!refcount)
{
- if (This->pMarshal) IUnknown_Release(This->pMarshal);
- HeapFree(GetProcessHeap(),0,This);
+ if (moniker->pMarshal) IUnknown_Release(moniker->pMarshal);
+ heap_free(moniker);
}
- return ref;
+ return refcount;
}
/******************************************************************************
@@ -610,20 +607,20 @@ static const IROTDataVtbl VT_ROTDataImpl =
AntiMonikerROTDataImpl_GetComparisonData
};
-/******************************************************************************
- * AntiMoniker_Construct (local function)
- *******************************************************************************/
-static HRESULT AntiMonikerImpl_Construct(AntiMonikerImpl* This)
+static HRESULT create_anti_moniker(DWORD order, IMoniker **ret)
{
+ AntiMonikerImpl *moniker;
+
+ moniker = heap_alloc_zero(sizeof(*moniker));
+ if (!moniker)
+ return E_OUTOFMEMORY;
- TRACE("(%p)\n",This);
+ moniker->IMoniker_iface.lpVtbl = &VT_AntiMonikerImpl;
+ moniker->IROTData_iface.lpVtbl = &VT_ROTDataImpl;
+ moniker->refcount = 1;
+ moniker->count = order;
- /* Initialize the virtual function table. */
- This->IMoniker_iface.lpVtbl = &VT_AntiMonikerImpl;
- This->IROTData_iface.lpVtbl = &VT_ROTDataImpl;
- This->ref = 0;
- This->pMarshal = NULL;
- This->count = 1;
+ *ret = &moniker->IMoniker_iface;
return S_OK;
}
@@ -631,27 +628,11 @@ static HRESULT AntiMonikerImpl_Construct(AntiMonikerImpl* This)
/******************************************************************************
* CreateAntiMoniker [OLE32.@]
******************************************************************************/
-HRESULT WINAPI CreateAntiMoniker(IMoniker **ppmk)
+HRESULT WINAPI CreateAntiMoniker(IMoniker **moniker)
{
- AntiMonikerImpl* newAntiMoniker;
- HRESULT hr;
-
- TRACE("(%p)\n",ppmk);
-
- newAntiMoniker = HeapAlloc(GetProcessHeap(), 0, sizeof(AntiMonikerImpl));
-
- if (newAntiMoniker == 0)
- return STG_E_INSUFFICIENTMEMORY;
-
- hr = AntiMonikerImpl_Construct(newAntiMoniker);
- if (FAILED(hr))
- {
- HeapFree(GetProcessHeap(),0,newAntiMoniker);
- return hr;
- }
+ TRACE("%p.\n", moniker);
- return AntiMonikerImpl_QueryInterface(&newAntiMoniker->IMoniker_iface, &IID_IMoniker,
- (void**)ppmk);
+ return create_anti_moniker(1, moniker);
}
HRESULT WINAPI AntiMoniker_CreateInstance(IClassFactory *iface,
More information about the wine-cvs
mailing list