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?
相关问题
- Multiple sockets for clients to connect to
- How to know full paths to DLL's from .csproj f
- What is the best way to do a search in a large fil
- Inheritance impossible in Windows Runtime Componen
- glDrawElements only draws half a quad
I think you can also use ruby/dl http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/95a483230caf3d39
or ffi makes it easier and more cross VM friendly:
https://github.com/ffi/ffi/wiki/Windows-Examples
You can use Fiddle: http://ruby-doc.org/stdlib-2.0.0/libdoc/fiddle/rdoc/Fiddle.html
Fiddle is a little-known module that was added to Ruby's standard library in 1.9.x. It allow you to interact directly with C libraries from Ruby.
It works by wrapping libffi, a popular C library that allows code written in one language to call methods written in another. In case you haven't heard of it, "ffi" stands for "foreign function interface." And you're not just limited to C. Once you learn Fiddle, you can use libraries written in Rust and other languages that support it.
http://blog.honeybadger.io/use-any-c-library-from-ruby-via-fiddle-the-ruby-standard-librarys-best-kept-secret/
or
Have a look at
Win32API
stdlib. 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:
There is the win32-api "drop-in replacement for Win32API" by Daniel Berger. However, it appears that it may not stay current, as he has left it to the open source community. It hasn't been updated since 18 March, 2015. It supports up to ruby 2.2 as of this answer.