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
2009-06-22 00:09:30
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
2009-06-22 00:41:05
A:
I think you can use ruby/dl http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/95a483230caf3d39
rogerdpack
2009-06-22 17:35:02