Method: Win::Gui::Window.return_string
- Defined in:
- lib/win/gui/window.rb
.return_string(encode = nil) ⇒ Object
Helper method that creates def_block returning (possibly encoded) string as a result of api function call or nil if zero characters was returned by api call
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/win/gui/window.rb', line 85 def return_string( encode = nil ) #:nodoc: lambda do |api, *args| namespace.enforce_count( args, api.prototype, -2) buffer = FFI::MemoryPointer.new :char, 1024 args += [buffer, buffer.size] num_chars = api.call(*args) return nil if num_chars == 0 if encode string = buffer.get_bytes(0, num_chars*2) string = string.force_encoding('utf-16LE').encode(encode) else string = buffer.get_bytes(0, num_chars) end string.rstrip end end |