Module: Fzeet::Windows::COM::Helpers

Defined in:
lib/fzeet/windows/com/Common.rb

Instance Method Summary collapse

Instance Method Details

#QueryInstance(klass) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/fzeet/windows/com/Common.rb', line 124

def QueryInstance(klass)
  instance = nil

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

    instance = klass.new(ppv.read_pointer)
  }

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

  instance
end

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



142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/fzeet/windows/com/Common.rb', line 142

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

  FFI::MemoryPointer.new(:pointer) { |ppv|
    send(name, *args, klass::IID, ppv)

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

  self
ensure
  instance.Release if instance
end