IHTMLDocument2* pDocument;
HRESULT hr = GetDHtmlDocument(&pDocument);
IHTMLWindow2* pWindow;
hr = pDocument->get_parentWindow(&pWindow);
VARIANT ret;
ret.vt = VT_EMPTY;
CComBSTR func=_T("getAlert()");
CComBSTR lang=_T("javascript");
//hr = pWindow->execScript( _T("getAlert()"), _T("javascript"), &ret);
// hr = pWindow->execScript( func, lang,&ret);
DISPID dispid;
DISPPARAMS dispparams;
memset(&dispparams, 0, sizeof dispparams);
dispparams.cArgs=1;
dispparams.rgvarg = new VARIANT[dispparams.cArgs];
CComBSTR fromMFC=_T("from mfc");
fromMFC.CopyTo(&dispparams.rgvarg[0].bstrVal);
dispparams.rgvarg[0].vt = VT_BSTR;
EXCEPINFO excepInfo;
memset(&excepInfo, 0, sizeof excepInfo);
CComVariant vaResult;
UINT nArgErr = (UINT)-1;
CComBSTR szMember = _T("getAlert");
hr = pWindow->GetIDsOfNames(IID_NULL, &szMember,1,LOCALE_SYSTEM_DEFAULT,&dispid);
hr = pWindow->Invoke(dispid, IID_NULL, 0, DISPATCH_METHOD, &dispparams, &vaResult, &excepInfo,&nArgErr);
MessageBox(vaResult.bstrVal);
pDocument->Release();
pWindow->Release();
CDHtmlDialog 调用javascript
最新推荐文章于 2023-02-07 00:41:42 发布