AfxMessageBox("gethere");
IHTMLElement * pElem = NULL;
//LPDISPATCH pDispatch;
IDispatch * pDispatch=NULL;
IHTMLDocument2 * pDoc=NULL;
IHTMLElementCollection * pAllElem = NULL;
VARIANT name;///////////////////////////////////////////
BSTR tag; //for Element's tagName
long p; //for IHTMLElementCollection's item number
pDispatch=m_webbrowser.GetDocument();
ASSERT(pDispatch); HRESULT hr=pDispatch->QueryInterface(IID_IHTMLDocument2,(void**)&pDoc);
pDoc->get_all(&pAllElem); ASSERT(pAllElem);
if(pAllElem!=NULL)
{
AfxMessageBox("gethere1");
for(int i=0;i<100;i++)//遍历所有元素
{
name.lVal = i;
pAllElem->item(name,name,(IDispatch**)&pElem);//获取元素对象指针
ASSERT(pElem);////远行时出错??????????????????
pElem->get_tagName(&tag);//获取tagName
CString ss(tag); //转化成CString
//if(ss.CompareNoCase("table") ==0)//比较是否为table
AfxMessageBox(ss); //在对话框中显示tagName
::SysFreeString(tag);
}
}
得不到原素对象的pElem的指针!!
IHTMLElement * pElem = NULL;
//LPDISPATCH pDispatch;
IDispatch * pDispatch=NULL;
IHTMLDocument2 * pDoc=NULL;
IHTMLElementCollection * pAllElem = NULL;
VARIANT name;///////////////////////////////////////////
BSTR tag; //for Element's tagName
long p; //for IHTMLElementCollection's item number
pDispatch=m_webbrowser.GetDocument();
ASSERT(pDispatch); HRESULT hr=pDispatch->QueryInterface(IID_IHTMLDocument2,(void**)&pDoc);
pDoc->get_all(&pAllElem); ASSERT(pAllElem);
if(pAllElem!=NULL)
{
AfxMessageBox("gethere1");
for(int i=0;i<100;i++)//遍历所有元素
{
name.lVal = i;
pAllElem->item(name,name,(IDispatch**)&pElem);//获取元素对象指针
ASSERT(pElem);////远行时出错??????????????????
pElem->get_tagName(&tag);//获取tagName
CString ss(tag); //转化成CString
//if(ss.CompareNoCase("table") ==0)//比较是否为table
AfxMessageBox(ss); //在对话框中显示tagName
::SysFreeString(tag);
}
}
得不到原素对象的pElem的指针!!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货