2006-05-18 14:49:52 +02:00
|
|
|
/*
|
1999-01-28 18:56:14 +01:00
|
|
|
* ItemMonikers implementation
|
|
|
|
*
|
|
|
|
* Copyright 1999 Noomen Hamza
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
1999-01-28 18:56:14 +01:00
|
|
|
|
|
|
|
#include <assert.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2001-01-26 21:43:40 +01:00
|
|
|
#include <string.h>
|
2003-01-07 21:36:20 +01:00
|
|
|
|
2004-10-07 05:06:48 +02:00
|
|
|
#define COBJMACROS
|
2003-01-07 21:36:20 +01:00
|
|
|
#define NONAMELESSUNION
|
2004-10-07 05:06:48 +02:00
|
|
|
|
1999-01-28 18:56:14 +01:00
|
|
|
#include "winerror.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2000-09-26 02:00:55 +02:00
|
|
|
#include "winbase.h"
|
2003-09-09 21:39:31 +02:00
|
|
|
#include "winuser.h"
|
2000-11-28 23:40:56 +01:00
|
|
|
#include "winnls.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2019-12-13 11:06:54 +01:00
|
|
|
#include "wine/heap.h"
|
2002-12-05 21:33:07 +01:00
|
|
|
#include "ole2.h"
|
2002-12-19 02:09:40 +01:00
|
|
|
#include "moniker.h"
|
1999-01-28 18:56:14 +01:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ole);
|
1999-04-19 16:56:29 +02:00
|
|
|
|
1999-03-23 14:48:56 +01:00
|
|
|
/* ItemMoniker data structure */
|
1999-01-28 18:56:14 +01:00
|
|
|
typedef struct ItemMonikerImpl{
|
2011-08-24 12:14:29 +02:00
|
|
|
IMoniker IMoniker_iface; /* VTable relative to the IMoniker interface.*/
|
|
|
|
IROTData IROTData_iface; /* VTable relative to the IROTData interface.*/
|
|
|
|
LONG ref;
|
1999-03-23 14:48:56 +01:00
|
|
|
LPOLESTR itemName; /* item name identified by this ItemMoniker */
|
|
|
|
LPOLESTR itemDelimiter; /* Delimiter string */
|
2005-05-19 16:22:14 +02:00
|
|
|
IUnknown *pMarshal; /* custom marshaler */
|
1999-01-28 18:56:14 +01:00
|
|
|
} ItemMonikerImpl;
|
|
|
|
|
2011-08-24 12:14:29 +02:00
|
|
|
static inline ItemMonikerImpl *impl_from_IMoniker(IMoniker *iface)
|
2005-07-27 13:10:52 +02:00
|
|
|
{
|
2011-08-24 12:14:29 +02:00
|
|
|
return CONTAINING_RECORD(iface, ItemMonikerImpl, IMoniker_iface);
|
|
|
|
}
|
|
|
|
|
2020-01-23 00:03:06 +01:00
|
|
|
static ItemMonikerImpl *unsafe_impl_from_IMoniker(IMoniker *iface);
|
|
|
|
|
2011-08-24 12:14:29 +02:00
|
|
|
static inline ItemMonikerImpl *impl_from_IROTData(IROTData *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, ItemMonikerImpl, IROTData_iface);
|
2005-07-27 13:10:52 +02:00
|
|
|
}
|
|
|
|
|
2020-01-23 00:03:04 +01:00
|
|
|
struct container_lock
|
|
|
|
{
|
|
|
|
IUnknown IUnknown_iface;
|
|
|
|
LONG refcount;
|
|
|
|
IOleItemContainer *container;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct container_lock *impl_lock_from_IUnknown(IUnknown *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct container_lock, IUnknown_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI container_lock_QueryInterface(IUnknown *iface, REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
if (IsEqualIID(riid, &IID_IUnknown))
|
|
|
|
{
|
|
|
|
*obj = iface;
|
|
|
|
IUnknown_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("Unsupported interface %s.\n", debugstr_guid(riid));
|
|
|
|
*obj = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI container_lock_AddRef(IUnknown *iface)
|
|
|
|
{
|
|
|
|
struct container_lock *lock = impl_lock_from_IUnknown(iface);
|
|
|
|
return InterlockedIncrement(&lock->refcount);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI container_lock_Release(IUnknown *iface)
|
|
|
|
{
|
|
|
|
struct container_lock *lock = impl_lock_from_IUnknown(iface);
|
|
|
|
ULONG refcount = InterlockedDecrement(&lock->refcount);
|
|
|
|
|
|
|
|
if (!refcount)
|
|
|
|
{
|
|
|
|
IOleItemContainer_LockContainer(lock->container, FALSE);
|
|
|
|
IOleItemContainer_Release(lock->container);
|
|
|
|
heap_free(lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IUnknownVtbl container_lock_vtbl =
|
|
|
|
{
|
|
|
|
container_lock_QueryInterface,
|
|
|
|
container_lock_AddRef,
|
|
|
|
container_lock_Release,
|
|
|
|
};
|
|
|
|
|
|
|
|
static HRESULT set_container_lock(IOleItemContainer *container, IBindCtx *pbc)
|
|
|
|
{
|
|
|
|
struct container_lock *lock;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (!(lock = heap_alloc(sizeof(*lock))))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
if (FAILED(hr = IOleItemContainer_LockContainer(container, TRUE)))
|
|
|
|
{
|
|
|
|
heap_free(lock);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
lock->IUnknown_iface.lpVtbl = &container_lock_vtbl;
|
|
|
|
lock->refcount = 1;
|
|
|
|
lock->container = container;
|
|
|
|
IOleItemContainer_AddRef(lock->container);
|
|
|
|
|
|
|
|
hr = IBindCtx_RegisterObjectBound(pbc, &lock->IUnknown_iface);
|
|
|
|
IUnknown_Release(&lock->IUnknown_iface);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
1999-01-28 18:56:14 +01:00
|
|
|
/*******************************************************************************
|
|
|
|
* ItemMoniker_QueryInterface
|
|
|
|
*******************************************************************************/
|
2020-01-31 11:37:38 +01:00
|
|
|
static HRESULT WINAPI ItemMonikerImpl_QueryInterface(IMoniker *iface, REFIID riid, void **ppvObject)
|
1999-02-18 14:26:22 +01:00
|
|
|
{
|
2011-08-24 12:14:29 +02:00
|
|
|
ItemMonikerImpl *This = impl_from_IMoniker(iface);
|
1999-01-28 18:56:14 +01:00
|
|
|
|
2020-01-31 11:37:38 +01:00
|
|
|
TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), ppvObject);
|
1999-01-28 18:56:14 +01:00
|
|
|
|
2011-08-24 12:18:49 +02:00
|
|
|
if (!ppvObject)
|
|
|
|
return E_INVALIDARG;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2011-08-24 12:18:49 +02:00
|
|
|
if (IsEqualIID(&IID_IUnknown, riid) ||
|
|
|
|
IsEqualIID(&IID_IPersist, riid) ||
|
|
|
|
IsEqualIID(&IID_IPersistStream, riid) ||
|
2020-01-31 11:37:38 +01:00
|
|
|
IsEqualIID(&IID_IMoniker, riid) ||
|
|
|
|
IsEqualGUID(&CLSID_ItemMoniker, riid))
|
|
|
|
{
|
2011-08-24 12:18:49 +02:00
|
|
|
*ppvObject = iface;
|
2020-01-31 11:37:38 +01:00
|
|
|
}
|
1999-03-23 14:48:56 +01:00
|
|
|
else if (IsEqualIID(&IID_IROTData, riid))
|
2011-08-24 12:14:29 +02:00
|
|
|
*ppvObject = &This->IROTData_iface;
|
2005-05-19 16:22:14 +02:00
|
|
|
else if (IsEqualIID(&IID_IMarshal, riid))
|
|
|
|
{
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
if (!This->pMarshal)
|
|
|
|
hr = MonikerMarshal_Create(iface, &This->pMarshal);
|
|
|
|
if (hr != S_OK)
|
|
|
|
return hr;
|
|
|
|
return IUnknown_QueryInterface(This->pMarshal, riid, ppvObject);
|
|
|
|
}
|
2011-08-24 12:18:49 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
*ppvObject = NULL;
|
1999-03-23 14:48:56 +01:00
|
|
|
return E_NOINTERFACE;
|
2011-08-24 12:18:49 +02:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2011-08-24 12:18:49 +02:00
|
|
|
IMoniker_AddRef(iface);
|
|
|
|
return S_OK;
|
1999-01-28 18:56:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* ItemMoniker_AddRef
|
|
|
|
******************************************************************************/
|
2010-01-21 12:58:24 +01:00
|
|
|
static ULONG WINAPI ItemMonikerImpl_AddRef(IMoniker* iface)
|
1999-02-18 14:26:22 +01:00
|
|
|
{
|
2011-08-24 12:14:29 +02:00
|
|
|
ItemMonikerImpl *This = impl_from_IMoniker(iface);
|
1999-01-28 18:56:14 +01:00
|
|
|
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("(%p)\n",This);
|
1999-01-28 18:56:14 +01:00
|
|
|
|
2004-09-24 03:16:53 +02:00
|
|
|
return InterlockedIncrement(&This->ref);
|
1999-01-28 18:56:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* ItemMoniker_Release
|
|
|
|
******************************************************************************/
|
2010-01-21 12:58:24 +01:00
|
|
|
static ULONG WINAPI ItemMonikerImpl_Release(IMoniker* iface)
|
1999-02-18 14:26:22 +01:00
|
|
|
{
|
2020-01-28 08:32:19 +01:00
|
|
|
ItemMonikerImpl *moniker = impl_from_IMoniker(iface);
|
|
|
|
ULONG refcount = InterlockedDecrement(&moniker->ref);
|
1999-01-28 18:56:14 +01:00
|
|
|
|
2020-01-28 08:32:19 +01:00
|
|
|
TRACE("%p, refcount %u.\n", iface, refcount);
|
1999-01-28 18:56:14 +01:00
|
|
|
|
2020-01-28 08:32:19 +01:00
|
|
|
if (!refcount)
|
|
|
|
{
|
|
|
|
if (moniker->pMarshal) IUnknown_Release(moniker->pMarshal);
|
|
|
|
heap_free(moniker->itemName);
|
|
|
|
heap_free(moniker->itemDelimiter);
|
|
|
|
heap_free(moniker);
|
|
|
|
}
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2020-01-28 08:32:19 +01:00
|
|
|
return refcount;
|
1999-01-28 18:56:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* ItemMoniker_GetClassID
|
|
|
|
******************************************************************************/
|
2010-01-21 12:58:24 +01:00
|
|
|
static HRESULT WINAPI ItemMonikerImpl_GetClassID(IMoniker* iface,CLSID *pClassID)
|
1999-02-18 14:26:22 +01:00
|
|
|
{
|
2005-02-18 21:13:23 +01:00
|
|
|
TRACE("(%p,%p)\n",iface,pClassID);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
|
|
|
if (pClassID==NULL)
|
|
|
|
return E_POINTER;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-03-23 14:48:56 +01:00
|
|
|
*pClassID = CLSID_ItemMoniker;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-03-23 14:48:56 +01:00
|
|
|
return S_OK;
|
1999-01-28 18:56:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* ItemMoniker_IsDirty
|
|
|
|
******************************************************************************/
|
2010-01-21 12:58:24 +01:00
|
|
|
static HRESULT WINAPI ItemMonikerImpl_IsDirty(IMoniker* iface)
|
1999-01-28 18:56:14 +01:00
|
|
|
{
|
1999-03-23 14:48:56 +01:00
|
|
|
/* Note that the OLE-provided implementations of the IPersistStream::IsDirty
|
|
|
|
method in the OLE-provided moniker interfaces always return S_FALSE because
|
|
|
|
their internal state never changes. */
|
1999-02-18 14:26:22 +01:00
|
|
|
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("(%p)\n",iface);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
|
|
|
return S_FALSE;
|
1999-01-28 18:56:14 +01:00
|
|
|
}
|
|
|
|
|
2019-12-13 11:06:56 +01:00
|
|
|
static HRESULT item_moniker_load_string_record(IStream *stream, WCHAR **ret)
|
1999-01-28 18:56:14 +01:00
|
|
|
{
|
2019-12-13 11:06:56 +01:00
|
|
|
DWORD str_len, read_len, lenW, i;
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
char *buffer;
|
|
|
|
WCHAR *str;
|
2005-02-18 21:13:23 +01:00
|
|
|
|
2019-12-13 11:06:56 +01:00
|
|
|
IStream_Read(stream, &str_len, sizeof(str_len), &read_len);
|
|
|
|
if (read_len != sizeof(str_len))
|
1999-03-23 14:48:56 +01:00
|
|
|
return E_FAIL;
|
|
|
|
|
2019-12-13 11:06:56 +01:00
|
|
|
if (!str_len)
|
|
|
|
{
|
|
|
|
heap_free(*ret);
|
|
|
|
*ret = NULL;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(buffer = heap_alloc(str_len)))
|
2000-11-28 23:40:56 +01:00
|
|
|
return E_OUTOFMEMORY;
|
2019-12-13 11:06:56 +01:00
|
|
|
|
|
|
|
IStream_Read(stream, buffer, str_len, &read_len);
|
|
|
|
if (read_len != str_len)
|
2000-11-28 23:40:56 +01:00
|
|
|
{
|
2019-12-13 11:06:56 +01:00
|
|
|
heap_free(buffer);
|
1999-03-23 14:48:56 +01:00
|
|
|
return E_FAIL;
|
2000-11-28 23:40:56 +01:00
|
|
|
}
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2019-12-13 11:06:56 +01:00
|
|
|
/* Skip ansi buffer, it must be null terminated. */
|
|
|
|
i = 0;
|
|
|
|
while (i < str_len && buffer[i])
|
|
|
|
i++;
|
|
|
|
|
|
|
|
if (buffer[i])
|
2000-11-28 23:40:56 +01:00
|
|
|
{
|
2019-12-13 11:06:56 +01:00
|
|
|
WARN("Expected null terminated ansi name.\n");
|
|
|
|
hr = E_FAIL;
|
|
|
|
goto end;
|
2000-11-28 23:40:56 +01:00
|
|
|
}
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2019-12-13 11:06:56 +01:00
|
|
|
if (i < str_len - 1)
|
2000-11-28 23:40:56 +01:00
|
|
|
{
|
2019-12-13 11:06:56 +01:00
|
|
|
str_len -= i + 1;
|
|
|
|
|
|
|
|
if (str_len % sizeof(WCHAR))
|
|
|
|
{
|
|
|
|
WARN("Unexpected Unicode name length %d.\n", str_len);
|
|
|
|
hr = E_FAIL;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
str = heap_alloc(str_len + sizeof(WCHAR));
|
|
|
|
if (str)
|
|
|
|
{
|
|
|
|
memcpy(str, &buffer[i + 1], str_len);
|
|
|
|
str[str_len / sizeof(WCHAR)] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lenW = MultiByteToWideChar(CP_ACP, 0, buffer, -1, NULL, 0);
|
|
|
|
str = heap_alloc(lenW * sizeof(WCHAR));
|
|
|
|
if (str)
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, buffer, -1, str, lenW);
|
2000-11-28 23:40:56 +01:00
|
|
|
}
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2019-12-13 11:06:56 +01:00
|
|
|
if (str)
|
2000-11-28 23:40:56 +01:00
|
|
|
{
|
2019-12-13 11:06:56 +01:00
|
|
|
heap_free(*ret);
|
|
|
|
*ret = str;
|
2000-11-28 23:40:56 +01:00
|
|
|
}
|
2019-12-13 11:06:56 +01:00
|
|
|
else
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
end:
|
|
|
|
heap_free(buffer);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* ItemMoniker_Load
|
|
|
|
******************************************************************************/
|
|
|
|
static HRESULT WINAPI ItemMonikerImpl_Load(IMoniker *iface, IStream *stream)
|
|
|
|
{
|
|
|
|
ItemMonikerImpl *This = impl_from_IMoniker(iface);
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p, %p)\n", iface, stream);
|
|
|
|
|
|
|
|
/* Delimiter and name use the same record structure: 4 bytes byte-length field, followed by
|
|
|
|
string data. Data starts with single byte null-terminated string, WCHAR non-terminated
|
|
|
|
string optionally follows. Length of WCHAR string is determined as a difference between total
|
|
|
|
byte-length and single byte string length. */
|
|
|
|
|
|
|
|
hr = item_moniker_load_string_record(stream, &This->itemDelimiter);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = item_moniker_load_string_record(stream, &This->itemName);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2019-12-13 11:06:56 +01:00
|
|
|
return hr;
|
1999-01-28 18:56:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
1999-02-18 14:26:22 +01:00
|
|
|
* ItemMoniker_Save
|
1999-01-28 18:56:14 +01:00
|
|
|
******************************************************************************/
|
2019-12-13 11:06:54 +01:00
|
|
|
static HRESULT WINAPI ItemMonikerImpl_Save(IMoniker *iface, IStream *stream, BOOL fClearDirty)
|
1999-01-28 18:56:14 +01:00
|
|
|
{
|
2011-08-24 12:14:29 +02:00
|
|
|
ItemMonikerImpl *This = impl_from_IMoniker(iface);
|
2019-12-13 11:06:54 +01:00
|
|
|
int str_len;
|
|
|
|
HRESULT hr;
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
TRACE("(%p, %p, %d)\n", iface, stream, fClearDirty);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2003-06-18 05:30:39 +02:00
|
|
|
/* data written by this function are : 1) DWORD : size of item delimiter string ('\0' included ) */
|
1999-03-23 14:48:56 +01:00
|
|
|
/* 2) String (type A): item delimiter string ('\0' included) */
|
|
|
|
/* 3) DWORD : size of item name string ('\0' included) */
|
|
|
|
/* 4) String (type A): item name string ('\0' included) */
|
2019-12-13 11:06:54 +01:00
|
|
|
if (This->itemDelimiter)
|
|
|
|
{
|
|
|
|
str_len = WideCharToMultiByte(CP_ACP, 0, This->itemDelimiter, -1, NULL, 0, NULL, NULL);
|
|
|
|
str = heap_alloc(str_len);
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, This->itemDelimiter, -1, str, str_len, NULL, NULL);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2019-12-13 11:06:54 +01:00
|
|
|
hr = IStream_Write(stream, &str_len, sizeof(str_len), NULL);
|
|
|
|
hr = IStream_Write(stream, str, str_len, NULL);
|
2005-02-18 21:13:23 +01:00
|
|
|
|
2019-12-13 11:06:54 +01:00
|
|
|
heap_free(str);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
str_len = 0;
|
|
|
|
hr = IStream_Write(stream, &str_len, sizeof(str_len), NULL);
|
|
|
|
}
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2019-12-13 11:06:54 +01:00
|
|
|
str_len = WideCharToMultiByte(CP_ACP, 0, This->itemName, -1, NULL, 0, NULL, NULL);
|
|
|
|
str = heap_alloc(str_len);
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, This->itemName, -1, str, str_len, NULL, NULL);
|
|
|
|
hr = IStream_Write(stream, &str_len, sizeof(str_len), NULL);
|
|
|
|
hr = IStream_Write(stream, str, str_len, NULL);
|
|
|
|
heap_free(str);
|
2007-11-10 17:04:40 +01:00
|
|
|
|
2019-12-13 11:06:54 +01:00
|
|
|
return hr;
|
1999-01-28 18:56:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* ItemMoniker_GetSizeMax
|
|
|
|
******************************************************************************/
|
2011-08-24 12:14:29 +02:00
|
|
|
static HRESULT WINAPI ItemMonikerImpl_GetSizeMax(IMoniker* iface, ULARGE_INTEGER* pcbSize)
|
1999-01-28 18:56:14 +01:00
|
|
|
{
|
2011-08-24 12:14:29 +02:00
|
|
|
ItemMonikerImpl *This = impl_from_IMoniker(iface);
|
1999-03-23 14:48:56 +01:00
|
|
|
DWORD nameLength=lstrlenW(This->itemName)+1;
|
1999-02-18 14:26:22 +01:00
|
|
|
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("(%p,%p)\n",iface,pcbSize);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2005-05-23 12:27:42 +02:00
|
|
|
if (!pcbSize)
|
1999-03-23 14:48:56 +01:00
|
|
|
return E_POINTER;
|
|
|
|
|
2008-04-09 21:33:37 +02:00
|
|
|
/* for more details see ItemMonikerImpl_Save comments */
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2004-01-23 02:51:33 +01:00
|
|
|
pcbSize->u.LowPart = sizeof(DWORD) + /* DWORD which contains delimiter length */
|
2001-02-28 06:31:02 +01:00
|
|
|
sizeof(DWORD) + /* DWORD which contains item name length */
|
2005-05-23 12:27:42 +02:00
|
|
|
nameLength*4 + /* item name string */
|
|
|
|
18; /* strange, but true */
|
2019-12-13 11:06:54 +01:00
|
|
|
if (This->itemDelimiter)
|
|
|
|
pcbSize->u.LowPart += (lstrlenW(This->itemDelimiter) + 1) * 4;
|
|
|
|
|
2004-01-23 02:51:33 +01:00
|
|
|
pcbSize->u.HighPart=0;
|
1999-03-23 14:48:56 +01:00
|
|
|
|
|
|
|
return S_OK;
|
1999-01-28 18:56:14 +01:00
|
|
|
}
|
|
|
|
|
2020-01-22 10:11:46 +01:00
|
|
|
static DWORD get_bind_speed_from_bindctx(IBindCtx *pbc)
|
|
|
|
{
|
|
|
|
DWORD bind_speed = BINDSPEED_INDEFINITE;
|
|
|
|
BIND_OPTS bind_opts;
|
|
|
|
|
|
|
|
bind_opts.cbStruct = sizeof(bind_opts);
|
|
|
|
if (SUCCEEDED(IBindCtx_GetBindOptions(pbc, &bind_opts)) && bind_opts.dwTickCountDeadline)
|
|
|
|
bind_speed = bind_opts.dwTickCountDeadline < 2500 ? BINDSPEED_IMMEDIATE : BINDSPEED_MODERATE;
|
|
|
|
|
|
|
|
return bind_speed;
|
|
|
|
}
|
|
|
|
|
1999-01-28 18:56:14 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* ItemMoniker_BindToObject
|
|
|
|
******************************************************************************/
|
2010-01-21 12:58:24 +01:00
|
|
|
static HRESULT WINAPI ItemMonikerImpl_BindToObject(IMoniker* iface,
|
|
|
|
IBindCtx* pbc,
|
|
|
|
IMoniker* pmkToLeft,
|
|
|
|
REFIID riid,
|
|
|
|
VOID** ppvResult)
|
1999-02-18 14:26:22 +01:00
|
|
|
{
|
2011-08-24 12:14:29 +02:00
|
|
|
ItemMonikerImpl *This = impl_from_IMoniker(iface);
|
2020-01-22 10:11:46 +01:00
|
|
|
IOleItemContainer *container;
|
|
|
|
HRESULT hr;
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2005-02-18 21:13:23 +01:00
|
|
|
TRACE("(%p,%p,%p,%s,%p)\n",iface,pbc,pmkToLeft,debugstr_guid(riid),ppvResult);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
|
|
|
if(ppvResult ==NULL)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
if(pmkToLeft==NULL)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
*ppvResult=0;
|
|
|
|
|
2020-01-22 10:11:46 +01:00
|
|
|
hr = IMoniker_BindToObject(pmkToLeft, pbc, NULL, &IID_IOleItemContainer, (void **)&container);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
2020-01-23 00:03:05 +01:00
|
|
|
if (FAILED(hr = set_container_lock(container, pbc)))
|
|
|
|
WARN("Failed to lock container, hr %#x.\n", hr);
|
|
|
|
|
2020-01-22 10:11:46 +01:00
|
|
|
hr = IOleItemContainer_GetObject(container, This->itemName, get_bind_speed_from_bindctx(pbc), pbc,
|
|
|
|
riid, ppvResult);
|
|
|
|
IOleItemContainer_Release(container);
|
1999-03-23 14:48:56 +01:00
|
|
|
}
|
|
|
|
|
2020-01-22 10:11:46 +01:00
|
|
|
return hr;
|
1999-01-28 18:56:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* ItemMoniker_BindToStorage
|
|
|
|
******************************************************************************/
|
2020-01-28 08:32:21 +01:00
|
|
|
static HRESULT WINAPI ItemMonikerImpl_BindToStorage(IMoniker *iface, IBindCtx *pbc, IMoniker *pmkToLeft, REFIID riid,
|
|
|
|
void **ppvResult)
|
1999-02-18 14:26:22 +01:00
|
|
|
{
|
2020-01-28 08:32:21 +01:00
|
|
|
ItemMonikerImpl *moniker = impl_from_IMoniker(iface);
|
|
|
|
IOleItemContainer *container;
|
|
|
|
HRESULT hr;
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2020-01-28 08:32:21 +01:00
|
|
|
TRACE("%p, %p, %p, %s, %p.\n", iface, pbc, pmkToLeft, debugstr_guid(riid), ppvResult);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2020-01-28 08:32:21 +01:00
|
|
|
*ppvResult = 0;
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2020-01-28 08:32:21 +01:00
|
|
|
if (!pmkToLeft)
|
1999-03-23 14:48:56 +01:00
|
|
|
return E_INVALIDARG;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2020-01-28 08:32:21 +01:00
|
|
|
hr = IMoniker_BindToObject(pmkToLeft, pbc, NULL, &IID_IOleItemContainer, (void **)&container);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
if (FAILED(hr = set_container_lock(container, pbc)))
|
|
|
|
WARN("Failed to lock container, hr %#x.\n", hr);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2020-01-28 08:32:21 +01:00
|
|
|
hr = IOleItemContainer_GetObjectStorage(container, moniker->itemName, pbc, riid, ppvResult);
|
|
|
|
IOleItemContainer_Release(container);
|
1999-03-23 14:48:56 +01:00
|
|
|
}
|
|
|
|
|
2020-01-28 08:32:21 +01:00
|
|
|
return hr;
|
1999-01-28 18:56:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* ItemMoniker_Reduce
|
|
|
|
******************************************************************************/
|
2010-01-21 12:58:24 +01:00
|
|
|
static HRESULT WINAPI ItemMonikerImpl_Reduce(IMoniker* iface,
|
|
|
|
IBindCtx* pbc,
|
|
|
|
DWORD dwReduceHowFar,
|
|
|
|
IMoniker** ppmkToLeft,
|
|
|
|
IMoniker** ppmkReduced)
|
1999-02-18 14:26:22 +01:00
|
|
|
{
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("(%p,%p,%d,%p,%p)\n",iface,pbc,dwReduceHowFar,ppmkToLeft,ppmkReduced);
|
1999-01-28 18:56:14 +01:00
|
|
|
|
1999-03-23 14:48:56 +01:00
|
|
|
if (ppmkReduced==NULL)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
ItemMonikerImpl_AddRef(iface);
|
1999-01-28 18:56:14 +01:00
|
|
|
|
1999-03-23 14:48:56 +01:00
|
|
|
*ppmkReduced=iface;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-03-23 14:48:56 +01:00
|
|
|
return MK_S_REDUCED_TO_SELF;
|
|
|
|
}
|
1999-01-28 18:56:14 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* ItemMoniker_ComposeWith
|
|
|
|
******************************************************************************/
|
2010-01-21 12:58:24 +01:00
|
|
|
static HRESULT WINAPI ItemMonikerImpl_ComposeWith(IMoniker* iface,
|
|
|
|
IMoniker* pmkRight,
|
|
|
|
BOOL fOnlyIfNotGeneric,
|
|
|
|
IMoniker** ppmkComposite)
|
1999-02-18 14:26:22 +01:00
|
|
|
{
|
1999-03-23 14:48:56 +01:00
|
|
|
HRESULT res=S_OK;
|
2020-01-29 14:57:04 +01:00
|
|
|
DWORD mkSys,mkSys2, order;
|
1999-03-23 14:48:56 +01:00
|
|
|
IEnumMoniker* penumMk=0;
|
|
|
|
IMoniker *pmostLeftMk=0;
|
|
|
|
IMoniker* tempMkComposite=0;
|
1999-01-28 18:56:14 +01:00
|
|
|
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("(%p,%p,%d,%p)\n",iface,pmkRight,fOnlyIfNotGeneric,ppmkComposite);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
|
|
|
if ((ppmkComposite==NULL)||(pmkRight==NULL))
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
*ppmkComposite=0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2020-01-29 14:57:04 +01:00
|
|
|
if (is_anti_moniker(pmkRight, &order))
|
|
|
|
{
|
|
|
|
return order > 1 ? create_anti_moniker(order - 1, ppmkComposite) : S_OK;
|
|
|
|
}
|
1999-03-23 14:48:56 +01:00
|
|
|
else
|
|
|
|
/* if pmkRight is a composite whose leftmost component is an anti-moniker, */
|
|
|
|
/* the returned moniker is the composite after the leftmost anti-moniker is removed. */
|
2020-01-29 14:57:04 +01:00
|
|
|
IMoniker_IsSystemMoniker(pmkRight,&mkSys);
|
1999-03-23 14:48:56 +01:00
|
|
|
if(mkSys==MKSYS_GENERICCOMPOSITE){
|
|
|
|
|
|
|
|
res=IMoniker_Enum(pmkRight,TRUE,&penumMk);
|
|
|
|
|
|
|
|
if (FAILED(res))
|
|
|
|
return res;
|
|
|
|
|
|
|
|
res=IEnumMoniker_Next(penumMk,1,&pmostLeftMk,NULL);
|
|
|
|
|
|
|
|
IMoniker_IsSystemMoniker(pmostLeftMk,&mkSys2);
|
|
|
|
|
|
|
|
if(mkSys2==MKSYS_ANTIMONIKER){
|
|
|
|
|
|
|
|
IMoniker_Release(pmostLeftMk);
|
|
|
|
|
|
|
|
tempMkComposite=iface;
|
|
|
|
IMoniker_AddRef(iface);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-03-23 14:48:56 +01:00
|
|
|
while(IEnumMoniker_Next(penumMk,1,&pmostLeftMk,NULL)==S_OK){
|
|
|
|
|
|
|
|
res=CreateGenericComposite(tempMkComposite,pmostLeftMk,ppmkComposite);
|
|
|
|
|
|
|
|
IMoniker_Release(tempMkComposite);
|
|
|
|
IMoniker_Release(pmostLeftMk);
|
|
|
|
|
|
|
|
tempMkComposite=*ppmkComposite;
|
|
|
|
IMoniker_AddRef(tempMkComposite);
|
2001-09-11 02:32:32 +02:00
|
|
|
}
|
1999-03-23 14:48:56 +01:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return CreateGenericComposite(iface,pmkRight,ppmkComposite);
|
|
|
|
}
|
|
|
|
/* If pmkRight is not an anti-moniker, the method combines the two monikers into a generic
|
|
|
|
composite if fOnlyIfNotGeneric is FALSE; if fOnlyIfNotGeneric is TRUE, the method returns
|
|
|
|
a NULL moniker and a return value of MK_E_NEEDGENERIC */
|
|
|
|
else
|
|
|
|
if (!fOnlyIfNotGeneric)
|
|
|
|
return CreateGenericComposite(iface,pmkRight,ppmkComposite);
|
|
|
|
|
|
|
|
else
|
|
|
|
return MK_E_NEEDGENERIC;
|
1999-01-28 18:56:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* ItemMoniker_Enum
|
|
|
|
******************************************************************************/
|
2010-01-21 12:58:24 +01:00
|
|
|
static HRESULT WINAPI ItemMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker)
|
1999-02-18 14:26:22 +01:00
|
|
|
{
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("(%p,%d,%p)\n",iface,fForward,ppenumMoniker);
|
1999-01-28 18:56:14 +01:00
|
|
|
|
1999-03-23 14:48:56 +01:00
|
|
|
if (ppenumMoniker == NULL)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
*ppenumMoniker = NULL;
|
1999-01-28 18:56:14 +01:00
|
|
|
|
1999-03-23 14:48:56 +01:00
|
|
|
return S_OK;
|
1999-01-28 18:56:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* ItemMoniker_IsEqual
|
|
|
|
******************************************************************************/
|
2020-01-23 00:03:06 +01:00
|
|
|
static HRESULT WINAPI ItemMonikerImpl_IsEqual(IMoniker *iface, IMoniker *other)
|
1999-02-18 14:26:22 +01:00
|
|
|
{
|
2020-01-23 00:03:06 +01:00
|
|
|
ItemMonikerImpl *moniker = impl_from_IMoniker(iface), *other_moniker;
|
1999-01-28 18:56:14 +01:00
|
|
|
|
2020-01-23 00:03:06 +01:00
|
|
|
TRACE("%p, %p.\n", iface, other);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2020-01-23 00:03:06 +01:00
|
|
|
if (!other)
|
|
|
|
return E_INVALIDARG;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2020-01-23 00:03:06 +01:00
|
|
|
other_moniker = unsafe_impl_from_IMoniker(other);
|
|
|
|
if (!other_moniker)
|
|
|
|
return S_FALSE;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2020-01-23 00:03:06 +01:00
|
|
|
return !wcsicmp(moniker->itemName, other_moniker->itemName) ? S_OK : S_FALSE;
|
1999-01-28 18:56:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* ItemMoniker_Hash
|
|
|
|
******************************************************************************/
|
2010-01-21 12:58:24 +01:00
|
|
|
static HRESULT WINAPI ItemMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash)
|
1999-02-18 14:26:22 +01:00
|
|
|
{
|
2011-08-24 12:14:29 +02:00
|
|
|
ItemMonikerImpl *This = impl_from_IMoniker(iface);
|
2006-05-08 13:41:58 +02:00
|
|
|
DWORD h = 0;
|
|
|
|
int i,len;
|
1999-03-23 14:48:56 +01:00
|
|
|
int off = 0;
|
|
|
|
LPOLESTR val;
|
|
|
|
|
|
|
|
if (pdwHash==NULL)
|
|
|
|
return E_POINTER;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-03-23 14:48:56 +01:00
|
|
|
val = This->itemName;
|
|
|
|
len = lstrlenW(val);
|
|
|
|
|
2006-05-08 13:41:58 +02:00
|
|
|
for (i = len ; i > 0; i--)
|
2019-06-17 09:36:46 +02:00
|
|
|
h = (h * 3) ^ towupper(val[off++]);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
|
|
|
*pdwHash=h;
|
|
|
|
|
|
|
|
return S_OK;
|
1999-01-28 18:56:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* ItemMoniker_IsRunning
|
|
|
|
******************************************************************************/
|
2020-01-28 08:32:20 +01:00
|
|
|
static HRESULT WINAPI ItemMonikerImpl_IsRunning(IMoniker *iface, IBindCtx *pbc, IMoniker *pmkToLeft,
|
|
|
|
IMoniker *pmkNewlyRunning)
|
1999-02-18 14:26:22 +01:00
|
|
|
{
|
2020-01-28 08:32:20 +01:00
|
|
|
ItemMonikerImpl *moniker = impl_from_IMoniker(iface);
|
|
|
|
IOleItemContainer *container;
|
1999-03-23 14:48:56 +01:00
|
|
|
IRunningObjectTable* rot;
|
2020-01-28 08:32:20 +01:00
|
|
|
HRESULT hr;
|
1999-01-28 18:56:14 +01:00
|
|
|
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pmkNewlyRunning);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2020-01-28 08:32:20 +01:00
|
|
|
if (!pbc)
|
|
|
|
return E_INVALIDARG;
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2020-01-28 08:32:20 +01:00
|
|
|
if (!pmkToLeft)
|
|
|
|
{
|
|
|
|
if (pmkNewlyRunning)
|
|
|
|
{
|
|
|
|
return IMoniker_IsEqual(iface, pmkNewlyRunning);
|
1999-03-23 14:48:56 +01:00
|
|
|
}
|
2020-01-28 08:32:20 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
hr = IBindCtx_GetRunningObjectTable(pbc, &rot);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
hr = IRunningObjectTable_IsRunning(rot, iface);
|
|
|
|
IRunningObjectTable_Release(rot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Container itself must be running too. */
|
|
|
|
hr = IMoniker_IsRunning(pmkToLeft, pbc, NULL, NULL);
|
|
|
|
if (hr != S_OK)
|
|
|
|
return hr;
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2020-01-28 08:32:20 +01:00
|
|
|
hr = IMoniker_BindToObject(pmkToLeft, pbc, NULL, &IID_IOleItemContainer, (void **)&container);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
hr = IOleItemContainer_IsRunning(container, moniker->itemName);
|
|
|
|
IOleItemContainer_Release(container);
|
1999-03-23 14:48:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-28 08:32:20 +01:00
|
|
|
return hr;
|
1999-01-28 18:56:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* ItemMoniker_GetTimeOfLastChange
|
|
|
|
******************************************************************************/
|
2010-01-21 12:58:24 +01:00
|
|
|
static HRESULT WINAPI ItemMonikerImpl_GetTimeOfLastChange(IMoniker* iface,
|
|
|
|
IBindCtx* pbc,
|
|
|
|
IMoniker* pmkToLeft,
|
|
|
|
FILETIME* pItemTime)
|
1999-02-18 14:26:22 +01:00
|
|
|
{
|
1999-03-23 14:48:56 +01:00
|
|
|
IRunningObjectTable* rot;
|
|
|
|
HRESULT res;
|
|
|
|
IMoniker *compositeMk;
|
1999-01-28 18:56:14 +01:00
|
|
|
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pItemTime);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
|
|
|
if (pItemTime==NULL)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
/* If pmkToLeft is NULL, this method returns MK_E_NOTBINDABLE */
|
|
|
|
if (pmkToLeft==NULL)
|
|
|
|
|
|
|
|
return MK_E_NOTBINDABLE;
|
|
|
|
else {
|
|
|
|
|
|
|
|
/* Otherwise, the method creates a composite of pmkToLeft and this moniker and uses the ROT to access */
|
|
|
|
/* the time of last change. If the object is not in the ROT, the method calls */
|
|
|
|
/* IMoniker::GetTimeOfLastChange on the pmkToLeft parameter. */
|
|
|
|
|
|
|
|
res=CreateGenericComposite(pmkToLeft,iface,&compositeMk);
|
2015-03-20 07:41:34 +01:00
|
|
|
if (FAILED(res))
|
|
|
|
return res;
|
1999-03-23 14:48:56 +01:00
|
|
|
|
|
|
|
res=IBindCtx_GetRunningObjectTable(pbc,&rot);
|
2015-03-20 07:41:34 +01:00
|
|
|
if (FAILED(res)) {
|
|
|
|
IMoniker_Release(compositeMk);
|
|
|
|
return res;
|
|
|
|
}
|
1999-03-23 14:48:56 +01:00
|
|
|
|
|
|
|
if (IRunningObjectTable_GetTimeOfLastChange(rot,compositeMk,pItemTime)!=S_OK)
|
|
|
|
|
|
|
|
res=IMoniker_GetTimeOfLastChange(pmkToLeft,pbc,NULL,pItemTime);
|
|
|
|
|
|
|
|
IMoniker_Release(compositeMk);
|
2001-09-11 02:32:32 +02:00
|
|
|
}
|
1999-03-23 14:48:56 +01:00
|
|
|
|
|
|
|
return res;
|
1999-01-28 18:56:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* ItemMoniker_Inverse
|
|
|
|
******************************************************************************/
|
2010-01-21 12:58:24 +01:00
|
|
|
static HRESULT WINAPI ItemMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk)
|
1999-02-18 14:26:22 +01:00
|
|
|
{
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("(%p,%p)\n",iface,ppmk);
|
1999-01-28 18:56:14 +01:00
|
|
|
|
1999-03-23 14:48:56 +01:00
|
|
|
if (ppmk==NULL)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
return CreateAntiMoniker(ppmk);
|
1999-01-28 18:56:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* ItemMoniker_CommonPrefixWith
|
|
|
|
******************************************************************************/
|
2010-01-21 12:58:24 +01:00
|
|
|
static HRESULT WINAPI ItemMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** ppmkPrefix)
|
1999-02-18 14:26:22 +01:00
|
|
|
{
|
1999-03-23 14:48:56 +01:00
|
|
|
DWORD mkSys;
|
2005-02-18 21:13:23 +01:00
|
|
|
|
|
|
|
TRACE("(%p,%p)\n", pmkOther, ppmkPrefix);
|
|
|
|
|
1999-03-23 14:48:56 +01:00
|
|
|
IMoniker_IsSystemMoniker(pmkOther,&mkSys);
|
|
|
|
/* If the other moniker is an item moniker that is equal to this moniker, this method sets *ppmkPrefix */
|
|
|
|
/* to this moniker and returns MK_S_US */
|
|
|
|
|
|
|
|
if((mkSys==MKSYS_ITEMMONIKER) && (IMoniker_IsEqual(iface,pmkOther)==S_OK) ){
|
|
|
|
|
|
|
|
*ppmkPrefix=iface;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-03-23 14:48:56 +01:00
|
|
|
IMoniker_AddRef(iface);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-03-23 14:48:56 +01:00
|
|
|
return MK_S_US;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
/* otherwise, the method calls the MonikerCommonPrefixWith function. This function correctly handles */
|
|
|
|
/* the case where the other moniker is a generic composite. */
|
|
|
|
return MonikerCommonPrefixWith(iface,pmkOther,ppmkPrefix);
|
1999-01-28 18:56:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* ItemMoniker_RelativePathTo
|
|
|
|
******************************************************************************/
|
2010-01-21 12:58:24 +01:00
|
|
|
static HRESULT WINAPI ItemMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath)
|
1999-02-18 14:26:22 +01:00
|
|
|
{
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("(%p,%p,%p)\n",iface,pmOther,ppmkRelPath);
|
1999-01-28 18:56:14 +01:00
|
|
|
|
1999-03-23 14:48:56 +01:00
|
|
|
if (ppmkRelPath==NULL)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
*ppmkRelPath=0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-03-23 14:48:56 +01:00
|
|
|
return MK_E_NOTBINDABLE;
|
1999-01-28 18:56:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* ItemMoniker_GetDisplayName
|
|
|
|
******************************************************************************/
|
2010-01-21 12:58:24 +01:00
|
|
|
static HRESULT WINAPI ItemMonikerImpl_GetDisplayName(IMoniker* iface,
|
|
|
|
IBindCtx* pbc,
|
|
|
|
IMoniker* pmkToLeft,
|
|
|
|
LPOLESTR *ppszDisplayName)
|
1999-02-18 14:26:22 +01:00
|
|
|
{
|
2011-08-24 12:14:29 +02:00
|
|
|
ItemMonikerImpl *This = impl_from_IMoniker(iface);
|
2019-12-13 11:06:54 +01:00
|
|
|
SIZE_T size;
|
1999-01-28 18:56:14 +01:00
|
|
|
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,ppszDisplayName);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
|
|
|
if (ppszDisplayName==NULL)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
if (pmkToLeft!=NULL){
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2019-12-13 11:06:54 +01:00
|
|
|
size = lstrlenW(This->itemName) + 1;
|
|
|
|
if (This->itemDelimiter)
|
|
|
|
size += lstrlenW(This->itemDelimiter);
|
|
|
|
size *= sizeof(WCHAR);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2019-12-13 11:06:54 +01:00
|
|
|
*ppszDisplayName = CoTaskMemAlloc(size);
|
1999-03-23 14:48:56 +01:00
|
|
|
if (*ppszDisplayName==NULL)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2019-12-13 11:06:54 +01:00
|
|
|
(*ppszDisplayName)[0] = 0;
|
|
|
|
if (This->itemDelimiter)
|
|
|
|
lstrcatW(*ppszDisplayName, This->itemDelimiter);
|
2002-07-16 03:43:24 +02:00
|
|
|
lstrcatW(*ppszDisplayName,This->itemName);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2005-02-18 21:13:23 +01:00
|
|
|
TRACE("-- %s\n", debugstr_w(*ppszDisplayName));
|
|
|
|
|
1999-03-23 14:48:56 +01:00
|
|
|
return S_OK;
|
1999-01-28 18:56:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* ItemMoniker_ParseDisplayName
|
|
|
|
******************************************************************************/
|
2020-01-22 10:11:47 +01:00
|
|
|
static HRESULT WINAPI ItemMonikerImpl_ParseDisplayName(IMoniker *iface, IBindCtx *pbc, IMoniker *pmkToLeft,
|
|
|
|
LPOLESTR displayname, ULONG *eaten, IMoniker **ppmkOut)
|
1999-02-18 14:26:22 +01:00
|
|
|
{
|
2011-08-24 12:14:29 +02:00
|
|
|
ItemMonikerImpl *This = impl_from_IMoniker(iface);
|
2020-01-22 10:11:47 +01:00
|
|
|
IOleItemContainer *container;
|
|
|
|
IParseDisplayName *parser;
|
|
|
|
HRESULT hr;
|
2005-02-18 21:13:23 +01:00
|
|
|
|
2020-01-22 10:11:47 +01:00
|
|
|
TRACE("%p, %p, %p, %s, %p, %p.\n", iface, pbc, pmkToLeft, debugstr_w(displayname), eaten, ppmkOut);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2020-01-22 10:11:47 +01:00
|
|
|
if (!pmkToLeft)
|
1999-03-23 14:48:56 +01:00
|
|
|
return MK_E_SYNTAX;
|
|
|
|
|
2020-01-22 10:11:47 +01:00
|
|
|
hr = IMoniker_BindToObject(pmkToLeft, pbc, NULL, &IID_IOleItemContainer, (void **)&container);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
2020-01-23 00:03:04 +01:00
|
|
|
if (SUCCEEDED(hr = set_container_lock(container, pbc)))
|
2020-01-23 00:03:02 +01:00
|
|
|
{
|
2020-01-23 00:03:04 +01:00
|
|
|
hr = IOleItemContainer_GetObject(container, This->itemName, get_bind_speed_from_bindctx(pbc), pbc,
|
|
|
|
&IID_IParseDisplayName, (void **)&parser);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
hr = IParseDisplayName_ParseDisplayName(parser, pbc, displayname, eaten, ppmkOut);
|
|
|
|
IParseDisplayName_Release(parser);
|
|
|
|
}
|
2020-01-23 00:03:02 +01:00
|
|
|
}
|
2020-01-22 10:11:47 +01:00
|
|
|
IOleItemContainer_Release(container);
|
2001-09-11 02:32:32 +02:00
|
|
|
}
|
2020-01-22 10:11:47 +01:00
|
|
|
|
|
|
|
return hr;
|
1999-01-28 18:56:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2001-04-20 20:36:05 +02:00
|
|
|
* ItemMoniker_IsSystemMoniker
|
1999-01-28 18:56:14 +01:00
|
|
|
******************************************************************************/
|
2010-01-21 12:58:24 +01:00
|
|
|
static HRESULT WINAPI ItemMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys)
|
1999-02-18 14:26:22 +01:00
|
|
|
{
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("(%p,%p)\n",iface,pwdMksys);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
|
|
|
if (!pwdMksys)
|
|
|
|
return E_POINTER;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-03-23 14:48:56 +01:00
|
|
|
(*pwdMksys)=MKSYS_ITEMMONIKER;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
1999-01-28 18:56:14 +01:00
|
|
|
|
1999-03-23 14:48:56 +01:00
|
|
|
/*******************************************************************************
|
|
|
|
* ItemMonikerIROTData_QueryInterface
|
|
|
|
*******************************************************************************/
|
2011-08-24 12:14:29 +02:00
|
|
|
static HRESULT WINAPI ItemMonikerROTDataImpl_QueryInterface(IROTData *iface,REFIID riid,
|
|
|
|
void **ppvObject)
|
1999-03-23 14:48:56 +01:00
|
|
|
{
|
|
|
|
|
2011-08-24 12:14:29 +02:00
|
|
|
ItemMonikerImpl *This = impl_from_IROTData(iface);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2016-09-15 23:15:59 +02:00
|
|
|
TRACE("(%p,%s,%p)\n",iface,debugstr_guid(riid),ppvObject);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2011-08-24 12:14:29 +02:00
|
|
|
return ItemMonikerImpl_QueryInterface(&This->IMoniker_iface, riid, ppvObject);
|
1999-03-23 14:48:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ItemMonikerIROTData_AddRef
|
|
|
|
*/
|
2010-01-21 12:58:24 +01:00
|
|
|
static ULONG WINAPI ItemMonikerROTDataImpl_AddRef(IROTData *iface)
|
1999-03-23 14:48:56 +01:00
|
|
|
{
|
2011-08-24 12:14:29 +02:00
|
|
|
ItemMonikerImpl *This = impl_from_IROTData(iface);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("(%p)\n",iface);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2011-08-24 12:14:29 +02:00
|
|
|
return ItemMonikerImpl_AddRef(&This->IMoniker_iface);
|
1999-03-23 14:48:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ItemMonikerIROTData_Release
|
|
|
|
*/
|
2010-01-21 12:58:24 +01:00
|
|
|
static ULONG WINAPI ItemMonikerROTDataImpl_Release(IROTData* iface)
|
1999-03-23 14:48:56 +01:00
|
|
|
{
|
2011-08-24 12:14:29 +02:00
|
|
|
ItemMonikerImpl *This = impl_from_IROTData(iface);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("(%p)\n",iface);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2011-08-24 12:14:29 +02:00
|
|
|
return ItemMonikerImpl_Release(&This->IMoniker_iface);
|
1999-03-23 14:48:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2008-04-14 01:01:50 +02:00
|
|
|
* ItemMonikerIROTData_GetComparisonData
|
1999-03-23 14:48:56 +01:00
|
|
|
******************************************************************************/
|
2019-12-13 11:06:54 +01:00
|
|
|
static HRESULT WINAPI ItemMonikerROTDataImpl_GetComparisonData(IROTData *iface, BYTE *buffer, ULONG max_len,
|
|
|
|
ULONG *data_len)
|
1999-03-23 14:48:56 +01:00
|
|
|
{
|
2011-08-24 12:14:29 +02:00
|
|
|
ItemMonikerImpl *This = impl_from_IROTData(iface);
|
2019-12-13 11:06:54 +01:00
|
|
|
int name_len = lstrlenW(This->itemName);
|
|
|
|
int delim_len, i;
|
|
|
|
WCHAR *ptrW;
|
2005-05-18 20:28:15 +02:00
|
|
|
|
2019-12-13 11:06:54 +01:00
|
|
|
TRACE("(%p, %p, %u, %p)\n", iface, buffer, max_len, data_len);
|
2005-05-18 20:28:15 +02:00
|
|
|
|
2019-12-13 11:06:54 +01:00
|
|
|
delim_len = This->itemDelimiter && This->itemDelimiter[0] ? lstrlenW(This->itemDelimiter) : 0;
|
|
|
|
*data_len = sizeof(CLSID) + sizeof(WCHAR) + (delim_len + name_len) * sizeof(WCHAR);
|
|
|
|
if (max_len < *data_len)
|
2005-05-18 20:28:15 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
/* write CLSID */
|
2019-12-13 11:06:54 +01:00
|
|
|
memcpy(buffer, &CLSID_ItemMoniker, sizeof(CLSID));
|
|
|
|
buffer += sizeof(CLSID);
|
|
|
|
|
2005-05-18 20:28:15 +02:00
|
|
|
/* write delimiter */
|
2019-12-13 11:06:54 +01:00
|
|
|
for (i = 0, ptrW = (WCHAR *)buffer; i < delim_len; ++i)
|
|
|
|
ptrW[i] = towupper(This->itemDelimiter[i]);
|
|
|
|
buffer += (delim_len * sizeof(WCHAR));
|
|
|
|
|
2005-05-18 20:28:15 +02:00
|
|
|
/* write name */
|
2019-12-13 11:06:54 +01:00
|
|
|
for (i = 0, ptrW = (WCHAR *)buffer; i < name_len; ++i)
|
|
|
|
ptrW[i] = towupper(This->itemName[i]);
|
|
|
|
ptrW[i] = 0;
|
2005-05-18 20:28:15 +02:00
|
|
|
|
|
|
|
return S_OK;
|
1999-01-28 18:56:14 +01:00
|
|
|
}
|
|
|
|
|
2010-01-21 12:58:24 +01:00
|
|
|
/********************************************************************************/
|
|
|
|
/* Virtual function table for the ItemMonikerImpl class which include IPersist,*/
|
|
|
|
/* IPersistStream and IMoniker functions. */
|
|
|
|
static const IMonikerVtbl VT_ItemMonikerImpl =
|
|
|
|
{
|
|
|
|
ItemMonikerImpl_QueryInterface,
|
|
|
|
ItemMonikerImpl_AddRef,
|
|
|
|
ItemMonikerImpl_Release,
|
|
|
|
ItemMonikerImpl_GetClassID,
|
|
|
|
ItemMonikerImpl_IsDirty,
|
|
|
|
ItemMonikerImpl_Load,
|
|
|
|
ItemMonikerImpl_Save,
|
|
|
|
ItemMonikerImpl_GetSizeMax,
|
|
|
|
ItemMonikerImpl_BindToObject,
|
|
|
|
ItemMonikerImpl_BindToStorage,
|
|
|
|
ItemMonikerImpl_Reduce,
|
|
|
|
ItemMonikerImpl_ComposeWith,
|
|
|
|
ItemMonikerImpl_Enum,
|
|
|
|
ItemMonikerImpl_IsEqual,
|
|
|
|
ItemMonikerImpl_Hash,
|
|
|
|
ItemMonikerImpl_IsRunning,
|
|
|
|
ItemMonikerImpl_GetTimeOfLastChange,
|
|
|
|
ItemMonikerImpl_Inverse,
|
|
|
|
ItemMonikerImpl_CommonPrefixWith,
|
|
|
|
ItemMonikerImpl_RelativePathTo,
|
|
|
|
ItemMonikerImpl_GetDisplayName,
|
|
|
|
ItemMonikerImpl_ParseDisplayName,
|
|
|
|
ItemMonikerImpl_IsSystemMoniker
|
|
|
|
};
|
|
|
|
|
2020-01-23 00:03:06 +01:00
|
|
|
static ItemMonikerImpl *unsafe_impl_from_IMoniker(IMoniker *iface)
|
|
|
|
{
|
|
|
|
if (iface->lpVtbl != &VT_ItemMonikerImpl)
|
|
|
|
return NULL;
|
|
|
|
return CONTAINING_RECORD(iface, ItemMonikerImpl, IMoniker_iface);
|
|
|
|
}
|
|
|
|
|
2010-01-21 12:58:24 +01:00
|
|
|
/********************************************************************************/
|
|
|
|
/* Virtual function table for the IROTData class. */
|
|
|
|
static const IROTDataVtbl VT_ROTDataImpl =
|
|
|
|
{
|
|
|
|
ItemMonikerROTDataImpl_QueryInterface,
|
|
|
|
ItemMonikerROTDataImpl_AddRef,
|
|
|
|
ItemMonikerROTDataImpl_Release,
|
|
|
|
ItemMonikerROTDataImpl_GetComparisonData
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************
|
2020-01-28 08:32:19 +01:00
|
|
|
* CreateItemMoniker [OLE32.@]
|
|
|
|
******************************************************************************/
|
|
|
|
HRESULT WINAPI CreateItemMoniker(const WCHAR *delimiter, const WCHAR *name, IMoniker **ret)
|
2010-01-21 12:58:24 +01:00
|
|
|
{
|
2020-01-28 08:32:19 +01:00
|
|
|
ItemMonikerImpl *moniker;
|
2019-12-13 11:06:54 +01:00
|
|
|
int str_len;
|
2020-01-28 08:32:19 +01:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("%s, %s, %p.\n", debugstr_w(delimiter), debugstr_w(name), ret);
|
2010-01-21 12:58:24 +01:00
|
|
|
|
2020-01-28 08:32:19 +01:00
|
|
|
if (!(moniker = heap_alloc_zero(sizeof(*moniker))))
|
|
|
|
return E_OUTOFMEMORY;
|
2010-01-21 12:58:24 +01:00
|
|
|
|
2020-01-28 08:32:19 +01:00
|
|
|
moniker->IMoniker_iface.lpVtbl = &VT_ItemMonikerImpl;
|
|
|
|
moniker->IROTData_iface.lpVtbl = &VT_ROTDataImpl;
|
|
|
|
moniker->ref = 1;
|
2010-01-21 12:58:24 +01:00
|
|
|
|
2019-12-13 11:06:54 +01:00
|
|
|
str_len = (lstrlenW(name) + 1) * sizeof(WCHAR);
|
2020-01-28 08:32:19 +01:00
|
|
|
moniker->itemName = heap_alloc(str_len);
|
|
|
|
if (!moniker->itemName)
|
|
|
|
{
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
memcpy(moniker->itemName, name, str_len);
|
2010-01-21 12:58:24 +01:00
|
|
|
|
2019-12-13 11:06:54 +01:00
|
|
|
if (delimiter)
|
|
|
|
{
|
|
|
|
str_len = (lstrlenW(delimiter) + 1) * sizeof(WCHAR);
|
2020-01-28 08:32:19 +01:00
|
|
|
moniker->itemDelimiter = heap_alloc(str_len);
|
|
|
|
if (!moniker->itemDelimiter)
|
2019-12-13 11:06:54 +01:00
|
|
|
{
|
2020-01-28 08:32:19 +01:00
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
goto failed;
|
2019-12-13 11:06:54 +01:00
|
|
|
}
|
2020-01-28 08:32:19 +01:00
|
|
|
memcpy(moniker->itemDelimiter, delimiter, str_len);
|
2010-01-21 12:58:24 +01:00
|
|
|
}
|
2019-12-13 11:06:54 +01:00
|
|
|
|
2020-01-28 08:32:19 +01:00
|
|
|
*ret = &moniker->IMoniker_iface;
|
2010-01-21 12:58:24 +01:00
|
|
|
|
|
|
|
return S_OK;
|
1999-01-28 18:56:14 +01:00
|
|
|
|
2020-01-28 08:32:19 +01:00
|
|
|
failed:
|
|
|
|
IMoniker_Release(&moniker->IMoniker_iface);
|
1999-01-28 18:56:14 +01:00
|
|
|
|
2020-01-28 08:32:19 +01:00
|
|
|
return hr;
|
1999-01-28 18:56:14 +01:00
|
|
|
}
|
2005-05-19 16:22:14 +02:00
|
|
|
|
2020-01-28 08:32:19 +01:00
|
|
|
HRESULT WINAPI ItemMoniker_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
|
2005-05-19 16:22:14 +02:00
|
|
|
{
|
2020-01-28 08:32:19 +01:00
|
|
|
IMoniker *moniker;
|
|
|
|
HRESULT hr;
|
2005-05-19 16:22:14 +02:00
|
|
|
|
2020-01-28 08:32:19 +01:00
|
|
|
TRACE("(%p, %s, %p)\n", outer, debugstr_guid(riid), ppv);
|
2005-05-19 16:22:14 +02:00
|
|
|
|
|
|
|
*ppv = NULL;
|
|
|
|
|
2020-01-28 08:32:19 +01:00
|
|
|
if (outer)
|
2005-05-19 16:22:14 +02:00
|
|
|
return CLASS_E_NOAGGREGATION;
|
|
|
|
|
2020-11-26 22:20:04 +01:00
|
|
|
if (FAILED(hr = CreateItemMoniker(L"", L"", &moniker)))
|
2020-01-28 08:32:19 +01:00
|
|
|
return hr;
|
2005-05-19 16:22:14 +02:00
|
|
|
|
2020-01-28 08:32:19 +01:00
|
|
|
hr = IMoniker_QueryInterface(moniker, riid, ppv);
|
|
|
|
IMoniker_Release(moniker);
|
2005-05-19 16:22:14 +02:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|