TCHAR HostName[300];
USES_CONVERSION;
CComPtr<IDispatch> pDispatch;
CComQIPtr< IHTMLElementCollection > pElementCol;
CComPtr<IHTMLAnchorElement> pLoct;
hr = pIHTMLDocument2->get_links(&pElementCol ); //取得link集合....
if ( FAILED( hr ) ) return; long p=0;
if(SUCCEEDED(pElementCol->get_length(&p)))
if(p!=0)
{
for(long i=0;i<p;i++)
{ CComBSTR String;
_variant_t index=i; if(SUCCEEDED(pElementCol->item( index, index, &pDispatch)))
if(SUCCEEDED(pDispatch->QueryInterface( IID_IHTMLAnchorElement,(void **) &pLoct))) pLoct->get_href(&String);
ZeroMemory(HostName,300);
lstrcpy(HostName,_bstr_t(String));
//添加到列表
m_LinksList.InsertItem(i,HostName);
m_LinksList.SetCheck(i,TRUE); }
}网上流传最广的网页连接提取代码,我试了,获得第1个地址后
if(SUCCEEDED(pElementCol->item( index, index, &pDispatch)))这句就出错了,也就是执行了1次,什么道理?
USES_CONVERSION;
CComPtr<IDispatch> pDispatch;
CComQIPtr< IHTMLElementCollection > pElementCol;
CComPtr<IHTMLAnchorElement> pLoct;
hr = pIHTMLDocument2->get_links(&pElementCol ); //取得link集合....
if ( FAILED( hr ) ) return; long p=0;
if(SUCCEEDED(pElementCol->get_length(&p)))
if(p!=0)
{
for(long i=0;i<p;i++)
{ CComBSTR String;
_variant_t index=i; if(SUCCEEDED(pElementCol->item( index, index, &pDispatch)))
if(SUCCEEDED(pDispatch->QueryInterface( IID_IHTMLAnchorElement,(void **) &pLoct))) pLoct->get_href(&String);
ZeroMemory(HostName,300);
lstrcpy(HostName,_bstr_t(String));
//添加到列表
m_LinksList.InsertItem(i,HostName);
m_LinksList.SetCheck(i,TRUE); }
}网上流传最广的网页连接提取代码,我试了,获得第1个地址后
if(SUCCEEDED(pElementCol->item( index, index, &pDispatch)))这句就出错了,也就是执行了1次,什么道理?
解决方案 »
- 有没有人有改写好的日期类?
- 收藏 不显示删除回复显示所有回复显示星级回复显示得分回复 关于--edit box控件,在一个类里读写另一个类的edit box成员变量,更新显示没失应--问题
- 菜鸟求教问题有关CSocket
- Winsock重叠操作投递WSARecv 错误
- vc 读取文件夹里的图片在dialog对话框显示
- 有关排列组合的算法问题,请指教!
- CDateTimeCtrl问题,大送分!!!!!
- VC++初学者提问~~~
- 专家请看 :有关 内存回收的问题。马上结帐哦!
- 关于VC的用途?我原来是VB程序员,现在想学VC(主要是为了好换工作).....
- 隐藏垂直滚动条问题
- RUNTIME ERROR ! 什么原因?
1、在循环体内的最后放置 pDispatch.Release(); 语句
2、把CComPtr <IDispatch> pDispatch; 这个语句放到循环内申明,就无需调用Release了