运行了下程序崩溃了。win7直接提示已停止工作。怎么处理

运行了下程序崩溃了。win7直接提示已停止工作。怎么办啊
m_web.Navigate("http://1.1.1.2/srun_portal.html?userip=10.56.9.99&userurl=http://www.baidu.com&ac_id=2&sys=",NULL,NULL,NULL,NULL); 


HRESULT hr;

VARIANT index;

IDispatch *pDisp;

pDisp = m_web.GetDocument(); //m_web是控件型变量

IHTMLDocument2* pDoc; //文档接口

hr = pDisp->QueryInterface( IID_IHTMLDocument2, (void**)&pDoc );

 

IHTMLElementCollection* pColl = NULL;                //枚举网页元素

 

hr = pDoc->get_all( &pColl );

 

LONG elementcount;

hr = pColl->get_length( &elementcount );//Find the count of the elements

for ( int i=0; i< elementcount; i++ )//Loop through each elment

{

IDispatch* pDisp2;

 

V_VT(&index) = VT_I4;

V_I4(&index) = i;

hr = pColl->item( index,index, &pDisp2 );//Get an element

 

if ( hr == S_OK )

{

IHTMLElement* pElmt;         //网页元素

hr = pDisp2->QueryInterface(IID_IHTMLElement,(void **)&pElmt );

if ( hr == S_OK )

{

BSTR bstr = SysAllocString(L"");

pElmt->get_id(&bstr); //获得网页元素id

pElmt->Release();

}

pDisp2->Release();

}

}

 

pColl->Release();

pDoc->Release();

pDisp->Release();

------解决方案--------------------
刚调用完Navigate不能使用GetDocument()方法,应该在DocumentComplete事件中调用
------解决方案--------------------
在DocumentComplete事件中获取页面DOM内容来处理