1

I need to call a c++ function from the javascript. Please somebody hlp..

2
  • 5
    Javascript running in the browser? Javascript running on the web server? Please be more specific. Commented Dec 15, 2010 at 5:36
  • 4
    and perhaps also state what you're actually trying to do. The solution might not involve c++ (or javascript) at all. Commented Dec 15, 2010 at 5:38

5 Answers 5

3

If you are talking about a web browser, then running native code from Javascript is usually done by exposing the necessary functions through a web browser plugin. Different web browsers have different ways to write plugins; Firefox and Chrome use NPAPI whereas Internet Explorer uses ActiveX.

There is an open source project called Firebreath which makes it really easy to write cross-platform browser plugins which work on both NPAPI and ActiveX hosts.

http://www.firebreath.org

Sign up to request clarification or add additional context in comments.

Comments

2

Take a look at WebKit/Qt (assuming you are interested in writing a browser that exports additional features to the JavaScript - special hardware-related API and the likes)

1 Comment

+1 Very good answer. That's the first thing that popped into my head too.
2

You can invoke any c++ function after compiling it into dll using javascript by extending Activex Object

like

var myNativeObj= new ActiveXObject("foo.dll");

myNativeObj.someMethod();//Some Method is defined in class

but this is restricted to Internet Explorer browser alone.

2 Comments

then how to compile a class to dll, please give a step to step example or a link to better tutorial. Its first time I'm working with this kind.. Thanks in advance..
If you are using VisualC++ you have options creating for DLL within the IDE.
1

You can write browser extension and use it from javascript code.

NPAPI in Chrome, NPAPI in Mozilla/Firefox

Comments

0

In IE, you can use ActiveX.
In Firefox, you can use js-ctypes: https://wiki.mozilla.org/Jsctypes/api
In Chrome, I'm not sure, V8 maybe have a support.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.