Skip to content

Commit

Permalink
move macros to main API module; improved comments
Browse files Browse the repository at this point in the history
  • Loading branch information
schisamo committed Dec 13, 2011
1 parent 54f81af commit ebf96b5
Showing 1 changed file with 9 additions and 44 deletions.
53 changes: 9 additions & 44 deletions chef/lib/chef/win32/api/error.rb
Expand Up @@ -22,9 +22,12 @@ class Chef
module Win32
module API
module Error

extend Chef::Win32::API

###############################################
# Win32 API Constants
###############################################

S_OK = 0
NO_ERROR = 0
ERROR_SUCCESS = 0
Expand Down Expand Up @@ -870,51 +873,12 @@ module Error
SEM_NOGPFAULTERRORBOX = 0x0002
SEM_NOOPENFILEERRORBOX = 0x8000

def IS_ERROR(status)
status >> 31 == 1
end

def MAKE_HRESULT(sev, fac, code)
sev << 31 | fac << 16 | code
end

def MAKE_SCODE(sev, fac, code)
sev << 31 | fac << 16 | code
end

def HRESULT_CODE(hr)
hr & 0xFFFF
end

def HRESULT_FACILITY(hr)
(hr >> 16) & 0x1fff
end
###############################################
# Win32 API Bindings
###############################################

def HRESULT_FROM_NT(x)
x | 0x10000000 # FACILITY_NT_BIT
end
ffi_lib 'kernel32', 'user32'

def HRESULT_FROM_WIN32(x)
if x <= 0
x
else
(x & 0x0000FFFF) | (7 << 16) | 0x80000000
end
end

def HRESULT_SEVERITY(hr)
(hr >> 31) & 0x1
end

def FAILED(status)
status < 0
end

def SUCCEEDED(status)
status >= 0
end

# Functions
=begin
DWORD WINAPI FormatMessage(
__in DWORD dwFlags,
Expand Down Expand Up @@ -950,6 +914,7 @@ def SUCCEEDED(status)
);
=end
attach_function :SetErrorMode, [:UINT], :UINT

end
end
end
Expand Down

0 comments on commit ebf96b5

Please sign in to comment.