MCPcopy Create free account
hub / github.com/SOUI2/soui / ExecuteScript

Function ExecuteScript

controls.extend/SDocHostUIHandler.cpp:196–264  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

194 }
195
196 VARIANT ExecuteScript(IWebBrowser2 *pWebBrowser, const SStringW & fun,SArray<SStringW> & params)
197 {
198 VARIANT varErr;
199 VariantInit( &varErr );
200
201 //get document dispatch interface
202 IDispatch* pDisp = NULL;
203
204 HRESULT hr = pWebBrowser->get_Document( &pDisp );
205
206 if ( FAILED( hr ) || pDisp == NULL )
207 {
208 return varErr;
209 }
210
211 IHTMLDocument2* pDoc = NULL;
212 pDisp->QueryInterface( IID_IHTMLDocument2,(void**)&pDoc );
213 pDisp->Release();
214
215 IDispatch* pScript = NULL;
216 hr = pDoc->get_Script( &pScript );
217 pDoc->Release();
218
219 if ( FAILED( hr ) || pScript == NULL )
220 {
221 return varErr;
222 }
223
224 sbstr bstrMember((int)fun.GetLength(),fun );
225 DISPID dispid = 0;
226 BSTR bstr = (BSTR)bstrMember;
227 hr = pScript->GetIDsOfNames( IID_NULL,&(bstr),1,LOCALE_SYSTEM_DEFAULT,&dispid );
228
229 if ( FAILED( hr ) )
230 {
231 return varErr;
232 }
233
234 DISPPARAMS dispparams;
235 ::ZeroMemory( &dispparams,sizeof( DISPPARAMS ) );
236 dispparams.cArgs = (UINT)params.GetCount();
237 dispparams.rgvarg = new VARIANT[dispparams.cArgs];
238 dispparams.cNamedArgs = 0;
239
240 for ( size_t i = 0;i < params.GetCount();i++ )
241 {
242 size_t indx = params.GetCount() - i - 1;
243 sbstr bstrParam((int)params[indx].GetLength(),params[indx]);
244 dispparams.rgvarg[i].bstrVal = bstrParam.Release();
245 dispparams.rgvarg[i].vt = VT_BSTR;
246 }
247
248 EXCEPINFO excepinfo;
249 ::ZeroMemory( &excepinfo,sizeof( EXCEPINFO ) );
250 VARIANT varRet;
251 UINT nArgErr = (UINT)-1; //initialize to invalid arg
252
253 hr = pScript->Invoke( dispid,IID_NULL,0,DISPATCH_METHOD,&dispparams,&varRet,&excepinfo,&nArgErr );

Callers

nothing calls this directly

Calls 6

QueryInterfaceMethod · 0.45
ReleaseMethod · 0.45
GetLengthMethod · 0.45
GetIDsOfNamesMethod · 0.45
GetCountMethod · 0.45
InvokeMethod · 0.45

Tested by

no test coverage detected