为什么得不到IHTMLElement接口指针?!急。。。谢谢
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);
}
}
大家帮忙啊!!