def self.format_error_code(code)
dwLanguageId = 0
flags = FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_ARGUMENT_ARRAY |
FORMAT_MESSAGE_IGNORE_INSERTS |
FORMAT_MESSAGE_MAX_WIDTH_MASK
error_string = ''
FFI::MemoryPointer.new(:pointer, 1) do |buffer_ptr|
length = FormatMessageW(flags, FFI::Pointer::NULL, code, dwLanguageId,
buffer_ptr, 0, FFI::Pointer::NULL)
if length == Facter::Util::Windows::FFI::WIN32_FALSE
raise Facter::Error.new("FormatMessageW could not format code #{code}")
end
Facter::Util::Windows::FFI.read_win32_local_pointer(buffer_ptr) do |wide_string_ptr|
if wide_string_ptr.null?
raise Facter::Error.new("FormatMessageW failed to allocate buffer for code #{code}")
end
error_string = Facter::Util::Windows::FFI.read_wide_string(wide_string_ptr, length)
end
end
error_string
end