CogetInterceptor
I use CoGetInterceptor API to intercept function calls from an
interface in a BHO plugin. IWebBrowser2 interface is intercepted in
SetSite.
It intercepts the calls in INVOKE of the BHO (IWebBrowser2 -------
get_document function) but not intercepting any calls to the same
IWebBrowser2 ---->getdocument in other BHO plugins unless it is
intercepted inside that BHO. Deubugging shows that it is having same
memory address referred.
//define function pointer for CoGetInterceptor API in OLE32.DLL
typedef HRESULT (__stdcall * getInterceptor)(
REFIID ,
IUnknown* ,
REFIID ,
void** );
getInterceptor fptrgetInterceptor;
HINSTANCE hinstLib;
class CCallFrameEvents : public ICallFrameEvents
{
public:
public:
// CCallFrameEvents
// ICallFrameEvents
//intercepted object function calls come
//to the OnCall handler
STDMETHOD(OnCall)(ICallFrame* pCallFrame)
{
//all the object function calls comes
//here after interception
MessageBox(NULL,
_T("CCallFrameEvents::OnCall intercept
handler"), _T("ICallFrameEvents"),0);
return S_OK;
}
// IUnknown
STDMETHOD_(ULONG, AddRef)()
{
return 1;
}
STDMETHOD_(ULONG, Release)()
{
return 1;
}
STDMETHOD(QueryInterface)(REFIID InterfaceIdentifier, VOID**
ppvObject)
{
return E_NOINTERFACE;
}
};
ICallInterceptor* pCallInterceptor;
CCallFrameEvents pHandler ;
//IN SET SITE OF BHO
STDMETHODIMP CIHTMLFormAnalyse::SetSite(IUnknown *pUnkSite)
{
CComQIPtr<IWebBrowser2, &IID_IWebBrowser2> m_pQIWebBrowser2;
m_pQIWebBrowser2 = pUnkSite;
fptrgetInterceptor = NULL;
// Get a handle to the DLL module.
hinstLib = LoadLibrary(_T("ole32.dll"));
if(hinstLib != NULL)
{
//get the address of the CoGetInterceptor function
fptrgetInterceptor = (getInterceptor)GetProcAddress
(hinstLib, "CoGetInterceptor");
}
if(fptrgetInterceptor != NULL)
{
hr = fptrgetInterceptor(__uuidof(IWebBrowser2), NULL,
__uuidof(ICallInterceptor),(VOID**)&pCallInterceptor);
if(pCallInterceptor != NULL)
{
//register sink with callback class
hr = pCallInterceptor-
RegisterSink(pHandler);
//query the interface of object whose
//function calls should be intercepted
hr = pCallInterceptor->QueryInterface
(&m_pQIWebBrowser2.p);
}
}
}
Thanks in advance