BHO HtmlEventObject 崩溃
我有一个用 C++ 编写的浏览器帮助程序对象,但在接收 OnHelp HtmlEvent 时遇到问题。
当我尝试访问属性时,浏览器崩溃。
VARIANT_BOOL STDMETHODCALLTYPE OnHelp(IHTMLEventObj2 *pEvtObj)
{
std::cout << "OnHelp Event" << std::endl;
if(pEvtObj != NULL) {
VARIANT var;
pEvtObj->getAttribute(L"formID", 0, &var);
std::cout << (char*)var.bstrVal << std::endl;
}
else {
std::cout << "PELEM = NULL" << std::endl;
}
return VARIANT_TRUE;
}
由于某种原因它在 getAttribute 行崩溃?在 C# 中执行此操作时效果非常好。我希望有人能帮我解决这个问题。
编辑:
真正的问题是我需要使用 IHTMLEventObj 然后查询 IHTMLEventObj2 的参数。
VARIANT_BOOL STDMETHODCALLTYPE OnHelp(IHTMLEventObj *pEvtObj)
{
IHTMLEventObj2 *pEvtObj2;
pEvtObj->QueryInterface(IID_IHTMLEventObj2, (void**)&pEvtObj2);
if(pEvtObj2 != NULL) {
VARIANT var;
pEvtObj2->getAttribute(CComBSTR(L"url"), 0, &var);
std::cout << _bstr_t(var.bstrVal) << std::endl;
}
else {
std::cout << "PELEM = NULL" << std::endl;
}
return VARIANT_TRUE;
}
I have a browser helper object written in C++ but I have a problem when recieving a OnHelp HtmlEvent.
When I try to access a attribute the browser crashes.
VARIANT_BOOL STDMETHODCALLTYPE OnHelp(IHTMLEventObj2 *pEvtObj)
{
std::cout << "OnHelp Event" << std::endl;
if(pEvtObj != NULL) {
VARIANT var;
pEvtObj->getAttribute(L"formID", 0, &var);
std::cout << (char*)var.bstrVal << std::endl;
}
else {
std::cout << "PELEM = NULL" << std::endl;
}
return VARIANT_TRUE;
}
It crashes on the getAttribute line for some reason? When doing this in C# it works perfectly. I hope somebody can help me fix this.
Edit:
The real problem was with the parameter I needed to use IHTMLEventObj and then query for IHTMLEventObj2.
VARIANT_BOOL STDMETHODCALLTYPE OnHelp(IHTMLEventObj *pEvtObj)
{
IHTMLEventObj2 *pEvtObj2;
pEvtObj->QueryInterface(IID_IHTMLEventObj2, (void**)&pEvtObj2);
if(pEvtObj2 != NULL) {
VARIANT var;
pEvtObj2->getAttribute(CComBSTR(L"url"), 0, &var);
std::cout << _bstr_t(var.bstrVal) << std::endl;
}
else {
std::cout << "PELEM = NULL" << std::endl;
}
return VARIANT_TRUE;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
getAttribute 的第一个参数是
BSTR
,但您传递的wchar_t*
/unsigned int *
取决于 VC 编译设置。BSTR
是一个系统字符串,预计将由接收方法释放。尝试
The first arg for getAttribute is a
BSTR
, but your passing awchar_t*
/unsigned int *
depending on VC compile settings.BSTR
is a system string which is expected to be deallocated by the receiving method.Try