0

Hy,

I'm working at a project that must call from C++ a custom function made in JavaScript. I'm able to run the function

The project should work only on Windows (actually it's a Windows service), so it's ok to use interfaces IWebBrowser2 and IHtmlDocument2

The function's signature is string function(string). I'm able to run the function in C++, based on this tutorial (I'm using IWebBrowser2 and IHtmlDocument2 interface), but I'm not able to get the output from that JS function back in C++.

Is there any method to retrieve the output from that JS function back in C++, using those interfaces? ( or maybe other)

Thank you,

Community
  • 1
  • 1
banuj
  • 2,640
  • 24
  • 32
  • 2
    When you call the function through `Invoke` the return value in placed in a `VARAINT`. It's the 6th parameter to Invoke. – Captain Obvlious May 29 '13 at 21:21
  • Do you need to just call a javascript function defined as a text, or a javascript function in a web page context? – Simon Mourier May 30 '13 at 05:25
  • @SimonMourier I need to call just a javascript function defined as a text. – banuj May 30 '13 at 06:09
  • You can reuse the script engines in Windows, check this out: http://www.codeproject.com/Articles/349554/Cplusplus-Win32-and-Scripting-Quick-way-to-add-Scr and here http://stackoverflow.com/questions/4744105/parse-and-execute-js-by-c-sharp (in C# but you can translate it back to c++ where it comes from) – Simon Mourier May 30 '13 at 06:31

1 Answers1

0

I'll answer to my own question, if someone will have the same question:

Short answer is you can't obtain the output of javascript script using these interfaces. The IWebBrowser2 and IHtmlDocument are running in a context based on IE, so you can't obtain the output of running scripts.

The solutions for this problem are:

If you plan to use V8 in your application, the basic example for calling a function is provided at Calling a v8 javascript function from c++ with an argument (But, be aware of the Dispose() function, which is wrongly placed)

If you plan to use Active Script Interfaces, the basic example is provided at Run JavaScript function from C++ without MFC . It's a useful example that shows how to run a JavaScript function.

Community
  • 1
  • 1
banuj
  • 2,640
  • 24
  • 32