c++执行JavaScript

#include 
#include 

void ExecuteJavaScript(CString javascript)
{
    HRESULT hr;
    CComPtr < IDispatch > spDispDoc;
    spDispDoc = m_web.get_Document();
    if (spDispDoc == NULL)
    {
        return;
    }
    CComQIPtr< IHTMLDocument2 > spDocument2;
    spDocument2 = spDispDoc;
    CComQIPtr spWindow2;
    hr = spDocument2->get_parentWindow(&spWindow2);
    if (FAILED(hr))
    {
        return;
    }

    CString Type = L"javascript";
    VARIANT ret;
    ret.vt = VT_EMPTY;
    BSTR bstr = javascript.AllocSysString();
    BSTR btype = Type.AllocSysString();
    int i = spWindow2->execScript(bstr, btype, &ret);
    ::SysFreeString(bstr);
    ::SysFreeString(btype);
}

CExplorer1 m_web; //webrowser控件添加的变量

你可能感兴趣的:(c++执行JavaScript)