诸位帮忙看一下,为什么IHTMLDocument3的getElementById不好用?解决办法
诸位帮忙看一下,为什么IHTMLDocument3的getElementById不好用?
程序段具体是将id为captureimg的img标签中的src属性设置为给定的url字符串
CComQIPtr <IHTMLDocument3> pdoc=(IHTMLDocument3*)m_pHtmlView->GetHtmlDocument();
if(!pdoc)
return;
CComPtr <IHTMLElement> el=0;
CComPtr <IHTMLElementCollection> collection=0;
pdoc->getElementById(CComBSTR("captureimg"),&el); //这句运行到这里就出现错误
VARIANT param;
param.vt=VT_BSTR;
param.bstrVal=_T("http://192.168.1.81/images/246.bmp");
if(el&&el->setAttribute(CComBSTR("src"),param)==S_OK)
{
::AfxMessageBox(_T("切换图片成功"));
}
pdoc.Release();
el.Release();
collection.Release();
这几句运行到 pdoc->getElementById(CComBSTR("captureimg"),&el); 这里就出现错误, 请问是什么原因?
IntelliSense里面确实是写的这么用的啊?
还有底下的几个Release()用得正确吗,请指点谢谢
------解决方案--------------------
把代码重新用高亮着色贴清楚啊
程序段具体是将id为captureimg的img标签中的src属性设置为给定的url字符串
CComQIPtr <IHTMLDocument3> pdoc=(IHTMLDocument3*)m_pHtmlView->GetHtmlDocument();
if(!pdoc)
return;
CComPtr <IHTMLElement> el=0;
CComPtr <IHTMLElementCollection> collection=0;
pdoc->getElementById(CComBSTR("captureimg"),&el); //这句运行到这里就出现错误
VARIANT param;
param.vt=VT_BSTR;
param.bstrVal=_T("http://192.168.1.81/images/246.bmp");
if(el&&el->setAttribute(CComBSTR("src"),param)==S_OK)
{
::AfxMessageBox(_T("切换图片成功"));
}
pdoc.Release();
el.Release();
collection.Release();
这几句运行到 pdoc->getElementById(CComBSTR("captureimg"),&el); 这里就出现错误, 请问是什么原因?
IntelliSense里面确实是写的这么用的啊?
还有底下的几个Release()用得正确吗,请指点谢谢
------解决方案--------------------
把代码重新用高亮着色贴清楚啊