user740316
user740316

Reputation:

How to call a Windows DLL from within Ruby?

What is the easiest way to use a custom DLL from within Ruby ?

In Python I would use ctypes, just as described as in this example. But now how should I do it in Ruby, preferably using native functionalities over third party libs ? Is there any way Ruby can be as simple as Python for manipulating a DLL ?

Thank you o/

Upvotes: 4

Views: 5827

Answers (2)

Assad Ebrahim
Assad Ebrahim

Reputation: 6361

Try Ruby's FFI module.

Two examples to get you started:

  1. Calling a C function from a DLL that returns a pointer to a string

  2. Calling a Win32 function from within Ruby

The older DL module seems to be less used and not as easy.

Upvotes: 2

matt
matt

Reputation: 79723

Have a look at the dl module in the standard library. It’s not brilliantly documented, but the example there should point you in the right direction.

Ruby used to have a Win32API module for use in Windows, but that has been deprecated now so you should just use dl directly.

Upvotes: 0

Related Questions