从 Javascript 调用 DLL 方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11517319/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 06:08:42  来源:igfitidea点击:

Call DLL methods from Javascript

javascriptdll

提问by Prasad Jadhav

I want to call a methods of a dll from javascript.

我想从 javascript 调用 dll 的方法。

I followed this article Creating activex objects with c#

我跟着这篇文章Creating activex objects with c#

Since activeX works in IE only, how should I be able to call those methods from javascript in FireFox or Chrome?

由于 activeX 仅适用于 IE,我应该如何在 FireFox 或 Chrome 中从 javascript 调用这些方法?

I am already having an application which uses ActiveX object to call Dll Methods, but it works in IE only.

我已经有一个使用 ActiveX 对象来调用 Dll 方法的应用程序,但它仅适用于 IE。

Is there any possible way that will make my application browser Independent?

有什么可能的方法可以使我的应用程序浏览器独立?

UPDATED

更新

I used Jquery async AJAX and webservice to call dll methods:

我使用 Jquery async AJAX 和 webservice 来调用 dll 方法:

var to_return = $.ajax({
         type: "POST",
         url: "Default.aspx/CallMe", //CallMe is WebService method
         data: "{}", // parameter to pass
         async: false,
         contentType: "application/json; charset=utf-8",
         dataType: "json",
     });

     alert(to_return.responseText);

If CallMe()returns a string it is alerting it as {"d":"True"}where "True" is the string returned from CallMe.

如果CallMe()返回一个字符串,它会以{"d":"True"} 的形式警告它,其中 "True" 是从 CallMe 返回的字符串。

How will I able to get only returned string from it?

我如何才能从中获取仅返回的字符串?

Also, if CallMe()method of webservice returns an Object of a class present in that DLL? How can I retrieve that object in JavaScript? and Will I be able to call methods of that class using that returned object?

此外,如果Web 服务的CallMe()方法返回该 DLL 中存在的类的对象?如何在 JavaScript 中检索该对象?我是否能够使用返回的对象调用该类的方法?

Please Help.

请帮忙。

采纳答案by VitaliyG

You can't just execute a dll method in browser (this is done for security reasons).
In order to execute some compiled code in browser you will have to use a plugin

您不能只在浏览器中执行 dll 方法(这是出于安全原因)。
为了在浏览器中执行一些编译的代码,你必须使用一个插件

ActiveX is just a method of implementing browser plugin in IE. All other browsers use different plugin interfaces.
Then if user will install your plugin in browser - this plugin will be available from JS and you can use it to execute some function in dll.

ActiveX 只是在 IE 中实现浏览器插件的一种方法。所有其他浏览器使用不同的插件接口。
然后,如果用户将您的插件安装在浏览器中 - 该插件将从 JS 中获得,您可以使用它在 dll 中执行某些功能。

回答by Nirmal

something like this should work :

这样的事情应该工作:

var obj = new ActiveXObject("ABCDll.testMethod");
var vResult = obj.TestMethod();
alert(vResult);

:: update ::

:: 更新 ::

check hazerd's answer from this link.

从这个链接检查哈泽德的回答。