Module: Puppet::Util::Windows::COM::Helpers

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

Instance Method Summary collapse

Instance Method Details

#QueryInstance(klass) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/puppet/util/windows/com.rb', line 92

def QueryInstance(klass)
  instance = nil

  FFI::MemoryPointer.new(:pointer) do |ppv|
    QueryInterface(klass::IID, ppv)

    instance = klass.new(ppv.read_pointer)
  end

  begin
    yield instance
    return self
  ensure
    instance.Release
  end if block_given?

  instance
end

#UseInstance(klass, name, *args) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/puppet/util/windows/com.rb', line 111

def UseInstance(klass, name, *args)
  instance = nil

  FFI::MemoryPointer.new(:pointer) do |ppv|
    send(name, *args, ppv)

    yield instance = klass.new(ppv.read_pointer)
  end

  self
ensure
  instance.Release if instance && ! instance.null?
end