Module: Puppet::Util::Windows::COM::Instance

Defined in:
lib/puppet/util/windows/com.rb

Class Method Summary collapse

Class Method Details

.[](iface) ⇒ Object



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/puppet/util/windows/com.rb', line 128

def self.[](iface)
  Class.new(iface) do
    send(:include, Helpers)

    def initialize(pointer)
      self.pointer = pointer

      @vtbl = self.class::VTBL.new(self[:lpVtbl])
    end

    attr_reader :vtbl

    self::VTBL.members.each do |name|
      define_method(name) do |*args|
        if Puppet::Util::Windows::COM.FAILED(result = @vtbl[name].call(self, *args))
          raise Puppet::Util::Windows::Error.new(_("Failed to call %{klass}::%{name} with HRESULT: %{result}.") % { klass: self, name: name, result: result }, result)
        end
        result
      end
    end

    layout \
      :lpVtbl, :pointer
  end
end