Module: WindowsCOM::COMVtbl_

Defined in:
lib/windows_com/common.rb

Class Method Summary collapse

Class Method Details

.[](parent_vtbl, spec) ⇒ Object



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/windows_com/common.rb', line 154

def self.[](parent_vtbl, spec)
=begin
  IUnknown::Vtbl::Spec example (*this* ptr is NOT included in spec signature):

  {
QueryInterface: [[:pointer, :pointer], :long],
AddRef: [[], :ulong],
Release: [[], :ulong]
  }
=end

  Class.new(FFI::Struct) {
    const_set :ParentVtbl, parent_vtbl

    const_set :Spec, {}
    self::Spec.merge!(self::ParentVtbl::Spec) if self::ParentVtbl
    self::Spec.merge!(spec)

    layout_args = self::Spec.map { |name, sig|
      params, ret = sig
      ffi_params = [:pointer, *params] # prepend *this* ptr to FFI func signature


      [name, callback(ffi_params, ret)]
    }
    layout_args.flatten!
    layout(*layout_args)
  }
end