从JavaScript调用C ++ dll [英] Calling C++ dlls from JavaScript

查看:134
本文介绍了从JavaScript调用C ++ dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要求,我需要开发一个HTML连接到任何网络的应用程序。在这个HTML页面中,我需要显示一些系统特定的信息,如BIOS信息或电池信息等。对于这些,我们有用C和C ++编写的逻辑。



这里我需要与这些dll进行通信并在HTML页面中显示。有没有办法使用Javascript调用C ++ dll。如果是,请提供工作示例代码。

I have a requirement, that I need to develop an application in HTML with out connected to any of network. In this HTML page I need to display some system specific information like BIOS info or Battery Info.. etc. For these we have logic written in C and C++.

Here I need to communicate with these dlls and display in HTML page. Is there any way to call C++ dlls using Javascript. If yes, please provide working sample code.

推荐答案

不要试图逃避浏览器的沙箱来调用本机代码。实现一个像web服务器一样工作的应用程序 - 你可以直接使用C ++代码。



虽然使用起来很痛苦但我建议使用WT作为好看的地方。它使用QT样式的对象模型并生成相当可移植的网页。
Don't fart about trying to escape the browser's sandbox to call native code. Implement an app that works like a web-server - you can use the C++ code directly then.

While it can be pain to use I'd suggest WT as a good place to look. It uses a QT style object model and generates fairly portable web pages.


你不能这样做。这是出于明显的安全原因而设置的:由Web浏览器托管的JavaScript不应该被授予对客户端系统的访问权限,并且使用这种功能将打开恶意Web应用程序入侵客户端系统的大门。



有一个脏的解决方法:通过使用ActiveX组件。但我强烈反对在这方面采取任何措施。首先,它会破坏我上面描述的安全机制。许多精通计算机的用户如果得知您尝试在浏览器中使用DirectX,就会将您的网站列入黑名单。此外,此功能不适用于所有浏览器和系统。它主要是IE和Microsoft OS的功能。



尽管如此,仍然使用这种基于ActiveX的方法。我通常只在两种情况下面对它:1)在企业网络中用作企业技术的一部分;对我来说,这已经是一个坏公司的症状和不安全的方法,尽管有内联网安全的假象; 2)由名牌计算机制造商用于远程计算机诊断和服务;但这是唯一可能的,因为一旦他们购买了预装了操作系统和其他软件的计算机,计算机买家就会对这些品牌公司产生信任。



如您所见,您的结论应该是:ActiveX不是一种选择。该怎么办?如果你解释你的最终目标,也许你可以获得和建议;为什么你认为你想要的系统信息应该是基于Web或浏览器的...



-SA
You cannot do it. This is set this way by apparent security reason: JavaScript hosted by a Web browser should not be given an access to the client system, and using such capability would open the doors for intrusion of malicious Web applications into clients' systems.

There is one dirty workaround: through the use of an ActiveX component. But I would strongly discourage doing any steps in this directions. First of all, it would break the safety mechanism I described above. Many computer-savvy users would blacklist your site if they learn that you are trying to use DirectX in the browser. Besides, this feature won't work on all browsers and systems. It is mainly the IE and Microsoft OS "feature".

Still, this ActiveX-based approach is used. I usually face it only in two situations: 1) used as a part of corporate technology inside a corporate network; to me, this is already a symptom of a bad company and ill approaches to safety, despite of the illusion of "intranet-only" safety; 2) use by brand-name computer manufacturers for remote computer diagnostics and service; but this is only possible due to the trust computer buyers have to those brand-name companies, once they already purchased a computer with pre-installed OS and other software.

As you can see, your conclusion should be: ActiveX is not an option. What to do? Perhaps you can get and advice if you explain your ultimate goals; why do you think that the system information you want should be Web- or browser-based…

—SA


一些想法......



1.你可以在mozilla中做到这一点,例如。 Firefox。



写一个chrome扩展名(不要与其他chrome混淆)。可信扩展可以通过XPCOM调用本机代码。



https://developer.mozilla.org/en-US/docs/The_Joy_of_XUL [ ^ ]



2.另一种选择是编写一个基本上是嵌入式Web服务器的本机程序(绑定到localhost)以XML格式提供信息。利用所有常用的AJAX技术。部署两个部分 - 一个app作为HTML / CSS / JS和一个服务EXE。嵌入式Web服务器甚至可以提供应用程序内容以进一步简化部署。



C ++嵌入式Web服务器 [ ^ ]
A couple of ideas ...

1. You can do this in mozilla eg. Firefox.

Write a "chrome" extension (not to be confused with that other "chrome"). Trusted extensions can call native code by way of XPCOM.

https://developer.mozilla.org/en-US/docs/The_Joy_of_XUL[^]

2. Another option is to write a native program that is basically an embedded web server (bind to localhost) that offers the information in XML form. Leverages all the usual AJAX techniques. Deploy two parts - an "app" as HTML/CSS/JS and a service EXE. The embedded web server could even serve up the app content to further simplify deployment.

A C++ Embedded Web Server[^]


这篇关于从JavaScript调用C ++ dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆