佚名通过本文主要向大家介绍了vc随机数函数,vc图形库函数,vc函数库,vc sleep函数,vc延时函数等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
问题: VC模拟点击的函数,一直报错,大侠帮帮忙哈?
描述:
错误提示 Debug Assertion Failed!
解决方案1:
描述:
本帖最后由 VisualEleven 于 2012-02-23 15:50:53 编辑
void CMy188View::ClickBtn(CString strID)
{
HRESULT hr;
IDispatch *pDisp;
pDisp = m_webBroweser.GetDocument(); //获取webbrowser控件文档接口
IHTMLDocument2* pDoc;
hr = pDisp->QueryInterface(IID_IHTMLDocument2,(void**)&pDoc); //获取登录界面的文档接口
IHTMLElementCollection* pColl = NULL;
hr = pDoc->get_all(&pColl); //获取网页元素集合
IDispatch* pDisp2;
VARIANT index;
VARIANT varID;
V_VT(&index) = VT_I4;
V_I4(&index) = 0;
varID = StringToVariant(strID); //按钮ID字符串格式转换
hr = pColl->item(varID,index,&pDisp2);
if((hr == S_OK)&&(pDisp2!=NULL))
{
IHTMLElement* pElem = NULL;
hr = pDisp2->QueryInterface(IID_IHTMLElement,(void**)&pElem);
if((hr == S_OK) && (pElem != NULL))
{
pElem->click(); //点击按钮
pElem->Release();
}
pDisp2->Release();
pDisp->Release();
}
}
错误提示 Debug Assertion Failed!
解决方案1:
IHTMLDocument2* pDoc = pDisp;
if(!pDoc) return;
这样试试,直接把pDisp赋给pDoc,检测pDoc是否成功
你Debug下看看返回的指针是否有效?
解决方案3:调试先