关于 IHTMLElement 的 get_tagName的问题。
我在MFC中用Microsoft Web浏览器加载了网易的网页。我用下面的代码遍历所有的元素,我想用IHTMLElement 的 get_tagName 取值以后用 MessageBox 把取到值显示出来。但是弹出来的提示框里面全是乱码。请问怎样才能用 MessageBox 把取到值显示出来,比如显示 “input”
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_ie.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
AfxMessageBox(ss); //在对话框中显示tagName
::SysFreeString(tag);
}
}