Commit 2a93a8ad authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

ole32: Add a helper to create antimoniker of specific order.

parent 292774d9
......@@ -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,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment