Call C# DLL

Sarah 161 Reputation points
2022-03-18T10:18:02.797+00:00

I need to call C# DLL.

1) I saw on one of the forums that we can use DLLExport in c# and use 'require' to import the DLL in NodeJS. I tried the same for my React app. But get error "require is not defined and have trouble resolving it for ReactJS. Please find the below link that I used as reference to make use of DLLExport and require.
https://www.youtube.com/watch?v=pN5NXDtOuek

2) I noticed in the below forum that EdgeJS can be used as a bridge between NodeJS V8 and C# CLR. But haven't tried yet.
https://stackoverflow.com/questions/34791334/call-function-from-dll-loaded-in-front-end-javascript-load-dll-in-clientside-ja

Now, I wonder if I am using the right approach. Can NodeJS samples be used as reference to make React call DLL, as NodeJS is server side.
If it cant be done, would you mind explaining me why?

I would appreciate any pointers on this. Thank you.

Developer technologies | Windows Presentation Foundation
Developer technologies | ASP.NET | Other
Developer technologies | C#
0 comments No comments
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 77,926 Reputation points Volunteer Moderator
    2022-03-18T15:09:35.577+00:00

    Only JavaScript being run by node, not the browser can call a dll. Browsers security will not all allow calling a dll. Node programs can call a dll, because it has support for JavaScript to call c/c++ code.

    Browser JavaScript can call code compiled to WASM. But WASM runs in a stand box and does not have access to printers, files or network.

    You can host the dll on the server, and call it to get the image. Or there are several JavaScript libraries to create a QR code in a canvas, from which the browser will print. This is the most common approach for printing QR codes. But label printers are a challenge.

    Your final option is to write a browser extension. that is installed.

    https://developer.chrome.com/docs/extensions/

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.