Class: MiniTerm::Win32API

Inherits:
Object
  • Object
show all
Defined in:
lib/mini_term/windows/win_32_api.rb

Overview

The classic Win32API gem is deprecated, so we emulate it with fiddle.

Constant Summary collapse

DLL =
{}
TYPES =
{"0" => Fiddle::TYPE_VOID,
"S" => Fiddle::TYPE_VOIDP,
"I" => Fiddle::TYPE_LONG}

Instance Method Summary collapse

Constructor Details

#initialize(dll_name, func, import, export = "0", _ct = nil) ⇒ Win32API



16
17
18
19
20
# File 'lib/mini_term/windows/win_32_api.rb', line 16

def initialize(dll_name, func, import, export = "0", _ct = nil)
  @proto = import.join.tr("VPpNnLlIi", "0SSI").chomp('0').split('')
  handle = DLL[dll_name] ||= Fiddle.dlopen(dll_name)
  @func = Fiddle::Function.new(handle[func], TYPES.values_at(*@proto), 1)
end

Instance Method Details

#call(*args) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/mini_term/windows/win_32_api.rb', line 22

def call(*args)
  args.each_with_index do |x, i|
    if @proto[i] == "S"
      args[i] = [x == 0 ? nil : x].pack("p").unpack("l!*")[0]
    end
  end

  @func.call(*args).to_i
end