mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3370 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
25 lines
564 B
Ruby
25 lines
564 B
Ruby
# -*- ruby -*-
|
|
|
|
require 'dl'
|
|
|
|
class Win32API
|
|
DLL = {}
|
|
|
|
def initialize(dllname, func, import, export = "0")
|
|
prototype = (export + import.to_s).tr("VPpNnLlIi", "0SSI")
|
|
handle = DLL[dllname] ||= DL::Handle.new(dllname)
|
|
@sym = handle.sym(func, prototype)
|
|
end
|
|
|
|
def call(*args)
|
|
import = @sym.proto.split("", 2)[1]
|
|
args.each_with_index do |x, i|
|
|
args[i] = nil if x == 0 and import[i] == ?S
|
|
args[i], = [x].pack("I").unpack("i") if import[i] == ?I
|
|
end
|
|
ret, = @sym.call(*args)
|
|
return ret || 0
|
|
end
|
|
|
|
alias Call call
|
|
end
|