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

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

问题描述

我想使用Ruby访问DLL中的函数。我想使用C的低级访问,同时仍然保留编写Ruby代码的简单性。如何实现这一点?

解决方案

看看 Win32API stdlib。对于Windows 32 API或DLL,这是一个非常简单(但又是奥术)的界面。



文档在这里,一些这里的例子。给你一个口味:

 需要Win32API
def get_computer_name
name =* 128
size =128
Win32API.new('kernel32','GetComputerName',['P','P'],'I')call(name,size)
name.unpack(A *)
end


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?

解决方案

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:

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天全站免登陆