2006-05-18 14:49:52 +02:00
|
|
|
/*
|
1999-01-28 18:56:14 +01:00
|
|
|
* BindCtx 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
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
1999-01-28 18:56:14 +01:00
|
|
|
#include <string.h>
|
2004-10-07 05:06:48 +02:00
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
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"
|
2007-03-08 12:00:21 +01:00
|
|
|
#include "winnls.h"
|
2002-12-05 21:33:07 +01:00
|
|
|
#include "objbase.h"
|
2007-03-08 12:00:21 +01:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2021-09-20 12:08:45 +02:00
|
|
|
#include "wine/heap.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
|
|
|
|
2007-03-13 13:38:03 +01:00
|
|
|
#define BINDCTX_FIRST_TABLE_SIZE 4
|
1999-03-23 14:48:56 +01:00
|
|
|
|
|
|
|
/* data structure of the BindCtx table elements */
|
|
|
|
typedef struct BindCtxObject{
|
|
|
|
|
|
|
|
IUnknown* pObj; /* point on a bound object */
|
|
|
|
|
|
|
|
LPOLESTR pkeyObj; /* key associated to this bound object */
|
|
|
|
|
|
|
|
BYTE regType; /* registration type: 1 if RegisterObjectParam and 0 if RegisterObjectBound */
|
|
|
|
|
|
|
|
} BindCtxObject;
|
|
|
|
|
2008-04-09 21:33:37 +02:00
|
|
|
/* BindCtx data structure */
|
1999-01-28 18:56:14 +01:00
|
|
|
typedef struct BindCtxImpl{
|
|
|
|
|
2010-12-08 22:59:43 +01:00
|
|
|
IBindCtx IBindCtx_iface;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2005-07-05 13:02:54 +02:00
|
|
|
LONG ref; /* reference counter for this object */
|
1999-01-28 18:56:14 +01:00
|
|
|
|
2001-02-28 06:31:02 +01:00
|
|
|
BindCtxObject* bindCtxTable; /* this is a table in which all bounded objects are stored*/
|
1999-03-23 14:48:56 +01:00
|
|
|
DWORD bindCtxTableLastIndex; /* first free index in the table */
|
|
|
|
DWORD bindCtxTableSize; /* size table */
|
1999-01-28 18:56:14 +01:00
|
|
|
|
2019-11-03 21:58:58 +01:00
|
|
|
BIND_OPTS3 options;
|
1999-02-18 14:26:22 +01:00
|
|
|
|
1999-03-23 14:48:56 +01:00
|
|
|
} BindCtxImpl;
|
1999-01-28 18:56:14 +01:00
|
|
|
|
1999-03-23 14:48:56 +01:00
|
|
|
/* IBindCtx prototype functions : */
|
2005-03-27 20:16:25 +02:00
|
|
|
static HRESULT WINAPI BindCtxImpl_ReleaseBoundObjects(IBindCtx*);
|
|
|
|
static HRESULT BindCtxImpl_GetObjectIndex(BindCtxImpl*, IUnknown*, LPOLESTR, DWORD *);
|
2007-03-13 13:38:03 +01:00
|
|
|
static HRESULT BindCtxImpl_ExpandTable(BindCtxImpl *);
|
1999-01-28 18:56:14 +01:00
|
|
|
|
2010-12-08 22:59:43 +01:00
|
|
|
static inline BindCtxImpl *impl_from_IBindCtx(IBindCtx *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, BindCtxImpl, IBindCtx_iface);
|
|
|
|
}
|
|
|
|
|
1999-01-28 18:56:14 +01:00
|
|
|
/*******************************************************************************
|
|
|
|
* BindCtx_QueryInterface
|
|
|
|
*******************************************************************************/
|
2005-03-27 20:16:25 +02:00
|
|
|
static HRESULT WINAPI
|
|
|
|
BindCtxImpl_QueryInterface(IBindCtx* iface,REFIID riid,void** ppvObject)
|
1999-02-18 14:26:22 +01:00
|
|
|
{
|
2010-12-08 22:59:43 +01:00
|
|
|
BindCtxImpl *This = impl_from_IBindCtx(iface);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2007-12-30 17:44:32 +01:00
|
|
|
TRACE("(%p %s %p)\n",This, debugstr_guid(riid), ppvObject);
|
1999-01-28 18:56:14 +01:00
|
|
|
|
2005-03-27 20:16:25 +02:00
|
|
|
/* Perform a sanity check on the parameters.*/
|
2007-12-30 17:44:32 +01:00
|
|
|
if (!ppvObject)
|
|
|
|
return E_POINTER;
|
1999-01-28 18:56:14 +01:00
|
|
|
|
2005-03-27 20:16:25 +02:00
|
|
|
/* Initialize the return parameter.*/
|
|
|
|
*ppvObject = 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2005-03-27 20:16:25 +02:00
|
|
|
/* Compare the riid with the interface IDs implemented by this object.*/
|
|
|
|
if (IsEqualIID(&IID_IUnknown, riid) ||
|
|
|
|
IsEqualIID(&IID_IBindCtx, riid))
|
|
|
|
{
|
2015-03-20 08:15:42 +01:00
|
|
|
*ppvObject = &This->IBindCtx_iface;
|
2005-03-27 20:16:25 +02:00
|
|
|
IBindCtx_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
1999-01-28 18:56:14 +01:00
|
|
|
|
2005-03-27 20:16:25 +02:00
|
|
|
return E_NOINTERFACE;
|
1999-01-28 18:56:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
1999-03-23 14:48:56 +01:00
|
|
|
* BindCtx_AddRef
|
1999-01-28 18:56:14 +01:00
|
|
|
******************************************************************************/
|
2005-03-27 20:16:25 +02:00
|
|
|
static ULONG WINAPI BindCtxImpl_AddRef(IBindCtx* iface)
|
1999-02-18 14:26:22 +01:00
|
|
|
{
|
2010-12-08 22:59:43 +01:00
|
|
|
BindCtxImpl *This = impl_from_IBindCtx(iface);
|
1999-03-23 14:48:56 +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
|
|
|
}
|
|
|
|
|
2005-03-27 20:16:25 +02:00
|
|
|
static ULONG WINAPI BindCtxImpl_Release(IBindCtx* iface)
|
1999-02-18 14:26:22 +01:00
|
|
|
{
|
2021-09-20 12:08:45 +02:00
|
|
|
BindCtxImpl *context = impl_from_IBindCtx(iface);
|
|
|
|
ULONG refcount = InterlockedDecrement(&context->ref);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2021-09-20 12:08:45 +02:00
|
|
|
TRACE("%p refcount %d.\n", iface, refcount);
|
1999-01-28 18:56:14 +01:00
|
|
|
|
2021-09-20 12:08:45 +02:00
|
|
|
if (!refcount)
|
2005-03-27 20:16:25 +02:00
|
|
|
{
|
2021-09-20 12:08:45 +02:00
|
|
|
BindCtxImpl_ReleaseBoundObjects(&context->IBindCtx_iface);
|
|
|
|
heap_free(context->bindCtxTable);
|
|
|
|
heap_free(context);
|
1999-01-28 18:56:14 +01:00
|
|
|
}
|
2021-09-20 12:08:45 +02:00
|
|
|
|
|
|
|
return refcount;
|
1999-01-28 18:56:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* BindCtx_RegisterObjectBound
|
|
|
|
******************************************************************************/
|
2005-03-27 20:16:25 +02:00
|
|
|
static HRESULT WINAPI
|
|
|
|
BindCtxImpl_RegisterObjectBound(IBindCtx* iface,IUnknown* punk)
|
1999-02-18 14:26:22 +01:00
|
|
|
{
|
2010-12-08 22:59:43 +01:00
|
|
|
BindCtxImpl *This = impl_from_IBindCtx(iface);
|
1999-03-23 14:48:56 +01:00
|
|
|
DWORD lastIndex=This->bindCtxTableLastIndex;
|
|
|
|
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("(%p,%p)\n",This,punk);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
|
|
|
if (punk==NULL)
|
2007-03-09 10:48:26 +01:00
|
|
|
return S_OK;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2007-03-13 13:38:03 +01:00
|
|
|
if (lastIndex == This->bindCtxTableSize)
|
|
|
|
{
|
|
|
|
HRESULT hr = BindCtxImpl_ExpandTable(This);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
1999-03-23 14:48:56 +01:00
|
|
|
IUnknown_AddRef(punk);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-03-23 14:48:56 +01:00
|
|
|
/* put the object in the first free element in the table */
|
|
|
|
This->bindCtxTable[lastIndex].pObj = punk;
|
|
|
|
This->bindCtxTable[lastIndex].pkeyObj = NULL;
|
|
|
|
This->bindCtxTable[lastIndex].regType = 0;
|
|
|
|
lastIndex= ++This->bindCtxTableLastIndex;
|
|
|
|
|
|
|
|
return S_OK;
|
1999-01-28 18:56:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* BindCtx_RevokeObjectBound
|
|
|
|
******************************************************************************/
|
2005-03-27 20:16:25 +02:00
|
|
|
static HRESULT WINAPI
|
|
|
|
BindCtxImpl_RevokeObjectBound(IBindCtx* iface, IUnknown* punk)
|
1999-02-18 14:26:22 +01:00
|
|
|
{
|
1999-03-23 14:48:56 +01:00
|
|
|
DWORD index,j;
|
|
|
|
|
2010-12-08 22:59:43 +01:00
|
|
|
BindCtxImpl *This = impl_from_IBindCtx(iface);
|
1999-01-28 18:56:14 +01:00
|
|
|
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("(%p,%p)\n",This,punk);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
2007-03-09 10:48:26 +01:00
|
|
|
if (!punk)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2004-07-24 01:02:09 +02:00
|
|
|
/* check if the object was registered or not */
|
1999-03-23 14:48:56 +01:00
|
|
|
if (BindCtxImpl_GetObjectIndex(This,punk,NULL,&index)==S_FALSE)
|
|
|
|
return MK_E_NOTBOUND;
|
|
|
|
|
2003-04-05 07:10:37 +02:00
|
|
|
if(This->bindCtxTable[index].pObj)
|
|
|
|
IUnknown_Release(This->bindCtxTable[index].pObj);
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree(GetProcessHeap(),0,This->bindCtxTable[index].pkeyObj);
|
2003-04-05 07:10:37 +02:00
|
|
|
|
2001-04-20 20:36:05 +02:00
|
|
|
/* left-shift all elements in the right side of the current revoked object */
|
1999-03-23 14:48:56 +01:00
|
|
|
for(j=index; j<This->bindCtxTableLastIndex-1; j++)
|
|
|
|
This->bindCtxTable[j]= This->bindCtxTable[j+1];
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-03-23 14:48:56 +01:00
|
|
|
This->bindCtxTableLastIndex--;
|
|
|
|
|
|
|
|
return S_OK;
|
1999-01-28 18:56:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
1999-03-23 14:48:56 +01:00
|
|
|
* BindCtx_ReleaseBoundObjects
|
1999-01-28 18:56:14 +01:00
|
|
|
******************************************************************************/
|
2005-03-27 20:16:25 +02:00
|
|
|
static HRESULT WINAPI
|
|
|
|
BindCtxImpl_ReleaseBoundObjects(IBindCtx* iface)
|
1999-02-18 14:26:22 +01:00
|
|
|
{
|
1999-03-23 14:48:56 +01:00
|
|
|
DWORD i;
|
|
|
|
|
2010-12-08 22:59:43 +01:00
|
|
|
BindCtxImpl *This = impl_from_IBindCtx(iface);
|
1999-01-28 18:56:14 +01:00
|
|
|
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("(%p)\n",This);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
|
|
|
for(i=0;i<This->bindCtxTableLastIndex;i++)
|
2003-04-05 07:10:37 +02:00
|
|
|
{
|
|
|
|
if(This->bindCtxTable[i].pObj)
|
|
|
|
IUnknown_Release(This->bindCtxTable[i].pObj);
|
2005-01-03 15:56:42 +01:00
|
|
|
HeapFree(GetProcessHeap(),0,This->bindCtxTable[i].pkeyObj);
|
2003-04-05 07:10:37 +02:00
|
|
|
}
|
|
|
|
|
1999-03-23 14:48:56 +01:00
|
|
|
This->bindCtxTableLastIndex = 0;
|
|
|
|
|
|
|
|
return S_OK;
|
1999-01-28 18:56:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* BindCtx_SetBindOptions
|
|
|
|
******************************************************************************/
|
2005-03-27 20:16:25 +02:00
|
|
|
static HRESULT WINAPI
|
|
|
|
BindCtxImpl_SetBindOptions(IBindCtx* iface,BIND_OPTS *pbindopts)
|
1999-02-18 14:26:22 +01:00
|
|
|
{
|
2010-12-08 22:59:43 +01:00
|
|
|
BindCtxImpl *This = impl_from_IBindCtx(iface);
|
1999-01-28 18:56:14 +01:00
|
|
|
|
2019-11-03 21:58:58 +01:00
|
|
|
TRACE("(%p,%p)\n",This, pbindopts);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
|
|
|
if (pbindopts==NULL)
|
|
|
|
return E_POINTER;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2019-11-03 21:58:58 +01:00
|
|
|
if (pbindopts->cbStruct > sizeof(This->options))
|
1999-12-10 04:23:35 +01:00
|
|
|
{
|
2019-11-03 21:58:58 +01:00
|
|
|
WARN("invalid size %u.\n", pbindopts->cbStruct);
|
|
|
|
return E_INVALIDARG;
|
1999-12-10 04:23:35 +01:00
|
|
|
}
|
2019-11-03 21:58:58 +01:00
|
|
|
memcpy(&This->options, pbindopts, pbindopts->cbStruct);
|
1999-03-23 14:48:56 +01:00
|
|
|
return S_OK;
|
1999-01-28 18:56:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* BindCtx_GetBindOptions
|
|
|
|
******************************************************************************/
|
2005-03-27 20:16:25 +02:00
|
|
|
static HRESULT WINAPI
|
|
|
|
BindCtxImpl_GetBindOptions(IBindCtx* iface,BIND_OPTS *pbindopts)
|
1999-02-18 14:26:22 +01:00
|
|
|
{
|
2010-12-08 22:59:43 +01:00
|
|
|
BindCtxImpl *This = impl_from_IBindCtx(iface);
|
2019-11-03 21:58:58 +01:00
|
|
|
DWORD size;
|
1999-01-28 18:56:14 +01:00
|
|
|
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("(%p,%p)\n",This,pbindopts);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
|
|
|
if (pbindopts==NULL)
|
|
|
|
return E_POINTER;
|
|
|
|
|
2019-11-03 21:58:58 +01:00
|
|
|
size = min(pbindopts->cbStruct, sizeof(This->options));
|
|
|
|
memcpy(pbindopts, &This->options, size);
|
|
|
|
pbindopts->cbStruct = size;
|
2007-03-08 12:00:21 +01:00
|
|
|
|
1999-03-23 14:48:56 +01:00
|
|
|
return S_OK;
|
1999-01-28 18:56:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* BindCtx_GetRunningObjectTable
|
|
|
|
******************************************************************************/
|
2005-03-27 20:16:25 +02:00
|
|
|
static HRESULT WINAPI
|
|
|
|
BindCtxImpl_GetRunningObjectTable(IBindCtx* iface,IRunningObjectTable** pprot)
|
1999-02-18 14:26:22 +01:00
|
|
|
{
|
2010-12-08 22:59:43 +01:00
|
|
|
BindCtxImpl *This = impl_from_IBindCtx(iface);
|
1999-01-28 18:56:14 +01:00
|
|
|
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("(%p,%p)\n",This,pprot);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
|
|
|
if (pprot==NULL)
|
|
|
|
return E_POINTER;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2010-07-21 12:03:35 +02:00
|
|
|
return GetRunningObjectTable(0, pprot);
|
1999-01-28 18:56:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* BindCtx_RegisterObjectParam
|
|
|
|
******************************************************************************/
|
2005-03-27 20:16:25 +02:00
|
|
|
static HRESULT WINAPI
|
|
|
|
BindCtxImpl_RegisterObjectParam(IBindCtx* iface,LPOLESTR pszkey, IUnknown* punk)
|
1999-02-18 14:26:22 +01:00
|
|
|
{
|
2003-01-02 18:51:34 +01:00
|
|
|
DWORD index=0;
|
2010-12-08 22:59:43 +01:00
|
|
|
BindCtxImpl *This = impl_from_IBindCtx(iface);
|
1999-01-28 18:56:14 +01:00
|
|
|
|
2003-01-02 18:51:34 +01:00
|
|
|
TRACE("(%p,%s,%p)\n",This,debugstr_w(pszkey),punk);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
|
|
|
if (punk==NULL)
|
|
|
|
return E_INVALIDARG;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2003-01-02 18:51:34 +01:00
|
|
|
if (pszkey!=NULL && BindCtxImpl_GetObjectIndex(This,NULL,pszkey,&index)==S_OK)
|
|
|
|
{
|
|
|
|
TRACE("Overwriting existing key\n");
|
|
|
|
if(This->bindCtxTable[index].pObj!=NULL)
|
|
|
|
IUnknown_Release(This->bindCtxTable[index].pObj);
|
|
|
|
This->bindCtxTable[index].pObj=punk;
|
2003-08-30 00:10:01 +02:00
|
|
|
IUnknown_AddRef(punk);
|
2003-01-02 18:51:34 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
2007-03-13 13:38:03 +01:00
|
|
|
|
|
|
|
if (This->bindCtxTableLastIndex == This->bindCtxTableSize)
|
|
|
|
{
|
|
|
|
HRESULT hr = BindCtxImpl_ExpandTable(This);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
1999-03-23 14:48:56 +01:00
|
|
|
This->bindCtxTable[This->bindCtxTableLastIndex].pObj = punk;
|
|
|
|
This->bindCtxTable[This->bindCtxTableLastIndex].regType = 1;
|
|
|
|
|
|
|
|
if (pszkey==NULL)
|
|
|
|
|
|
|
|
This->bindCtxTable[This->bindCtxTableLastIndex].pkeyObj=NULL;
|
|
|
|
|
2005-03-27 20:16:25 +02:00
|
|
|
else
|
|
|
|
{
|
1999-03-23 14:48:56 +01:00
|
|
|
|
|
|
|
This->bindCtxTable[This->bindCtxTableLastIndex].pkeyObj=
|
|
|
|
HeapAlloc(GetProcessHeap(),0,(sizeof(WCHAR)*(1+lstrlenW(pszkey))));
|
|
|
|
|
|
|
|
if (This->bindCtxTable[This->bindCtxTableLastIndex].pkeyObj==NULL)
|
|
|
|
return E_OUTOFMEMORY;
|
2005-03-27 20:16:25 +02:00
|
|
|
lstrcpyW(This->bindCtxTable[This->bindCtxTableLastIndex].pkeyObj,pszkey);
|
2001-09-11 02:32:32 +02:00
|
|
|
}
|
1999-01-28 18:56:14 +01:00
|
|
|
|
1999-03-23 14:48:56 +01:00
|
|
|
This->bindCtxTableLastIndex++;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2003-08-30 00:10:01 +02:00
|
|
|
IUnknown_AddRef(punk);
|
1999-03-23 14:48:56 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
2003-08-30 00:10:01 +02:00
|
|
|
|
1999-01-28 18:56:14 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* BindCtx_GetObjectParam
|
|
|
|
******************************************************************************/
|
2005-03-27 20:16:25 +02:00
|
|
|
static HRESULT WINAPI
|
|
|
|
BindCtxImpl_GetObjectParam(IBindCtx* iface,LPOLESTR pszkey, IUnknown** punk)
|
1999-02-18 14:26:22 +01:00
|
|
|
{
|
1999-03-23 14:48:56 +01:00
|
|
|
DWORD index;
|
2010-12-08 22:59:43 +01:00
|
|
|
BindCtxImpl *This = impl_from_IBindCtx(iface);
|
1999-01-28 18:56:14 +01:00
|
|
|
|
2003-01-02 18:51:34 +01:00
|
|
|
TRACE("(%p,%s,%p)\n",This,debugstr_w(pszkey),punk);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
|
|
|
if (punk==NULL)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
*punk=0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-03-23 14:48:56 +01:00
|
|
|
if (BindCtxImpl_GetObjectIndex(This,NULL,pszkey,&index)==S_FALSE)
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
IUnknown_AddRef(This->bindCtxTable[index].pObj);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-03-23 14:48:56 +01:00
|
|
|
*punk = This->bindCtxTable[index].pObj;
|
|
|
|
|
|
|
|
return S_OK;
|
1999-01-28 18:56:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
1999-03-23 14:48:56 +01:00
|
|
|
* BindCtx_RevokeObjectParam
|
1999-01-28 18:56:14 +01:00
|
|
|
******************************************************************************/
|
2005-03-27 20:16:25 +02:00
|
|
|
static HRESULT WINAPI
|
|
|
|
BindCtxImpl_RevokeObjectParam(IBindCtx* iface,LPOLESTR ppenum)
|
1999-02-18 14:26:22 +01:00
|
|
|
{
|
1999-03-23 14:48:56 +01:00
|
|
|
DWORD index,j;
|
|
|
|
|
2010-12-08 22:59:43 +01:00
|
|
|
BindCtxImpl *This = impl_from_IBindCtx(iface);
|
1999-01-28 18:56:14 +01:00
|
|
|
|
2003-01-02 18:51:34 +01:00
|
|
|
TRACE("(%p,%s)\n",This,debugstr_w(ppenum));
|
1999-03-23 14:48:56 +01:00
|
|
|
|
|
|
|
if (BindCtxImpl_GetObjectIndex(This,NULL,ppenum,&index)==S_FALSE)
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
/* release the object if it's found */
|
2003-04-05 07:10:37 +02:00
|
|
|
if(This->bindCtxTable[index].pObj)
|
|
|
|
IUnknown_Release(This->bindCtxTable[index].pObj);
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree(GetProcessHeap(),0,This->bindCtxTable[index].pkeyObj);
|
2003-04-05 07:10:37 +02:00
|
|
|
|
1999-03-23 14:48:56 +01:00
|
|
|
/* remove the object from the table with a left-shifting of all objects in the right side */
|
|
|
|
for(j=index; j<This->bindCtxTableLastIndex-1; j++)
|
|
|
|
This->bindCtxTable[j]= This->bindCtxTable[j+1];
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-03-23 14:48:56 +01:00
|
|
|
This->bindCtxTableLastIndex--;
|
|
|
|
|
|
|
|
return S_OK;
|
1999-01-28 18:56:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
1999-03-23 14:48:56 +01:00
|
|
|
* BindCtx_EnumObjectParam
|
1999-01-28 18:56:14 +01:00
|
|
|
******************************************************************************/
|
2005-03-27 20:16:25 +02:00
|
|
|
static HRESULT WINAPI
|
|
|
|
BindCtxImpl_EnumObjectParam(IBindCtx* iface,IEnumString** pszkey)
|
1999-02-18 14:26:22 +01:00
|
|
|
{
|
2007-03-08 12:01:06 +01:00
|
|
|
TRACE("(%p,%p)\n",iface,pszkey);
|
|
|
|
|
|
|
|
*pszkey = NULL;
|
|
|
|
|
|
|
|
/* not implemented in native either */
|
1999-01-28 18:56:14 +01:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
1999-03-23 14:48:56 +01:00
|
|
|
/********************************************************************************
|
|
|
|
* GetObjectIndex (local function)
|
|
|
|
********************************************************************************/
|
2005-03-27 20:16:25 +02:00
|
|
|
static HRESULT BindCtxImpl_GetObjectIndex(BindCtxImpl* This,
|
1999-03-23 14:48:56 +01:00
|
|
|
IUnknown* punk,
|
|
|
|
LPOLESTR pszkey,
|
|
|
|
DWORD *index)
|
|
|
|
{
|
|
|
|
DWORD i;
|
2013-10-15 00:27:16 +02:00
|
|
|
BOOL found = FALSE;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("(%p,%p,%p,%p)\n",This,punk,pszkey,index);
|
1999-03-23 14:48:56 +01:00
|
|
|
|
|
|
|
if (punk==NULL)
|
|
|
|
/* search object identified by a register key */
|
2005-03-27 20:16:25 +02:00
|
|
|
for(i=0; ( (i<This->bindCtxTableLastIndex) && (!found));i++)
|
|
|
|
{
|
1999-03-23 14:48:56 +01:00
|
|
|
if(This->bindCtxTable[i].regType==1){
|
|
|
|
|
|
|
|
if ( ( (This->bindCtxTable[i].pkeyObj==NULL) && (pszkey==NULL) ) ||
|
|
|
|
( (This->bindCtxTable[i].pkeyObj!=NULL) &&
|
|
|
|
(pszkey!=NULL) &&
|
2019-06-17 09:36:46 +02:00
|
|
|
(wcscmp(This->bindCtxTable[i].pkeyObj,pszkey)==0)
|
1999-03-23 14:48:56 +01:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2013-10-15 00:27:16 +02:00
|
|
|
found = TRUE;
|
1999-03-23 14:48:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
/* search object identified by a moniker*/
|
|
|
|
for(i=0; ( (i<This->bindCtxTableLastIndex) && (!found));i++)
|
|
|
|
if(This->bindCtxTable[i].pObj==punk)
|
2013-10-15 00:27:16 +02:00
|
|
|
found = TRUE;
|
1999-03-23 14:48:56 +01:00
|
|
|
|
|
|
|
if (index != NULL)
|
|
|
|
*index=i-1;
|
|
|
|
|
|
|
|
if (found)
|
|
|
|
return S_OK;
|
2003-01-02 18:51:34 +01:00
|
|
|
TRACE("key not found\n");
|
|
|
|
return S_FALSE;
|
1999-03-23 14:48:56 +01:00
|
|
|
}
|
1999-01-28 18:56:14 +01:00
|
|
|
|
2007-03-13 13:38:03 +01:00
|
|
|
static HRESULT BindCtxImpl_ExpandTable(BindCtxImpl *This)
|
|
|
|
{
|
|
|
|
if (!This->bindCtxTableSize)
|
|
|
|
{
|
|
|
|
This->bindCtxTableSize = BINDCTX_FIRST_TABLE_SIZE;
|
|
|
|
This->bindCtxTable = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,
|
|
|
|
This->bindCtxTableSize * sizeof(BindCtxObject));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
This->bindCtxTableSize *= 2;
|
|
|
|
|
|
|
|
This->bindCtxTable = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,This->bindCtxTable,
|
|
|
|
This->bindCtxTableSize * sizeof(BindCtxObject));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!This->bindCtxTable)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2005-06-06 21:50:35 +02:00
|
|
|
static const IBindCtxVtbl VT_BindCtxImpl =
|
2005-03-27 20:16:25 +02:00
|
|
|
{
|
|
|
|
BindCtxImpl_QueryInterface,
|
|
|
|
BindCtxImpl_AddRef,
|
|
|
|
BindCtxImpl_Release,
|
|
|
|
BindCtxImpl_RegisterObjectBound,
|
|
|
|
BindCtxImpl_RevokeObjectBound,
|
|
|
|
BindCtxImpl_ReleaseBoundObjects,
|
|
|
|
BindCtxImpl_SetBindOptions,
|
|
|
|
BindCtxImpl_GetBindOptions,
|
|
|
|
BindCtxImpl_GetRunningObjectTable,
|
|
|
|
BindCtxImpl_RegisterObjectParam,
|
|
|
|
BindCtxImpl_GetObjectParam,
|
|
|
|
BindCtxImpl_EnumObjectParam,
|
|
|
|
BindCtxImpl_RevokeObjectParam
|
|
|
|
};
|
|
|
|
|
1999-01-28 18:56:14 +01:00
|
|
|
/******************************************************************************
|
2003-09-11 05:06:25 +02:00
|
|
|
* CreateBindCtx (OLE32.@)
|
2007-03-26 19:23:51 +02:00
|
|
|
*/
|
2021-09-20 12:08:45 +02:00
|
|
|
HRESULT WINAPI CreateBindCtx(DWORD reserved, IBindCtx **bind_context)
|
1999-02-18 14:26:22 +01:00
|
|
|
{
|
2021-09-20 12:08:45 +02:00
|
|
|
BindCtxImpl *object;
|
1999-01-28 18:56:14 +01:00
|
|
|
|
2021-09-20 12:08:45 +02:00
|
|
|
TRACE("%#x, %p\n", reserved, bind_context);
|
1999-01-28 18:56:14 +01:00
|
|
|
|
2021-09-20 12:08:45 +02:00
|
|
|
if (!bind_context) return E_INVALIDARG;
|
2007-03-09 10:46:58 +01:00
|
|
|
|
2021-09-20 12:08:45 +02:00
|
|
|
*bind_context = NULL;
|
2007-03-08 11:59:38 +01:00
|
|
|
|
2021-09-20 12:08:45 +02:00
|
|
|
if (reserved)
|
2007-03-08 11:59:38 +01:00
|
|
|
{
|
2021-09-20 12:08:45 +02:00
|
|
|
WARN("reserved should be 0, not 0x%x\n", reserved);
|
2007-03-08 11:59:38 +01:00
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2021-09-20 12:08:45 +02:00
|
|
|
if (!(object = heap_alloc_zero(sizeof(*object))))
|
1999-03-23 14:48:56 +01:00
|
|
|
return E_OUTOFMEMORY;
|
1999-01-28 18:56:14 +01:00
|
|
|
|
2021-09-20 12:08:45 +02:00
|
|
|
object->IBindCtx_iface.lpVtbl = &VT_BindCtxImpl;
|
|
|
|
object->ref = 1;
|
|
|
|
object->options.cbStruct = sizeof(object->options);
|
|
|
|
object->options.grfMode = STGM_READWRITE;
|
|
|
|
object->options.dwClassContext = CLSCTX_SERVER;
|
|
|
|
object->options.locale = GetThreadLocale();
|
1999-01-28 18:56:14 +01:00
|
|
|
|
2021-09-20 12:08:45 +02:00
|
|
|
*bind_context = &object->IBindCtx_iface;
|
|
|
|
|
|
|
|
return S_OK;
|
1999-01-28 18:56:14 +01:00
|
|
|
}
|
2002-12-12 03:17:39 +01:00
|
|
|
|
2007-03-26 19:23:51 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* BindMoniker [OLE32.@]
|
|
|
|
*
|
|
|
|
* Binds to a moniker.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pmk [I] Moniker to bind to.
|
|
|
|
* grfOpt [I] Reserved option flags. Set to 0.
|
|
|
|
* riid [I] ID of the interface to bind to.
|
|
|
|
* pvResult [O] Address that receives the interface of the object that was bound to.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK.
|
|
|
|
* Failure: Any HRESULT code.
|
|
|
|
*/
|
2002-12-12 03:17:39 +01:00
|
|
|
HRESULT WINAPI BindMoniker(LPMONIKER pmk, DWORD grfOpt, REFIID riid, LPVOID * ppvResult)
|
|
|
|
{
|
|
|
|
HRESULT res;
|
|
|
|
IBindCtx * pbc;
|
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("(%p, %x, %s, %p)\n", pmk, grfOpt, debugstr_guid(riid), ppvResult);
|
2002-12-12 03:17:39 +01:00
|
|
|
|
|
|
|
res = CreateBindCtx(grfOpt, &pbc);
|
|
|
|
if (SUCCEEDED(res))
|
2008-02-13 13:34:44 +01:00
|
|
|
{
|
2002-12-12 03:17:39 +01:00
|
|
|
res = IMoniker_BindToObject(pmk, pbc, NULL, riid, ppvResult);
|
2008-02-13 13:34:44 +01:00
|
|
|
IBindCtx_Release(pbc);
|
|
|
|
}
|
2002-12-12 03:17:39 +01:00
|
|
|
return res;
|
|
|
|
}
|