Class: NPGRT::Win32API::API
- Inherits:
-
Object
- Object
- NPGRT::Win32API::API
- Defined in:
- lib/npgrt/win32api.rb
Instance Method Summary collapse
- #call(*args) ⇒ Object
- #findapi(dll, func, param, ret) ⇒ Object
- #guess(args) ⇒ Object
-
#initialize(dll, func, param = nil, ret = "L") ⇒ API
constructor
A new instance of API.
- #inspect ⇒ Object
Constructor Details
#initialize(dll, func, param = nil, ret = "L") ⇒ API
Returns a new instance of API.
7 8 9 |
# File 'lib/npgrt/win32api.rb', line 7 def initialize(dll, func, param = nil, ret = "L") @dll, @func, @param, @ret = dll, func, param, ret end |
Instance Method Details
#call(*args) ⇒ Object
27 28 29 30 31 |
# File 'lib/npgrt/win32api.rb', line 27 def call(*args) param = @param || guess(args) @api ||= findapi(@dll, @func, param, @ret) @api.call(*args) end |
#findapi(dll, func, param, ret) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/npgrt/win32api.rb', line 11 def findapi(dll, func, param, ret) [dll, File.basename(dll) + "_" + NPGRT::PlatformWidth.to_s + File.extname(dll)].each{|d| [func, func + "A", func + "W"].each{|f| if (a = begin W.new(d, f, param, ret) rescue LoadError, RuntimeError nil end ) return a end } } raise Errno::ENOENT, " NPGRT::API: Can't find a proper DLL for #{dll}!#{func}" end |
#guess(args) ⇒ Object
37 38 39 |
# File 'lib/npgrt/win32api.rb', line 37 def guess(args) args.map{|x| Integer === x ? "L" : "p"} end |
#inspect ⇒ Object
33 34 35 |
# File 'lib/npgrt/win32api.rb', line 33 def inspect "#<API #{@dll}!#{@func} takes #{@param || '<auto>'} returns #{@ret}>" end |