Cyber-Drugs
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\msh tml.tlb" // **you need this !
void CCustomModalDialog::Execut eScriptFun ction()
{
// m_WebBrowser is an instance of IWebBrowser2
MSHTML::IHTMLDocument2Ptr spDoc(m_browser.GetDocumen t());
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(di spid, DISPATCH_METHOD, VT_VARIANT,
(void*)&vtResult, parms,
"5+Math.sin(9)");
}
}
}
}
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\msh
void CCustomModalDialog::Execut
{
// m_WebBrowser is an instance of IWebBrowser2
MSHTML::IHTMLDocument2Ptr spDoc(m_browser.GetDocumen
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_
LOCALE_SYSTEM_DEFAULT, &dispid);
if (SUCCEEDED(hr))
{
COleVariant vtResult;
static BYTE parms[] = VTS_BSTR;
COleDispatchDriver dispDriver(spDisp, FALSE);
dispDriver.InvokeHelper(di
(void*)&vtResult, parms,
"5+Math.sin(9)");
}
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
In above function its a provision implementged to accept paramteres using CStringArray.. you are suppose to pass parameters in this array as strings.
-MAHESH
-MAHESH
ASKER
Thanks mahesh1402, that's great! :)
ASKER
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!