开发者

Running C/C++ code in a webbrowser?

I'm new to webdevelopment and I am looking for some tutorials or resources about how to run C++ code in a browser. I soon going to do a degree project which implements a sound service in a browser (like flash I guess) using a provided DLL + my own program, so I'm looking for some starters on where to look.

I don't have alot of webdevelopment exp开发者_如何转开发erience but I do have a programming background C/C++.

Cheers


In almost all normal cases you would not want to have C++ code running in your web browser. Running C++ code is in most cases akin to giving full control of your computer to the running code. It can basically do anything, from installing viruses to deleting everything on your hard drive. This is something you would not want to allow any random website you visit to do.

With that being said, there are a few options to do this is a so called "secured" way. One way that only works on Microsoft Internet Explorer is using ActiveX controls. Here's a page where you can start to learn about it.
Another option, that only works in google chrome at the moment is using Google's native client (NaCl). Here's where you can start to learn about this option.
If you want to do it on firefox, you'll need the user to install an addin. Here's a good starting page for this option.

Normal web development uses Javascript instead of C++ to allow for programmability in web pages.


emscriptem will allow you to translate C/C++ into Javascript via LLVM.

According to that page

Emscripten is an LLVM-to-JavaScript compiler. It takes LLVM bitcode (which can be generated from C/C++, using llvm-gcc or clang, or any other language that can be converted into LLVM) and compiles that into JavaScript, which can be run on the web (or anywhere else JavaScript can run).


I think the browser should be used for HTML and JavaScript and that using C++ in a browser is not a good idea (just to have said it.)

If you want to run C/C++ code then you have to create a plugin. But plugins will be architecture/browser dependent and may not even be allowed on all platforms (iPhone/iPad). There are also secturity issues to deal with.

There are some toolkits for running C++ in a browser.

  • For Windows you can use ActiveX controls and they can be written in C++ (ATL).
  • Google has a Native client for running C++ on the client.


Using C++ in browsers is currently limited to browser plugins.

Microsoft Internet Explorer uses ActiveX and all the other browser vendors use NPAPI.

Googles Native Client is a sandbox that will need to eventually be a plugin in browsers other than Chrome.

I highly recommend that you take a look at the firebreath project for creating a plugin for both ActiveX and NPAPI.

There are not many cases for creating plugins other than visualizers for proprietary file formats or creating games that require accelerated graphics.


Depending on exactly what you're trying to do, you may be able to get some use out of Adobe's Flash Alchemy - http://labs.adobe.com/technologies/alchemy/ - which allows you to offload processing to pre-compiled C++ code. I think that's probably as close as you're going to get, though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜