I am using this code to sink events in a IWebBrowser2 webbrowser on c++:
STDMETHODIMP AdviseSink::Invoke(DISPID dispIdMember,
REFIID riid,
LCID lcid,
WORD wFlags,
DISPPARAMS* pDispParams,
VARIANT* pVarResult,
EXCEPINFO* pExcepInfo,
UINT* puArgErr)
{
if (!pDispParams)
return DISP_E_PARAMNOTOPTIONAL;
switch (dispIdMember)
{
case DISPID_DOCUMENTCOMPLETE:
{
DocumentComplete(pVarResult);
return S_OK;
}
case DISPID_NAVIGATECOMPLETE2:
return S_OK;
default:
return DISP_E_MEMBERNOTFOUND;
}
return S_OK;
}
void DocumentComplete(VARIANT *url)
{
std::string strValue = (char*)_bstr_t(url);
}
When calling (void)DocumentComplete I get this error:
*Unhandled exception at 0x7c812afb in webhost.exe: Microsoft C++ exception: _com_error at memory location 0x0012ed50.*
If comment the line on DocumentComplete, it doesn't show any errors. Also try..catch blocks doens't catch the exception.
What I am trying to do is to use Variant * url to compare it with a std::string.
How can I do this?