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

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

问题描述

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

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 标准库.这是 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.

文档在这里,一些此处的示例.给你尝尝:

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