summaryrefslogtreecommitdiff
path: root/ext/win32/lib/Win32API.rb
diff options
context:
space:
mode:
Diffstat (limited to 'ext/win32/lib/Win32API.rb')
-rw-r--r--ext/win32/lib/Win32API.rb18
1 files changed, 12 insertions, 6 deletions
diff --git a/ext/win32/lib/Win32API.rb b/ext/win32/lib/Win32API.rb
index 4d7d488..24b33f1 100644
--- a/ext/win32/lib/Win32API.rb
+++ b/ext/win32/lib/Win32API.rb
@@ -2,18 +2,24 @@
# for backward compatibility
warn "Warning:#{caller[0].sub(/:in `.*'\z/, '')}: Win32API is deprecated after Ruby 1.9.1; use dl directly instead" if $VERBOSE
-require 'dl'
+require 'fiddle'
class Win32API
DLL = {}
- TYPEMAP = {"0" => DL::TYPE_VOID, "S" => DL::TYPE_VOIDP, "I" => DL::TYPE_LONG}
- POINTER_TYPE = DL::SIZEOF_VOIDP == DL::SIZEOF_LONG_LONG ? 'q*' : 'l!*'
+ TYPEMAP = {"0" => Fiddle::TYPE_VOID, "S" => Fiddle::TYPE_VOIDP, "I" => Fiddle::TYPE_LONG}
+ POINTER_TYPE = Fiddle::SIZEOF_VOIDP == Fiddle::SIZEOF_LONG_LONG ? 'q*' : 'l!*'
def initialize(dllname, func, import, export = "0", calltype = :stdcall)
@proto = [import].join.tr("VPpNnLlIi", "0SSI").sub(/^(.)0*$/, '\1')
- handle = DLL[dllname] ||= DL.dlopen(dllname)
- @func = DL::CFunc.new(handle[func], TYPEMAP[export.tr("VPpNnLlIi", "0SSI")], func, calltype)
- rescue DL::DLError => e
+ handle = DLL[dllname] ||= Fiddle.dlopen(dllname)
+
+ @func = Fiddle::Function.new(
+ handle[func],
+ import.map { |win_type| TYPEMAP[win_type.tr("VPpNnLlIi", "0SSI")] },
+ TYPEMAP[export.tr("VPpNnLlIi", "0SSI")],
+ Fiddle::Importer::CALL_TYPE_TO_ABI[calltype]
+ )
+ rescue Fiddle::DLError => e
raise LoadError, e.message, e.backtrace
end