Line | |
---|
1 | # -*- ruby -*-
|
---|
2 |
|
---|
3 | require 'dl'
|
---|
4 |
|
---|
5 | class Win32API
|
---|
6 | DLL = {}
|
---|
7 |
|
---|
8 | def initialize(dllname, func, import, export = "0")
|
---|
9 | prototype = (export + import.to_s).tr("VPpNnLlIi", "0SSI")
|
---|
10 | handle = DLL[dllname] ||= DL::Handle.new(dllname)
|
---|
11 | @sym = handle.sym(func, prototype)
|
---|
12 | end
|
---|
13 |
|
---|
14 | def call(*args)
|
---|
15 | import = @sym.proto.split("", 2)[1]
|
---|
16 | args.each_with_index do |x, i|
|
---|
17 | args[i] = nil if x == 0 and import[i] == ?S
|
---|
18 | args[i], = [x].pack("I").unpack("i") if import[i] == ?I
|
---|
19 | end
|
---|
20 | ret, = @sym.call(*args)
|
---|
21 | return ret || 0
|
---|
22 | end
|
---|
23 |
|
---|
24 | alias Call call
|
---|
25 | end
|
---|
Note:
See
TracBrowser
for help on using the repository browser.