4

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/

Community
  • 1
  • 1

2 Answers2

2

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.

Community
  • 1
  • 1
Assad Ebrahim
  • 6,234
  • 8
  • 42
  • 68
  • @NNzz: Excellent! No slight to matt, but if you think this is the correct answer ("easiest way to use a DLL from Ruby"), you can deselect the check mark, and then re-apply it. ;) Happy DLL-ing. – Assad Ebrahim Jan 07 '13 at 09:15
0

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.

matt
  • 78,533
  • 8
  • 163
  • 197