Class: VirtualBox::COM::XPCOMC::VBox

Inherits:
FFI::Struct
  • Object
show all
Defined in:
lib/virtualbox/com/xpcomc-ffi/xpcomc-vbox.rb

Instance Method Summary collapse

Instance Method Details

#binary_to_string(pointer, size) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/virtualbox/com/xpcomc-ffi/xpcomc-vbox.rb', line 42

def binary_to_string(pointer, size)
    return nil if pointer.null?
    return ''  if size == 0
    pointer.read_bytes(size)
ensure
    self[:pfnComUnallocMem].call(pointer) if !pointer.null?
end

#free(pointer) ⇒ Object



37
38
39
40
# File 'lib/virtualbox/com/xpcomc-ffi/xpcomc-vbox.rb', line 37

def free(pointer)
    return if pointer.nil? || pointer.null?
    self[:pfnComUnallocMem].call(pointer)
end

#string_to_utf16(string) ⇒ Object



50
51
52
53
54
55
# File 'lib/virtualbox/com/xpcomc-ffi/xpcomc-vbox.rb', line 50

def string_to_utf16(string)
    return nil if string.nil?
    ptr = ::FFI::MemoryPointer.new(:pointer)
    self[:pfnUtf8ToUtf16].call(string.dup, ptr)
    ptr.read_pointer()
end

#utf16_to_string(pointer) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'lib/virtualbox/com/xpcomc-ffi/xpcomc-vbox.rb', line 57

def utf16_to_string(pointer)
    return nil if pointer.null?
    result_pointer = ::FFI::MemoryPointer.new(:pointer)
    self[:pfnUtf16ToUtf8].call(pointer, result_pointer)
    result_pointer.read_pointer().read_string()
ensure
    self[:pfnUtf16Free].call(pointer       ) if !pointer.null?
    self[:pfnUtf8Free ].call(result_pointer) if !result_pointer.null?
end