在web按钮上有一个按钮执行JS windows.postmessage并发送一些数据。在C#bho 我想捕获这些数据并调用一些本地服务。我需要有关如何做到这一点的线索。
答案 0 :(得分:0)
HRESULT AddProperty(SHDocVw::IWebBrowser2* pBrowser, _bstr_t bstrName, _variant_t varValue)
{
CComQIPtr<IHTMLDocument> spDoc = pBrowser->Document;
CComPtr<IDispatch> spScript;
spDoc->get_Script(&spScript);
_variant_t varResult;
HRESULT hr = spScript.GetPropertyByName(OLESTR("window"), varResult.GetAddress());
CComQIPtr<IDispatchEx> spScriptEx = varResult;
DISPID id;
hr = spScriptEx->GetDispID(bstrName), fdexNameEnsure, &id);
if (SUCCEEDED(hr))
{
DISPID propid = DISPID_PROPERTYPUT;
DISPPARAMS dp = {NULL, NULL, 1, 1};
dp.rgdispidNamedArgs = &propid;
dp.rgvarg = &varValue;
hr = spScriptEx->InvokeEx(id, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPUT, &dp, NULL, NULL, NULL);
}
return hr;
}