joelmdesouza

joelmdesouza

I need to access the functions of a dll.
Is this possible in Elixir?

Showing Posts 1 to 10

NobbZ

NobbZ

Yes and no.

It will require you a lot of work writing glue-code in C (or Rust using rustler) yourself.

Since small mistakes in the implementation of the gluecode, errors in the glued shared object (or however your OS names them) can bring your complete BEAM-VM down.

Also calling into foreign code and returning the result is not allowed to take longer than a single millisecond to not confuse BEAMs scheduler. There is dirty scheduling available if you compiled erlang yourself and set the correct compileflags, according to rumors dirty scheduling shall be the default in the next major OTP release (mid '17).

If you still want to do this, do a google for “elixir NIF”


Another possibility is to use a C-Port, which would require you to write glue-code as well, but the danger to bring down the VM isn’t that high, also the scheduling problem isn’t in the way anymore. But then you do have the gluecode running in a dedicated BEAM-process which you have to talk to via message passing.


And the last option you have is to create a wrapper CLI tool, which does use the shared object, which you then use as a Port (note the missing C). It is started and owned by a dedicated BEAM-process but then runs outside of the VM. The owning process can send and receive messages from that port. Those messages are strings only (plus some Port-metadata), it would be the same as if you start that CLI-tool by hand and then hack some commands directly into your terminal and read the response but having that terminal managed and hidden by BEAM.

joelmdesouza

joelmdesouza OP

Thank you!

I’ll use other technology on that project then.

Onor.io

Onor.io

You’re assuming he’s dealing with a native DLL. It could be a DotNet assembly too.

NobbZ

NobbZ

Oh damn, I often forget that… It’s been a while that I used something related to CLR.

For those I have to assume that only the CLI/Port will do.

joelmdesouza

joelmdesouza OP

It’s a native dll.

OvermindDL1

OvermindDL1

What does it do and what do you need it for?

joelmdesouza

joelmdesouza OP

It serves to comply with Brazilian legislation.
It serves to communicate with a fiscal apparatus called SAT.

I have a python application that already addresses this need.
But I wanted to create an easier version to distribute.

OvermindDL1

OvermindDL1

If those calls to it cannot fail and they respond quickly then it would be easy to integrate as a NIF, but even using it via a PORT would be very easy (could even talk to your existing python thing if you wanted). :slight_smile:

joelmdesouza

joelmdesouza OP

Would you have any examples that would make this integration as a NIF?
Using some dll that I can test.

OvermindDL1

OvermindDL1

I like using Rustler and the Rustler docs has a good example project, so you can call your DLL from rust then (hmm, I’ve an idea for a generic FFI, perhaps via port… maybe someday). If you want to do it from C then there are tons of examples around for that, the ‘ranch’ project that is a dependency of Phoenix (via cowboy I think?) has a nif built in so you can look at that for one of many examples. :slight_smile:

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews