tags:

views:

1071

answers:

2

I want to access functions within a DLL using Ruby. I want to use the low-level access of C while still retaining the simplicity of writing Ruby code. How do I accomplish this?

+3  A: 

Have a look at Win32API. It's a fairly easy (but arcane) interface to the Windows 32 API, or DLLs.

Documentation is here, some examples here. To give you a taste:

require "Win32API"    
def get_computer_name
  name = " " * 128
  size = "128"
  Win32API.new('kernel32', 'GetComputerName', ['P', 'P'], 'I').call(name, size)  
  name.unpack("A*")  
end
molf
It works quite good, unless your DLL has parameters that Win32API can't handle (like doubles). Then you'll enter the Array.unpack nightmare
SztupY