1998-03-15 21:29:56 +01:00
|
|
|
/*
|
|
|
|
* Monikers
|
|
|
|
*
|
|
|
|
* Copyright 1998 Marcus Meissner
|
1999-01-28 18:56:14 +01:00
|
|
|
* Copyright 1999 Noomen Hamza
|
2005-05-23 11:54:53 +02:00
|
|
|
* Copyright 2005 Robert Shearman (for CodeWeavers)
|
2007-03-27 19:21:23 +02:00
|
|
|
* Copyright 2007 Robert Shearman
|
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
|
1998-03-15 21:29:56 +01:00
|
|
|
*/
|
|
|
|
|
2008-04-29 20:18:49 +02:00
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2001-01-26 21:43:40 +01:00
|
|
|
#include <string.h>
|
2000-11-08 06:05:15 +01:00
|
|
|
|
2004-10-07 05:06:48 +02:00
|
|
|
#define COBJMACROS
|
|
|
|
|
1998-03-15 21:29:56 +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-08 06:05:15 +01:00
|
|
|
#include "wtypes.h"
|
2000-03-08 19:25:22 +01:00
|
|
|
#include "ole2.h"
|
1998-03-15 21:29:56 +01:00
|
|
|
|
2005-05-23 11:54:53 +02:00
|
|
|
#include "wine/list.h"
|
|
|
|
#include "wine/debug.h"
|
2006-12-28 03:42:01 +01:00
|
|
|
#include "wine/unicode.h"
|
2007-09-10 17:10:45 +02:00
|
|
|
#include "wine/exception.h"
|
2005-05-23 11:54:53 +02:00
|
|
|
|
2000-11-25 04:08:23 +01:00
|
|
|
#include "compobj_private.h"
|
2007-03-27 19:21:23 +02:00
|
|
|
#include "moniker.h"
|
2007-09-10 17:10:45 +02:00
|
|
|
#include "irot.h"
|
2000-11-25 04:08:23 +01:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ole);
|
1999-04-19 16:56:29 +02:00
|
|
|
|
2006-12-28 03:41:56 +01:00
|
|
|
/* see MSDN docs for IROTData::GetComparisonData, which states what this
|
2008-03-01 05:36:46 +01:00
|
|
|
* constant is
|
|
|
|
*/
|
2006-12-28 03:41:56 +01:00
|
|
|
#define MAX_COMPARISON_DATA 2048
|
|
|
|
|
2008-02-15 16:19:29 +01:00
|
|
|
static LONG WINAPI rpc_filter(EXCEPTION_POINTERS *eptr)
|
2007-09-10 17:10:45 +02:00
|
|
|
{
|
2008-04-11 12:00:46 +02:00
|
|
|
return I_RpcExceptionFilter(eptr->ExceptionRecord->ExceptionCode);
|
2007-09-10 17:10:45 +02:00
|
|
|
}
|
|
|
|
|
1999-03-23 14:48:56 +01:00
|
|
|
/* define the structure of the running object table elements */
|
2005-05-23 11:54:53 +02:00
|
|
|
struct rot_entry
|
|
|
|
{
|
|
|
|
struct list entry;
|
2007-09-10 17:10:45 +02:00
|
|
|
InterfaceData* object; /* marshaled running object*/
|
|
|
|
MonikerComparisonData* moniker_data; /* moniker comparison data that identifies this object */
|
2005-05-23 11:54:53 +02:00
|
|
|
DWORD cookie; /* cookie identifying this object */
|
|
|
|
FILETIME last_modified;
|
2007-12-25 20:08:25 +01:00
|
|
|
IrotContextHandle ctxt_handle;
|
2005-05-23 11:54:53 +02:00
|
|
|
};
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2000-02-20 20:17:53 +01:00
|
|
|
/* define the RunningObjectTableImpl structure */
|
2005-05-23 11:54:53 +02:00
|
|
|
typedef struct RunningObjectTableImpl
|
|
|
|
{
|
2010-12-15 00:58:12 +01:00
|
|
|
IRunningObjectTable IRunningObjectTable_iface;
|
2005-07-05 13:02:54 +02:00
|
|
|
LONG ref;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2005-05-23 11:54:53 +02:00
|
|
|
struct list rot; /* list of ROT entries */
|
|
|
|
CRITICAL_SECTION lock;
|
1999-03-23 14:48:56 +01:00
|
|
|
} RunningObjectTableImpl;
|
|
|
|
|
2005-04-15 18:11:29 +02:00
|
|
|
static RunningObjectTableImpl* runningObjectTableInstance = NULL;
|
2007-09-10 17:10:45 +02:00
|
|
|
static IrotHandle irot_handle;
|
2005-05-14 20:50:14 +02:00
|
|
|
|
2005-05-23 11:54:53 +02:00
|
|
|
/* define the EnumMonikerImpl structure */
|
|
|
|
typedef struct EnumMonikerImpl
|
|
|
|
{
|
2010-12-15 00:58:12 +01:00
|
|
|
IEnumMoniker IEnumMoniker_iface;
|
2005-07-05 13:02:54 +02:00
|
|
|
LONG ref;
|
2005-05-14 20:50:14 +02:00
|
|
|
|
2007-11-10 17:05:23 +01:00
|
|
|
InterfaceList *moniker_list;
|
2005-05-23 11:54:53 +02:00
|
|
|
ULONG pos;
|
2005-05-14 20:50:14 +02:00
|
|
|
} EnumMonikerImpl;
|
|
|
|
|
2010-12-15 00:58:12 +01:00
|
|
|
static inline RunningObjectTableImpl *impl_from_IRunningObjectTable(IRunningObjectTable *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, RunningObjectTableImpl, IRunningObjectTable_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline EnumMonikerImpl *impl_from_IEnumMoniker(IEnumMoniker *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, EnumMonikerImpl, IEnumMoniker_iface);
|
|
|
|
}
|
2005-05-14 20:50:14 +02:00
|
|
|
|
|
|
|
/* IEnumMoniker Local functions*/
|
2008-11-25 16:41:41 +01:00
|
|
|
static HRESULT EnumMonikerImpl_CreateEnumROTMoniker(InterfaceList *moniker_list,
|
2007-11-10 17:05:23 +01:00
|
|
|
ULONG pos, IEnumMoniker **ppenumMoniker);
|
2005-05-23 11:54:53 +02:00
|
|
|
|
2007-09-10 17:10:45 +02:00
|
|
|
static IrotHandle get_irot_handle(void)
|
|
|
|
{
|
|
|
|
if (!irot_handle)
|
|
|
|
{
|
|
|
|
RPC_STATUS status;
|
|
|
|
RPC_WSTR binding;
|
|
|
|
IrotHandle new_handle;
|
|
|
|
unsigned short ncacn_np[] = IROT_PROTSEQ;
|
|
|
|
unsigned short endpoint[] = IROT_ENDPOINT;
|
|
|
|
status = RpcStringBindingComposeW(NULL, ncacn_np, NULL, endpoint, NULL, &binding);
|
|
|
|
if (status == RPC_S_OK)
|
|
|
|
{
|
|
|
|
status = RpcBindingFromStringBindingW(binding, &new_handle);
|
|
|
|
RpcStringFreeW(&binding);
|
|
|
|
}
|
|
|
|
if (status != RPC_S_OK)
|
|
|
|
return NULL;
|
|
|
|
if (InterlockedCompareExchangePointer(&irot_handle, new_handle, NULL))
|
|
|
|
/* another thread beat us to it */
|
|
|
|
RpcBindingFree(&new_handle);
|
|
|
|
}
|
|
|
|
return irot_handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL start_rpcss(void)
|
|
|
|
{
|
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
STARTUPINFOW si;
|
2009-10-27 11:20:34 +01:00
|
|
|
WCHAR cmd[MAX_PATH];
|
|
|
|
static const WCHAR rpcss[] = {'\\','r','p','c','s','s','.','e','x','e',0};
|
2007-09-10 17:10:45 +02:00
|
|
|
BOOL rslt;
|
2010-03-29 15:47:52 +02:00
|
|
|
void *redir;
|
2007-09-10 17:10:45 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
ZeroMemory(&si, sizeof(STARTUPINFOA));
|
|
|
|
si.cb = sizeof(STARTUPINFOA);
|
2009-10-27 11:20:34 +01:00
|
|
|
GetSystemDirectoryW( cmd, MAX_PATH - sizeof(rpcss)/sizeof(WCHAR) );
|
|
|
|
strcatW( cmd, rpcss );
|
2007-09-10 17:10:45 +02:00
|
|
|
|
2010-03-29 15:47:52 +02:00
|
|
|
Wow64DisableWow64FsRedirection( &redir );
|
2013-01-14 21:20:06 +01:00
|
|
|
rslt = CreateProcessW( cmd, cmd, NULL, NULL, FALSE, DETACHED_PROCESS, NULL, NULL, &si, &pi );
|
2010-03-29 15:47:52 +02:00
|
|
|
Wow64RevertWow64FsRedirection( redir );
|
2007-09-10 17:10:45 +02:00
|
|
|
|
|
|
|
if (rslt)
|
|
|
|
{
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
CloseHandle(pi.hThread);
|
|
|
|
Sleep(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rslt;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT create_stream_on_mip_ro(const InterfaceData *mip, IStream **stream)
|
2005-05-23 11:54:53 +02:00
|
|
|
{
|
|
|
|
HGLOBAL hglobal = GlobalAlloc(0, mip->ulCntData);
|
|
|
|
void *pv = GlobalLock(hglobal);
|
|
|
|
memcpy(pv, mip->abData, mip->ulCntData);
|
|
|
|
GlobalUnlock(hglobal);
|
|
|
|
return CreateStreamOnHGlobal(hglobal, TRUE, stream);
|
|
|
|
}
|
|
|
|
|
2011-10-31 21:49:48 +01:00
|
|
|
static void rot_entry_delete(struct rot_entry *rot_entry)
|
2005-05-23 11:54:53 +02:00
|
|
|
{
|
2007-09-10 17:10:45 +02:00
|
|
|
if (rot_entry->cookie)
|
2005-05-23 11:54:53 +02:00
|
|
|
{
|
2007-09-10 17:10:45 +02:00
|
|
|
InterfaceData *object = NULL;
|
|
|
|
InterfaceData *moniker = NULL;
|
|
|
|
__TRY
|
|
|
|
{
|
2007-12-25 20:08:25 +01:00
|
|
|
IrotRevoke(get_irot_handle(), rot_entry->cookie,
|
|
|
|
&rot_entry->ctxt_handle, &object, &moniker);
|
2007-09-10 17:10:45 +02:00
|
|
|
}
|
|
|
|
__EXCEPT(rpc_filter)
|
2005-05-23 11:54:53 +02:00
|
|
|
{
|
|
|
|
}
|
2007-09-10 17:10:45 +02:00
|
|
|
__ENDTRY
|
|
|
|
MIDL_user_free(object);
|
|
|
|
if (moniker)
|
|
|
|
{
|
|
|
|
IStream *stream;
|
|
|
|
HRESULT hr;
|
|
|
|
hr = create_stream_on_mip_ro(moniker, &stream);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
CoReleaseMarshalData(stream);
|
2012-08-13 11:40:33 +02:00
|
|
|
IStream_Release(stream);
|
2007-09-10 17:10:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
MIDL_user_free(moniker);
|
2005-05-23 11:54:53 +02:00
|
|
|
}
|
2007-09-10 17:10:45 +02:00
|
|
|
if (rot_entry->object)
|
2005-05-23 11:54:53 +02:00
|
|
|
{
|
|
|
|
IStream *stream;
|
|
|
|
HRESULT hr;
|
2007-09-10 17:10:45 +02:00
|
|
|
hr = create_stream_on_mip_ro(rot_entry->object, &stream);
|
2005-05-23 11:54:53 +02:00
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
CoReleaseMarshalData(stream);
|
2012-08-13 11:40:33 +02:00
|
|
|
IStream_Release(stream);
|
2005-05-23 11:54:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, rot_entry->object);
|
|
|
|
HeapFree(GetProcessHeap(), 0, rot_entry->moniker_data);
|
|
|
|
HeapFree(GetProcessHeap(), 0, rot_entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* moniker_data must be freed with HeapFree when no longer in use */
|
2007-09-10 17:10:45 +02:00
|
|
|
static HRESULT get_moniker_comparison_data(IMoniker *pMoniker, MonikerComparisonData **moniker_data)
|
2005-05-23 11:54:53 +02:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
IROTData *pROTData = NULL;
|
|
|
|
hr = IMoniker_QueryInterface(pMoniker, &IID_IROTData, (void *)&pROTData);
|
2006-12-28 03:42:01 +01:00
|
|
|
if (SUCCEEDED(hr))
|
2005-05-23 11:54:53 +02:00
|
|
|
{
|
2006-12-28 03:42:01 +01:00
|
|
|
ULONG size = MAX_COMPARISON_DATA;
|
2007-09-10 17:10:45 +02:00
|
|
|
*moniker_data = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(MonikerComparisonData, abData[size]));
|
|
|
|
if (!*moniker_data)
|
|
|
|
{
|
|
|
|
IROTData_Release(pROTData);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
2006-12-28 03:42:01 +01:00
|
|
|
hr = IROTData_GetComparisonData(pROTData, (*moniker_data)->abData, size, &size);
|
2007-09-10 17:10:45 +02:00
|
|
|
IROTData_Release(pROTData);
|
2006-12-28 03:42:01 +01:00
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
ERR("Failed to copy comparison data into buffer, hr = 0x%08x\n", hr);
|
|
|
|
HeapFree(GetProcessHeap(), 0, *moniker_data);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
(*moniker_data)->ulCntData = size;
|
2005-05-23 11:54:53 +02:00
|
|
|
}
|
2006-12-28 03:42:01 +01:00
|
|
|
else
|
2005-05-23 11:54:53 +02:00
|
|
|
{
|
2006-12-28 03:42:01 +01:00
|
|
|
IBindCtx *pbc;
|
|
|
|
LPOLESTR pszDisplayName;
|
|
|
|
CLSID clsid;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
TRACE("generating comparison data from display name\n");
|
|
|
|
|
|
|
|
hr = CreateBindCtx(0, &pbc);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
hr = IMoniker_GetDisplayName(pMoniker, pbc, NULL, &pszDisplayName);
|
|
|
|
IBindCtx_Release(pbc);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
hr = IMoniker_GetClassID(pMoniker, &clsid);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
CoTaskMemFree(pszDisplayName);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = strlenW(pszDisplayName);
|
|
|
|
*moniker_data = HeapAlloc(GetProcessHeap(), 0,
|
2007-09-10 17:10:45 +02:00
|
|
|
FIELD_OFFSET(MonikerComparisonData, abData[sizeof(CLSID) + (len+1)*sizeof(WCHAR)]));
|
2006-12-28 03:42:01 +01:00
|
|
|
if (!*moniker_data)
|
|
|
|
{
|
|
|
|
CoTaskMemFree(pszDisplayName);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
(*moniker_data)->ulCntData = sizeof(CLSID) + (len+1)*sizeof(WCHAR);
|
|
|
|
|
|
|
|
memcpy(&(*moniker_data)->abData[0], &clsid, sizeof(clsid));
|
|
|
|
memcpy(&(*moniker_data)->abData[sizeof(clsid)], pszDisplayName, (len+1)*sizeof(WCHAR));
|
2007-11-10 17:05:31 +01:00
|
|
|
CoTaskMemFree(pszDisplayName);
|
2005-05-23 11:54:53 +02:00
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2006-12-28 03:41:52 +01:00
|
|
|
static HRESULT reduce_moniker(IMoniker *pmk, IBindCtx *pbc, IMoniker **pmkReduced)
|
2006-12-28 03:41:45 +01:00
|
|
|
{
|
2006-12-28 03:41:52 +01:00
|
|
|
IBindCtx *pbcNew = NULL;
|
|
|
|
HRESULT hr;
|
|
|
|
if (!pbc)
|
|
|
|
{
|
|
|
|
hr = CreateBindCtx(0, &pbcNew);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
pbc = pbcNew;
|
|
|
|
}
|
2006-12-28 03:41:45 +01:00
|
|
|
hr = IMoniker_Reduce(pmk, pbc, MKRREDUCE_ALL, NULL, pmkReduced);
|
|
|
|
if (FAILED(hr))
|
|
|
|
ERR("reducing moniker failed with error 0x%08x\n", hr);
|
2006-12-28 03:41:52 +01:00
|
|
|
if (pbcNew) IBindCtx_Release(pbcNew);
|
2006-12-28 03:41:45 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
1999-03-23 14:48:56 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* RunningObjectTable_QueryInterface
|
1998-03-15 21:29:56 +01:00
|
|
|
*/
|
2005-05-11 17:56:45 +02:00
|
|
|
static HRESULT WINAPI
|
|
|
|
RunningObjectTableImpl_QueryInterface(IRunningObjectTable* iface,
|
|
|
|
REFIID riid,void** ppvObject)
|
1999-03-23 14:48:56 +01:00
|
|
|
{
|
2010-12-15 00:58:12 +01:00
|
|
|
RunningObjectTableImpl *This = impl_from_IRunningObjectTable(iface);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("(%p,%p,%p)\n",This,riid,ppvObject);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2000-02-20 20:17:53 +01:00
|
|
|
/* validate arguments */
|
1999-03-23 14:48:56 +01:00
|
|
|
|
|
|
|
if (ppvObject==0)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
*ppvObject = 0;
|
|
|
|
|
2005-05-11 17:56:45 +02:00
|
|
|
if (IsEqualIID(&IID_IUnknown, riid) ||
|
|
|
|
IsEqualIID(&IID_IRunningObjectTable, riid))
|
2015-03-20 08:15:42 +01:00
|
|
|
*ppvObject = &This->IRunningObjectTable_iface;
|
1999-03-23 14:48:56 +01:00
|
|
|
|
|
|
|
if ((*ppvObject)==0)
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
|
2005-05-11 17:56:45 +02:00
|
|
|
IRunningObjectTable_AddRef(iface);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RunningObjectTable_AddRef
|
|
|
|
*/
|
2005-05-11 17:56:45 +02:00
|
|
|
static ULONG WINAPI
|
|
|
|
RunningObjectTableImpl_AddRef(IRunningObjectTable* iface)
|
1999-03-23 14:48:56 +01:00
|
|
|
{
|
2010-12-15 00:58:12 +01:00
|
|
|
RunningObjectTableImpl *This = impl_from_IRunningObjectTable(iface);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("(%p)\n",This);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2004-09-24 03:16:53 +02:00
|
|
|
return InterlockedIncrement(&This->ref);
|
1999-03-23 14:48:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2009-04-24 13:15:47 +02:00
|
|
|
* RunningObjectTable_Destroy
|
1999-03-23 14:48:56 +01:00
|
|
|
*/
|
2008-11-25 16:41:41 +01:00
|
|
|
static HRESULT
|
2005-05-11 17:56:45 +02:00
|
|
|
RunningObjectTableImpl_Destroy(void)
|
1999-03-23 14:48:56 +01:00
|
|
|
{
|
2005-05-23 11:54:53 +02:00
|
|
|
struct list *cursor, *cursor2;
|
2007-09-10 17:10:45 +02:00
|
|
|
IrotHandle old_handle;
|
2005-05-23 11:54:53 +02:00
|
|
|
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("()\n");
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-03-23 14:48:56 +01:00
|
|
|
if (runningObjectTableInstance==NULL)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
/* free the ROT table memory */
|
2005-05-23 11:54:53 +02:00
|
|
|
LIST_FOR_EACH_SAFE(cursor, cursor2, &runningObjectTableInstance->rot)
|
|
|
|
{
|
|
|
|
struct rot_entry *rot_entry = LIST_ENTRY(cursor, struct rot_entry, entry);
|
|
|
|
list_remove(&rot_entry->entry);
|
|
|
|
rot_entry_delete(rot_entry);
|
|
|
|
}
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2007-03-11 00:21:23 +01:00
|
|
|
DEBUG_CLEAR_CRITSEC_NAME(&runningObjectTableInstance->lock);
|
|
|
|
DeleteCriticalSection(&runningObjectTableInstance->lock);
|
|
|
|
|
1999-03-23 14:48:56 +01:00
|
|
|
/* free the ROT structure memory */
|
|
|
|
HeapFree(GetProcessHeap(),0,runningObjectTableInstance);
|
2005-04-15 18:11:29 +02:00
|
|
|
runningObjectTableInstance = NULL;
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2007-09-10 17:10:45 +02:00
|
|
|
old_handle = irot_handle;
|
|
|
|
irot_handle = NULL;
|
|
|
|
if (old_handle)
|
|
|
|
RpcBindingFree(&old_handle);
|
|
|
|
|
1999-03-23 14:48:56 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RunningObjectTable_Release
|
|
|
|
*/
|
2005-05-11 17:56:45 +02:00
|
|
|
static ULONG WINAPI
|
|
|
|
RunningObjectTableImpl_Release(IRunningObjectTable* iface)
|
1999-03-23 14:48:56 +01:00
|
|
|
{
|
2010-12-15 00:58:12 +01:00
|
|
|
RunningObjectTableImpl *This = impl_from_IRunningObjectTable(iface);
|
2004-09-24 03:16:53 +02:00
|
|
|
ULONG ref;
|
1999-03-23 14:48:56 +01:00
|
|
|
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("(%p)\n",This);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2004-09-24 03:16:53 +02:00
|
|
|
ref = InterlockedDecrement(&This->ref);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2013-11-20 23:39:28 +01:00
|
|
|
/* uninitialize ROT structure if there are no more references to it */
|
2005-05-23 11:54:53 +02:00
|
|
|
if (ref == 0)
|
|
|
|
{
|
|
|
|
struct list *cursor, *cursor2;
|
|
|
|
LIST_FOR_EACH_SAFE(cursor, cursor2, &This->rot)
|
1999-03-23 14:48:56 +01:00
|
|
|
{
|
2005-05-23 11:54:53 +02:00
|
|
|
struct rot_entry *rot_entry = LIST_ENTRY(cursor, struct rot_entry, entry);
|
|
|
|
list_remove(&rot_entry->entry);
|
|
|
|
rot_entry_delete(rot_entry);
|
1999-03-23 14:48:56 +01:00
|
|
|
}
|
2005-05-23 11:54:53 +02:00
|
|
|
/* RunningObjectTable data structure will be not destroyed here ! the destruction will be done only
|
|
|
|
* when RunningObjectTableImpl_UnInitialize function is called
|
|
|
|
*/
|
1999-03-23 14:48:56 +01:00
|
|
|
}
|
|
|
|
|
2004-09-24 03:16:53 +02:00
|
|
|
return ref;
|
1999-03-23 14:48:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RunningObjectTable_Register
|
2005-05-11 17:56:45 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* grfFlags [in] Registration options
|
|
|
|
* punkObject [in] the object being registered
|
|
|
|
* pmkObjectName [in] the moniker of the object being registered
|
2009-04-24 13:15:47 +02:00
|
|
|
* pdwRegister [out] the value identifying the registration
|
1999-03-23 14:48:56 +01:00
|
|
|
*/
|
2005-05-11 17:56:45 +02:00
|
|
|
static HRESULT WINAPI
|
|
|
|
RunningObjectTableImpl_Register(IRunningObjectTable* iface, DWORD grfFlags,
|
|
|
|
IUnknown *punkObject, IMoniker *pmkObjectName, DWORD *pdwRegister)
|
1999-03-23 14:48:56 +01:00
|
|
|
{
|
2010-12-15 00:58:12 +01:00
|
|
|
RunningObjectTableImpl *This = impl_from_IRunningObjectTable(iface);
|
2005-05-23 11:54:53 +02:00
|
|
|
struct rot_entry *rot_entry;
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
IStream *pStream = NULL;
|
|
|
|
DWORD mshlflags;
|
2006-12-28 03:41:52 +01:00
|
|
|
IBindCtx *pbc;
|
2007-09-10 17:10:45 +02:00
|
|
|
InterfaceData *moniker = NULL;
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("(%p,%d,%p,%p,%p)\n",This,grfFlags,punkObject,pmkObjectName,pdwRegister);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2006-12-28 03:41:34 +01:00
|
|
|
if (grfFlags & ~(ROTFLAGS_REGISTRATIONKEEPSALIVE|ROTFLAGS_ALLOWANYCLIENT))
|
2005-05-23 11:54:53 +02:00
|
|
|
{
|
2006-12-28 03:41:34 +01:00
|
|
|
ERR("Invalid grfFlags: 0x%08x\n", grfFlags & ~(ROTFLAGS_REGISTRATIONKEEPSALIVE|ROTFLAGS_ALLOWANYCLIENT));
|
1999-03-23 14:48:56 +01:00
|
|
|
return E_INVALIDARG;
|
2005-05-23 11:54:53 +02:00
|
|
|
}
|
1999-03-23 14:48:56 +01:00
|
|
|
|
|
|
|
if (punkObject==NULL || pmkObjectName==NULL || pdwRegister==NULL)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2005-05-23 11:54:53 +02:00
|
|
|
rot_entry = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*rot_entry));
|
|
|
|
if (!rot_entry)
|
|
|
|
return E_OUTOFMEMORY;
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2005-05-23 11:54:53 +02:00
|
|
|
/* marshal object */
|
|
|
|
hr = CreateStreamOnHGlobal(NULL, TRUE, &pStream);
|
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
rot_entry_delete(rot_entry);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
mshlflags = (grfFlags & ROTFLAGS_REGISTRATIONKEEPSALIVE) ? MSHLFLAGS_TABLESTRONG : MSHLFLAGS_TABLEWEAK;
|
|
|
|
hr = CoMarshalInterface(pStream, &IID_IUnknown, punkObject, MSHCTX_LOCAL | MSHCTX_NOSHAREDMEM, NULL, mshlflags);
|
|
|
|
/* FIXME: a cleaner way would be to create an IStream class that writes
|
|
|
|
* directly to an MInterfacePointer */
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
HGLOBAL hglobal;
|
|
|
|
hr = GetHGlobalFromStream(pStream, &hglobal);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
SIZE_T size = GlobalSize(hglobal);
|
|
|
|
const void *pv = GlobalLock(hglobal);
|
|
|
|
rot_entry->object = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(MInterfacePointer, abData[size]));
|
|
|
|
rot_entry->object->ulCntData = size;
|
2008-07-11 11:41:44 +02:00
|
|
|
memcpy(rot_entry->object->abData, pv, size);
|
2005-05-23 11:54:53 +02:00
|
|
|
GlobalUnlock(hglobal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
IStream_Release(pStream);
|
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
rot_entry_delete(rot_entry);
|
|
|
|
return hr;
|
2001-09-11 02:32:32 +02:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-12-28 03:41:52 +01:00
|
|
|
hr = CreateBindCtx(0, &pbc);
|
2006-12-28 03:41:45 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
rot_entry_delete(rot_entry);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2006-12-28 03:41:52 +01:00
|
|
|
hr = reduce_moniker(pmkObjectName, pbc, &pmkObjectName);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
rot_entry_delete(rot_entry);
|
|
|
|
IBindCtx_Release(pbc);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IMoniker_GetTimeOfLastChange(pmkObjectName, pbc, NULL,
|
|
|
|
&rot_entry->last_modified);
|
|
|
|
IBindCtx_Release(pbc);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
CoFileTimeNow(&rot_entry->last_modified);
|
|
|
|
hr = S_OK;
|
|
|
|
}
|
|
|
|
|
2006-12-28 03:41:45 +01:00
|
|
|
hr = get_moniker_comparison_data(pmkObjectName,
|
|
|
|
&rot_entry->moniker_data);
|
2005-05-23 11:54:53 +02:00
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
rot_entry_delete(rot_entry);
|
2006-12-28 03:41:45 +01:00
|
|
|
IMoniker_Release(pmkObjectName);
|
2005-05-23 11:54:53 +02:00
|
|
|
return hr;
|
|
|
|
}
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2005-05-23 11:54:53 +02:00
|
|
|
hr = CreateStreamOnHGlobal(NULL, TRUE, &pStream);
|
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
rot_entry_delete(rot_entry);
|
2006-12-28 03:41:45 +01:00
|
|
|
IMoniker_Release(pmkObjectName);
|
2005-05-23 11:54:53 +02:00
|
|
|
return hr;
|
1999-03-23 14:48:56 +01:00
|
|
|
}
|
2005-05-23 11:54:53 +02:00
|
|
|
/* marshal moniker */
|
2006-12-28 03:41:45 +01:00
|
|
|
hr = CoMarshalInterface(pStream, &IID_IMoniker, (IUnknown *)pmkObjectName,
|
|
|
|
MSHCTX_LOCAL | MSHCTX_NOSHAREDMEM, NULL, MSHLFLAGS_TABLESTRONG);
|
2005-05-23 11:54:53 +02:00
|
|
|
/* FIXME: a cleaner way would be to create an IStream class that writes
|
|
|
|
* directly to an MInterfacePointer */
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
HGLOBAL hglobal;
|
|
|
|
hr = GetHGlobalFromStream(pStream, &hglobal);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
SIZE_T size = GlobalSize(hglobal);
|
|
|
|
const void *pv = GlobalLock(hglobal);
|
2007-09-10 17:10:45 +02:00
|
|
|
moniker = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(InterfaceData, abData[size]));
|
|
|
|
moniker->ulCntData = size;
|
2008-07-11 11:41:44 +02:00
|
|
|
memcpy(moniker->abData, pv, size);
|
2005-05-23 11:54:53 +02:00
|
|
|
GlobalUnlock(hglobal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
IStream_Release(pStream);
|
2006-12-28 03:41:45 +01:00
|
|
|
IMoniker_Release(pmkObjectName);
|
2005-05-23 11:54:53 +02:00
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
2007-11-10 17:05:51 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, moniker);
|
2005-05-23 11:54:53 +02:00
|
|
|
rot_entry_delete(rot_entry);
|
|
|
|
return hr;
|
2004-07-29 04:44:09 +02:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2007-09-10 17:10:45 +02:00
|
|
|
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
__TRY
|
|
|
|
{
|
2007-12-25 20:08:25 +01:00
|
|
|
hr = IrotRegister(get_irot_handle(), rot_entry->moniker_data,
|
|
|
|
rot_entry->object, moniker,
|
|
|
|
&rot_entry->last_modified, grfFlags,
|
|
|
|
&rot_entry->cookie, &rot_entry->ctxt_handle);
|
2007-09-10 17:10:45 +02:00
|
|
|
}
|
|
|
|
__EXCEPT(rpc_filter)
|
|
|
|
{
|
|
|
|
hr = HRESULT_FROM_WIN32(GetExceptionCode());
|
|
|
|
}
|
|
|
|
__ENDTRY
|
|
|
|
if (hr == HRESULT_FROM_WIN32(RPC_S_SERVER_UNAVAILABLE))
|
|
|
|
{
|
|
|
|
if (start_rpcss())
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2007-11-10 17:05:51 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, moniker);
|
2007-09-10 17:10:45 +02:00
|
|
|
if (FAILED(hr))
|
2005-05-23 11:54:53 +02:00
|
|
|
{
|
|
|
|
rot_entry_delete(rot_entry);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* gives a registration identifier to the registered object*/
|
|
|
|
*pdwRegister = rot_entry->cookie;
|
|
|
|
|
|
|
|
EnterCriticalSection(&This->lock);
|
|
|
|
list_add_tail(&This->rot, &rot_entry->entry);
|
|
|
|
LeaveCriticalSection(&This->lock);
|
|
|
|
|
|
|
|
return hr;
|
1999-03-23 14:48:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RunningObjectTable_Revoke
|
2005-05-11 17:56:45 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* dwRegister [in] Value identifying registration to be revoked
|
1999-03-23 14:48:56 +01:00
|
|
|
*/
|
2005-05-11 17:56:45 +02:00
|
|
|
static HRESULT WINAPI
|
|
|
|
RunningObjectTableImpl_Revoke( IRunningObjectTable* iface, DWORD dwRegister)
|
1999-03-23 14:48:56 +01:00
|
|
|
{
|
2010-12-15 00:58:12 +01:00
|
|
|
RunningObjectTableImpl *This = impl_from_IRunningObjectTable(iface);
|
2005-05-23 11:54:53 +02:00
|
|
|
struct rot_entry *rot_entry;
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("(%p,%d)\n",This,dwRegister);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2005-05-23 11:54:53 +02:00
|
|
|
EnterCriticalSection(&This->lock);
|
|
|
|
LIST_FOR_EACH_ENTRY(rot_entry, &This->rot, struct rot_entry, entry)
|
|
|
|
{
|
|
|
|
if (rot_entry->cookie == dwRegister)
|
|
|
|
{
|
|
|
|
list_remove(&rot_entry->entry);
|
|
|
|
LeaveCriticalSection(&This->lock);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2005-05-23 11:54:53 +02:00
|
|
|
rot_entry_delete(rot_entry);
|
|
|
|
return S_OK;
|
|
|
|
}
|
2004-07-29 04:44:09 +02:00
|
|
|
}
|
2005-05-23 11:54:53 +02:00
|
|
|
LeaveCriticalSection(&This->lock);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2005-05-23 11:54:53 +02:00
|
|
|
return E_INVALIDARG;
|
1999-03-23 14:48:56 +01:00
|
|
|
}
|
1998-10-11 16:21:42 +02:00
|
|
|
|
1999-03-23 14:48:56 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* RunningObjectTable_IsRunning
|
2005-05-11 17:56:45 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pmkObjectName [in] moniker of the object whose status is desired
|
1999-03-23 14:48:56 +01:00
|
|
|
*/
|
2005-05-11 17:56:45 +02:00
|
|
|
static HRESULT WINAPI
|
|
|
|
RunningObjectTableImpl_IsRunning( IRunningObjectTable* iface, IMoniker *pmkObjectName)
|
2002-06-01 01:06:46 +02:00
|
|
|
{
|
2010-12-15 00:58:12 +01:00
|
|
|
RunningObjectTableImpl *This = impl_from_IRunningObjectTable(iface);
|
2007-09-10 17:10:45 +02:00
|
|
|
MonikerComparisonData *moniker_data;
|
2005-05-23 11:54:53 +02:00
|
|
|
HRESULT hr;
|
2007-09-10 17:10:45 +02:00
|
|
|
const struct rot_entry *rot_entry;
|
1999-03-23 14:48:56 +01:00
|
|
|
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("(%p,%p)\n",This,pmkObjectName);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2006-12-28 03:41:52 +01:00
|
|
|
hr = reduce_moniker(pmkObjectName, NULL, &pmkObjectName);
|
2006-12-28 03:41:45 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
2005-05-23 11:54:53 +02:00
|
|
|
hr = get_moniker_comparison_data(pmkObjectName, &moniker_data);
|
2006-12-28 03:41:45 +01:00
|
|
|
IMoniker_Release(pmkObjectName);
|
2005-05-23 11:54:53 +02:00
|
|
|
if (hr != S_OK)
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
hr = S_FALSE;
|
|
|
|
EnterCriticalSection(&This->lock);
|
2007-09-10 17:10:45 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(rot_entry, &This->rot, const struct rot_entry, entry)
|
2005-05-23 11:54:53 +02:00
|
|
|
{
|
|
|
|
if ((rot_entry->moniker_data->ulCntData == moniker_data->ulCntData) &&
|
2008-07-11 11:41:44 +02:00
|
|
|
!memcmp(moniker_data->abData, rot_entry->moniker_data->abData, moniker_data->ulCntData))
|
2005-05-23 11:54:53 +02:00
|
|
|
{
|
|
|
|
hr = S_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LeaveCriticalSection(&This->lock);
|
|
|
|
|
2007-09-10 17:10:45 +02:00
|
|
|
if (hr == S_FALSE)
|
|
|
|
{
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
__TRY
|
|
|
|
{
|
|
|
|
hr = IrotIsRunning(get_irot_handle(), moniker_data);
|
|
|
|
}
|
|
|
|
__EXCEPT(rpc_filter)
|
|
|
|
{
|
|
|
|
hr = HRESULT_FROM_WIN32(GetExceptionCode());
|
|
|
|
}
|
|
|
|
__ENDTRY
|
|
|
|
if (hr == HRESULT_FROM_WIN32(RPC_S_SERVER_UNAVAILABLE))
|
|
|
|
{
|
|
|
|
if (start_rpcss())
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-05-23 11:54:53 +02:00
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, moniker_data);
|
|
|
|
|
|
|
|
return hr;
|
1999-03-23 14:48:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RunningObjectTable_GetObject
|
2005-05-11 17:56:45 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pmkObjectName [in] Pointer to the moniker on the object
|
|
|
|
* ppunkObject [out] variable that receives the IUnknown interface pointer
|
1999-03-23 14:48:56 +01:00
|
|
|
*/
|
2005-05-11 17:56:45 +02:00
|
|
|
static HRESULT WINAPI
|
|
|
|
RunningObjectTableImpl_GetObject( IRunningObjectTable* iface,
|
|
|
|
IMoniker *pmkObjectName, IUnknown **ppunkObject)
|
1999-03-23 14:48:56 +01:00
|
|
|
{
|
2010-12-15 00:58:12 +01:00
|
|
|
RunningObjectTableImpl *This = impl_from_IRunningObjectTable(iface);
|
2007-09-10 17:10:45 +02:00
|
|
|
MonikerComparisonData *moniker_data;
|
2007-12-05 17:09:58 +01:00
|
|
|
InterfaceData *object = NULL;
|
2007-09-10 17:10:45 +02:00
|
|
|
IrotCookie cookie;
|
2005-05-23 11:54:53 +02:00
|
|
|
HRESULT hr;
|
|
|
|
struct rot_entry *rot_entry;
|
1999-03-23 14:48:56 +01:00
|
|
|
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("(%p,%p,%p)\n",This,pmkObjectName,ppunkObject);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2005-05-23 11:54:53 +02:00
|
|
|
if (ppunkObject == NULL)
|
1999-03-23 14:48:56 +01:00
|
|
|
return E_POINTER;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2005-05-23 11:54:53 +02:00
|
|
|
*ppunkObject = NULL;
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2006-12-28 03:41:52 +01:00
|
|
|
hr = reduce_moniker(pmkObjectName, NULL, &pmkObjectName);
|
2006-12-28 03:41:45 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
2005-05-23 11:54:53 +02:00
|
|
|
hr = get_moniker_comparison_data(pmkObjectName, &moniker_data);
|
2006-12-28 03:41:45 +01:00
|
|
|
IMoniker_Release(pmkObjectName);
|
2005-05-23 11:54:53 +02:00
|
|
|
if (hr != S_OK)
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
EnterCriticalSection(&This->lock);
|
|
|
|
LIST_FOR_EACH_ENTRY(rot_entry, &This->rot, struct rot_entry, entry)
|
|
|
|
{
|
|
|
|
if ((rot_entry->moniker_data->ulCntData == moniker_data->ulCntData) &&
|
2008-07-11 11:41:44 +02:00
|
|
|
!memcmp(moniker_data->abData, rot_entry->moniker_data->abData, moniker_data->ulCntData))
|
2005-05-23 11:54:53 +02:00
|
|
|
{
|
|
|
|
IStream *pStream;
|
|
|
|
hr = create_stream_on_mip_ro(rot_entry->object, &pStream);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
hr = CoUnmarshalInterface(pStream, &IID_IUnknown, (void **)ppunkObject);
|
|
|
|
IStream_Release(pStream);
|
|
|
|
}
|
|
|
|
|
|
|
|
LeaveCriticalSection(&This->lock);
|
|
|
|
HeapFree(GetProcessHeap(), 0, moniker_data);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
2004-07-29 04:44:09 +02:00
|
|
|
}
|
2005-05-23 11:54:53 +02:00
|
|
|
LeaveCriticalSection(&This->lock);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2007-09-10 17:10:45 +02:00
|
|
|
TRACE("moniker unavailable locally, calling SCM\n");
|
|
|
|
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
__TRY
|
|
|
|
{
|
|
|
|
hr = IrotGetObject(get_irot_handle(), moniker_data, &object, &cookie);
|
|
|
|
}
|
|
|
|
__EXCEPT(rpc_filter)
|
|
|
|
{
|
|
|
|
hr = HRESULT_FROM_WIN32(GetExceptionCode());
|
|
|
|
}
|
|
|
|
__ENDTRY
|
|
|
|
if (hr == HRESULT_FROM_WIN32(RPC_S_SERVER_UNAVAILABLE))
|
|
|
|
{
|
|
|
|
if (start_rpcss())
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
IStream *pStream;
|
|
|
|
hr = create_stream_on_mip_ro(object, &pStream);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
hr = CoUnmarshalInterface(pStream, &IID_IUnknown, (void **)ppunkObject);
|
|
|
|
IStream_Release(pStream);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
WARN("Moniker unavailable, IrotGetObject returned 0x%08x\n", hr);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2005-05-23 11:54:53 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, moniker_data);
|
|
|
|
|
|
|
|
return hr;
|
1999-03-23 14:48:56 +01:00
|
|
|
}
|
1998-11-22 18:56:07 +01:00
|
|
|
|
1999-01-28 18:56:14 +01:00
|
|
|
/***********************************************************************
|
1999-03-23 14:48:56 +01:00
|
|
|
* RunningObjectTable_NoteChangeTime
|
2005-05-11 17:56:45 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* dwRegister [in] Value identifying registration being updated
|
|
|
|
* pfiletime [in] Pointer to structure containing object's last change time
|
1998-11-22 18:56:07 +01:00
|
|
|
*/
|
2005-05-11 17:56:45 +02:00
|
|
|
static HRESULT WINAPI
|
|
|
|
RunningObjectTableImpl_NoteChangeTime(IRunningObjectTable* iface,
|
|
|
|
DWORD dwRegister, FILETIME *pfiletime)
|
1999-03-23 14:48:56 +01:00
|
|
|
{
|
2010-12-15 00:58:12 +01:00
|
|
|
RunningObjectTableImpl *This = impl_from_IRunningObjectTable(iface);
|
2005-05-23 11:54:53 +02:00
|
|
|
struct rot_entry *rot_entry;
|
2007-09-10 17:10:45 +02:00
|
|
|
HRESULT hr = E_INVALIDARG;
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("(%p,%d,%p)\n",This,dwRegister,pfiletime);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2005-05-23 11:54:53 +02:00
|
|
|
EnterCriticalSection(&This->lock);
|
|
|
|
LIST_FOR_EACH_ENTRY(rot_entry, &This->rot, struct rot_entry, entry)
|
|
|
|
{
|
|
|
|
if (rot_entry->cookie == dwRegister)
|
|
|
|
{
|
|
|
|
rot_entry->last_modified = *pfiletime;
|
|
|
|
LeaveCriticalSection(&This->lock);
|
2007-09-10 17:10:45 +02:00
|
|
|
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
__TRY
|
|
|
|
{
|
|
|
|
hr = IrotNoteChangeTime(get_irot_handle(), dwRegister, pfiletime);
|
|
|
|
}
|
|
|
|
__EXCEPT(rpc_filter)
|
|
|
|
{
|
|
|
|
hr = HRESULT_FROM_WIN32(GetExceptionCode());
|
|
|
|
}
|
|
|
|
__ENDTRY
|
|
|
|
if (hr == HRESULT_FROM_WIN32(RPC_S_SERVER_UNAVAILABLE))
|
|
|
|
{
|
|
|
|
if (start_rpcss())
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2007-12-21 08:18:35 +01:00
|
|
|
|
|
|
|
goto done;
|
2005-05-23 11:54:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
LeaveCriticalSection(&This->lock);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2007-12-21 08:18:35 +01:00
|
|
|
done:
|
2007-09-10 17:10:45 +02:00
|
|
|
TRACE("-- 0x08%x\n", hr);
|
|
|
|
return hr;
|
1999-03-23 14:48:56 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-03-23 14:48:56 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* RunningObjectTable_GetTimeOfLastChange
|
2005-05-11 17:56:45 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pmkObjectName [in] moniker of the object whose status is desired
|
|
|
|
* pfiletime [out] structure that receives object's last change time
|
1999-03-23 14:48:56 +01:00
|
|
|
*/
|
2005-05-11 17:56:45 +02:00
|
|
|
static HRESULT WINAPI
|
|
|
|
RunningObjectTableImpl_GetTimeOfLastChange(IRunningObjectTable* iface,
|
|
|
|
IMoniker *pmkObjectName, FILETIME *pfiletime)
|
1999-03-23 14:48:56 +01:00
|
|
|
{
|
2005-05-23 11:54:53 +02:00
|
|
|
HRESULT hr = MK_E_UNAVAILABLE;
|
2010-12-15 00:58:12 +01:00
|
|
|
RunningObjectTableImpl *This = impl_from_IRunningObjectTable(iface);
|
2007-09-10 17:10:45 +02:00
|
|
|
MonikerComparisonData *moniker_data;
|
|
|
|
const struct rot_entry *rot_entry;
|
1999-03-23 14:48:56 +01:00
|
|
|
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("(%p,%p,%p)\n",This,pmkObjectName,pfiletime);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
|
|
|
if (pmkObjectName==NULL || pfiletime==NULL)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2006-12-28 03:41:52 +01:00
|
|
|
hr = reduce_moniker(pmkObjectName, NULL, &pmkObjectName);
|
2006-12-28 03:41:45 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
2005-05-23 11:54:53 +02:00
|
|
|
hr = get_moniker_comparison_data(pmkObjectName, &moniker_data);
|
2006-12-28 03:41:45 +01:00
|
|
|
IMoniker_Release(pmkObjectName);
|
2005-05-23 11:54:53 +02:00
|
|
|
if (hr != S_OK)
|
|
|
|
return hr;
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2005-05-23 11:54:53 +02:00
|
|
|
hr = MK_E_UNAVAILABLE;
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2005-05-23 11:54:53 +02:00
|
|
|
EnterCriticalSection(&This->lock);
|
2007-09-10 17:10:45 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(rot_entry, &This->rot, const struct rot_entry, entry)
|
2005-05-23 11:54:53 +02:00
|
|
|
{
|
|
|
|
if ((rot_entry->moniker_data->ulCntData == moniker_data->ulCntData) &&
|
2008-07-11 11:41:44 +02:00
|
|
|
!memcmp(moniker_data->abData, rot_entry->moniker_data->abData, moniker_data->ulCntData))
|
2005-05-23 11:54:53 +02:00
|
|
|
{
|
|
|
|
*pfiletime = rot_entry->last_modified;
|
|
|
|
hr = S_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LeaveCriticalSection(&This->lock);
|
|
|
|
|
2007-09-10 17:10:45 +02:00
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
__TRY
|
|
|
|
{
|
|
|
|
hr = IrotGetTimeOfLastChange(get_irot_handle(), moniker_data, pfiletime);
|
|
|
|
}
|
|
|
|
__EXCEPT(rpc_filter)
|
|
|
|
{
|
|
|
|
hr = HRESULT_FROM_WIN32(GetExceptionCode());
|
|
|
|
}
|
|
|
|
__ENDTRY
|
|
|
|
if (hr == HRESULT_FROM_WIN32(RPC_S_SERVER_UNAVAILABLE))
|
|
|
|
{
|
|
|
|
if (start_rpcss())
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-05-23 11:54:53 +02:00
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, moniker_data);
|
2007-09-10 17:10:45 +02:00
|
|
|
|
|
|
|
TRACE("-- 0x%08x\n", hr);
|
2005-05-23 11:54:53 +02:00
|
|
|
return hr;
|
1999-03-23 14:48:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RunningObjectTable_EnumRunning
|
2005-05-11 17:56:45 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* ppenumMoniker [out] receives the IEnumMoniker interface pointer
|
1999-03-23 14:48:56 +01:00
|
|
|
*/
|
2005-05-11 17:56:45 +02:00
|
|
|
static HRESULT WINAPI
|
|
|
|
RunningObjectTableImpl_EnumRunning(IRunningObjectTable* iface,
|
|
|
|
IEnumMoniker **ppenumMoniker)
|
1999-03-23 14:48:56 +01:00
|
|
|
{
|
2010-12-15 00:58:12 +01:00
|
|
|
RunningObjectTableImpl *This = impl_from_IRunningObjectTable(iface);
|
2007-09-10 17:10:45 +02:00
|
|
|
InterfaceList *interface_list = NULL;
|
|
|
|
HRESULT hr;
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2007-09-10 17:10:45 +02:00
|
|
|
TRACE("(%p, %p)\n", This, ppenumMoniker);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2007-09-10 17:10:45 +02:00
|
|
|
*ppenumMoniker = NULL;
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2007-09-10 17:10:45 +02:00
|
|
|
while (TRUE)
|
2005-05-23 11:54:53 +02:00
|
|
|
{
|
2007-09-10 17:10:45 +02:00
|
|
|
__TRY
|
|
|
|
{
|
|
|
|
hr = IrotEnumRunning(get_irot_handle(), &interface_list);
|
|
|
|
}
|
|
|
|
__EXCEPT(rpc_filter)
|
|
|
|
{
|
|
|
|
hr = HRESULT_FROM_WIN32(GetExceptionCode());
|
|
|
|
}
|
|
|
|
__ENDTRY
|
|
|
|
if (hr == HRESULT_FROM_WIN32(RPC_S_SERVER_UNAVAILABLE))
|
|
|
|
{
|
|
|
|
if (start_rpcss())
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
2005-05-23 11:54:53 +02:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2007-09-10 17:10:45 +02:00
|
|
|
if (SUCCEEDED(hr))
|
2007-11-10 17:05:23 +01:00
|
|
|
hr = EnumMonikerImpl_CreateEnumROTMoniker(interface_list,
|
2007-09-10 17:10:45 +02:00
|
|
|
0, ppenumMoniker);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2005-05-23 11:54:53 +02:00
|
|
|
return hr;
|
1999-03-23 14:48:56 +01:00
|
|
|
}
|
|
|
|
|
2007-03-26 19:25:21 +02:00
|
|
|
/* Virtual function table for the IRunningObjectTable class. */
|
|
|
|
static const IRunningObjectTableVtbl VT_RunningObjectTableImpl =
|
|
|
|
{
|
|
|
|
RunningObjectTableImpl_QueryInterface,
|
|
|
|
RunningObjectTableImpl_AddRef,
|
|
|
|
RunningObjectTableImpl_Release,
|
|
|
|
RunningObjectTableImpl_Register,
|
|
|
|
RunningObjectTableImpl_Revoke,
|
|
|
|
RunningObjectTableImpl_IsRunning,
|
|
|
|
RunningObjectTableImpl_GetObject,
|
|
|
|
RunningObjectTableImpl_NoteChangeTime,
|
|
|
|
RunningObjectTableImpl_GetTimeOfLastChange,
|
|
|
|
RunningObjectTableImpl_EnumRunning
|
|
|
|
};
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RunningObjectTable_Initialize
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI RunningObjectTableImpl_Initialize(void)
|
|
|
|
{
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
/* create the unique instance of the RunningObjectTableImpl structure */
|
|
|
|
runningObjectTableInstance = HeapAlloc(GetProcessHeap(), 0, sizeof(RunningObjectTableImpl));
|
|
|
|
|
|
|
|
if (!runningObjectTableInstance)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
/* initialize the virtual table function */
|
2010-12-15 00:58:12 +01:00
|
|
|
runningObjectTableInstance->IRunningObjectTable_iface.lpVtbl = &VT_RunningObjectTableImpl;
|
2007-03-26 19:25:21 +02:00
|
|
|
|
2008-04-28 00:01:16 +02:00
|
|
|
/* the initial reference is set to "1" so that it isn't destroyed after its
|
|
|
|
* first use until the process is destroyed, as the running object table is
|
|
|
|
* a process-wide cache of a global table */
|
2007-03-26 19:25:21 +02:00
|
|
|
runningObjectTableInstance->ref = 1;
|
|
|
|
|
|
|
|
list_init(&runningObjectTableInstance->rot);
|
|
|
|
InitializeCriticalSection(&runningObjectTableInstance->lock);
|
|
|
|
DEBUG_SET_CRITSEC_NAME(&runningObjectTableInstance->lock, "RunningObjectTableImpl.lock");
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RunningObjectTable_UnInitialize
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI RunningObjectTableImpl_UnInitialize(void)
|
|
|
|
{
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
if (runningObjectTableInstance==NULL)
|
|
|
|
return E_POINTER;
|
|
|
|
|
2010-12-15 00:58:12 +01:00
|
|
|
RunningObjectTableImpl_Release(&runningObjectTableInstance->IRunningObjectTable_iface);
|
2007-03-26 19:25:21 +02:00
|
|
|
|
|
|
|
RunningObjectTableImpl_Destroy();
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
1999-03-23 14:48:56 +01:00
|
|
|
/***********************************************************************
|
2003-09-11 05:06:25 +02:00
|
|
|
* GetRunningObjectTable (OLE32.@)
|
2007-03-26 19:23:51 +02:00
|
|
|
*
|
|
|
|
* Retrieves the global running object table.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* reserved [I] Reserved. Set to 0.
|
|
|
|
* pprot [O] Address that receives the pointer to the running object table.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK.
|
|
|
|
* Failure: Any HRESULT code.
|
1999-03-23 14:48:56 +01:00
|
|
|
*/
|
2005-05-11 17:56:45 +02:00
|
|
|
HRESULT WINAPI
|
|
|
|
GetRunningObjectTable(DWORD reserved, LPRUNNINGOBJECTTABLE *pprot)
|
1999-03-23 14:48:56 +01:00
|
|
|
{
|
|
|
|
IID riid=IID_IRunningObjectTable;
|
|
|
|
HRESULT res;
|
|
|
|
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("()\n");
|
1999-03-23 14:48:56 +01:00
|
|
|
|
|
|
|
if (reserved!=0)
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
|
|
|
|
if(runningObjectTableInstance==NULL)
|
|
|
|
return CO_E_NOTINITIALIZED;
|
|
|
|
|
2010-12-15 00:58:12 +01:00
|
|
|
res = IRunningObjectTable_QueryInterface(&runningObjectTableInstance->IRunningObjectTable_iface,
|
|
|
|
&riid,(void**)pprot);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
|
|
|
return res;
|
1998-11-22 18:56:07 +01:00
|
|
|
}
|
2000-01-15 23:14:20 +01:00
|
|
|
|
2007-03-27 19:21:23 +02:00
|
|
|
static HRESULT get_moniker_for_progid_display_name(LPBC pbc,
|
|
|
|
LPCOLESTR szDisplayName,
|
|
|
|
LPDWORD pchEaten,
|
|
|
|
LPMONIKER *ppmk)
|
|
|
|
{
|
|
|
|
CLSID clsid;
|
|
|
|
HRESULT hr;
|
|
|
|
LPWSTR progid;
|
|
|
|
LPCWSTR start = szDisplayName;
|
|
|
|
LPCWSTR end;
|
|
|
|
int len;
|
|
|
|
IMoniker *class_moniker;
|
|
|
|
|
|
|
|
if (*start == '@')
|
|
|
|
start++;
|
|
|
|
|
|
|
|
/* find end delimiter */
|
|
|
|
for (end = start; *end; end++)
|
|
|
|
if (*end == ':')
|
|
|
|
break;
|
|
|
|
|
|
|
|
len = end - start;
|
|
|
|
|
|
|
|
/* must start with '@' or have a ':' somewhere and mustn't be one character
|
|
|
|
* long (since that looks like an absolute path) */
|
|
|
|
if (((start == szDisplayName) && (*end == '\0')) || (len <= 1))
|
|
|
|
return MK_E_SYNTAX;
|
|
|
|
|
|
|
|
progid = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
|
|
|
|
if (progid)
|
|
|
|
{
|
|
|
|
memcpy(progid, start, len * sizeof(WCHAR));
|
|
|
|
progid[len] = '\0';
|
|
|
|
}
|
|
|
|
hr = CLSIDFromProgID(progid, &clsid);
|
|
|
|
HeapFree(GetProcessHeap(), 0, progid);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return MK_E_SYNTAX;
|
|
|
|
|
|
|
|
hr = CreateClassMoniker(&clsid, &class_moniker);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
IParseDisplayName *pdn;
|
|
|
|
hr = IMoniker_BindToObject(class_moniker, pbc, NULL,
|
|
|
|
&IID_IParseDisplayName, (void **)&pdn);
|
2008-01-06 17:20:26 +01:00
|
|
|
/* fallback to using IClassFactory to get IParseDisplayName -
|
|
|
|
* adsldp.dll depends on this */
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
IClassFactory *pcf;
|
|
|
|
hr = IMoniker_BindToObject(class_moniker, pbc, NULL,
|
|
|
|
&IID_IClassFactory, (void **)&pcf);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
hr = IClassFactory_CreateInstance(pcf, NULL,
|
|
|
|
&IID_IParseDisplayName,
|
|
|
|
(void **)&pdn);
|
|
|
|
IClassFactory_Release(pcf);
|
|
|
|
}
|
|
|
|
}
|
2007-03-27 19:21:23 +02:00
|
|
|
IMoniker_Release(class_moniker);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
hr = IParseDisplayName_ParseDisplayName(pdn, pbc,
|
|
|
|
(LPOLESTR)szDisplayName,
|
|
|
|
pchEaten, ppmk);
|
|
|
|
IParseDisplayName_Release(pdn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2000-01-15 23:14:20 +01:00
|
|
|
/******************************************************************************
|
2007-03-26 19:25:21 +02:00
|
|
|
* MkParseDisplayName [OLE32.@]
|
|
|
|
*/
|
2007-03-27 19:21:23 +02:00
|
|
|
HRESULT WINAPI MkParseDisplayName(LPBC pbc, LPCOLESTR szDisplayName,
|
2007-03-26 19:25:21 +02:00
|
|
|
LPDWORD pchEaten, LPMONIKER *ppmk)
|
|
|
|
{
|
2007-03-27 19:21:23 +02:00
|
|
|
HRESULT hr = MK_E_SYNTAX;
|
|
|
|
static const WCHAR wszClsidColon[] = {'c','l','s','i','d',':'};
|
|
|
|
IMoniker *moniker;
|
|
|
|
DWORD chEaten;
|
|
|
|
|
|
|
|
TRACE("(%p, %s, %p, %p)\n", pbc, debugstr_w(szDisplayName), pchEaten, ppmk);
|
2007-03-26 19:25:21 +02:00
|
|
|
|
2010-05-20 17:35:27 +02:00
|
|
|
if (!pbc || !IsValidInterface((LPUNKNOWN) pbc))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (!szDisplayName || !*szDisplayName)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (!pchEaten || !ppmk)
|
2007-03-26 19:25:21 +02:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2007-03-27 19:21:23 +02:00
|
|
|
*pchEaten = 0;
|
|
|
|
*ppmk = NULL;
|
|
|
|
|
|
|
|
if (!strncmpiW(szDisplayName, wszClsidColon, sizeof(wszClsidColon)/sizeof(wszClsidColon[0])))
|
|
|
|
{
|
|
|
|
hr = ClassMoniker_CreateFromDisplayName(pbc, szDisplayName, &chEaten, &moniker);
|
|
|
|
if (FAILED(hr) && (hr != MK_E_SYNTAX))
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hr = get_moniker_for_progid_display_name(pbc, szDisplayName, &chEaten, &moniker);
|
|
|
|
if (FAILED(hr) && (hr != MK_E_SYNTAX))
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
hr = FileMoniker_CreateFromDisplayName(pbc, szDisplayName, &chEaten, &moniker);
|
|
|
|
if (FAILED(hr) && (hr != MK_E_SYNTAX))
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
IMoniker *next_moniker;
|
|
|
|
*pchEaten += chEaten;
|
|
|
|
szDisplayName += chEaten;
|
|
|
|
if (!*szDisplayName)
|
|
|
|
{
|
|
|
|
*ppmk = moniker;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
chEaten = 0;
|
|
|
|
hr = IMoniker_ParseDisplayName(moniker, pbc, NULL,
|
|
|
|
(LPOLESTR)szDisplayName, &chEaten,
|
|
|
|
&next_moniker);
|
|
|
|
IMoniker_Release(moniker);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
*pchEaten = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
moniker = next_moniker;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2007-03-26 19:25:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetClassFile (OLE32.@)
|
2007-03-26 19:23:51 +02:00
|
|
|
*
|
2007-03-26 19:25:21 +02:00
|
|
|
* Retrieves the class ID associated with the given filename.
|
2007-03-26 19:23:51 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2007-03-26 19:25:21 +02:00
|
|
|
* filePathName [I] Filename to retrieve the class ID for.
|
|
|
|
* pclsid [O] Address that receives the class ID for the file.
|
2007-03-26 19:23:51 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK.
|
|
|
|
* Failure: Any HRESULT code.
|
2000-01-15 23:14:20 +01:00
|
|
|
*/
|
2007-03-26 19:25:21 +02:00
|
|
|
HRESULT WINAPI GetClassFile(LPCOLESTR filePathName,CLSID *pclsid)
|
2000-01-15 23:14:20 +01:00
|
|
|
{
|
2007-03-26 19:25:21 +02:00
|
|
|
IStorage *pstg=0;
|
|
|
|
HRESULT res;
|
|
|
|
int nbElm, length, i;
|
2015-03-20 07:49:56 +01:00
|
|
|
LONG sizeProgId, ret;
|
2007-03-26 19:25:21 +02:00
|
|
|
LPOLESTR *pathDec=0,absFile=0,progId=0;
|
|
|
|
LPWSTR extension;
|
|
|
|
static const WCHAR bkslashW[] = {'\\',0};
|
|
|
|
static const WCHAR dotW[] = {'.',0};
|
2005-05-11 17:56:45 +02:00
|
|
|
|
2007-03-26 19:25:21 +02:00
|
|
|
TRACE("%s, %p\n", debugstr_w(filePathName), pclsid);
|
2006-08-02 21:29:04 +02:00
|
|
|
|
2007-03-26 19:25:21 +02:00
|
|
|
/* if the file contain a storage object the return the CLSID written by IStorage_SetClass method*/
|
|
|
|
if((StgIsStorageFile(filePathName))==S_OK){
|
2006-08-02 21:29:04 +02:00
|
|
|
|
2007-03-26 19:25:21 +02:00
|
|
|
res=StgOpenStorage(filePathName,NULL,STGM_READ | STGM_SHARE_DENY_WRITE,NULL,0,&pstg);
|
2000-02-20 20:17:53 +01:00
|
|
|
|
2015-05-31 14:03:50 +02:00
|
|
|
if (SUCCEEDED(res)) {
|
2007-03-26 19:25:21 +02:00
|
|
|
res=ReadClassStg(pstg,pclsid);
|
2015-05-31 14:03:50 +02:00
|
|
|
IStorage_Release(pstg);
|
|
|
|
}
|
2000-02-20 20:17:53 +01:00
|
|
|
|
2007-03-26 19:25:21 +02:00
|
|
|
return res;
|
|
|
|
}
|
2008-04-09 21:33:37 +02:00
|
|
|
/* If the file is not a storage object then attempt to match various bits in the file against a
|
2008-05-06 15:54:52 +02:00
|
|
|
pattern in the registry. This case is not frequently used, so I present only the pseudocode for
|
2008-04-09 21:33:37 +02:00
|
|
|
this case.
|
2003-07-19 00:59:58 +02:00
|
|
|
|
2007-03-26 19:25:21 +02:00
|
|
|
for(i=0;i<nFileTypes;i++)
|
2005-05-11 17:56:45 +02:00
|
|
|
|
2007-03-26 19:25:21 +02:00
|
|
|
for(i=0;j<nPatternsForType;j++){
|
2005-05-11 17:56:45 +02:00
|
|
|
|
2007-03-26 19:25:21 +02:00
|
|
|
PATTERN pat;
|
|
|
|
HANDLE hFile;
|
2005-05-11 17:56:45 +02:00
|
|
|
|
2007-03-26 19:25:21 +02:00
|
|
|
pat=ReadPatternFromRegistry(i,j);
|
|
|
|
hFile=CreateFileW(filePathName,,,,,,hFile);
|
|
|
|
SetFilePosition(hFile,pat.offset);
|
|
|
|
ReadFile(hFile,buf,pat.size,&r,NULL);
|
|
|
|
if (memcmp(buf&pat.mask,pat.pattern.pat.size)==0){
|
2005-05-11 17:56:45 +02:00
|
|
|
|
2007-03-26 19:25:21 +02:00
|
|
|
*pclsid=ReadCLSIDFromRegistry(i);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
2005-05-11 17:56:45 +02:00
|
|
|
|
2007-03-26 19:25:21 +02:00
|
|
|
/* if the above strategies fail then search for the extension key in the registry */
|
2005-05-11 17:56:45 +02:00
|
|
|
|
2007-03-26 19:25:21 +02:00
|
|
|
/* get the last element (absolute file) in the path name */
|
|
|
|
nbElm=FileMonikerImpl_DecomposePath(filePathName,&pathDec);
|
|
|
|
absFile=pathDec[nbElm-1];
|
2005-05-11 17:56:45 +02:00
|
|
|
|
2008-04-09 21:33:37 +02:00
|
|
|
/* failed if the path represents a directory and not an absolute file name*/
|
2014-03-25 04:57:49 +01:00
|
|
|
if (!lstrcmpW(absFile, bkslashW)) {
|
|
|
|
CoTaskMemFree(pathDec);
|
2007-03-26 19:25:21 +02:00
|
|
|
return MK_E_INVALIDEXTENSION;
|
2014-03-25 04:57:49 +01:00
|
|
|
}
|
2005-05-11 17:56:45 +02:00
|
|
|
|
2007-03-26 19:25:21 +02:00
|
|
|
/* get the extension of the file */
|
|
|
|
extension = NULL;
|
|
|
|
length=lstrlenW(absFile);
|
|
|
|
for(i = length-1; (i >= 0) && *(extension = &absFile[i]) != '.'; i--)
|
|
|
|
/* nothing */;
|
2005-05-11 17:56:45 +02:00
|
|
|
|
2014-03-25 04:57:49 +01:00
|
|
|
if (!extension || !lstrcmpW(extension, dotW)) {
|
|
|
|
CoTaskMemFree(pathDec);
|
2007-03-26 19:25:21 +02:00
|
|
|
return MK_E_INVALIDEXTENSION;
|
2014-03-25 04:57:49 +01:00
|
|
|
}
|
2005-05-11 17:56:45 +02:00
|
|
|
|
2015-03-20 07:49:56 +01:00
|
|
|
ret = RegQueryValueW(HKEY_CLASSES_ROOT, extension, NULL, &sizeProgId);
|
2005-05-11 17:56:45 +02:00
|
|
|
|
2007-03-26 19:25:21 +02:00
|
|
|
/* get the progId associated to the extension */
|
|
|
|
progId = CoTaskMemAlloc(sizeProgId);
|
2015-03-20 07:49:56 +01:00
|
|
|
ret = RegQueryValueW(HKEY_CLASSES_ROOT, extension, progId, &sizeProgId);
|
|
|
|
if (!ret)
|
2007-03-26 19:25:21 +02:00
|
|
|
/* return the clsid associated to the progId */
|
2015-03-20 07:49:56 +01:00
|
|
|
res = CLSIDFromProgID(progId,pclsid);
|
|
|
|
else
|
|
|
|
res = HRESULT_FROM_WIN32(ret);
|
2007-03-26 19:25:21 +02:00
|
|
|
|
|
|
|
for(i=0; pathDec[i]!=NULL;i++)
|
|
|
|
CoTaskMemFree(pathDec[i]);
|
|
|
|
CoTaskMemFree(pathDec);
|
|
|
|
|
|
|
|
CoTaskMemFree(progId);
|
2015-03-20 07:49:56 +01:00
|
|
|
return res != S_OK ? MK_E_INVALIDEXTENSION : res;
|
2005-05-11 17:56:45 +02:00
|
|
|
}
|
2005-05-14 20:50:14 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* EnumMoniker_QueryInterface
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI EnumMonikerImpl_QueryInterface(IEnumMoniker* iface,REFIID riid,void** ppvObject)
|
|
|
|
{
|
2010-12-15 00:58:12 +01:00
|
|
|
EnumMonikerImpl *This = impl_from_IEnumMoniker(iface);
|
2005-05-14 20:50:14 +02:00
|
|
|
|
|
|
|
TRACE("(%p,%p,%p)\n",This,riid,ppvObject);
|
|
|
|
|
|
|
|
/* validate arguments */
|
|
|
|
if (ppvObject == NULL)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
*ppvObject = NULL;
|
|
|
|
|
2015-03-20 07:52:06 +01:00
|
|
|
if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IEnumMoniker, riid))
|
|
|
|
*ppvObject = &This->IEnumMoniker_iface;
|
2005-05-14 20:50:14 +02:00
|
|
|
else
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
|
|
|
|
IEnumMoniker_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* EnumMoniker_AddRef
|
|
|
|
*/
|
|
|
|
static ULONG WINAPI EnumMonikerImpl_AddRef(IEnumMoniker* iface)
|
|
|
|
{
|
2010-12-15 00:58:12 +01:00
|
|
|
EnumMonikerImpl *This = impl_from_IEnumMoniker(iface);
|
2005-05-14 20:50:14 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n",This);
|
|
|
|
|
|
|
|
return InterlockedIncrement(&This->ref);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* EnumMoniker_release
|
|
|
|
*/
|
|
|
|
static ULONG WINAPI EnumMonikerImpl_Release(IEnumMoniker* iface)
|
|
|
|
{
|
2010-12-15 00:58:12 +01:00
|
|
|
EnumMonikerImpl *This = impl_from_IEnumMoniker(iface);
|
2005-05-14 20:50:14 +02:00
|
|
|
ULONG ref;
|
|
|
|
|
|
|
|
TRACE("(%p)\n",This);
|
|
|
|
|
|
|
|
ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
2013-11-20 23:39:28 +01:00
|
|
|
/* uninitialize ROT structure if there are no more references to it */
|
2005-05-23 11:54:53 +02:00
|
|
|
if (ref == 0)
|
|
|
|
{
|
|
|
|
ULONG i;
|
2005-05-14 20:50:14 +02:00
|
|
|
|
2005-05-23 11:54:53 +02:00
|
|
|
TRACE("(%p) Deleting\n",This);
|
2005-05-14 20:50:14 +02:00
|
|
|
|
2007-11-10 17:05:23 +01:00
|
|
|
for (i = 0; i < This->moniker_list->size; i++)
|
|
|
|
HeapFree(GetProcessHeap(), 0, This->moniker_list->interfaces[i]);
|
|
|
|
HeapFree(GetProcessHeap(), 0, This->moniker_list);
|
2005-05-23 11:54:53 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
2005-05-14 20:50:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
/***********************************************************************
|
2009-01-08 16:14:55 +01:00
|
|
|
* EnumMoniker_Next
|
2005-05-14 20:50:14 +02:00
|
|
|
*/
|
|
|
|
static HRESULT WINAPI EnumMonikerImpl_Next(IEnumMoniker* iface, ULONG celt, IMoniker** rgelt, ULONG * pceltFetched)
|
|
|
|
{
|
|
|
|
ULONG i;
|
2010-12-15 00:58:12 +01:00
|
|
|
EnumMonikerImpl *This = impl_from_IEnumMoniker(iface);
|
2005-05-23 11:54:53 +02:00
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
2007-11-10 17:05:23 +01:00
|
|
|
TRACE("(%p) TabCurrentPos %d Tablastindx %d\n", This, This->pos, This->moniker_list->size);
|
2005-05-14 20:50:14 +02:00
|
|
|
|
|
|
|
/* retrieve the requested number of moniker from the current position */
|
2007-11-10 17:05:23 +01:00
|
|
|
for(i = 0; (This->pos < This->moniker_list->size) && (i < celt); i++)
|
2005-05-23 11:54:53 +02:00
|
|
|
{
|
|
|
|
IStream *stream;
|
2007-11-10 17:05:23 +01:00
|
|
|
hr = create_stream_on_mip_ro(This->moniker_list->interfaces[This->pos++], &stream);
|
2005-05-23 11:54:53 +02:00
|
|
|
if (hr != S_OK) break;
|
|
|
|
hr = CoUnmarshalInterface(stream, &IID_IMoniker, (void **)&rgelt[i]);
|
|
|
|
IStream_Release(stream);
|
|
|
|
if (hr != S_OK) break;
|
|
|
|
}
|
2005-05-14 20:50:14 +02:00
|
|
|
|
2005-05-23 11:54:53 +02:00
|
|
|
if (pceltFetched != NULL)
|
2005-05-14 20:50:14 +02:00
|
|
|
*pceltFetched= i;
|
|
|
|
|
2005-05-23 11:54:53 +02:00
|
|
|
if (hr != S_OK)
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
if (i == celt)
|
2005-05-14 20:50:14 +02:00
|
|
|
return S_OK;
|
|
|
|
else
|
|
|
|
return S_FALSE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2009-01-08 16:14:55 +01:00
|
|
|
* EnumMoniker_Skip
|
2005-05-14 20:50:14 +02:00
|
|
|
*/
|
|
|
|
static HRESULT WINAPI EnumMonikerImpl_Skip(IEnumMoniker* iface, ULONG celt)
|
|
|
|
{
|
2010-12-15 00:58:12 +01:00
|
|
|
EnumMonikerImpl *This = impl_from_IEnumMoniker(iface);
|
2005-05-14 20:50:14 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n",This);
|
|
|
|
|
2007-11-10 17:05:23 +01:00
|
|
|
if (This->pos + celt >= This->moniker_list->size)
|
2005-05-23 11:54:53 +02:00
|
|
|
return S_FALSE;
|
2005-05-14 20:50:14 +02:00
|
|
|
|
2005-05-23 11:54:53 +02:00
|
|
|
This->pos += celt;
|
2005-05-14 20:50:14 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2009-01-08 16:14:55 +01:00
|
|
|
* EnumMoniker_Reset
|
2005-05-14 20:50:14 +02:00
|
|
|
*/
|
|
|
|
static HRESULT WINAPI EnumMonikerImpl_Reset(IEnumMoniker* iface)
|
|
|
|
{
|
2010-12-15 00:58:12 +01:00
|
|
|
EnumMonikerImpl *This = impl_from_IEnumMoniker(iface);
|
2005-05-14 20:50:14 +02:00
|
|
|
|
2005-05-23 11:54:53 +02:00
|
|
|
This->pos = 0; /* set back to start of list */
|
2005-05-14 20:50:14 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n",This);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2009-01-08 16:14:55 +01:00
|
|
|
* EnumMoniker_Clone
|
2005-05-14 20:50:14 +02:00
|
|
|
*/
|
|
|
|
static HRESULT WINAPI EnumMonikerImpl_Clone(IEnumMoniker* iface, IEnumMoniker ** ppenum)
|
|
|
|
{
|
2010-12-15 00:58:12 +01:00
|
|
|
EnumMonikerImpl *This = impl_from_IEnumMoniker(iface);
|
2007-11-10 17:05:23 +01:00
|
|
|
InterfaceList *moniker_list;
|
2005-05-23 11:54:53 +02:00
|
|
|
ULONG i;
|
2005-05-14 20:50:14 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n",This);
|
2005-05-23 11:54:53 +02:00
|
|
|
|
2007-09-10 17:10:45 +02:00
|
|
|
*ppenum = NULL;
|
|
|
|
|
2007-11-10 17:05:23 +01:00
|
|
|
moniker_list = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(InterfaceList, interfaces[This->moniker_list->size]));
|
|
|
|
if (!moniker_list)
|
2007-09-10 17:10:45 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2007-11-10 17:05:23 +01:00
|
|
|
moniker_list->size = This->moniker_list->size;
|
|
|
|
for (i = 0; i < This->moniker_list->size; i++)
|
2005-05-23 11:54:53 +02:00
|
|
|
{
|
2007-11-10 17:05:23 +01:00
|
|
|
SIZE_T size = FIELD_OFFSET(InterfaceData, abData[This->moniker_list->interfaces[i]->ulCntData]);
|
|
|
|
moniker_list->interfaces[i] = HeapAlloc(GetProcessHeap(), 0, size);
|
|
|
|
if (!moniker_list->interfaces[i])
|
2007-09-10 17:10:45 +02:00
|
|
|
{
|
|
|
|
ULONG end = i;
|
|
|
|
for (i = 0; i < end; i++)
|
2007-11-10 17:05:23 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, moniker_list->interfaces[i]);
|
|
|
|
HeapFree(GetProcessHeap(), 0, moniker_list);
|
2007-09-10 17:10:45 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
2007-11-10 17:05:23 +01:00
|
|
|
memcpy(moniker_list->interfaces[i], This->moniker_list->interfaces[i], size);
|
2005-05-23 11:54:53 +02:00
|
|
|
}
|
|
|
|
|
2005-05-14 20:50:14 +02:00
|
|
|
/* copy the enum structure */
|
2007-11-10 17:05:23 +01:00
|
|
|
return EnumMonikerImpl_CreateEnumROTMoniker(moniker_list, This->pos, ppenum);
|
2005-05-14 20:50:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Virtual function table for the IEnumMoniker class. */
|
2005-05-23 11:54:53 +02:00
|
|
|
static const IEnumMonikerVtbl VT_EnumMonikerImpl =
|
2005-05-14 20:50:14 +02:00
|
|
|
{
|
|
|
|
EnumMonikerImpl_QueryInterface,
|
|
|
|
EnumMonikerImpl_AddRef,
|
|
|
|
EnumMonikerImpl_Release,
|
|
|
|
EnumMonikerImpl_Next,
|
|
|
|
EnumMonikerImpl_Skip,
|
|
|
|
EnumMonikerImpl_Reset,
|
|
|
|
EnumMonikerImpl_Clone
|
|
|
|
};
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* EnumMonikerImpl_CreateEnumROTMoniker
|
|
|
|
* Used by EnumRunning to create the structure and EnumClone
|
|
|
|
* to copy the structure
|
|
|
|
*/
|
2008-11-25 16:41:41 +01:00
|
|
|
static HRESULT EnumMonikerImpl_CreateEnumROTMoniker(InterfaceList *moniker_list,
|
2005-05-23 11:54:53 +02:00
|
|
|
ULONG current_pos,
|
|
|
|
IEnumMoniker **ppenumMoniker)
|
2005-05-14 20:50:14 +02:00
|
|
|
{
|
|
|
|
EnumMonikerImpl* This = NULL;
|
|
|
|
|
2005-05-23 11:54:53 +02:00
|
|
|
if (!ppenumMoniker)
|
2005-05-14 20:50:14 +02:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
This = HeapAlloc(GetProcessHeap(), 0, sizeof(EnumMonikerImpl));
|
2005-05-23 11:54:53 +02:00
|
|
|
if (!This) return E_OUTOFMEMORY;
|
2005-05-14 20:50:14 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
|
|
|
/* initialize the virtual table function */
|
2010-12-15 00:58:12 +01:00
|
|
|
This->IEnumMoniker_iface.lpVtbl = &VT_EnumMonikerImpl;
|
2005-05-14 20:50:14 +02:00
|
|
|
|
|
|
|
/* the initial reference is set to "1" */
|
|
|
|
This->ref = 1; /* set the ref count to one */
|
2005-06-02 22:06:22 +02:00
|
|
|
This->pos = current_pos; /* Set the list start posn */
|
2007-11-10 17:05:23 +01:00
|
|
|
This->moniker_list = moniker_list;
|
2005-05-14 20:50:14 +02:00
|
|
|
|
2010-12-15 00:58:12 +01:00
|
|
|
*ppenumMoniker = &This->IEnumMoniker_iface;
|
2005-05-14 20:50:14 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
2005-05-19 16:22:14 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* Shared implementation of moniker marshaler based on saving and loading of
|
|
|
|
* monikers */
|
|
|
|
|
|
|
|
typedef struct MonikerMarshal
|
|
|
|
{
|
2010-12-15 00:58:12 +01:00
|
|
|
IUnknown IUnknown_iface;
|
|
|
|
IMarshal IMarshal_iface;
|
|
|
|
|
2005-07-05 13:02:54 +02:00
|
|
|
LONG ref;
|
2005-05-19 16:22:14 +02:00
|
|
|
IMoniker *moniker;
|
|
|
|
} MonikerMarshal;
|
|
|
|
|
2010-12-15 00:58:12 +01:00
|
|
|
static inline MonikerMarshal *impl_from_IUnknown(IUnknown *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, MonikerMarshal, IUnknown_iface);
|
|
|
|
}
|
|
|
|
|
2005-07-27 13:10:52 +02:00
|
|
|
static inline MonikerMarshal *impl_from_IMarshal( IMarshal *iface )
|
|
|
|
{
|
2010-12-15 00:58:12 +01:00
|
|
|
return CONTAINING_RECORD(iface, MonikerMarshal, IMarshal_iface);
|
2005-07-27 13:10:52 +02:00
|
|
|
}
|
|
|
|
|
2005-05-19 16:22:14 +02:00
|
|
|
static HRESULT WINAPI MonikerMarshalInner_QueryInterface(IUnknown *iface, REFIID riid, LPVOID *ppv)
|
|
|
|
{
|
2010-12-15 00:58:12 +01:00
|
|
|
MonikerMarshal *This = impl_from_IUnknown(iface);
|
2005-05-19 16:22:14 +02:00
|
|
|
TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
|
|
|
|
*ppv = NULL;
|
|
|
|
if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IMarshal, riid))
|
|
|
|
{
|
2010-12-15 00:58:12 +01:00
|
|
|
*ppv = &This->IMarshal_iface;
|
|
|
|
IUnknown_AddRef((IUnknown *)&This->IMarshal_iface);
|
2005-05-19 16:22:14 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
FIXME("No interface for %s\n", debugstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI MonikerMarshalInner_AddRef(IUnknown *iface)
|
|
|
|
{
|
2010-12-15 00:58:12 +01:00
|
|
|
MonikerMarshal *This = impl_from_IUnknown(iface);
|
2005-05-19 16:22:14 +02:00
|
|
|
return InterlockedIncrement(&This->ref);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI MonikerMarshalInner_Release(IUnknown *iface)
|
|
|
|
{
|
2010-12-15 00:58:12 +01:00
|
|
|
MonikerMarshal *This = impl_from_IUnknown(iface);
|
2005-05-19 16:22:14 +02:00
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
|
|
|
if (!ref) HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IUnknownVtbl VT_MonikerMarshalInner =
|
|
|
|
{
|
|
|
|
MonikerMarshalInner_QueryInterface,
|
|
|
|
MonikerMarshalInner_AddRef,
|
|
|
|
MonikerMarshalInner_Release
|
|
|
|
};
|
|
|
|
|
|
|
|
static HRESULT WINAPI MonikerMarshal_QueryInterface(IMarshal *iface, REFIID riid, LPVOID *ppv)
|
|
|
|
{
|
2005-07-27 13:10:52 +02:00
|
|
|
MonikerMarshal *This = impl_from_IMarshal(iface);
|
2005-05-19 16:22:14 +02:00
|
|
|
return IMoniker_QueryInterface(This->moniker, riid, ppv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI MonikerMarshal_AddRef(IMarshal *iface)
|
|
|
|
{
|
2005-07-27 13:10:52 +02:00
|
|
|
MonikerMarshal *This = impl_from_IMarshal(iface);
|
2005-05-19 16:22:14 +02:00
|
|
|
return IMoniker_AddRef(This->moniker);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI MonikerMarshal_Release(IMarshal *iface)
|
|
|
|
{
|
2005-07-27 13:10:52 +02:00
|
|
|
MonikerMarshal *This = impl_from_IMarshal(iface);
|
2005-05-19 16:22:14 +02:00
|
|
|
return IMoniker_Release(This->moniker);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MonikerMarshal_GetUnmarshalClass(
|
|
|
|
LPMARSHAL iface, REFIID riid, void* pv, DWORD dwDestContext,
|
|
|
|
void* pvDestContext, DWORD mshlflags, CLSID* pCid)
|
|
|
|
{
|
2005-07-27 13:10:52 +02:00
|
|
|
MonikerMarshal *This = impl_from_IMarshal(iface);
|
2005-05-19 16:22:14 +02:00
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("(%s, %p, %x, %p, %x, %p)\n", debugstr_guid(riid), pv,
|
2005-05-19 16:22:14 +02:00
|
|
|
dwDestContext, pvDestContext, mshlflags, pCid);
|
|
|
|
|
|
|
|
return IMoniker_GetClassID(This->moniker, pCid);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MonikerMarshal_GetMarshalSizeMax(
|
|
|
|
LPMARSHAL iface, REFIID riid, void* pv, DWORD dwDestContext,
|
|
|
|
void* pvDestContext, DWORD mshlflags, DWORD* pSize)
|
|
|
|
{
|
2005-07-27 13:10:52 +02:00
|
|
|
MonikerMarshal *This = impl_from_IMarshal(iface);
|
2005-05-19 16:22:14 +02:00
|
|
|
HRESULT hr;
|
|
|
|
ULARGE_INTEGER size;
|
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("(%s, %p, %x, %p, %x, %p)\n", debugstr_guid(riid), pv,
|
2005-05-19 16:22:14 +02:00
|
|
|
dwDestContext, pvDestContext, mshlflags, pSize);
|
|
|
|
|
|
|
|
hr = IMoniker_GetSizeMax(This->moniker, &size);
|
|
|
|
if (hr == S_OK)
|
|
|
|
*pSize = (DWORD)size.QuadPart;
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MonikerMarshal_MarshalInterface(LPMARSHAL iface, IStream *pStm,
|
|
|
|
REFIID riid, void* pv, DWORD dwDestContext,
|
|
|
|
void* pvDestContext, DWORD mshlflags)
|
|
|
|
{
|
2005-07-27 13:10:52 +02:00
|
|
|
MonikerMarshal *This = impl_from_IMarshal(iface);
|
2005-05-19 16:22:14 +02:00
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("(%p, %s, %p, %x, %p, %x)\n", pStm, debugstr_guid(riid), pv,
|
2005-05-19 16:22:14 +02:00
|
|
|
dwDestContext, pvDestContext, mshlflags);
|
|
|
|
|
|
|
|
return IMoniker_Save(This->moniker, pStm, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MonikerMarshal_UnmarshalInterface(LPMARSHAL iface, IStream *pStm, REFIID riid, void **ppv)
|
|
|
|
{
|
2005-07-27 13:10:52 +02:00
|
|
|
MonikerMarshal *This = impl_from_IMarshal(iface);
|
2005-05-19 16:22:14 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p, %s, %p)\n", pStm, debugstr_guid(riid), ppv);
|
|
|
|
|
|
|
|
hr = IMoniker_Load(This->moniker, pStm);
|
|
|
|
if (hr == S_OK)
|
|
|
|
hr = IMoniker_QueryInterface(This->moniker, riid, ppv);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MonikerMarshal_ReleaseMarshalData(LPMARSHAL iface, IStream *pStm)
|
|
|
|
{
|
|
|
|
TRACE("()\n");
|
|
|
|
/* can't release a state-based marshal as nothing on server side to
|
|
|
|
* release */
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MonikerMarshal_DisconnectObject(LPMARSHAL iface, DWORD dwReserved)
|
|
|
|
{
|
|
|
|
TRACE("()\n");
|
|
|
|
/* can't disconnect a state-based marshal as nothing on server side to
|
|
|
|
* disconnect from */
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IMarshalVtbl VT_MonikerMarshal =
|
|
|
|
{
|
|
|
|
MonikerMarshal_QueryInterface,
|
|
|
|
MonikerMarshal_AddRef,
|
|
|
|
MonikerMarshal_Release,
|
|
|
|
MonikerMarshal_GetUnmarshalClass,
|
|
|
|
MonikerMarshal_GetMarshalSizeMax,
|
|
|
|
MonikerMarshal_MarshalInterface,
|
|
|
|
MonikerMarshal_UnmarshalInterface,
|
|
|
|
MonikerMarshal_ReleaseMarshalData,
|
|
|
|
MonikerMarshal_DisconnectObject
|
|
|
|
};
|
|
|
|
|
|
|
|
HRESULT MonikerMarshal_Create(IMoniker *inner, IUnknown **outer)
|
|
|
|
{
|
|
|
|
MonikerMarshal *This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
|
|
|
|
if (!This) return E_OUTOFMEMORY;
|
|
|
|
|
2010-12-15 00:58:12 +01:00
|
|
|
This->IUnknown_iface.lpVtbl = &VT_MonikerMarshalInner;
|
|
|
|
This->IMarshal_iface.lpVtbl = &VT_MonikerMarshal;
|
2005-05-19 16:22:14 +02:00
|
|
|
This->ref = 1;
|
|
|
|
This->moniker = inner;
|
|
|
|
|
2010-12-15 00:58:12 +01:00
|
|
|
*outer = &This->IUnknown_iface;
|
2005-05-19 16:22:14 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
2007-09-10 17:10:45 +02:00
|
|
|
|
2009-01-30 14:46:17 +01:00
|
|
|
void * __RPC_USER MIDL_user_allocate(SIZE_T size)
|
2007-09-10 17:10:45 +02:00
|
|
|
{
|
|
|
|
return HeapAlloc(GetProcessHeap(), 0, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void __RPC_USER MIDL_user_free(void *p)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, p);
|
|
|
|
}
|