#pragma once
#include "IComEvtClient.h"


//this daclaration is from the Vc7\PlatformSDK\Include\ComDef.h
class __declspec(uuid("0000001b-0000-0000-c000-000000000046")) IdentityUnmarshal;


/******************************************************************************
CMySink - plamen

	simple implementation of event sink

	can be advised to all kinds of connection points, because of the 
		CallThisForEveryQI
	can acepts events from out-of-the-process servers, because of the 
			COM_INTERFACE_ENTRY_NOINTERFACE(IMarshal)
			COM_INTERFACE_ENTRY_NOINTERFACE(IdentityUnmarshal)
			COM_INTERFACE_ENTRY_NOINTERFACE(IStdMarshalInfo)
			COM_INTERFACE_ENTRY_NOINTERFACE(IExternalConnection)

	Strawberry Engine advises instance of com object, to new isntance of this class
	when a event arrives from the com object, this class accepts it
	and notifies Strawberry Engine
******************************************************************************/
namespace ComSupport
{
	HRESULT __stdcall CallThisForEveryQI(void* pv, REFIID riid, void** ppv,DWORD dw);
///
	class ATL_NO_VTABLE CMySink : 
		public CComObjectRootEx<CComMultiThreadModel>,
		public IDispatch
	{
	public:
		IComEvtClient* m_pEventMgr;


	// IDispatch
	public:
		STDMETHOD(GetTypeInfoCount)(UINT __RPC_FAR*)
			{return E_NOTIMPL;};
		
		STDMETHOD(GetTypeInfo)(UINT,LCID,ITypeInfo __RPC_FAR *__RPC_FAR *)
			{return E_NOTIMPL;};
		
		STDMETHOD(GetIDsOfNames)(REFIID ,LPOLESTR __RPC_FAR *,UINT ,LCID ,DISPID __RPC_FAR *)
			{return E_NOTIMPL;};

		STDMETHOD(Invoke)( 
			/* [in] */ DISPID dispIdMember,
			/* [in] */ REFIID riid,
			/* [in] */ LCID lcid,
			/* [in] */ WORD wFlags,
			/* [out][in] */ DISPPARAMS __RPC_FAR *pDispParams,
			/* [out] */ VARIANT __RPC_FAR *pVarResult,
			/* [out] */ EXCEPINFO __RPC_FAR *pExcepInfo,
			/* [out] */ UINT __RPC_FAR *puArgErr);

	public:
		BEGIN_COM_MAP(CMySink)
			COM_INTERFACE_ENTRY(IDispatch)
			COM_INTERFACE_ENTRY_NOINTERFACE(IMarshal)
			COM_INTERFACE_ENTRY_NOINTERFACE(IdentityUnmarshal)
			COM_INTERFACE_ENTRY_NOINTERFACE(IStdMarshalInfo)
			COM_INTERFACE_ENTRY_NOINTERFACE(IExternalConnection)
			COM_INTERFACE_ENTRY_FUNC_BLIND(0, CallThisForEveryQI)
		END_COM_MAP()

	};
}