VC and JavaScript Interaction (ii)

Source: Internet
Author: User

Recently about VC + + through the IDispatch invoke to achieve and JS Interactive do point TP, and the previously did not understand the "direct read JS variable value" and "pass a number of parameters" part of the re-implementation.

1, call JS function, and pass multiple parameters

ccomqiptr<ihtmldocument2> PDoc = M_browser.get_document (); if (PDOC) {ccomqiptr<idispatch> spDisp; HRESULT hr = Pdoc->get_script (&spdisp), if (SUCCEEDED (HR)) {//Function name to invoke tchar* Szmember = _t ("SetText");D ispid Dispi D HRESULT hr = Spdisp->getidsofnames (Iid_null, &szmember, 1,locale_system_default, &dispid); if (SUCCEEDED (HR ) {Dispparams dispparams;memset (&dispparams, 0, sizeof dispparams);d Ispparams.cargs = 2;//The parameters to be passed, it is strongly recommended to use the following form.                                  When transferring a string, change to a BSTR.   ccomvariant* pvars = new Ccomvariant[2];     PVARS[1] = L "1";   Pvars[0] = L "2"; Pvars[0]. ChangeType (VT_I4);p vars[1]. ChangeType (VT_I4);d ispparams.rgvarg = Pvars;dispparams.cnamedargs = 0; Excepinfo Excepinfo;memset (&excepinfo, 0, sizeof (excepinfo)); CComVariant Varesult;  UINT NARGERR = (UINT)-1; Initialize to invalid ARGHR = Spdisp->invoke (DispID, Iid_null, Locale_system_default, dispatch_method,& Dispparams,&varesult,&excepinfo,&nargerr);}}}

2, directly read the JS variable (not by assigning value to a control and then reading the form)

ccomqiptr<ihtmldocument2> PDoc = M_browser.get_document (); if (PDOC) {ccomqiptr<idispatch> spDisp; HRESULT hr = Pdoc->get_script (&spdisp), if (SUCCEEDED (HR)) {                         //js variable name tchar* szmember = _t ("Nitem");D Ispid DISPID; HRESULT hr = Spdisp->getidsofnames (Iid_null, &szmember, 1,locale_system_default, &dispid); if (SUCCEEDED (HR ) {Dispparams dispparams;memset (&dispparams, 0, sizeof dispparams); Excepinfo Excepinfo;memset (&excepinfo, 0, sizeof (excepinfo)); CComVariant Varesult; UINT NARGERR = (UINT)-1;  Initialize to invalid ARGHR = Spdisp->invoke (DispID, Iid_null, Locale_system_default, dispatch_propertyget,& Dispparams,&varesult,&excepinfo,&nargerr);}}}

Reference:

http://blog.csdn.net/hzlyh/article/details/5411086

Unfortunately, the JS variable directly assigned to the time, invoke has not been successful, but still need to continue to investigate .....

VC and JavaScript Interaction (ii)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.