Re: ICallFrameEvents
The call to CoGetInterceptor API gives the error - system cannot find
the file specified.
Am i going the correct way or is there anything more to be added
#include <windows.h>
#include <atlbase.h>
CComModule _Module;
#include <atlcom.h>
#include <oaidl.h>
#include <callobj.h>
#include <objbase.h>
#include "..\\IntIntercept\\IntIntercept.h"
#include "..\\IntIntercept\\IntIntercept_i.c"
template<class T>
class InterceptCallHandler : public CComObjectRoot,public
ICallFrameEvents
{
public:
BEGIN_COM_MAP(InterceptCallHandler)
COM_INTERFACE_ENTRY(ICallFrameEvents)
END_COM_MAP()
void init(CComPtr<T> spnterface)
{
m_spnterface= spnterface;
}
STDMETHOD(OnCall)(ICallFrame* pFrame)
{
LPWSTR itf, method;
HRESULT hr = pFrame->GetNames(&itf, &method);
hr = pFrame->Invoke(m_spnterface.p);
CoTaskMemFree(itf);
CoTaskMemFree(method);
return hr;
}
private:
CComPtr<T> m_spnterface;
};
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
CoInitialize( NULL);
HRESULT hr ;
{
CComPtr<ICallInterceptor> spICallInterceptor;
hr = CoGetInterceptor(__uuidof(IMathBasics), 0,
__uuidof(ICallInterceptor),reinterpret_cast<void**>(&spICallInterceptor));
CComObject<InterceptCallHandler<IMathBasics> >* pHandler;
CComObject<InterceptCallHandler<IMathBasics>
::CreateInstance(&pHandler);
hr = spICallInterceptor->RegisterSink(pHandler);
CComPtr<IMathBasics> spMathBasics ;
hr =
CoCreateInstance(CLSID_MathBasics,NULL,CLSCTX_ALL,IID_IMathBasics,
reinterpret_cast<void**>(&spMathBasics));
pHandler->init(spMathBasics);
IMathBasics* pMathBasicsDummy = NULL;
hr = spICallInterceptor.QueryInterface(&pMathBasicsDummy);
long result;
hr = pMathBasicsDummy->Add(1,2,&result);
hr = pMathBasicsDummy->Subtract(4,3,&result);
pMathBasicsDummy->Release();
}//smart pointer release before couninitialize
CoUninitialize();
return 0;
}
Thanks in advance
Bejoy