求助:很奇怪的问题,程序中有一句话,onTimer来执行可以通过,但是使用线程来执行就不能执行!
void CXRingView::OnTest()
{
// TODO: Add your command handler code here
IDispatch* pDispatch = GetHtmlDocument();
//Only if a resource or web page is loaded can we get the document
if( pDispatch != NULL )
{
IHTMLDocument2* pHtmlDoc;
COleVariant varIndex,varTemp;
varIndex.vt=VT_I4;
CString strElementID,strTemp;
HRESULT hr = pDispatch->QueryInterface( __uuidof( IHTMLDocument2 ), (void**)&pHtmlDoc );
pDispatch->Release();
if( SUCCEEDED( hr ) )
{
IHTMLElementCollection * pElemColl;
pHtmlDoc->get_all(&pElemColl);
int l_Length;
pElemColl->get_length((LONG *)&l_Length);
for(int i=0;i<l_Length;i++)
{
varIndex.lVal=i;
pElemColl->item(varIndex,varTemp,&pDispatch);
if(pDispatch!=NULL)
{
CComBSTR b;
IHTMLInputTextElement* pInputElement=NULL;
if ( pDispatch->QueryInterface(IID_IHTMLInputTextElement,(void**)&pInputElement)==0)
{
pInputElement->get_name(&b);
b.ToLower();
if(b==L"usernumber")
{
pInputElement->put_value(L"13000000000");
}
if(b==L"password")
{
pInputElement->put_value(L"00000");
}
}
pDispatch->Release();
}
}
}
}
pDispatch = GetHtmlDocument();
if( pDispatch != NULL )
{
IHTMLDocument2* pHtmlDoc;
COleVariant varIndex,varTemp;
varIndex.vt=VT_I4;
CString strElementID,strTemp;
HRESULT hr = pDispatch->QueryInterface( __uuidof( IHTMLDocument2 ), (void**)&pHtmlDoc );
pDispatch->Release();
if( SUCCEEDED( hr ) )
{
CComQIPtr<IHTMLWindow2> pHTMLWnd;
pHtmlDoc->get_parentWindow( &pHTMLWnd );
if ( pHTMLWnd != NULL ){
CString strjs=_T("userLogin()");
CComBSTR bstrjs = strjs.AllocSysString();
CComBSTR bstrlan = SysAllocString(L"javascript");
VARIANT varRet;
HRESULT hr=pHTMLWnd->execScript(bstrjs, bstrlan, &varRet);
if( SUCCEEDED( hr ) )
{
}
else
{
DWORD dw=::GetLastError();
CString szDW;
szDW.Format("%d",dw);
AfxMessageBox(szDW);
}
}
}
}
}
HRESULT hr=pHTMLWnd->execScript(bstrjs, bstrlan, &varRet);
这句话在ontimer中可以执行,但是现成调用这个函数这句话就不能执行 hr返回值不是0,是一个很大的负数,求助高手原因如何,在线等答,即刻给分