Module: PDK::Util::Windows::File

Extended by:
FFI::Library, String
Defined in:
lib/pdk/util/windows.rb,
lib/pdk/util/windows/file.rb

Class Method Summary collapse

Methods included from FFI::Library

attach_function_private

Methods included from String

wide_string

Class Method Details

.get_long_pathname(path) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/pdk/util/windows/file.rb', line 11

def get_long_pathname(path)
  converted = ''
  FFI::Pointer.from_string_to_wide_string(path) do |path_ptr|
    # includes terminating NULL
    buffer_size = GetLongPathNameW(path_ptr, FFI::Pointer::NULL, 0)
    FFI::MemoryPointer.new(:wchar, buffer_size) do |converted_ptr|
      raise 'Failed to call GetLongPathName' if GetLongPathNameW(path_ptr, converted_ptr, buffer_size) == PDK::Util::Windows::WIN32_FALSE

      converted = converted_ptr.read_wide_string(buffer_size - 1)
    end
  end

  converted
end