更新时间:2022-05-14 04:14:11
与其使用Win32API
(我相信它是基于晦涩且很少使用的DL
模块构建的),不如使用Win32API
新的和改进的FFI
模块.
Instead of using Win32API
(which I believe is built on top of the obscure and little used DL
module), you might find better mileage using the new and improved FFI
module.
方法如下:
(1)获取ffi:gem install ffi
(1) Get ffi:gem install ffi
(2)然后尝试以下方法:
(2) Then try this:
require 'ffi'
module Win32
extend FFI::Library
ffi_lib 'user32'
attach_function :messageBox,
:MessageBoxA,[ :pointer, :string, :string, :long ], :int
end
rc = Win32.messageBox(nil, "Hello Ruby user!", "FFI is easy", 0x40)
puts rc
这似乎比您在编辑中发布的解决方案容易.
This seems easier than the solution you posted in your edit.
注意:用空指针代替Hwnd会使消息框没有所有者窗口.
Note: The null pointer instead of Hwnd makes the message box have no owner window.
FFI
代替Win32API FFI
instead of Win32API