Sha256: d29d498483df0f41823391df7c31641aed42d59cb3fc0e5000dd9197005d70e6
Contents?: true
Size: 1.21 KB
Versions: 3
Compression:
Stored size: 1.21 KB
Contents
require 'ffi' module Windows module TaskSchedulerHelper extend FFI::Library FORMAT_MESSAGE_IGNORE_INSERTS = 0x00000200 FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000 FORMAT_MESSAGE_MAX_WIDTH_MASK = 0x000000FF ffi_lib :kernel32 attach_function :FormatMessage, :FormatMessageA, [:ulong, :pointer, :ulong, :ulong, :pointer, :ulong, :pointer], :ulong def win_error(function, err=FFI.errno) err_msg = '' flags = FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_MAX_WIDTH_MASK # 0x0409 == MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US) # We use English for errors because Ruby uses English for errors. FFI::MemoryPointer.new(:char, 1024) do |buf| len = FormatMessage(flags, nil, err , 0x0409, buf, buf.size, nil) err_msg = function + ': ' + buf.read_string(len).strip end err_msg end def ole_error(function, err) regex = /OLE error code:(.*?)\sin/ match = regex.match(err.to_s) if match error = match.captures.first.hex win_error(function, error) else "#{function}: #{err.to_s}" end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
win32-taskscheduler-0.4.1 | lib/win32/windows/helper.rb |
win32-taskscheduler-0.4.0 | lib/win32/windows/helper.rb |
win32-taskscheduler-0.3.2 | lib/win32/windows/helper.rb |