bool CLoginTDlg::AutoLogin(IHTMLDocument2 * pIHTMLDocument2)
{
    CString strUrl,strTemp;
IHTMLElementCollection *objAllElement=NULL;   
IHTMLDocument2 *objDocument=pIHTMLDocument2;   
objDocument->get_all(&objAllElement); //得到网页所有元素的集合   
 objDocument->get_all(&objAllElement); //得到网页所有元素的集合
    //由于所有页面下载完后都会执行这个函数,所以必须根据URL判断消息来源网页
        CComPtr<IDispatch>pDisp;
        long   lcount   =   0;   
        objAllElement->get_length(&lcount);  
        for(int   i=0;i<lcount;i++)   
        {   
            _variant_t   index;   
            index.vt=VT_I4;   
            index.intVal=i;   
            IDispatchPtr   disp;   
            objAllElement->item(index,index,&disp);   
            if(disp==NULL)   
                continue;  
            else   
            {   
                CComQIPtr<IHTMLElement>   pInput(disp);   
                if(pInput)   
                {   
                    BSTR   bstrtype; 
                    pInput->get_tagName(&bstrtype);
                    //pInput->toString(&bstrtype);
                    //pInput->get_type(&bstrtype);   
                    //printf(_bstr_t(bstrtype));
                    _bstr_t bInner = bstrtype;
                    TCHAR *szIner =  bInner;
                    if(_tcscmp(szIner, _T("a"))==0)   
                    {
                        CComVariant Attribute;
                        pInput->getAttribute(_bstr_t(_T("href")),2,&Attribute);
                        CString  strAttrib = (LPCTSTR)Attribute.bstrVal;
                        if (strAttrib == _T("javascript:do_login(this)"))
                        {
                        //    AfxTrace(_T("%s/r/n"),(LPCTSTR)Attribute.bstrVal);
                            pInput->get_innerHTML(&bstrtype);
                            CString strLable = (LPCTSTR)bstrtype;
                            bInner = bstrtype;
                            TCHAR *szIner = bInner; 
                                                        //找到"登陆"这个超级链接
                                                        //触发执行Click事件   
                            if (_tcscmp(szIner, _T("登录")) == 0||_tcscmp(szIner, _T("로그인")) == 0)
                            {
                              //  AfxTrace(_T("%s/r/n"),szIner);
        
pInput->click();//这一点击事件一运行到此便会出错
// AfxMessageBox(L"szIner");
return true;
                            }
                        }
                    }
               SysFreeString(bstrtype);       
                }          
            }      
        }   
        objAllElement->Release();   [code=c][/code]