请教动态生成脚本的问题
最近在做RSS阅读器,窗口右边用一个HTMLView显示动态生成的HTML页面,纯文本的页面载入没有问题,但在使用Script的时候除了问题如下:
if( m_pHtmlDoc2)
{
HRESULT hr = S_OK;
//get script collection
IHTMLElementCollection *pElCol;
hr=m_pHtmlDoc2->get_scripts( &pElCol);
COleVariant vName( (long)0);
COleVariant vIndex( (long)0);
IDispatch *pDisp;
//get first element from script collection
hr=pElCol->item( vName, vIndex, &pDisp);
IHTMLScriptElement *pScriptEl;
hr=pDisp->QueryInterface( IID_IHTMLScriptElement, (void**)&pScriptEl);
//put text to first element
_bstr_t bpTextNew( m_lpstrScript);
hr=pScriptEl->put_text( bpTextNew);
if( hr==S_FALSE) return FALSE;
else return TRUE;
}
else return FALSE;
我刚开始载入了一个有Script的自定义空页面,但是如果我点击一些没有Script的页面,再载入自己生成的带Script的页面就会出错,调试发现就是hr=pElCol->item( vName, vIndex, &pDisp);这一句未能给pDisp赋值,导致后面调用空指针出错。
请大侠们给点建议。