windows-pr 0.2.0 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,72 +1,3 @@
1
- #####################################################################
2
- # device_io.rb
3
- #
4
- # Defines the following functions:
5
- #
6
- # DeviceIoControl()
7
- #
8
- # Defines the following constants:
9
- #
10
- # FILE_DEVICE_BEEP = 0x00000001
11
- # FILE_DEVICE_CD_ROM = 0x00000002
12
- # FILE_DEVICE_CD_ROM_FILE_SYSTEM = 0x00000003
13
- # FILE_DEVICE_CONTROLLER = 0x00000004
14
- # FILE_DEVICE_DATALINK = 0x00000005
15
- # FILE_DEVICE_DFS = 0x00000006
16
- # FILE_DEVICE_DISK = 0x00000007
17
- # FILE_DEVICE_DISK_FILE_SYSTEM = 0x00000008
18
- # FILE_DEVICE_FILE_SYSTEM = 0x00000009
19
- # FILE_DEVICE_INPORT_PORT = 0x0000000a
20
- # FILE_DEVICE_KEYBOARD = 0x0000000b
21
- # FILE_DEVICE_MAILSLOT = 0x0000000c
22
- # FILE_DEVICE_MIDI_IN = 0x0000000d
23
- # FILE_DEVICE_MIDI_OUT = 0x0000000e
24
- # FILE_DEVICE_MOUSE = 0x0000000f
25
- # FILE_DEVICE_MULTI_UNC_PROVIDER = 0x00000010
26
- # FILE_DEVICE_NAMED_PIPE = 0x00000011
27
- # FILE_DEVICE_NETWORK = 0x00000012
28
- # FILE_DEVICE_NETWORK_BROWSER = 0x00000013
29
- # FILE_DEVICE_NETWORK_FILE_SYSTEM = 0x00000014
30
- # FILE_DEVICE_NULL = 0x00000015
31
- # FILE_DEVICE_PARALLEL_PORT = 0x00000016
32
- # FILE_DEVICE_PHYSICAL_NETCARD = 0x00000017
33
- # FILE_DEVICE_PRINTER = 0x00000018
34
- # FILE_DEVICE_SCANNER = 0x00000019
35
- # FILE_DEVICE_SERIAL_MOUSE_PORT = 0x0000001a
36
- # FILE_DEVICE_SERIAL_PORT = 0x0000001b
37
- # FILE_DEVICE_SCREEN = 0x0000001c
38
- # FILE_DEVICE_SOUND = 0x0000001d
39
- # FILE_DEVICE_STREAMS = 0x0000001e
40
- # FILE_DEVICE_TAPE = 0x0000001f
41
- # FILE_DEVICE_TAPE_FILE_SYSTEM = 0x00000020
42
- # FILE_DEVICE_TRANSPORT = 0x00000021
43
- # FILE_DEVICE_UNKNOWN = 0x00000022
44
- # FILE_DEVICE_VIDEO = 0x00000023
45
- # FILE_DEVICE_VIRTUAL_DISK = 0x00000024
46
- # FILE_DEVICE_WAVE_IN = 0x00000025
47
- # FILE_DEVICE_WAVE_OUT = 0x00000026
48
- # FILE_DEVICE_8042_PORT = 0x00000027
49
- # FILE_DEVICE_NETWORK_REDIRECTOR = 0x00000028
50
- # FILE_DEVICE_BATTERY = 0x00000029
51
- # FILE_DEVICE_BUS_EXTENDER = 0x0000002a
52
- # FILE_DEVICE_MODEM = 0x0000002b
53
- # FILE_DEVICE_VDM = 0x0000002c
54
- # FILE_DEVICE_MASS_STORAGE = 0x0000002d
55
- # FILE_DEVICE_SMB = 0x0000002e
56
- # FILE_DEVICE_KS = 0x0000002f
57
- # FILE_DEVICE_CHANGER = 0x00000030
58
- # FILE_DEVICE_SMARTCARD = 0x00000031
59
- # FILE_DEVICE_ACPI = 0x00000032
60
- # FILE_DEVICE_DVD = 0x00000033
61
- # FILE_DEVICE_FULLSCREEN_VIDEO = 0x00000034
62
- # FILE_DEVICE_DFS_FILE_SYSTEM = 0x00000035
63
- # FILE_DEVICE_DFS_VOLUME = 0x00000036
64
- # FILE_DEVICE_SERENUM = 0x00000037
65
- # FILE_DEVICE_TERMSRV = 0x00000038
66
- # FILE_DEVICE_KSEC = 0x00000039
67
- # FILE_DEVICE_FIPS = 0x0000003A
68
- # FILE_DEVICE_INFINIBAND = 0x0000003B
69
- #####################################################################
70
1
  require 'Win32API'
71
2
 
72
3
  module Windows
@@ -132,10 +63,26 @@ module Windows
132
63
  FILE_DEVICE_FIPS = 0x0000003A
133
64
  FILE_DEVICE_INFINIBAND = 0x0000003B
134
65
 
66
+ METHOD_BUFFERED = 0
67
+ FILE_ANY_ACCESS = 0
68
+
135
69
  DeviceIoControl = Win32API.new('kernel32', 'DeviceIoControl', 'LLPLPLPP', 'I')
136
70
 
137
71
  def DeviceIoControl(dev, code, in_buf, in_buf_size, out_buf, out_buf_size, bytes, overlapped)
138
- DeviceIoControl.call(dev, code, in_buf, in_buf_size, out_buf, out_buf_size, bytes, overlapped)
72
+ DeviceIoControl.call(dev, code, in_buf, in_buf_size, out_buf, out_buf_size, bytes, overlapped) > 0
73
+ end
74
+
75
+ # Macros from WinIoCtl.h
76
+ def CTL_CODE(device, function, method, access)
77
+ ((device) << 16) | ((access) << 14) | ((function) << 2) | (method)
78
+ end
79
+
80
+ def FSCTL_SET_COMPRESSION
81
+ CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 16, 0, FILE_READ_DATA | FILE_WRITE_DATA)
82
+ end
83
+
84
+ def FSCTL_SET_SPARSE
85
+ CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 49, 0, FILE_SPECIAL_ACCESS)
139
86
  end
140
87
  end
141
88
  end
@@ -0,0 +1,80 @@
1
+ require 'windows/unicode'
2
+
3
+ module Windows
4
+ module Directory
5
+ CreateDirectory = Win32API.new('kernel32', 'CreateDirectory', 'PP', 'I')
6
+ CreateDirectoryW = Win32API.new('kernel32', 'CreateDirectoryW', 'PP', 'I')
7
+ CreateDirectoryEx = Win32API.new('kernel32', 'CreateDirectoryEx', 'PPP', 'I')
8
+ CreateDirectoryExW = Win32API.new('kernel32', 'CreateDirectoryExW', 'PPP', 'I')
9
+ FindCloseChangeNotification = Win32API.new('kernel32', 'FindCloseChangeNotification', 'L', 'I')
10
+ FindFirstChangeNotification = Win32API.new('kernel32', 'FindFirstChangeNotification', 'PIL', 'L')
11
+ FindNextChangeNotification = Win32API.new('kernel32', 'FindFirstChangeNotification', 'PIL', 'I')
12
+ GetCurrentDirectory = Win32API.new('kernel32', 'GetCurrentDirectory', 'LP', 'L')
13
+ GetCurrentDirectoryW = Win32API.new('kernel32', 'GetCurrentDirectoryW', 'LP', 'L')
14
+ ReadDirectoryChangesW = Win32API.new('kernel32', 'ReadDirectoryChangesW', 'LPLILPPP', 'I')
15
+ RemoveDirectory = Win32API.new('kernel32', 'RemoveDirectory', 'P', 'I')
16
+ RemoveDirectoryW = Win32API.new('kernel32', 'RemoveDirectoryW', 'P', 'I')
17
+ SetCurrentDirectory = Win32API.new('kernel32', 'SetCurrentDirectory', 'P', 'I')
18
+ SetCurrentDirectoryW = Win32API.new('kernel32', 'SetCurrentDirectoryW', 'P', 'I')
19
+
20
+ def CreateDirectory(path, attributes = 0)
21
+ CreateDirectory.call(path, attributes) != 0
22
+ end
23
+
24
+ def CreateDirectoryW(path, attributes)
25
+ path = multi_to_wide(path) unless IsTextUnicode(path)
26
+ CreateDirectoryW.call(path, attributes) != 0
27
+ end
28
+
29
+ def CreateDirectoryEx(template, new_dir, attributes)
30
+ CreateDirectoryEx.call(template, new_dir, attributes) != 0
31
+ end
32
+
33
+ def CreateDirectoryExW(template, new_dir, attributes)
34
+ new_dir = multi_to_wide(new_dir) unless IsTextUnicode(new_dir)
35
+ CreateDirectoryExW.call(template, new_dir, attributes) != 0
36
+ end
37
+
38
+ def FindCloseChangeNotification(handle)
39
+ FindCloseChangeNotification.call(handle) != 0
40
+ end
41
+
42
+ def FindFirstChangeNotification(path, subtree, filter)
43
+ FindFirstChangeNotification.call(path, subtree, filter)
44
+ end
45
+
46
+ def FindNextChangeNotification(handle)
47
+ FindNextChangeNotification.call(handle) != 0
48
+ end
49
+
50
+ def GetCurrentDirectory(buf_len, buf)
51
+ GetCurrentDirectory.call(buf_len, buf)
52
+ end
53
+
54
+ def GetCurrentDirectoryW(buf_len, buf)
55
+ GetCurrentDirectoryW.call(buf_len, buf)
56
+ end
57
+
58
+ def ReadDirectoryChangesW(handle, buf, buf_len, subtree, filter, bytes, overlapped, routine)
59
+ ReadDirectoryChangesW.call(handle, buf, buf_len, subtree, filter, bytes, overlapped, routine) != 0
60
+ end
61
+
62
+ def RemoveDirectory(path)
63
+ RemoveDirectory.call(path) != 0
64
+ end
65
+
66
+ def RemoveDirectoryW(path)
67
+ path = multi_to_wide(path) unless IsTextUnicode(path)
68
+ RemoveDirectoryW.call(path) != 0
69
+ end
70
+
71
+ def SetCurrentDirectory(path)
72
+ SetCurrentDirectory.call(path) != 0
73
+ end
74
+
75
+ def SetCurrentDirectoryW(path)
76
+ path = multi_to_wide(path) unless IsTextUnicode(path)
77
+ SetCurrentDirectoryW.call(path) != 0
78
+ end
79
+ end
80
+ end
data/lib/windows/error.rb CHANGED
@@ -1,35 +1,14 @@
1
1
  ############################################################################
2
2
  # error.rb
3
3
  #
4
- # Includes the following functions:
5
- #
6
- # GetLastError()
7
- # FormatError()
8
- # SetErrorMode()
9
- # SetLastError()
10
- # SetLastErrorex()
11
- #
12
- # Defines the following constants:
13
- #
14
- # FORMAT_MESSAGE_ALLOCATE_BUFFER
15
- # FORMAT_MESSAGE_IGNORE_INSERTS
16
- # FORMAT_MESSAGE_FROM_STRING
17
- # FORMAT_MESSAGE_FROM_HMODULE
18
- # FORMAT_MESSAGE_FROM_SYSTEM
19
- # FORMAT_MESSAGE_ARGUMENT_ARRAY
20
- # FORMAT_MESSAGE_MAX_WIDTH_MASK
21
- #
22
- # SEM_FAILCRITICALERRORS
23
- # SEM_NOALIGNMENTFAULTEXCEPT
24
- # SEM_NOGPFAULTERRORBOX
25
- # SEM_NOOPENFILEERRORBOX
4
+ # Includes all of the error codes in error.h and some from winerror.h.
26
5
  #
27
6
  # Adds the following convenience methods:
28
7
  #
29
8
  # get_last_error - Returns a human readable string for the error returned
30
9
  # by the GetLastError() function.
31
10
  ############################################################################
32
- require "Win32API"
11
+ require 'windows/unicode'
33
12
 
34
13
  module Windows
35
14
  module Error
@@ -41,16 +20,261 @@ module Windows
41
20
  FORMAT_MESSAGE_ARGUMENT_ARRAY = 0x00002000
42
21
  FORMAT_MESSAGE_MAX_WIDTH_MASK = 0x000000FF
43
22
 
44
- SEM_FAILCRITICALERRORS = 0x0001
45
- SEM_NOALIGNMENTFAULTEXCEPT = 0x0004
46
- SEM_NOGPFAULTERRORBOX = 0x0002
47
- SEM_NOOPENFILEERRORBOX = 0x8000
23
+ SEM_FAILCRITICALERRORS = 0x0001
24
+ SEM_NOALIGNMENTFAULTEXCEPT = 0x0004
25
+ SEM_NOGPFAULTERRORBOX = 0x0002
26
+ SEM_NOOPENFILEERRORBOX = 0x8000
27
+
28
+ NO_ERROR = 0
29
+ ERROR_SUCCESS = 0
30
+ ERROR_INVALID_FUNCTION = 1
31
+ ERROR_FILE_NOT_FOUND = 2
32
+ ERROR_PATH_NOT_FOUND = 3
33
+ ERROR_TOO_MANY_OPEN_FILES = 4
34
+ ERROR_ACCESS_DENIED = 5
35
+ ERROR_INVALID_HANDLE = 6
36
+ ERROR_ARENA_TRASHED = 7
37
+ ERROR_NOT_ENOUGH_MEMORY = 8
38
+ ERROR_INVALID_BLOCK = 9
39
+ ERROR_BAD_ENVIRONMENT = 10
40
+ ERROR_BAD_FORMAT = 11
41
+ ERROR_INVALID_ACCESS = 12
42
+ ERROR_INVALID_DATA = 13
43
+ ERROR_INVALID_DRIVE = 15
44
+ ERROR_CURRENT_DIRECTORY = 16
45
+ ERROR_NOT_SAME_DEVICE = 17
46
+ ERROR_NO_MORE_FILES = 18
47
+
48
+ ERROR_WRITE_PROTECT = 19
49
+ ERROR_BAD_UNIT = 20
50
+ ERROR_NOT_READY = 21
51
+ ERROR_BAD_COMMAND = 22
52
+ ERROR_CRC = 23
53
+ ERROR_BAD_LENGTH = 24
54
+ ERROR_SEEK = 25
55
+ ERROR_NOT_DOS_DISK = 26
56
+ ERROR_SECTOR_NOT_FOUND = 27
57
+ ERROR_OUT_OF_PAPER = 28
58
+ ERROR_WRITE_FAULT = 29
59
+ ERROR_READ_FAULT = 30
60
+ ERROR_GEN_FAILURE = 31
61
+
62
+ ERROR_SHARING_VIOLATION = 32
63
+ ERROR_LOCK_VIOLATION = 33
64
+ ERROR_WRONG_DISK = 34
65
+ ERROR_FCB_UNAVAILABLE = 35
66
+ ERROR_SHARING_BUFFER_EXCEEDED = 36
67
+
68
+ ERROR_NOT_SUPPORTED = 50
69
+
70
+ ERROR_FILE_EXISTS = 80
71
+ ERROR_DUP_FCB = 81
72
+ ERROR_CANNOT_MAKE = 82
73
+ ERROR_FAIL_I24 = 83
74
+
75
+ ERROR_OUT_OF_STRUCTURES = 84
76
+ ERROR_ALREADY_ASSIGNED = 85
77
+ ERROR_INVALID_PASSWORD = 86
78
+ ERROR_INVALID_PARAMETER = 87
79
+ ERROR_NET_WRITE_FAULT = 88
80
+
81
+ ERROR_NO_PROC_SLOTS = 89 # no process slots available
82
+ ERROR_NOT_FROZEN = 90
83
+ ERR_TSTOVFL = 91 # timer service table overflow
84
+ ERR_TSTDUP = 92 # timer service table duplicate
85
+ ERROR_NO_ITEMS = 93 # There were no items to operate upon
86
+ ERROR_INTERRUPT = 95 # interrupted system call
87
+
88
+ ERROR_TOO_MANY_SEMAPHORES = 100
89
+ ERROR_EXCL_SEM_ALREADY_OWNED = 101
90
+ ERROR_SEM_IS_SET = 102
91
+ ERROR_TOO_MANY_SEM_REQUESTS = 103
92
+ ERROR_INVALID_AT_INTERRUPT_TIME = 104
93
+
94
+ ERROR_SEM_OWNER_DIED = 105 # waitsem found owner died
95
+ ERROR_SEM_USER_LIMIT = 106 # too many procs have this sem
96
+ ERROR_DISK_CHANGE = 107 # insert disk b into drive a
97
+ ERROR_DRIVE_LOCKED = 108 # drive locked by another process
98
+ ERROR_BROKEN_PIPE = 109 # write on pipe with no reader
99
+
100
+ ERROR_OPEN_FAILED = 110 # open/created failed
101
+ ERROR_DISK_FULL = 112 # not enough space
102
+ ERROR_NO_MORE_SEARCH_HANDLES = 113 # can't allocate
103
+ ERROR_INVALID_TARGET_HANDLE = 114 # handle in DOSDUPHANDLE is invalid
104
+ ERROR_PROTECTION_VIOLATION = 115 # bad user virtual address
105
+ ERROR_VIOKBD_REQUEST = 116
106
+ ERROR_INVALID_CATEGORY = 117 # category for DEVIOCTL not defined
107
+ ERROR_INVALID_VERIFY_SWITCH = 118 # invalid value
108
+ ERROR_BAD_DRIVER_LEVEL = 119 # DosDevIOCTL not level four
109
+ ERROR_CALL_NOT_IMPLEMENTED = 120
110
+ ERROR_SEM_TIMEOUT = 121 # timeout from semaphore function
111
+ ERROR_INSUFFICIENT_BUFFER = 122
112
+
113
+ ERROR_INVALID_NAME = 123 # illegal char or malformed file system name
114
+ ERROR_INVALID_LEVEL = 124 # unimplemented level for info retrieval
115
+ ERROR_NO_VOLUME_LABEL = 125 # no volume label found
116
+ ERROR_MOD_NOT_FOUND = 126 # w_getprocaddr, w_getmodhandle
117
+ ERROR_PROC_NOT_FOUND = 127 # w_getprocaddr
118
+
119
+ ERROR_WAIT_NO_CHILDREN = 128 # CWait finds to children
120
+ ERROR_CHILD_NOT_COMPLETE = 129 # CWait children not dead yet
121
+
122
+ ERROR_DIRECT_ACCESS_HANDLE = 130 # invalid for direct disk access
123
+ ERROR_NEGATIVE_SEEK = 131 # tried to seek negative offset
124
+ ERROR_SEEK_ON_DEVICE = 132 # tried to seek on device or pipe
125
+
126
+ ERROR_IS_JOIN_TARGET = 133
127
+ ERROR_IS_JOINED = 134
128
+ ERROR_IS_SUBSTED = 135
129
+ ERROR_NOT_JOINED = 136
130
+ ERROR_NOT_SUBSTED = 137
131
+ ERROR_JOIN_TO_JOIN = 138
132
+ ERROR_SUBST_TO_SUBST = 139
133
+ ERROR_JOIN_TO_SUBST = 140
134
+ ERROR_SUBST_TO_JOIN = 141
135
+ ERROR_BUSY_DRIVE = 142
136
+ ERROR_SAME_DRIVE = 143
137
+ ERROR_DIR_NOT_ROOT = 144
138
+ ERROR_DIR_NOT_EMPTY = 145
139
+ ERROR_IS_SUBST_PATH = 146
140
+ ERROR_IS_JOIN_PATH = 147
141
+ ERROR_PATH_BUSY = 148
142
+ ERROR_IS_SUBST_TARGET = 149
143
+ ERROR_SYSTEM_TRACE = 150 # system trace error
144
+ ERROR_INVALID_EVENT_COUNT = 151 # DosMuxSemWait errors
145
+ ERROR_TOO_MANY_MUXWAITERS = 152
146
+ ERROR_INVALID_LIST_FORMAT = 153
147
+ ERROR_LABEL_TOO_LONG = 154
148
+ ERROR_TOO_MANY_TCBS = 155
149
+ ERROR_SIGNAL_REFUSED = 156
150
+ ERROR_DISCARDED = 157
151
+ ERROR_NOT_LOCKED = 158
152
+ ERROR_BAD_THREADID_ADDR = 159
153
+ ERROR_BAD_ARGUMENTS = 160
154
+ ERROR_BAD_PATHNAME = 161
155
+ ERROR_SIGNAL_PENDING = 162
156
+ ERROR_UNCERTAIN_MEDIA = 163
157
+ ERROR_MAX_THRDS_REACHED = 164
158
+ ERROR_MONITORS_NOT_SUPPORTED = 165
159
+
160
+ ERROR_INVALID_SEGMENT_NUMBER = 180
161
+ ERROR_INVALID_CALLGATE = 181
162
+ ERROR_INVALID_ORDINAL = 182
163
+ ERROR_ALREADY_EXISTS = 183
164
+ ERROR_NO_CHILD_PROCESS = 184
165
+ ERROR_CHILD_ALIVE_NOWAIT = 185
166
+ ERROR_INVALID_FLAG_NUMBER = 186
167
+ ERROR_SEM_NOT_FOUND = 187
168
+
169
+ ERROR_INVALID_STARTING_CODESEG = 188
170
+ ERROR_INVALID_STACKSEG = 189
171
+ ERROR_INVALID_MODULETYPE = 190
172
+ ERROR_INVALID_EXE_SIGNATURE = 191
173
+ ERROR_EXE_MARKED_INVALID = 192
174
+ ERROR_BAD_EXE_FORMAT = 193
175
+ ERROR_ITERATED_DATA_EXCEEDS_64k = 194
176
+ ERROR_INVALID_MINALLOCSIZE = 195
177
+ ERROR_DYNLINK_FROM_INVALID_RING = 196
178
+ ERROR_IOPL_NOT_ENABLED = 197
179
+ ERROR_INVALID_SEGDPL = 198
180
+ ERROR_AUTODATASEG_EXCEEDS_64k = 199
181
+ ERROR_RING2SEG_MUST_BE_MOVABLE = 200
182
+ ERROR_RELOC_CHAIN_XEEDS_SEGLIM = 201
183
+ ERROR_INFLOOP_IN_RELOC_CHAIN = 202
184
+
185
+ ERROR_ENVVAR_NOT_FOUND = 203
186
+ ERROR_NOT_CURRENT_CTRY = 204
187
+ ERROR_NO_SIGNAL_SENT = 205
188
+ ERROR_FILENAME_EXCED_RANGE = 206 # if filename > 8.3
189
+ ERROR_RING2_STACK_IN_USE = 207 # for FAPI
190
+ ERROR_META_EXPANSION_TOO_LONG = 208 # if "*a" > 8.3
191
+
192
+ ERROR_INVALID_SIGNAL_NUMBER = 209
193
+ ERROR_THREAD_1_INACTIVE = 210
194
+ ERROR_INFO_NOT_AVAIL = 211 #@@ PTM 5550
195
+ ERROR_LOCKED = 212
196
+ ERROR_BAD_DYNALINK = 213 #@@ PTM 5760
197
+ ERROR_TOO_MANY_MODULES = 214
198
+ ERROR_NESTING_NOT_ALLOWED = 215
199
+ ERROR_MORE_DATA = 234
200
+
201
+ ERROR_USER_DEFINED_BASE = 0xF000
202
+
203
+ ERROR_I24_WRITE_PROTECT = 0
204
+ ERROR_I24_BAD_UNIT = 1
205
+ ERROR_I24_NOT_READY = 2
206
+ ERROR_I24_BAD_COMMAND = 3
207
+ ERROR_I24_CRC = 4
208
+ ERROR_I24_BAD_LENGTH = 5
209
+ ERROR_I24_SEEK = 6
210
+ ERROR_I24_NOT_DOS_DISK = 7
211
+ ERROR_I24_SECTOR_NOT_FOUND = 8
212
+ ERROR_I24_OUT_OF_PAPER = 9
213
+ ERROR_I24_WRITE_FAULT = 0x0A
214
+ ERROR_I24_READ_FAULT = 0x0B
215
+ ERROR_I24_GEN_FAILURE = 0x0C
216
+ ERROR_I24_DISK_CHANGE = 0x0D
217
+ ERROR_I24_WRONG_DISK = 0x0F
218
+ ERROR_I24_UNCERTAIN_MEDIA = 0x10
219
+ ERROR_I24_CHAR_CALL_INTERRUPTED = 0x11
220
+ ERROR_I24_NO_MONITOR_SUPPORT = 0x12
221
+ ERROR_I24_INVALID_PARAMETER = 0x13
222
+
223
+ ALLOWED_FAIL = 0x0001
224
+ ALLOWED_ABORT = 0x0002
225
+ ALLOWED_RETRY = 0x0004
226
+ ALLOWED_IGNORE = 0x0008
227
+
228
+ I24_OPERATION = 0x1
229
+ I24_AREA = 0x6
230
+ I24_CLASS = 0x80
231
+
232
+
233
+ ERRCLASS_OUTRES = 1 # Out of Resource
234
+ ERRCLASS_TEMPSIT = 2 # Temporary Situation
235
+ ERRCLASS_AUTH = 3 # Permission problem
236
+ ERRCLASS_INTRN = 4 # Internal System Error
237
+ ERRCLASS_HRDFAIL = 5 # Hardware Failure
238
+ ERRCLASS_SYSFAIL = 6 # System Failure
239
+ ERRCLASS_APPERR = 7 # Application Error
240
+ ERRCLASS_NOTFND = 8 # Not Found
241
+ ERRCLASS_BADFMT = 9 # Bad Format
242
+ ERRCLASS_LOCKED = 10 # Locked
243
+ ERRCLASS_MEDIA = 11 # Media Failure
244
+ ERRCLASS_ALREADY = 12 # Collision with Existing Item
245
+ ERRCLASS_UNK = 13 # Unknown/other
246
+ ERRCLASS_CANT = 14
247
+ ERRCLASS_TIME = 15
248
+
249
+ ERRACT_RETRY = 1 # Retry
250
+ ERRACT_DLYRET = 2 # Delay Retry, retry after pause
251
+ ERRACT_USER = 3 # Ask user to regive info
252
+ ERRACT_ABORT = 4 # abort with clean up
253
+ ERRACT_PANIC = 5 # abort immediately
254
+ ERRACT_IGNORE = 6 # ignore
255
+ ERRACT_INTRET = 7 # Retry after User Intervention
256
+
257
+ ERRLOC_UNK = 1 # No appropriate value
258
+ ERRLOC_DISK = 2 # Random Access Mass Storage
259
+ ERRLOC_NET = 3 # Network
260
+ ERRLOC_SERDEV = 4 # Serial Device
261
+ ERRLOC_MEM = 5 # Memory
262
+
263
+ TC_NORMAL = 0
264
+ TC_HARDERR = 1
265
+ TC_GP_TRAP = 2
266
+ TC_SIGNAL = 3
267
+
268
+ # From WinError.h
269
+ ERROR_INVALID_FLAGS = 4100 # 1004L
270
+ ERROR_NO_UNICODE_TRANSLATION = 4371
48
271
 
49
272
  GetLastError = Win32API.new('kernel32', 'GetLastError', 'V', 'L')
50
273
  SetLastError = Win32API.new('kernel32', 'GetLastError', 'L', 'V')
51
274
  SetLastErrorEx = Win32API.new('kernel32', 'GetLastError', 'LL', 'V')
52
275
  SetErrorMode = Win32API.new('kernel32', 'SetErrorMode', 'I', 'I')
53
- FormatMessage = Win32API.new('kernel32', 'FormatMessage', 'LPLLPLP', 'L')
276
+ FormatMessage = Win32API.new('kernel32', 'FormatMessage', 'LLLLPLP', 'L')
277
+ FormatMessageW = Win32API.new('kernel32', 'FormatMessageW', 'LLLLPLP', 'L')
54
278
 
55
279
  def GetLastError
56
280
  GetLastError.call
@@ -72,21 +296,18 @@ module Windows
72
296
  FormatMessage.call(flags, src, msg_id, lang_id, buf, size, args)
73
297
  end
74
298
 
299
+ def FormatMessageW(flags, src, msg_id, lang_id, buf, size, args)
300
+ FormatMessageW.call(flags, src, msg_id, lang_id, buf, size, args)
301
+ end
302
+
75
303
  # Convenience method that wraps FormatMessage with some sane defaults and
76
304
  # returns a human readable string.
77
305
  #
78
306
  def get_last_error(err_num = GetLastError.call)
79
- buf = 0.chr * 260
80
- FormatMessage.call(
81
- FORMAT_MESSAGE_FROM_SYSTEM + FORMAT_MESSAGE_ARGUMENT_ARRAY,
82
- 0,
83
- err_num,
84
- 0,
85
- buf,
86
- buf.length,
87
- 0
88
- )
89
- buf.split(0.chr).first.chomp
307
+ buf = 0.chr * 260
308
+ flags = FORMAT_MESSAGE_FROM_SYSTEM + FORMAT_MESSAGE_ARGUMENT_ARRAY
309
+ FormatMessage.call(flags, 0, err_num, 0, buf, buf.size, 0)
310
+ buf.split(0.chr).first.chomp
90
311
  end
91
312
  end
92
313
  end