TML document COM object");
return false;
}
return true;
}
bool CWebPage::GetJScript(CComPtr<IDispatch>& spDisp)
{
CHECK_POINTER(m_spDoc);
if (NULL == m_spDoc)
{
return false;
}
HRESULT hr = m_spDoc->get_Script(&spDisp);
ATLASSERT(SUCCEEDED(hr));
return SUCCEEDED(hr);
}
bool CWebPage::GetJScripts(CComPtr<IHTMLElementCollection>& spColl)
{
CHECK_POINTER(m_spDoc);
HRESULT hr = m_spDoc->get_scripts(&spColl);
ATLASSERT(SUCCEEDED(hr));
return SUCCEEDED(hr);
}
bool CWebPage::CallJScript(const string strFunc,CComVariant* pVarResult)
{
vector<string> paramArray;
return CallJScript(strFunc,paramArray,pVarResult);
}
bool CWebPage::CallJScript(const string strFunc,const string strArg1,CComVariant* pVarResult)
{
vector<string> paramArray;
paramArray.push_back(strArg1);
return CallJScript(strFunc,paramArray,pVarResult);
}
bool CWebPage::CallJScript(const string strFunc, const vector<string>& paramArray,CComVariant* pVarResult)
{
CComPtr<IDispatch> spScript;
if(!GetJScript(spScript))
{
ShowError("Cannot GetScript");
return false;
}
CComBSTR bstrMember(strFunc.c_str());
DISPID dispid = NULL;
HRESULT hr = spScript->GetIDsOfNames(IID_NULL,&bstrMember,1,
LOCALE_SYSTEM_DEFAULT,&dispid);
if(FAILED(hr))
{
ShowError(GetSystemErrorMessage(hr).c_str());
return false;
}
const int arraySize = paramArray.size();
DISPPARAMS dispparams;
memset(&dispparams, 0, sizeof dispparams);
dispparams.cArgs = arraySize;
dispparams.rgvarg = new VARIANT[dispparams.cArgs];
for( int i = 0; i < arraySize; i++)
{
CComBSTR bstr = paramArray[arraySize - 1 - i].c_str();
bstr.CopyTo(&dispparams.rgvarg[i].bstrVal);
dispparams.rgvarg[i].vt = VT_BSTR;