Call DLL methods from Javascript

2019-01-25 18:14发布

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

I followed this article 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?

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

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

UPDATED

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

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.

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?

Please Help.

2条回答
放荡不羁爱自由
2楼-- · 2019-01-25 18:23

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

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.

查看更多
等我变得足够好
3楼-- · 2019-01-25 18:39

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.

查看更多
登录 后发表回答