1

我是 Ruby 新手,我一直试图让这段代码调用 MessageBox,但不能。我知道我错过了一些东西,但我不知道它是什么。对此的任何帮助将不胜感激!

这是到目前为止的代码:

require 'Win32API'

LoadLibrary = Win32API.new('kernel32','LoadLibrary','P','L')
GetProcAddress = Win32API.new('kernel32','GetProcAddress','LP','L')

Load = LoadLibrary.call('user32.dll')
Proc = GetProcAddress.call(Load,'MessageBox')

Proc.call(0,"Hello World!","MessageBox in Ruby",0)

我知道一切都很好,除了我的“Proc.call”。我错过了什么?

4

1 回答 1

0

这是您看到的错误吗?

undefined method `call' for 0:Fixnum (NoMethodError)

我认为没有必要为此使用GetProcAddress。下面是一些显示消息框的示例代码:

require 'Win32API'

msgbox = Win32API.new('user32','MessageBox',['L', 'P', 'P', 'L'], 'I')  
msgbox.call(0, 'Hello World!', 'MessageBox in Ruby', 0)

在您当前的代码中是来自而不是可调用对象Proc的返回值。GetProcAddress我怀疑这是0因为调用GetProcAddress失败了。

于 2012-09-18T13:11:28.627 回答