Commit e7ce88ab authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

ole32: Remove some internal helpers for item moniker.

parent 7e5a764d
...@@ -137,8 +137,6 @@ static HRESULT set_container_lock(IOleItemContainer *container, IBindCtx *pbc) ...@@ -137,8 +137,6 @@ static HRESULT set_container_lock(IOleItemContainer *container, IBindCtx *pbc)
return hr; return hr;
} }
static HRESULT ItemMonikerImpl_Destroy(ItemMonikerImpl* iface);
/******************************************************************************* /*******************************************************************************
* ItemMoniker_QueryInterface * ItemMoniker_QueryInterface
*******************************************************************************/ *******************************************************************************/
...@@ -195,17 +193,20 @@ static ULONG WINAPI ItemMonikerImpl_AddRef(IMoniker* iface) ...@@ -195,17 +193,20 @@ static ULONG WINAPI ItemMonikerImpl_AddRef(IMoniker* iface)
******************************************************************************/ ******************************************************************************/
static ULONG WINAPI ItemMonikerImpl_Release(IMoniker* iface) static ULONG WINAPI ItemMonikerImpl_Release(IMoniker* iface)
{ {
ItemMonikerImpl *This = impl_from_IMoniker(iface); ItemMonikerImpl *moniker = impl_from_IMoniker(iface);
ULONG ref; ULONG refcount = InterlockedDecrement(&moniker->ref);
TRACE("(%p)\n",This);
ref = InterlockedDecrement(&This->ref); TRACE("%p, refcount %u.\n", iface, refcount);
/* destroy the object if there are no more references to it */ if (!refcount)
if (ref == 0) ItemMonikerImpl_Destroy(This); {
if (moniker->pMarshal) IUnknown_Release(moniker->pMarshal);
heap_free(moniker->itemName);
heap_free(moniker->itemDelimiter);
heap_free(moniker);
}
return ref; return refcount;
} }
/****************************************************************************** /******************************************************************************
...@@ -1008,107 +1009,72 @@ static const IROTDataVtbl VT_ROTDataImpl = ...@@ -1008,107 +1009,72 @@ static const IROTDataVtbl VT_ROTDataImpl =
}; };
/****************************************************************************** /******************************************************************************
* ItemMoniker_Construct (local function) * CreateItemMoniker [OLE32.@]
*******************************************************************************/ ******************************************************************************/
static HRESULT ItemMonikerImpl_Construct(ItemMonikerImpl* This, const WCHAR *delimiter, const WCHAR *name) HRESULT WINAPI CreateItemMoniker(const WCHAR *delimiter, const WCHAR *name, IMoniker **ret)
{ {
ItemMonikerImpl *moniker;
int str_len; int str_len;
HRESULT hr;
TRACE("%s, %s, %p.\n", debugstr_w(delimiter), debugstr_w(name), ret);
TRACE("(%p, %s, %s)\n", This, debugstr_w(delimiter), debugstr_w(name)); if (!(moniker = heap_alloc_zero(sizeof(*moniker))))
return E_OUTOFMEMORY;
/* Initialize the virtual function table. */ moniker->IMoniker_iface.lpVtbl = &VT_ItemMonikerImpl;
This->IMoniker_iface.lpVtbl = &VT_ItemMonikerImpl; moniker->IROTData_iface.lpVtbl = &VT_ROTDataImpl;
This->IROTData_iface.lpVtbl = &VT_ROTDataImpl; moniker->ref = 1;
This->ref = 0;
This->pMarshal = NULL;
This->itemDelimiter = NULL;
str_len = (lstrlenW(name) + 1) * sizeof(WCHAR); str_len = (lstrlenW(name) + 1) * sizeof(WCHAR);
This->itemName = heap_alloc(str_len); moniker->itemName = heap_alloc(str_len);
if (!This->itemName) if (!moniker->itemName)
return E_OUTOFMEMORY; {
memcpy(This->itemName, name, str_len); hr = E_OUTOFMEMORY;
goto failed;
}
memcpy(moniker->itemName, name, str_len);
if (delimiter) if (delimiter)
{ {
str_len = (lstrlenW(delimiter) + 1) * sizeof(WCHAR); str_len = (lstrlenW(delimiter) + 1) * sizeof(WCHAR);
This->itemDelimiter = heap_alloc(str_len); moniker->itemDelimiter = heap_alloc(str_len);
if (!This->itemDelimiter) if (!moniker->itemDelimiter)
{ {
heap_free(This->itemName); hr = E_OUTOFMEMORY;
return E_OUTOFMEMORY; goto failed;
} }
memcpy(This->itemDelimiter, delimiter, str_len); memcpy(moniker->itemDelimiter, delimiter, str_len);
} }
return S_OK; *ret = &moniker->IMoniker_iface;
}
/******************************************************************************
* ItemMoniker_Destroy (local function)
*******************************************************************************/
static HRESULT ItemMonikerImpl_Destroy(ItemMonikerImpl* This)
{
TRACE("(%p)\n",This);
if (This->pMarshal) IUnknown_Release(This->pMarshal);
HeapFree(GetProcessHeap(),0,This->itemName);
HeapFree(GetProcessHeap(),0,This->itemDelimiter);
HeapFree(GetProcessHeap(),0,This);
return S_OK; return S_OK;
}
/******************************************************************************
* CreateItemMoniker [OLE32.@]
******************************************************************************/
HRESULT WINAPI CreateItemMoniker(LPCOLESTR lpszDelim, LPCOLESTR lpszItem, IMoniker **ppmk)
{
ItemMonikerImpl* newItemMoniker;
HRESULT hr;
TRACE("(%s,%s,%p)\n",debugstr_w(lpszDelim),debugstr_w(lpszItem),ppmk);
newItemMoniker = HeapAlloc(GetProcessHeap(), 0, sizeof(ItemMonikerImpl)); failed:
IMoniker_Release(&moniker->IMoniker_iface);
if (!newItemMoniker)
return STG_E_INSUFFICIENTMEMORY;
hr = ItemMonikerImpl_Construct(newItemMoniker,lpszDelim,lpszItem);
if (FAILED(hr)){
HeapFree(GetProcessHeap(),0,newItemMoniker);
return hr; return hr;
}
return ItemMonikerImpl_QueryInterface(&newItemMoniker->IMoniker_iface,&IID_IMoniker,
(void**)ppmk);
} }
HRESULT WINAPI ItemMoniker_CreateInstance(IClassFactory *iface, HRESULT WINAPI ItemMoniker_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
IUnknown *pUnk, REFIID riid, void **ppv)
{ {
ItemMonikerImpl* newItemMoniker; static const WCHAR emptyW[] = { 0 };
IMoniker *moniker;
HRESULT hr; HRESULT hr;
static const WCHAR wszEmpty[] = { 0 };
TRACE("(%p, %s, %p)\n", pUnk, debugstr_guid(riid), ppv); TRACE("(%p, %s, %p)\n", outer, debugstr_guid(riid), ppv);
*ppv = NULL; *ppv = NULL;
if (pUnk) if (outer)
return CLASS_E_NOAGGREGATION; return CLASS_E_NOAGGREGATION;
newItemMoniker = HeapAlloc(GetProcessHeap(), 0, sizeof(ItemMonikerImpl)); if (FAILED(hr = CreateItemMoniker(emptyW, emptyW, &moniker)))
if (!newItemMoniker) return hr;
return E_OUTOFMEMORY;
hr = ItemMonikerImpl_Construct(newItemMoniker, wszEmpty, wszEmpty);
if (SUCCEEDED(hr)) hr = IMoniker_QueryInterface(moniker, riid, ppv);
hr = ItemMonikerImpl_QueryInterface(&newItemMoniker->IMoniker_iface, riid, ppv); IMoniker_Release(moniker);
if (FAILED(hr))
HeapFree(GetProcessHeap(),0,newItemMoniker);
return hr; return hr;
} }
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