diff --git a/ChangeLog b/ChangeLog index e1b33691ce..5bf46ae7cb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Sat Jan 11 22:50:47 2003 WATANABE Hirofumi + + * ext/dl/lib/dl/win32.rb: compatibility improvement. + Sat Jan 11 01:44:16 2003 Nobuyoshi Nakada * configure.in (RUBY_CHECK_IO_NEED): added more tests. diff --git a/ext/dl/lib/dl/win32.rb b/ext/dl/lib/dl/win32.rb index b507be5fde..f0ea2a91e1 100644 --- a/ext/dl/lib/dl/win32.rb +++ b/ext/dl/lib/dl/win32.rb @@ -3,24 +3,27 @@ require 'dl' class Win32API - LIBRARY = {} + DLL = {} - attr_reader :val, :args - - def initialize(lib, func, args, ret) - LIBRARY[lib] ||= DL.dlopen(lib) - ty = (ret + args).tr('V','0') - @sym = LIBRARY[lib].sym(func, ty) - @__dll__ = LIBRARY[lib].to_i - @__dllname__ = lib - @__proc__ = @sym.to_i - @val = nil - @args = [] + def initialize(dllname, func, import, export = "0") + prototype = (export + import.to_s).tr("VPpNnLlIi", "0SSI") + handle = DLL[dllname] ||= DL::Handle.new(dllname) + begin + @sym = handle.sym(func, prototype) + rescue RuntimeError + @sym = handle.sym(func + "A", prototype) + end end def call(*args) - @val,@args = @sym.call(*args) - return @val + import = @sym.proto[1..-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