我如何在Ruby中调用Windows DLL函数? [英] How do I call Windows DLL functions from Ruby?

查看:460
本文介绍了我如何在Ruby中调用Windows DLL函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Ruby DLL中使用的功能。我想用C的低级别的访问,同时仍保留编写Ruby code的简单性。我如何做到这一点?

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?

推荐答案

看一看 的Win32API STDLIB。这是一个相当简单的(但晦涩难懂)接口到Windows 32 API,或DLL。

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

文档是这里,有的<一个href=\"http://www.rubytips.org/2008/05/13/accessing-windows-api-from-ruby-using-win32api-library/\">examples这里。为了给你一个味道:

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 

这篇关于我如何在Ruby中调用Windows DLL函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆