summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authoreban <eban@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-01-11 15:00:56 +0000
committereban <eban@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-01-11 15:00:56 +0000
commit3074716cadfffd28432f5bb6a6eef4762555efb8 (patch)
tree20ea98978a994e8bccc3c474ca9d6baf7f62ff88 /ext
parentd15f5e8d55834b229f9426fa01e8a6d758baf117 (diff)
* ext/dl/lib/dl/win32.rb: compatibility improvement.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3330 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/dl/lib/dl/win32.rb31
1 files changed, 17 insertions, 14 deletions
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