Hi all.
In my BHO I'd like to redirect some URL's before the page is loaded.
I've read the documentation about IExplorer Dispatch Events in MSDN, and found that this better to do before navigate
So I made a function connected to DISPID_BEFORENAVIGATE2:
<br />
void MyBhoClass::OnBeforeNavigate( IDispatch *pDisp, VARIANT *url, VARIANT *Flags, VARIANT *TargetFrameName, VARIANT *PostData, VARIANT *Headers, VARIANT_BOOL *Cancel )<br />
{<br />
std::string urltmp;<br />
wchar_to_char( url->bstrVal, urltmp );<br />
HRESULT hr;<br />
VARIANT vr;<br />
if( std::string::npos != urltmp.find( "xxx" ) )
{<br />
vr.vt = VT_BSTR;<br />
vr.bstrVal = SysAllocString( L"http://some.other.url.com" );<br />
hr = m_browser->Navigate2( &vr, 0, 0, 0, 0 );<br />
}<br />
}<br />
This code works well!
but in this part there is a problem:
<br />
<br />
void MyBhoClass::OnBeforeNavigate( IDispatch *pDisp, VARIANT *url, VARIANT *Flags, VARIANT *TargetFrameName, VARIANT *PostData, VARIANT *Headers, VARIANT_BOOL *Cancel )<br />
{<br />
std::string urltmp;<br />
wchar_to_char( url->bstrVal, urltmp );<br />
HRESULT hr;<br />
VARIANT vr;<br />
if( 0 == urltmp.find( "about:" ) )
{<br />
vr.vt = VT_BSTR;<br />
vr.bstrVal = SysAllocString( L"http://some.other.url.com" );<br />
MessageBox( GetForegroundWindow(), "Before Navigate!!!!", "Debug_before_navigate", MB_OK | MB_ICONEXCLAMATION );<br />
hr = m_browser->Navigate2( &vr, 0, 0, 0, 0 );<br />
}<br />
}<br />
when a new tab is open MessageBox is invoked. After calling the function Navigate2() we come one more time to OnBeforeNavigate() function, and here the variable "url" has the proper value (i.e "http://some.other.url.com"). Therefore OnBeforeNavigate() do "nothing" at this time. But the the browser opens a blank page.
And one more thing... during the debugging I c, that pressing F10 on Navigate2() function bring me to the beginning of function OnBeforeNavigate().
How can I do redirect when the new tab is open?
Thanks!
[SOLVED with workround]
Redirect gives the wanted result in DISPID_NAVIGATECOMPLETE2 handler. however... I can't understand why it don't work in DISPID_BEFORENAVIGATE2 :(