Need to call client side DLL from browser

2019-02-10 16:07发布

问题:

I got requirement from client that when any user swipe their card then their details should be capture in web page automatically on client side. However same we are doing in IE by creating ActiveX control in C#. Card service provider install their DLL on client side and from ActiveX control, we can call their DLL and get details.

But now client want the same operation in multiple browser, i.e. Mozilla Firefox and Chrome, which does not support ActiveX control. Can you please give me an idea how it is possible to call client side DLL method from browser?

回答1:

The only way you could do that would be to use the NPAPI — e.g., a "browser plugin" like the Java plugin. NPAPI plugins have full, unrestricted access to the client machine.

But note that Chrome is dropping support for NPAPI plugins (in fact, already has in Linux and will soon under Windows), so even if you wrote an NPAPI plugin and got people to install it, before long they wouldn't be able to use it in Chrome. Similarly, your ActiveX solution won't work in more modern versions of IE, since IE dropped support for them.

In short: You cannot do this in a modern browser. Instead, you'll need to create a program users download and install. That program could contain a hosted browser control, or you could try to use the OS's application automatic interface (if it has one) to find the browser window and paste the information into it. That would, of course, be different on every OS.



回答2:

I had to do the exact same thing and I've done it using EdgeJS. You can find the answer at Call Function from DLL loaded in front-end javascript (load dll in clientside javascript) .
At first, I used activex for IE. Then, I had to port it to other browsers. The trick is to marshal functions between V8 and CLR and when the event triggers you send the message to javascript.


The dll returns a delegate function as a receive handler. You initialize the dll with the send handler. I haven't found a method to run the dlls from the browser yet as you do with ActiveX.


It might be that, for security reasons, you might not be able to embed and run dlls in clientside javascript.

The solution in the stackoverflow question is a node process that runs on the client computer that has the Swipe Reader. The client application connects to the node process that runs a websocket server and communicates through websocket messages. I think you can port this on every platform (Win, Unix, MacOS).

Another solution is to build a C# application (windows only if you use .NET, all platforms if you only use the CoreCLR) that listens to swipes and triggers an event to send the data on all connected websockets.



回答3:

After gone through some links, it seems it can be possible through following option.

Option 1:

  • Firefox allows you to create XPI extension aka "addon"
  • Chrome has extensions

Calling a .dll function from a html page that runs on chrome and firefox

Option 2:

Create plug-in for those browser are written using the NPAPI.

How to write a browser plugin?

Option 3:

Write signed applets to call dll that runs from a html or any web application. It almost run on all browsers. Here is the link for sample

http://www.javaworld.com/javaworld/jw-10-1998/jw-10-apptowin32.html