Module: Puppet::Util::Windows::COM::Factory Private
- Defined in:
- lib/puppet/util/windows/com.rb
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Class Method Summary collapse
- .[](iface, clsid) ⇒ Object private
Class Method Details
.[](iface, clsid) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
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 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/puppet/util/windows/com.rb', line 156 def self.[](iface, clsid) Class.new(iface) do send(:include, Helpers) const_set(:CLSID, clsid) def initialize(opts = {}) @opts = opts @opts[:clsctx] ||= CLSCTX_INPROC_SERVER FFI::MemoryPointer.new(:pointer) do |ppv| hr = Puppet::Util::Windows::COM.CoCreateInstance(self.class::CLSID, FFI::Pointer::NULL, @opts[:clsctx], self.class::IID, ppv) if Puppet::Util::Windows::COM.FAILED(hr) raise _("CoCreateInstance failed (%{klass}).") % { klass: self.class } end self.pointer = ppv.read_pointer end @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 |