2000-07-25 14:26:12 +02:00
|
|
|
/*
|
|
|
|
* Implementation of a generic ConnectionPoint object.
|
|
|
|
*
|
|
|
|
* Copyright 2000 Huw D M Davies for CodeWeavers
|
|
|
|
*
|
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
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* NOTES:
|
2000-07-25 14:26:12 +02:00
|
|
|
* See one exported function here is CreateConnectionPoint, see
|
|
|
|
* comments just above that function for information.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2001-01-26 21:43:40 +01:00
|
|
|
#include <string.h>
|
2004-10-07 05:06:48 +02:00
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
2000-07-25 14:26:12 +02: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"
|
|
|
|
#include "wingdi.h"
|
2000-11-30 02:31:28 +01:00
|
|
|
#include "winuser.h"
|
|
|
|
#include "ole2.h"
|
2000-07-25 14:26:12 +02:00
|
|
|
#include "olectl.h"
|
|
|
|
#include "connpt.h"
|
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2000-07-25 14:26:12 +02:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ole);
|
2000-07-25 14:26:12 +02:00
|
|
|
|
|
|
|
#define MAXSINKS 10
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* Implementation of IConnectionPoint
|
|
|
|
*/
|
|
|
|
typedef struct ConnectionPointImpl {
|
|
|
|
|
2005-06-06 21:50:35 +02:00
|
|
|
const IConnectionPointVtbl *lpvtbl;
|
2000-07-25 14:26:12 +02:00
|
|
|
|
|
|
|
/* IUnknown of our main object*/
|
|
|
|
IUnknown *Obj;
|
|
|
|
|
|
|
|
/* Reference count */
|
2005-07-11 12:25:19 +02:00
|
|
|
LONG ref;
|
2000-07-25 14:26:12 +02:00
|
|
|
|
|
|
|
/* IID of sink interface */
|
|
|
|
IID iid;
|
|
|
|
|
|
|
|
/* Array of sink IUnknowns */
|
|
|
|
IUnknown **sinks;
|
|
|
|
DWORD maxSinks;
|
|
|
|
|
|
|
|
DWORD nSinks;
|
|
|
|
} ConnectionPointImpl;
|
|
|
|
|
2005-06-06 21:50:35 +02:00
|
|
|
static const IConnectionPointVtbl ConnectionPointImpl_VTable;
|
2000-07-25 14:26:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* Implementation of IEnumConnections
|
|
|
|
*/
|
|
|
|
typedef struct EnumConnectionsImpl {
|
|
|
|
|
2005-06-06 21:50:35 +02:00
|
|
|
const IEnumConnectionsVtbl *lpvtbl;
|
2000-07-25 14:26:12 +02:00
|
|
|
|
2005-07-11 12:25:19 +02:00
|
|
|
LONG ref;
|
2000-07-25 14:26:12 +02:00
|
|
|
|
|
|
|
/* IUnknown of ConnectionPoint, used for ref counting */
|
|
|
|
IUnknown *pUnk;
|
|
|
|
|
|
|
|
/* Connection Data */
|
|
|
|
CONNECTDATA *pCD;
|
|
|
|
DWORD nConns;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-07-25 14:26:12 +02:00
|
|
|
/* Next connection to enumerate from */
|
|
|
|
DWORD nCur;
|
|
|
|
|
|
|
|
} EnumConnectionsImpl;
|
|
|
|
|
|
|
|
static EnumConnectionsImpl *EnumConnectionsImpl_Construct(IUnknown *pUnk,
|
|
|
|
DWORD nSinks,
|
|
|
|
CONNECTDATA *pCD);
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* ConnectionPointImpl_Construct
|
|
|
|
*/
|
|
|
|
static ConnectionPointImpl *ConnectionPointImpl_Construct(IUnknown *pUnk,
|
|
|
|
REFIID riid)
|
|
|
|
{
|
|
|
|
ConnectionPointImpl *Obj;
|
|
|
|
|
|
|
|
Obj = HeapAlloc(GetProcessHeap(), 0, sizeof(*Obj));
|
|
|
|
Obj->lpvtbl = &ConnectionPointImpl_VTable;
|
|
|
|
Obj->Obj = pUnk;
|
|
|
|
Obj->ref = 1;
|
|
|
|
Obj->iid = *riid;
|
|
|
|
Obj->maxSinks = MAXSINKS;
|
2002-06-01 01:06:46 +02:00
|
|
|
Obj->sinks = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
2000-07-25 14:26:12 +02:00
|
|
|
sizeof(IUnknown*) * MAXSINKS);
|
|
|
|
Obj->nSinks = 0;
|
|
|
|
return Obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* ConnectionPointImpl_Destroy
|
|
|
|
*/
|
|
|
|
static void ConnectionPointImpl_Destroy(ConnectionPointImpl *Obj)
|
|
|
|
{
|
|
|
|
DWORD i;
|
|
|
|
for(i = 0; i < Obj->maxSinks; i++) {
|
|
|
|
if(Obj->sinks[i]) {
|
|
|
|
IUnknown_Release(Obj->sinks[i]);
|
|
|
|
Obj->sinks[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, Obj->sinks);
|
|
|
|
HeapFree(GetProcessHeap(), 0, Obj);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ConnectionPointImpl_AddRef(IConnectionPoint* iface);
|
|
|
|
/************************************************************************
|
|
|
|
* ConnectionPointImpl_QueryInterface (IUnknown)
|
|
|
|
*
|
|
|
|
* See Windows documentation for more details on IUnknown methods.
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI ConnectionPointImpl_QueryInterface(
|
|
|
|
IConnectionPoint* iface,
|
|
|
|
REFIID riid,
|
|
|
|
void** ppvObject)
|
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
ConnectionPointImpl *This = (ConnectionPointImpl *)iface;
|
2000-07-25 14:26:12 +02:00
|
|
|
TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppvObject);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Perform a sanity check on the parameters.
|
|
|
|
*/
|
|
|
|
if ( (This==0) || (ppvObject==0) )
|
|
|
|
return E_INVALIDARG;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-07-25 14:26:12 +02:00
|
|
|
/*
|
|
|
|
* Initialize the return parameter.
|
|
|
|
*/
|
|
|
|
*ppvObject = 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-07-25 14:26:12 +02:00
|
|
|
/*
|
|
|
|
* Compare the riid with the interface IDs implemented by this object.
|
|
|
|
*/
|
2006-03-01 13:17:00 +01:00
|
|
|
if (IsEqualIID(&IID_IUnknown, riid))
|
2000-07-25 14:26:12 +02:00
|
|
|
*ppvObject = (IConnectionPoint*)This;
|
2006-03-01 13:17:00 +01:00
|
|
|
else if (IsEqualIID(&IID_IConnectionPoint, riid))
|
2000-07-25 14:26:12 +02:00
|
|
|
*ppvObject = (IConnectionPoint*)This;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-07-25 14:26:12 +02:00
|
|
|
/*
|
|
|
|
* Check that we obtained an interface.
|
|
|
|
*/
|
|
|
|
if ((*ppvObject)==0)
|
|
|
|
{
|
|
|
|
FIXME("() : asking for un supported interface %s\n",debugstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-07-25 14:26:12 +02:00
|
|
|
/*
|
|
|
|
* Query Interface always increases the reference count by one when it is
|
|
|
|
* successful
|
|
|
|
*/
|
|
|
|
ConnectionPointImpl_AddRef((IConnectionPoint*)This);
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
return S_OK;
|
2000-07-25 14:26:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* ConnectionPointImpl_AddRef (IUnknown)
|
|
|
|
*
|
|
|
|
* See Windows documentation for more details on IUnknown methods.
|
|
|
|
*/
|
|
|
|
static ULONG WINAPI ConnectionPointImpl_AddRef(IConnectionPoint* iface)
|
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
ConnectionPointImpl *This = (ConnectionPointImpl *)iface;
|
2005-01-14 17:02:20 +01:00
|
|
|
ULONG refCount = InterlockedIncrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p)->(ref before=%ld)\n", This, refCount - 1);
|
|
|
|
|
|
|
|
return refCount;
|
2000-07-25 14:26:12 +02:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-07-25 14:26:12 +02:00
|
|
|
/************************************************************************
|
|
|
|
* ConnectionPointImpl_Release (IUnknown)
|
|
|
|
*
|
|
|
|
* See Windows documentation for more details on IUnknown methods.
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
static ULONG WINAPI ConnectionPointImpl_Release(
|
2000-07-25 14:26:12 +02:00
|
|
|
IConnectionPoint* iface)
|
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
ConnectionPointImpl *This = (ConnectionPointImpl *)iface;
|
2005-01-14 17:02:20 +01:00
|
|
|
ULONG refCount = InterlockedDecrement(&This->ref);
|
2000-07-25 14:26:12 +02:00
|
|
|
|
2005-01-14 17:02:20 +01:00
|
|
|
TRACE("(%p)->(ref before=%ld)\n", This, refCount + 1);
|
2000-07-25 14:26:12 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the reference count goes down to 0, perform suicide.
|
|
|
|
*/
|
2005-01-14 17:02:20 +01:00
|
|
|
if (!refCount) ConnectionPointImpl_Destroy(This);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2005-01-14 17:02:20 +01:00
|
|
|
return refCount;
|
2000-07-25 14:26:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* ConnectionPointImpl_GetConnectionInterface (IConnectionPoint)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI ConnectionPointImpl_GetConnectionInterface(
|
|
|
|
IConnectionPoint *iface,
|
|
|
|
IID *piid)
|
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
ConnectionPointImpl *This = (ConnectionPointImpl *)iface;
|
2000-07-25 14:26:12 +02:00
|
|
|
TRACE("(%p)->(%p) returning %s\n", This, piid, debugstr_guid(&(This->iid)));
|
|
|
|
*piid = This->iid;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* ConnectionPointImpl_GetConnectionPointContainer (IConnectionPoint)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI ConnectionPointImpl_GetConnectionPointContainer(
|
|
|
|
IConnectionPoint *iface,
|
|
|
|
IConnectionPointContainer **ppCPC)
|
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
ConnectionPointImpl *This = (ConnectionPointImpl *)iface;
|
2000-07-25 14:26:12 +02:00
|
|
|
TRACE("(%p)->(%p)\n", This, ppCPC);
|
|
|
|
|
|
|
|
return IUnknown_QueryInterface(This->Obj,
|
|
|
|
&IID_IConnectionPointContainer,
|
|
|
|
(LPVOID)ppCPC);
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* ConnectionPointImpl_Advise (IConnectionPoint)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI ConnectionPointImpl_Advise(IConnectionPoint *iface,
|
|
|
|
IUnknown *lpUnk,
|
|
|
|
DWORD *pdwCookie)
|
|
|
|
{
|
|
|
|
DWORD i;
|
2004-09-09 23:03:58 +02:00
|
|
|
ConnectionPointImpl *This = (ConnectionPointImpl *)iface;
|
2000-07-25 14:26:12 +02:00
|
|
|
IUnknown *lpSink;
|
|
|
|
TRACE("(%p)->(%p, %p)\n", This, lpUnk, pdwCookie);
|
|
|
|
|
|
|
|
*pdwCookie = 0;
|
|
|
|
if(FAILED(IUnknown_QueryInterface(lpUnk, &This->iid, (LPVOID)&lpSink)))
|
|
|
|
return CONNECT_E_CANNOTCONNECT;
|
|
|
|
|
|
|
|
for(i = 0; i < This->maxSinks; i++) {
|
|
|
|
if(This->sinks[i] == NULL)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(i == This->maxSinks) {
|
|
|
|
This->maxSinks += MAXSINKS;
|
|
|
|
This->sinks = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->sinks,
|
|
|
|
This->maxSinks * sizeof(IUnknown *));
|
|
|
|
}
|
|
|
|
This->sinks[i] = lpSink;
|
|
|
|
This->nSinks++;
|
|
|
|
*pdwCookie = i + 1;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* ConnectionPointImpl_Unadvise (IConnectionPoint)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI ConnectionPointImpl_Unadvise(IConnectionPoint *iface,
|
|
|
|
DWORD dwCookie)
|
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
ConnectionPointImpl *This = (ConnectionPointImpl *)iface;
|
2000-07-25 14:26:12 +02:00
|
|
|
TRACE("(%p)->(%ld)\n", This, dwCookie);
|
|
|
|
|
|
|
|
if(dwCookie == 0 || dwCookie > This->maxSinks) return E_INVALIDARG;
|
|
|
|
|
|
|
|
if(This->sinks[dwCookie-1] == NULL) return CONNECT_E_NOCONNECTION;
|
|
|
|
|
|
|
|
IUnknown_Release(This->sinks[dwCookie-1]);
|
|
|
|
This->sinks[dwCookie-1] = NULL;
|
|
|
|
This->nSinks--;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* ConnectionPointImpl_EnumConnections (IConnectionPoint)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI ConnectionPointImpl_EnumConnections(
|
|
|
|
IConnectionPoint *iface,
|
|
|
|
LPENUMCONNECTIONS *ppEnum)
|
2002-06-01 01:06:46 +02:00
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
ConnectionPointImpl *This = (ConnectionPointImpl *)iface;
|
2000-07-25 14:26:12 +02:00
|
|
|
CONNECTDATA *pCD;
|
|
|
|
DWORD i, nextslot;
|
|
|
|
EnumConnectionsImpl *EnumObj;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, ppEnum);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-07-25 14:26:12 +02:00
|
|
|
*ppEnum = NULL;
|
|
|
|
|
|
|
|
if(This->nSinks == 0) return OLE_E_NOCONNECTION;
|
|
|
|
|
|
|
|
pCD = HeapAlloc(GetProcessHeap(), 0, sizeof(CONNECTDATA) * This->nSinks);
|
|
|
|
|
|
|
|
for(i = 0, nextslot = 0; i < This->maxSinks; i++) {
|
|
|
|
if(This->sinks[i] != NULL) {
|
|
|
|
pCD[nextslot].pUnk = This->sinks[i];
|
|
|
|
pCD[nextslot].dwCookie = i + 1;
|
|
|
|
nextslot++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert(nextslot == This->nSinks);
|
|
|
|
|
|
|
|
/* Bump the ref count of this object up by one. It gets Released in
|
|
|
|
IEnumConnections_Release */
|
|
|
|
IUnknown_AddRef((IUnknown*)This);
|
|
|
|
|
|
|
|
EnumObj = EnumConnectionsImpl_Construct((IUnknown*)This, This->nSinks, pCD);
|
|
|
|
hr = IEnumConnections_QueryInterface((IEnumConnections*)EnumObj,
|
|
|
|
&IID_IEnumConnections, (LPVOID)ppEnum);
|
|
|
|
IEnumConnections_Release((IEnumConnections*)EnumObj);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, pCD);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2005-06-06 21:50:35 +02:00
|
|
|
static const IConnectionPointVtbl ConnectionPointImpl_VTable =
|
2000-07-25 14:26:12 +02:00
|
|
|
{
|
|
|
|
ConnectionPointImpl_QueryInterface,
|
|
|
|
ConnectionPointImpl_AddRef,
|
|
|
|
ConnectionPointImpl_Release,
|
|
|
|
ConnectionPointImpl_GetConnectionInterface,
|
|
|
|
ConnectionPointImpl_GetConnectionPointContainer,
|
|
|
|
ConnectionPointImpl_Advise,
|
|
|
|
ConnectionPointImpl_Unadvise,
|
|
|
|
ConnectionPointImpl_EnumConnections
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-06-06 21:50:35 +02:00
|
|
|
static const IEnumConnectionsVtbl EnumConnectionsImpl_VTable;
|
2000-07-25 14:26:12 +02:00
|
|
|
static ULONG WINAPI EnumConnectionsImpl_AddRef(IEnumConnections* iface);
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* EnumConnectionsImpl_Construct
|
|
|
|
*/
|
|
|
|
static EnumConnectionsImpl *EnumConnectionsImpl_Construct(IUnknown *pUnk,
|
|
|
|
DWORD nSinks,
|
|
|
|
CONNECTDATA *pCD)
|
|
|
|
{
|
|
|
|
EnumConnectionsImpl *Obj = HeapAlloc(GetProcessHeap(), 0, sizeof(*Obj));
|
|
|
|
DWORD i;
|
|
|
|
|
|
|
|
Obj->lpvtbl = &EnumConnectionsImpl_VTable;
|
|
|
|
Obj->ref = 1;
|
|
|
|
Obj->pUnk = pUnk;
|
|
|
|
Obj->pCD = HeapAlloc(GetProcessHeap(), 0, nSinks * sizeof(CONNECTDATA));
|
|
|
|
Obj->nConns = nSinks;
|
|
|
|
Obj->nCur = 0;
|
|
|
|
|
|
|
|
for(i = 0; i < nSinks; i++) {
|
|
|
|
Obj->pCD[i] = pCD[i];
|
|
|
|
IUnknown_AddRef(Obj->pCD[i].pUnk);
|
|
|
|
}
|
|
|
|
return Obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* EnumConnectionsImpl_Destroy
|
|
|
|
*/
|
|
|
|
static void EnumConnectionsImpl_Destroy(EnumConnectionsImpl *Obj)
|
|
|
|
{
|
|
|
|
DWORD i;
|
|
|
|
|
|
|
|
for(i = 0; i < Obj->nConns; i++)
|
|
|
|
IUnknown_Release(Obj->pCD[i].pUnk);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, Obj->pCD);
|
|
|
|
HeapFree(GetProcessHeap(), 0, Obj);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* EnumConnectionsImpl_QueryInterface (IUnknown)
|
|
|
|
*
|
|
|
|
* See Windows documentation for more details on IUnknown methods.
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI EnumConnectionsImpl_QueryInterface(
|
|
|
|
IEnumConnections* iface,
|
|
|
|
REFIID riid,
|
|
|
|
void** ppvObject)
|
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
ConnectionPointImpl *This = (ConnectionPointImpl *)iface;
|
2000-07-25 14:26:12 +02:00
|
|
|
TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppvObject);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Perform a sanity check on the parameters.
|
|
|
|
*/
|
|
|
|
if ( (This==0) || (ppvObject==0) )
|
|
|
|
return E_INVALIDARG;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-07-25 14:26:12 +02:00
|
|
|
/*
|
|
|
|
* Initialize the return parameter.
|
|
|
|
*/
|
|
|
|
*ppvObject = 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-07-25 14:26:12 +02:00
|
|
|
/*
|
|
|
|
* Compare the riid with the interface IDs implemented by this object.
|
|
|
|
*/
|
2006-03-01 13:17:00 +01:00
|
|
|
if (IsEqualIID(&IID_IUnknown, riid))
|
2000-07-25 14:26:12 +02:00
|
|
|
*ppvObject = (IEnumConnections*)This;
|
2006-03-01 13:17:00 +01:00
|
|
|
else if (IsEqualIID(&IID_IEnumConnections, riid))
|
2000-07-25 14:26:12 +02:00
|
|
|
*ppvObject = (IEnumConnections*)This;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-07-25 14:26:12 +02:00
|
|
|
/*
|
|
|
|
* Check that we obtained an interface.
|
|
|
|
*/
|
|
|
|
if ((*ppvObject)==0)
|
|
|
|
{
|
|
|
|
FIXME("() : asking for un supported interface %s\n",debugstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-07-25 14:26:12 +02:00
|
|
|
/*
|
|
|
|
* Query Interface always increases the reference count by one when it is
|
|
|
|
* successful
|
|
|
|
*/
|
|
|
|
EnumConnectionsImpl_AddRef((IEnumConnections*)This);
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
return S_OK;
|
2000-07-25 14:26:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* EnumConnectionsImpl_AddRef (IUnknown)
|
|
|
|
*
|
|
|
|
* See Windows documentation for more details on IUnknown methods.
|
|
|
|
*/
|
|
|
|
static ULONG WINAPI EnumConnectionsImpl_AddRef(IEnumConnections* iface)
|
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
EnumConnectionsImpl *This = (EnumConnectionsImpl *)iface;
|
2005-01-14 17:02:20 +01:00
|
|
|
ULONG refCount = InterlockedIncrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p)->(ref before=%ld)\n", This, refCount - 1);
|
|
|
|
|
2000-07-25 14:26:12 +02:00
|
|
|
IUnknown_AddRef(This->pUnk);
|
2005-01-14 17:02:20 +01:00
|
|
|
return refCount;
|
2000-07-25 14:26:12 +02:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-07-25 14:26:12 +02:00
|
|
|
/************************************************************************
|
|
|
|
* EnumConnectionsImpl_Release (IUnknown)
|
|
|
|
*
|
|
|
|
* See Windows documentation for more details on IUnknown methods.
|
|
|
|
*/
|
|
|
|
static ULONG WINAPI EnumConnectionsImpl_Release(IEnumConnections* iface)
|
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
EnumConnectionsImpl *This = (EnumConnectionsImpl *)iface;
|
2005-01-14 17:02:20 +01:00
|
|
|
ULONG refCount = InterlockedDecrement(&This->ref);
|
2000-07-25 14:26:12 +02:00
|
|
|
|
2005-01-14 17:02:20 +01:00
|
|
|
TRACE("(%p)->(ref before=%ld)\n", This, refCount + 1);
|
2000-07-25 14:26:12 +02:00
|
|
|
|
2005-01-14 17:02:20 +01:00
|
|
|
IUnknown_Release(This->pUnk);
|
2000-07-25 14:26:12 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the reference count goes down to 0, perform suicide.
|
|
|
|
*/
|
2005-01-14 17:02:20 +01:00
|
|
|
if (!refCount) EnumConnectionsImpl_Destroy(This);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2005-01-14 17:02:20 +01:00
|
|
|
return refCount;
|
2000-07-25 14:26:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* EnumConnectionsImpl_Next (IEnumConnections)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI EnumConnectionsImpl_Next(IEnumConnections* iface,
|
|
|
|
ULONG cConn, LPCONNECTDATA pCD,
|
|
|
|
ULONG *pEnum)
|
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
EnumConnectionsImpl *This = (EnumConnectionsImpl *)iface;
|
2000-07-25 14:26:12 +02:00
|
|
|
DWORD nRet = 0;
|
|
|
|
TRACE("(%p)->(%ld, %p, %p)\n", This, cConn, pCD, pEnum);
|
|
|
|
|
|
|
|
if(pEnum == NULL) {
|
|
|
|
if(cConn != 1)
|
|
|
|
return E_POINTER;
|
|
|
|
} else
|
|
|
|
*pEnum = 0;
|
|
|
|
|
|
|
|
if(This->nCur >= This->nConns)
|
|
|
|
return S_FALSE;
|
|
|
|
|
|
|
|
while(This->nCur < This->nConns && cConn) {
|
|
|
|
*pCD++ = This->pCD[This->nCur];
|
|
|
|
IUnknown_AddRef(This->pCD[This->nCur].pUnk);
|
|
|
|
This->nCur++;
|
|
|
|
cConn--;
|
|
|
|
nRet++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(pEnum)
|
|
|
|
*pEnum = nRet;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* EnumConnectionsImpl_Skip (IEnumConnections)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI EnumConnectionsImpl_Skip(IEnumConnections* iface,
|
|
|
|
ULONG cSkip)
|
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
EnumConnectionsImpl *This = (EnumConnectionsImpl *)iface;
|
2000-07-25 14:26:12 +02:00
|
|
|
TRACE("(%p)->(%ld)\n", This, cSkip);
|
|
|
|
|
|
|
|
if(This->nCur + cSkip >= This->nConns)
|
|
|
|
return S_FALSE;
|
|
|
|
|
|
|
|
This->nCur += cSkip;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* EnumConnectionsImpl_Reset (IEnumConnections)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI EnumConnectionsImpl_Reset(IEnumConnections* iface)
|
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
EnumConnectionsImpl *This = (EnumConnectionsImpl *)iface;
|
2000-07-25 14:26:12 +02:00
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
|
|
|
This->nCur = 0;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* EnumConnectionsImpl_Clone (IEnumConnections)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI EnumConnectionsImpl_Clone(IEnumConnections* iface,
|
|
|
|
LPENUMCONNECTIONS *ppEnum)
|
|
|
|
{
|
2004-09-09 23:03:58 +02:00
|
|
|
EnumConnectionsImpl *This = (EnumConnectionsImpl *)iface;
|
2000-07-25 14:26:12 +02:00
|
|
|
EnumConnectionsImpl *newObj;
|
|
|
|
TRACE("(%p)->(%p)\n", This, ppEnum);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-07-25 14:26:12 +02:00
|
|
|
newObj = EnumConnectionsImpl_Construct(This->pUnk, This->nConns, This->pCD);
|
|
|
|
newObj->nCur = This->nCur;
|
|
|
|
*ppEnum = (LPENUMCONNECTIONS)newObj;
|
|
|
|
IUnknown_AddRef(This->pUnk);
|
|
|
|
return S_OK;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2005-06-06 21:50:35 +02:00
|
|
|
static const IEnumConnectionsVtbl EnumConnectionsImpl_VTable =
|
2000-07-25 14:26:12 +02:00
|
|
|
{
|
|
|
|
EnumConnectionsImpl_QueryInterface,
|
|
|
|
EnumConnectionsImpl_AddRef,
|
|
|
|
EnumConnectionsImpl_Release,
|
|
|
|
EnumConnectionsImpl_Next,
|
|
|
|
EnumConnectionsImpl_Skip,
|
|
|
|
EnumConnectionsImpl_Reset,
|
|
|
|
EnumConnectionsImpl_Clone
|
|
|
|
};
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
*
|
|
|
|
* The exported function to create the connection point.
|
|
|
|
* NB not a windows API
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pUnk [in] IUnknown of object to which the ConnectionPoint is associated.
|
|
|
|
* Needed to access IConnectionPointContainer.
|
|
|
|
*
|
|
|
|
* riid [in] IID of sink interface that this ConnectionPoint manages
|
|
|
|
*
|
|
|
|
* pCP [out] returns IConnectionPoint
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
HRESULT CreateConnectionPoint(IUnknown *pUnk, REFIID riid,
|
|
|
|
IConnectionPoint **pCP)
|
|
|
|
{
|
|
|
|
ConnectionPointImpl *Obj;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
Obj = ConnectionPointImpl_Construct(pUnk, riid);
|
|
|
|
if(!Obj) return E_OUTOFMEMORY;
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
hr = IConnectionPoint_QueryInterface((IConnectionPoint *)Obj,
|
2000-07-25 14:26:12 +02:00
|
|
|
&IID_IConnectionPoint, (LPVOID)pCP);
|
|
|
|
IConnectionPoint_Release((IConnectionPoint *)Obj);
|
|
|
|
return hr;
|
|
|
|
}
|