Link to home
Start Free TrialLog in
Avatar of Cyber-Drugs
Cyber-DrugsFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Modifying a function

Hi guys,

I have a function which calls JavaScript functions via C++ code, but now need to modify it so that:

1/ I can define which JavaScript function I want to call, via a Parameter when calling this function.
2/ I can send up to 5 Parameters to the JavaScript Function via Paramters sent when calling this function.

Anybody able to help me out please?

Here is the code at the moment:

#import "C:\\windows\\system32\mshtml.tlb"   // **you need this !

void CCustomModalDialog::ExecuteScriptFunction()
{
  // m_WebBrowser is an instance of IWebBrowser2
  MSHTML::IHTMLDocument2Ptr spDoc(m_browser.GetDocument());

  if (spDoc)
  {
     IDispatchPtr spDisp(spDoc->GetScript());
     if (spDisp)
     {
        // Evaluate is the name of the script function.
         
        OLECHAR FAR* szMember = L"evaluate";
        DISPID dispid;

        HRESULT hr = spDisp->GetIDsOfNames(IID_NULL, &szMember, 1,
                                       LOCALE_SYSTEM_DEFAULT, &dispid);

        if (SUCCEEDED(hr))
        {
           COleVariant vtResult;
           static BYTE parms[] = VTS_BSTR;

           COleDispatchDriver dispDriver(spDisp, FALSE);

           dispDriver.InvokeHelper(dispid, DISPATCH_METHOD, VT_VARIANT,
                                   (void*)&vtResult, parms,
                                   "5+Math.sin(9)");
        }
     }
  }
}
ASKER CERTIFIED SOLUTION
Avatar of mahesh1402
mahesh1402
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Cyber-Drugs

ASKER

mahesh1402,

Thanks for the fast reply, just to check though, would I also be able to send an array over to a JavaScript function as a parameter?


Cheers!
In above function its a provision implementged to accept paramteres using CStringArray.. you are suppose to pass parameters in this array as strings.

-MAHESH
Thanks mahesh1402, that's great! :)