Class: Win32::LastErrorInfo

Inherits:
Object
  • Object
show all
Includes:
APIMapper
Defined in:
lib/Win32/Base.rb

Overview



This class is used to collect Win32 Last Error

Constant Summary collapse

FORMAT_MESSAGE_ALLOCATE_BUFFER =

constsFor: “Message Formats” (from WinBase.h)

0x00000100
FORMAT_MESSAGE_IGNORE_INSERTS =
0x00000200
FORMAT_MESSAGE_FROM_STRING =
0x00000400
FORMAT_MESSAGE_FROM_HMODULE =
0x00000800
FORMAT_MESSAGE_FROM_SYSTEM =
0x00001000
FORMAT_MESSAGE_ARGUMENT_ARRAY =
0x00002000
FORMAT_MESSAGE_MAX_WIDTH_MASK =
0x000000FF

Constants included from APIMapper

APIMapper::DLL, APIMapper::HANDLE, APIMapper::IN, APIMapper::NAME, APIMapper::OUT

Instance Method Summary collapse

Methods included from APIMapper

Initialize, #WCall, WCall

Constructor Details

#initialize(p_nErrorCode = nil) ⇒ LastErrorInfo


class methodsFor: “initialization”



163
164
165
166
# File 'lib/Win32/Base.rb', line 163

def initialize(p_nErrorCode = nil)
	@err = p_nErrorCode
	@err.nil? ? get() : set(p_nErrorCode)
end

Instance Method Details

#get(p_bSync = true) ⇒ Object



174
175
176
# File 'lib/Win32/Base.rb', line 174

def get(p_bSync = true)
	return p_bSync ? (@err = WCall('GetLastError')) : @err
end

#set(p_err, p_bSync = true) ⇒ Object



178
179
180
181
# File 'lib/Win32/Base.rb', line 178

def set(p_err, p_bSync = true)
	@err = p_err
	WCall('SetLastError', p_err) if p_bSync
end

#textObject



183
184
185
186
187
188
189
# File 'lib/Win32/Base.rb', line 183

def text
	pBuffer = " " * 1024		# buffer
	ret = WCall('FormatMessage',
				FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
				0, @err, LangID.new.to_i, pBuffer, 1024, 0)
	return pBuffer[0, (ret - 2) * 2].to_utf8		# we don't need the \r\n at the end
end

#to_iObject


methodsFor: “accessing”



170
171
172
# File 'lib/Win32/Base.rb', line 170

def to_i
	return @err
end

#to_sObject


methodsFor: “printing”



193
194
195
196
# File 'lib/Win32/Base.rb', line 193

def to_s
	get() if @err.nil?
	return "Win32 Error: #{@err}, " + text()
end