Method: FFI::Pointer#read_wide_string

Defined in:
lib/pdk/util/windows/api_types.rb

#read_wide_string(char_length, dst_encoding = Encoding::UTF_8, encode_options = {}) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/pdk/util/windows/api_types.rb', line 32

def read_wide_string(char_length, dst_encoding = Encoding::UTF_8, encode_options = {})
  # char_length is number of wide chars (typically excluding NULLs), *not* bytes
  str = get_bytes(0, char_length * 2).force_encoding('UTF-16LE')
  str.encode(dst_encoding, str.encoding, **encode_options)
rescue StandardError => e
  PDK.logger.debug format('Unable to convert value %{string} to encoding %{encoding} due to %{error}', string: str.dump, encoding: dst_encoding, error: e.inspect)
  raise
end