ole32: Standardize the COM usage.

This commit is contained in:
Huw Davies 2010-12-17 14:58:32 +00:00 committed by Alexandre Julliard
parent 06f2ef4fb5
commit 3a2aae49d3
1 changed files with 86 additions and 100 deletions

View File

@ -67,18 +67,8 @@ static HRESULT copy_statdata(STATDATA *dst, const STATDATA *src)
} }
/************************************************************************** /**************************************************************************
* OleAdviseHolderImpl Implementation * EnumSTATDATA Implementation
*/ */
typedef struct OleAdviseHolderImpl
{
const IOleAdviseHolderVtbl *lpVtbl;
LONG ref;
DWORD maxSinks;
IAdviseSink** arrayOfSinks;
} OleAdviseHolderImpl;
static HRESULT EnumSTATDATA_Construct(IUnknown *holder, ULONG index, DWORD array_len, STATDATA *data, IEnumSTATDATA **ppenum); static HRESULT EnumSTATDATA_Construct(IUnknown *holder, ULONG index, DWORD array_len, STATDATA *data, IEnumSTATDATA **ppenum);
@ -242,11 +232,28 @@ static HRESULT EnumSTATDATA_Construct(IUnknown *holder, ULONG index, DWORD array
return S_OK; return S_OK;
} }
/**************************************************************************
* OleAdviseHolder Implementation
*/
typedef struct
{
IOleAdviseHolder IOleAdviseHolder_iface;
LONG ref;
DWORD maxSinks;
IAdviseSink** arrayOfSinks;
} OleAdviseHolderImpl;
static inline OleAdviseHolderImpl *impl_from_IOleAdviseHolder(IOleAdviseHolder *iface)
{
return CONTAINING_RECORD(iface, OleAdviseHolderImpl, IOleAdviseHolder_iface);
}
/************************************************************************** /**************************************************************************
* OleAdviseHolderImpl_Destructor * OleAdviseHolderImpl_Destructor
*/ */
static void OleAdviseHolderImpl_Destructor( static void OleAdviseHolderImpl_Destructor(OleAdviseHolderImpl* ptrToDestroy)
OleAdviseHolderImpl* ptrToDestroy)
{ {
DWORD index; DWORD index;
TRACE("%p\n", ptrToDestroy); TRACE("%p\n", ptrToDestroy);
@ -273,32 +280,27 @@ static void OleAdviseHolderImpl_Destructor(
/************************************************************************** /**************************************************************************
* OleAdviseHolderImpl_QueryInterface * OleAdviseHolderImpl_QueryInterface
*/ */
static HRESULT WINAPI OleAdviseHolderImpl_QueryInterface( static HRESULT WINAPI OleAdviseHolderImpl_QueryInterface(IOleAdviseHolder *iface,
LPOLEADVISEHOLDER iface, REFIID iid, void **obj)
REFIID riid,
LPVOID* ppvObj)
{ {
OleAdviseHolderImpl *This = (OleAdviseHolderImpl *)iface; OleAdviseHolderImpl *This = impl_from_IOleAdviseHolder(iface);
TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppvObj); TRACE("(%p)->(%s,%p)\n",This, debugstr_guid(iid), obj);
if (ppvObj==NULL) if (obj == NULL)
return E_POINTER; return E_POINTER;
*ppvObj = NULL; *obj = NULL;
if (IsEqualIID(riid, &IID_IUnknown)) if (IsEqualIID(iid, &IID_IUnknown) ||
IsEqualIID(iid, &IID_IOleAdviseHolder))
{ {
*ppvObj = This; *obj = &This->IOleAdviseHolder_iface;
}
else if(IsEqualIID(riid, &IID_IOleAdviseHolder))
{
*ppvObj = This;
} }
if(*ppvObj == NULL) if(*obj == NULL)
return E_NOINTERFACE; return E_NOINTERFACE;
IUnknown_AddRef((IUnknown*)*ppvObj); IUnknown_AddRef((IUnknown*)*obj);
return S_OK; return S_OK;
} }
@ -306,10 +308,9 @@ static HRESULT WINAPI OleAdviseHolderImpl_QueryInterface(
/****************************************************************************** /******************************************************************************
* OleAdviseHolderImpl_AddRef * OleAdviseHolderImpl_AddRef
*/ */
static ULONG WINAPI OleAdviseHolderImpl_AddRef( static ULONG WINAPI OleAdviseHolderImpl_AddRef(IOleAdviseHolder *iface)
LPOLEADVISEHOLDER iface)
{ {
OleAdviseHolderImpl *This = (OleAdviseHolderImpl *)iface; OleAdviseHolderImpl *This = impl_from_IOleAdviseHolder(iface);
ULONG ref = InterlockedIncrement(&This->ref); ULONG ref = InterlockedIncrement(&This->ref);
TRACE("(%p)->(ref=%d)\n", This, ref - 1); TRACE("(%p)->(ref=%d)\n", This, ref - 1);
@ -320,10 +321,9 @@ static ULONG WINAPI OleAdviseHolderImpl_AddRef(
/****************************************************************************** /******************************************************************************
* OleAdviseHolderImpl_Release * OleAdviseHolderImpl_Release
*/ */
static ULONG WINAPI OleAdviseHolderImpl_Release( static ULONG WINAPI OleAdviseHolderImpl_Release(IOleAdviseHolder *iface)
LPOLEADVISEHOLDER iface)
{ {
OleAdviseHolderImpl *This = (OleAdviseHolderImpl *)iface; OleAdviseHolderImpl *This = impl_from_IOleAdviseHolder(iface);
ULONG ref; ULONG ref;
TRACE("(%p)->(ref=%d)\n", This, This->ref); TRACE("(%p)->(ref=%d)\n", This, This->ref);
ref = InterlockedDecrement(&This->ref); ref = InterlockedDecrement(&This->ref);
@ -336,14 +336,12 @@ static ULONG WINAPI OleAdviseHolderImpl_Release(
/****************************************************************************** /******************************************************************************
* OleAdviseHolderImpl_Advise * OleAdviseHolderImpl_Advise
*/ */
static HRESULT WINAPI OleAdviseHolderImpl_Advise( static HRESULT WINAPI OleAdviseHolderImpl_Advise(IOleAdviseHolder *iface,
LPOLEADVISEHOLDER iface,
IAdviseSink *pAdvise, IAdviseSink *pAdvise,
DWORD *pdwConnection) DWORD *pdwConnection)
{ {
DWORD index; DWORD index;
OleAdviseHolderImpl *This = impl_from_IOleAdviseHolder(iface);
OleAdviseHolderImpl *This = (OleAdviseHolderImpl *)iface;
TRACE("(%p)->(%p, %p)\n", This, pAdvise, pdwConnection); TRACE("(%p)->(%p, %p)\n", This, pAdvise, pdwConnection);
@ -391,11 +389,10 @@ static HRESULT WINAPI OleAdviseHolderImpl_Advise(
/****************************************************************************** /******************************************************************************
* OleAdviseHolderImpl_Unadvise * OleAdviseHolderImpl_Unadvise
*/ */
static HRESULT WINAPI OleAdviseHolderImpl_Unadvise( static HRESULT WINAPI OleAdviseHolderImpl_Unadvise(IOleAdviseHolder *iface,
LPOLEADVISEHOLDER iface,
DWORD dwConnection) DWORD dwConnection)
{ {
OleAdviseHolderImpl *This = (OleAdviseHolderImpl *)iface; OleAdviseHolderImpl *This = impl_from_IOleAdviseHolder(iface);
TRACE("(%p)->(%u)\n", This, dwConnection); TRACE("(%p)->(%u)\n", This, dwConnection);
@ -427,10 +424,9 @@ static HRESULT WINAPI OleAdviseHolderImpl_Unadvise(
/****************************************************************************** /******************************************************************************
* OleAdviseHolderImpl_EnumAdvise * OleAdviseHolderImpl_EnumAdvise
*/ */
static HRESULT WINAPI static HRESULT WINAPI OleAdviseHolderImpl_EnumAdvise(IOleAdviseHolder *iface, IEnumSTATDATA **ppenumAdvise)
OleAdviseHolderImpl_EnumAdvise (LPOLEADVISEHOLDER iface, IEnumSTATDATA **ppenumAdvise)
{ {
OleAdviseHolderImpl *This = (OleAdviseHolderImpl *)iface; OleAdviseHolderImpl *This = impl_from_IOleAdviseHolder(iface);
IUnknown *unk; IUnknown *unk;
DWORD i, count; DWORD i, count;
STATDATA *data; STATDATA *data;
@ -468,8 +464,7 @@ OleAdviseHolderImpl_EnumAdvise (LPOLEADVISEHOLDER iface, IEnumSTATDATA **ppenumA
/****************************************************************************** /******************************************************************************
* OleAdviseHolderImpl_SendOnRename * OleAdviseHolderImpl_SendOnRename
*/ */
static HRESULT WINAPI static HRESULT WINAPI OleAdviseHolderImpl_SendOnRename(IOleAdviseHolder *iface, IMoniker *pmk)
OleAdviseHolderImpl_SendOnRename (LPOLEADVISEHOLDER iface, IMoniker *pmk)
{ {
IEnumSTATDATA *pEnum; IEnumSTATDATA *pEnum;
HRESULT hr; HRESULT hr;
@ -495,8 +490,7 @@ OleAdviseHolderImpl_SendOnRename (LPOLEADVISEHOLDER iface, IMoniker *pmk)
/****************************************************************************** /******************************************************************************
* OleAdviseHolderImpl_SendOnSave * OleAdviseHolderImpl_SendOnSave
*/ */
static HRESULT WINAPI static HRESULT WINAPI OleAdviseHolderImpl_SendOnSave(IOleAdviseHolder *iface)
OleAdviseHolderImpl_SendOnSave (LPOLEADVISEHOLDER iface)
{ {
IEnumSTATDATA *pEnum; IEnumSTATDATA *pEnum;
HRESULT hr; HRESULT hr;
@ -522,8 +516,7 @@ OleAdviseHolderImpl_SendOnSave (LPOLEADVISEHOLDER iface)
/****************************************************************************** /******************************************************************************
* OleAdviseHolderImpl_SendOnClose * OleAdviseHolderImpl_SendOnClose
*/ */
static HRESULT WINAPI static HRESULT WINAPI OleAdviseHolderImpl_SendOnClose(IOleAdviseHolder *iface)
OleAdviseHolderImpl_SendOnClose (LPOLEADVISEHOLDER iface)
{ {
IEnumSTATDATA *pEnum; IEnumSTATDATA *pEnum;
HRESULT hr; HRESULT hr;
@ -566,14 +559,14 @@ static const IOleAdviseHolderVtbl oahvt =
* OleAdviseHolderImpl_Constructor * OleAdviseHolderImpl_Constructor
*/ */
static LPOLEADVISEHOLDER OleAdviseHolderImpl_Constructor(void) static IOleAdviseHolder *OleAdviseHolderImpl_Constructor(void)
{ {
OleAdviseHolderImpl* lpoah; OleAdviseHolderImpl* lpoah;
DWORD index; DWORD index;
lpoah = HeapAlloc(GetProcessHeap(), 0, sizeof(OleAdviseHolderImpl)); lpoah = HeapAlloc(GetProcessHeap(), 0, sizeof(OleAdviseHolderImpl));
lpoah->lpVtbl = &oahvt; lpoah->IOleAdviseHolder_iface.lpVtbl = &oahvt;
lpoah->ref = 1; lpoah->ref = 1;
lpoah->maxSinks = INITIAL_SINKS; lpoah->maxSinks = INITIAL_SINKS;
lpoah->arrayOfSinks = HeapAlloc(GetProcessHeap(), lpoah->arrayOfSinks = HeapAlloc(GetProcessHeap(),
@ -583,16 +576,16 @@ static LPOLEADVISEHOLDER OleAdviseHolderImpl_Constructor(void)
for (index = 0; index < lpoah->maxSinks; index++) for (index = 0; index < lpoah->maxSinks; index++)
lpoah->arrayOfSinks[index]=0; lpoah->arrayOfSinks[index]=0;
TRACE("returning %p\n", lpoah); TRACE("returning %p\n", &lpoah->IOleAdviseHolder_iface);
return (LPOLEADVISEHOLDER)lpoah; return &lpoah->IOleAdviseHolder_iface;
} }
/************************************************************************** /**************************************************************************
* DataAdviseHolder Implementation * DataAdviseHolder Implementation
*/ */
typedef struct DataAdviseHolder typedef struct
{ {
const IDataAdviseHolderVtbl *lpVtbl; IDataAdviseHolder IDataAdviseHolder_iface;
LONG ref; LONG ref;
DWORD maxCons; DWORD maxCons;
@ -604,6 +597,11 @@ typedef struct DataAdviseHolder
/* this connection has also has been advised to the delegate data object */ /* this connection has also has been advised to the delegate data object */
#define WINE_ADVF_REMOTE 0x80000000 #define WINE_ADVF_REMOTE 0x80000000
static inline DataAdviseHolder *impl_from_IDataAdviseHolder(IDataAdviseHolder *iface)
{
return CONTAINING_RECORD(iface, DataAdviseHolder, IDataAdviseHolder_iface);
}
/****************************************************************************** /******************************************************************************
* DataAdviseHolder_Destructor * DataAdviseHolder_Destructor
*/ */
@ -633,12 +631,10 @@ static void DataAdviseHolder_Destructor(DataAdviseHolder* ptrToDestroy)
/************************************************************************ /************************************************************************
* DataAdviseHolder_QueryInterface (IUnknown) * DataAdviseHolder_QueryInterface (IUnknown)
*/ */
static HRESULT WINAPI DataAdviseHolder_QueryInterface( static HRESULT WINAPI DataAdviseHolder_QueryInterface(IDataAdviseHolder *iface,
IDataAdviseHolder* iface, REFIID riid, void **ppvObject)
REFIID riid,
void** ppvObject)
{ {
DataAdviseHolder *This = (DataAdviseHolder *)iface; DataAdviseHolder *This = impl_from_IDataAdviseHolder(iface);
TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppvObject); TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppvObject);
if ( (This==0) || (ppvObject==0) ) if ( (This==0) || (ppvObject==0) )
@ -664,10 +660,9 @@ static HRESULT WINAPI DataAdviseHolder_QueryInterface(
/************************************************************************ /************************************************************************
* DataAdviseHolder_AddRef (IUnknown) * DataAdviseHolder_AddRef (IUnknown)
*/ */
static ULONG WINAPI DataAdviseHolder_AddRef( static ULONG WINAPI DataAdviseHolder_AddRef(IDataAdviseHolder *iface)
IDataAdviseHolder* iface)
{ {
DataAdviseHolder *This = (DataAdviseHolder *)iface; DataAdviseHolder *This = impl_from_IDataAdviseHolder(iface);
TRACE("(%p) (ref=%d)\n", This, This->ref); TRACE("(%p) (ref=%d)\n", This, This->ref);
return InterlockedIncrement(&This->ref); return InterlockedIncrement(&This->ref);
} }
@ -675,10 +670,9 @@ static ULONG WINAPI DataAdviseHolder_AddRef(
/************************************************************************ /************************************************************************
* DataAdviseHolder_Release (IUnknown) * DataAdviseHolder_Release (IUnknown)
*/ */
static ULONG WINAPI DataAdviseHolder_Release( static ULONG WINAPI DataAdviseHolder_Release(IDataAdviseHolder *iface)
IDataAdviseHolder* iface)
{ {
DataAdviseHolder *This = (DataAdviseHolder *)iface; DataAdviseHolder *This = impl_from_IDataAdviseHolder(iface);
ULONG ref; ULONG ref;
TRACE("(%p) (ref=%d)\n", This, This->ref); TRACE("(%p) (ref=%d)\n", This, This->ref);
@ -692,17 +686,14 @@ static ULONG WINAPI DataAdviseHolder_Release(
* DataAdviseHolder_Advise * DataAdviseHolder_Advise
* *
*/ */
static HRESULT WINAPI DataAdviseHolder_Advise( static HRESULT WINAPI DataAdviseHolder_Advise(IDataAdviseHolder *iface,
IDataAdviseHolder* iface, IDataObject *pDataObject, FORMATETC *pFetc,
IDataObject* pDataObject, DWORD advf, IAdviseSink *pAdvise,
FORMATETC* pFetc,
DWORD advf,
IAdviseSink* pAdvise,
DWORD *pdwConnection) DWORD *pdwConnection)
{ {
DWORD index; DWORD index;
STATDATA new_conn; STATDATA new_conn;
DataAdviseHolder *This = (DataAdviseHolder *)iface; DataAdviseHolder *This = impl_from_IDataAdviseHolder(iface);
TRACE("(%p)->(%p, %p, %08x, %p, %p)\n", This, pDataObject, pFetc, advf, TRACE("(%p)->(%p, %p, %08x, %p, %p)\n", This, pDataObject, pFetc, advf,
pAdvise, pdwConnection); pAdvise, pdwConnection);
@ -767,11 +758,10 @@ static HRESULT WINAPI DataAdviseHolder_Advise(
/****************************************************************************** /******************************************************************************
* DataAdviseHolder_Unadvise * DataAdviseHolder_Unadvise
*/ */
static HRESULT WINAPI DataAdviseHolder_Unadvise( static HRESULT WINAPI DataAdviseHolder_Unadvise(IDataAdviseHolder *iface,
IDataAdviseHolder* iface,
DWORD dwConnection) DWORD dwConnection)
{ {
DataAdviseHolder *This = (DataAdviseHolder *)iface; DataAdviseHolder *This = impl_from_IDataAdviseHolder(iface);
DWORD index; DWORD index;
TRACE("(%p)->(%u)\n", This, dwConnection); TRACE("(%p)->(%u)\n", This, dwConnection);
@ -798,7 +788,7 @@ static HRESULT WINAPI DataAdviseHolder_Unadvise(
static HRESULT WINAPI DataAdviseHolder_EnumAdvise(IDataAdviseHolder *iface, static HRESULT WINAPI DataAdviseHolder_EnumAdvise(IDataAdviseHolder *iface,
IEnumSTATDATA **enum_advise) IEnumSTATDATA **enum_advise)
{ {
DataAdviseHolder *This = (DataAdviseHolder *)iface; DataAdviseHolder *This = impl_from_IDataAdviseHolder(iface);
IUnknown *unk; IUnknown *unk;
HRESULT hr; HRESULT hr;
@ -813,13 +803,11 @@ static HRESULT WINAPI DataAdviseHolder_EnumAdvise(IDataAdviseHolder *iface,
/****************************************************************************** /******************************************************************************
* DataAdviseHolder_SendOnDataChange * DataAdviseHolder_SendOnDataChange
*/ */
static HRESULT WINAPI DataAdviseHolder_SendOnDataChange( static HRESULT WINAPI DataAdviseHolder_SendOnDataChange(IDataAdviseHolder *iface,
IDataAdviseHolder* iface,
IDataObject *pDataObject, IDataObject *pDataObject,
DWORD dwReserved, DWORD dwReserved, DWORD advf)
DWORD advf)
{ {
DataAdviseHolder *This = (DataAdviseHolder *)iface; DataAdviseHolder *This = impl_from_IDataAdviseHolder(iface);
DWORD index; DWORD index;
STGMEDIUM stg; STGMEDIUM stg;
HRESULT res; HRESULT res;
@ -869,7 +857,7 @@ static const IDataAdviseHolderVtbl DataAdviseHolderImpl_VTable =
HRESULT DataAdviseHolder_OnConnect(IDataAdviseHolder *iface, IDataObject *pDelegate) HRESULT DataAdviseHolder_OnConnect(IDataAdviseHolder *iface, IDataObject *pDelegate)
{ {
DataAdviseHolder *This = (DataAdviseHolder *)iface; DataAdviseHolder *This = impl_from_IDataAdviseHolder(iface);
DWORD index; DWORD index;
HRESULT hr = S_OK; HRESULT hr = S_OK;
@ -891,7 +879,7 @@ HRESULT DataAdviseHolder_OnConnect(IDataAdviseHolder *iface, IDataObject *pDeleg
void DataAdviseHolder_OnDisconnect(IDataAdviseHolder *iface) void DataAdviseHolder_OnDisconnect(IDataAdviseHolder *iface)
{ {
DataAdviseHolder *This = (DataAdviseHolder *)iface; DataAdviseHolder *This = impl_from_IDataAdviseHolder(iface);
DWORD index; DWORD index;
for(index = 0; index < This->maxCons; index++) for(index = 0; index < This->maxCons; index++)
@ -916,7 +904,7 @@ static IDataAdviseHolder* DataAdviseHolder_Constructor(void)
newHolder = HeapAlloc(GetProcessHeap(), 0, sizeof(DataAdviseHolder)); newHolder = HeapAlloc(GetProcessHeap(), 0, sizeof(DataAdviseHolder));
newHolder->lpVtbl = &DataAdviseHolderImpl_VTable; newHolder->IDataAdviseHolder_iface.lpVtbl = &DataAdviseHolderImpl_VTable;
newHolder->ref = 1; newHolder->ref = 1;
newHolder->maxCons = INITIAL_SINKS; newHolder->maxCons = INITIAL_SINKS;
newHolder->connections = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, newHolder->connections = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
@ -925,8 +913,8 @@ static IDataAdviseHolder* DataAdviseHolder_Constructor(void)
newHolder->maxCons * sizeof(*newHolder->remote_connections)); newHolder->maxCons * sizeof(*newHolder->remote_connections));
newHolder->delegate = NULL; newHolder->delegate = NULL;
TRACE("returning %p\n", newHolder); TRACE("returning %p\n", &newHolder->IDataAdviseHolder_iface);
return (IDataAdviseHolder*)newHolder; return &newHolder->IDataAdviseHolder_iface;
} }
/*********************************************************************** /***********************************************************************
@ -936,8 +924,7 @@ static IDataAdviseHolder* DataAdviseHolder_Constructor(void)
/*********************************************************************** /***********************************************************************
* CreateOleAdviseHolder [OLE32.@] * CreateOleAdviseHolder [OLE32.@]
*/ */
HRESULT WINAPI CreateOleAdviseHolder( HRESULT WINAPI CreateOleAdviseHolder(IOleAdviseHolder **ppOAHolder)
LPOLEADVISEHOLDER *ppOAHolder)
{ {
TRACE("(%p)\n", ppOAHolder); TRACE("(%p)\n", ppOAHolder);
@ -955,8 +942,7 @@ HRESULT WINAPI CreateOleAdviseHolder(
/****************************************************************************** /******************************************************************************
* CreateDataAdviseHolder [OLE32.@] * CreateDataAdviseHolder [OLE32.@]
*/ */
HRESULT WINAPI CreateDataAdviseHolder( HRESULT WINAPI CreateDataAdviseHolder(IDataAdviseHolder **ppDAHolder)
LPDATAADVISEHOLDER* ppDAHolder)
{ {
TRACE("(%p)\n", ppDAHolder); TRACE("(%p)\n", ppDAHolder);