Module: Windows::Helper

Extended by:
FFI::Library
Included in:
Win32::TaskScheduler
Defined in:
lib/win32/windows/helper.rb

Constant Summary collapse

FORMAT_MESSAGE_IGNORE_INSERTS =
0x00000200
FORMAT_MESSAGE_FROM_SYSTEM =
0x00001000
FORMAT_MESSAGE_MAX_WIDTH_MASK =
0x000000FF

Instance Method Summary collapse

Instance Method Details

#ole_error(function, err) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/win32/windows/helper.rb', line 30

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
    msg
  end
end

#win_error(function, err = FFI.errno) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/win32/windows/helper.rb', line 16

def win_error(function, err=FFI.errno)
  buf = FFI::MemoryPointer.new(:char, 1024)

  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.
  len = FormatMessage(flags, nil, err , 0x0409, buf, buf.size, nil)

  function + ': ' + buf.read_string(len).strip
end