windows-pr 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,16 +1,16 @@
1
- require 'windows/api'
2
-
3
- module Windows
4
- module COM
5
- module Accessibility
6
- API.auto_namespace = 'Windows::COM::Accessibility'
7
- API.auto_constant = true
8
- API.auto_method = true
9
- API.auto_unicode = false
10
-
11
- private
12
-
13
- API.new('ObjectFromLresult', 'LPIP', 'L', 'oleacc')
14
- end
15
- end
16
- end
1
+ require 'windows/api'
2
+
3
+ module Windows
4
+ module COM
5
+ module Accessibility
6
+ API.auto_namespace = 'Windows::COM::Accessibility'
7
+ API.auto_constant = true
8
+ API.auto_method = true
9
+ API.auto_unicode = false
10
+
11
+ private
12
+
13
+ API.new('ObjectFromLresult', 'LPIP', 'L', 'oleacc')
14
+ end
15
+ end
16
+ end
@@ -1,27 +1,27 @@
1
- require 'windows/api'
2
-
3
- # The Windows::Directory module contains functions that are used in directory
4
- # management. Note that functions that could be applied to files or
5
- # directories, such as CreateFile(), are probably in the Windows::File
6
- # module.
7
- #
8
- module Windows
9
- module Directory
10
- API.auto_namespace = 'Windows::Directory'
11
- API.auto_constant = true
12
- API.auto_method = true
13
- API.auto_unicode = true
14
-
15
- private
16
-
17
- API.new('CreateDirectory', 'PP', 'B')
18
- API.new('CreateDirectoryEx', 'PPP', 'B')
19
- API.new('FindCloseChangeNotification', 'L', 'B')
20
- API.new('FindFirstChangeNotification', 'PIL', 'L')
21
- API.new('FindNextChangeNotification', 'PIL', 'B')
22
- API.new('GetCurrentDirectory', 'LP', 'L')
23
- API.new('ReadDirectoryChangesW', 'LPLILPPP', 'B') # No ANSI equivalent
24
- API.new('RemoveDirectory', 'P', 'B')
25
- API.new('SetCurrentDirectory', 'P', 'B')
26
- end
27
- end
1
+ require 'windows/api'
2
+
3
+ # The Windows::Directory module contains functions that are used in directory
4
+ # management. Note that functions that could be applied to files or
5
+ # directories, such as CreateFile(), are probably in the Windows::File
6
+ # module.
7
+ #
8
+ module Windows
9
+ module Directory
10
+ API.auto_namespace = 'Windows::Directory'
11
+ API.auto_constant = true
12
+ API.auto_method = true
13
+ API.auto_unicode = true
14
+
15
+ private
16
+
17
+ API.new('CreateDirectory', 'PP', 'B')
18
+ API.new('CreateDirectoryEx', 'PPP', 'B')
19
+ API.new('FindCloseChangeNotification', 'L', 'B')
20
+ API.new('FindFirstChangeNotification', 'PIL', 'L')
21
+ API.new('FindNextChangeNotification', 'PIL', 'B')
22
+ API.new('GetCurrentDirectory', 'LP', 'L')
23
+ API.new('ReadDirectoryChangesW', 'LPLILPPP', 'B') # No ANSI equivalent
24
+ API.new('RemoveDirectory', 'P', 'B')
25
+ API.new('SetCurrentDirectory', 'P', 'B')
26
+ end
27
+ end
@@ -1,484 +1,498 @@
1
- ############################################################################
2
- # error.rb
3
- #
4
- # Includes all of the error codes in error.h, msterr.h and some from
5
- # winerror.h.
6
- #
7
- # Adds the following convenience methods:
8
- #
9
- # get_last_error - Returns a human readable string for the error returned
10
- # by the GetLastError() function.
11
- ############################################################################
12
- require 'windows/api'
13
-
14
- module Windows
15
- module Error
16
- API.auto_namespace = 'Windows::Error'
17
- API.auto_method = true
18
- API.auto_constant = true
19
- API.auto_unicode = true
20
-
21
- private
22
-
23
- FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x00000100
24
- FORMAT_MESSAGE_IGNORE_INSERTS = 0x00000200
25
- FORMAT_MESSAGE_FROM_STRING = 0x00000400
26
- FORMAT_MESSAGE_FROM_HMODULE = 0x00000800
27
- FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000
28
- FORMAT_MESSAGE_ARGUMENT_ARRAY = 0x00002000
29
- FORMAT_MESSAGE_MAX_WIDTH_MASK = 0x000000FF
30
-
31
- SEM_FAILCRITICALERRORS = 0x0001
32
- SEM_NOALIGNMENTFAULTEXCEPT = 0x0004
33
- SEM_NOGPFAULTERRORBOX = 0x0002
34
- SEM_NOOPENFILEERRORBOX = 0x8000
35
-
36
- S_OK = 0
37
- NO_ERROR = 0
38
- ERROR_SUCCESS = 0
39
- ERROR_INVALID_FUNCTION = 1
40
- ERROR_FILE_NOT_FOUND = 2
41
- ERROR_PATH_NOT_FOUND = 3
42
- ERROR_TOO_MANY_OPEN_FILES = 4
43
- ERROR_ACCESS_DENIED = 5
44
- ERROR_INVALID_HANDLE = 6
45
- ERROR_ARENA_TRASHED = 7
46
- ERROR_NOT_ENOUGH_MEMORY = 8
47
- ERROR_INVALID_BLOCK = 9
48
- ERROR_BAD_ENVIRONMENT = 10
49
- ERROR_BAD_FORMAT = 11
50
- ERROR_INVALID_ACCESS = 12
51
- ERROR_INVALID_DATA = 13
52
- ERROR_INVALID_DRIVE = 15
53
- ERROR_CURRENT_DIRECTORY = 16
54
- ERROR_NOT_SAME_DEVICE = 17
55
- ERROR_NO_MORE_FILES = 18
56
-
57
- ERROR_WRITE_PROTECT = 19
58
- ERROR_BAD_UNIT = 20
59
- ERROR_NOT_READY = 21
60
- ERROR_BAD_COMMAND = 22
61
- ERROR_CRC = 23
62
- ERROR_BAD_LENGTH = 24
63
- ERROR_SEEK = 25
64
- ERROR_NOT_DOS_DISK = 26
65
- ERROR_SECTOR_NOT_FOUND = 27
66
- ERROR_OUT_OF_PAPER = 28
67
- ERROR_WRITE_FAULT = 29
68
- ERROR_READ_FAULT = 30
69
- ERROR_GEN_FAILURE = 31
70
-
71
- ERROR_SHARING_VIOLATION = 32
72
- ERROR_LOCK_VIOLATION = 33
73
- ERROR_WRONG_DISK = 34
74
- ERROR_FCB_UNAVAILABLE = 35
75
- ERROR_SHARING_BUFFER_EXCEEDED = 36
76
- ERROR_HANDLE_EOF = 38
77
- ERROR_HANDLE_DISK_FULL = 39
78
-
79
- ERROR_NOT_SUPPORTED = 50
80
-
81
- ERROR_FILE_EXISTS = 80
82
- ERROR_DUP_FCB = 81
83
- ERROR_CANNOT_MAKE = 82
84
- ERROR_FAIL_I24 = 83
85
-
86
- ERROR_OUT_OF_STRUCTURES = 84
87
- ERROR_ALREADY_ASSIGNED = 85
88
- ERROR_INVALID_PASSWORD = 86
89
- ERROR_INVALID_PARAMETER = 87
90
- ERROR_NET_WRITE_FAULT = 88
91
-
92
- ERROR_NO_PROC_SLOTS = 89 # no process slots available
93
- ERROR_NOT_FROZEN = 90
94
- ERR_TSTOVFL = 91 # timer service table overflow
95
- ERR_TSTDUP = 92 # timer service table duplicate
96
- ERROR_NO_ITEMS = 93 # There were no items to operate upon
97
- ERROR_INTERRUPT = 95 # interrupted system call
98
-
99
- ERROR_TOO_MANY_SEMAPHORES = 100
100
- ERROR_EXCL_SEM_ALREADY_OWNED = 101
101
- ERROR_SEM_IS_SET = 102
102
- ERROR_TOO_MANY_SEM_REQUESTS = 103
103
- ERROR_INVALID_AT_INTERRUPT_TIME = 104
104
-
105
- ERROR_SEM_OWNER_DIED = 105 # waitsem found owner died
106
- ERROR_SEM_USER_LIMIT = 106 # too many procs have this sem
107
- ERROR_DISK_CHANGE = 107 # insert disk b into drive a
108
- ERROR_DRIVE_LOCKED = 108 # drive locked by another process
109
- ERROR_BROKEN_PIPE = 109 # write on pipe with no reader
110
-
111
- ERROR_OPEN_FAILED = 110 # open/created failed
112
- ERROR_DISK_FULL = 112 # not enough space
113
- ERROR_NO_MORE_SEARCH_HANDLES = 113 # can't allocate
114
- ERROR_INVALID_TARGET_HANDLE = 114 # handle in DOSDUPHANDLE is invalid
115
- ERROR_PROTECTION_VIOLATION = 115 # bad user virtual address
116
- ERROR_VIOKBD_REQUEST = 116
117
- ERROR_INVALID_CATEGORY = 117 # category for DEVIOCTL not defined
118
- ERROR_INVALID_VERIFY_SWITCH = 118 # invalid value
119
- ERROR_BAD_DRIVER_LEVEL = 119 # DosDevIOCTL not level four
120
- ERROR_CALL_NOT_IMPLEMENTED = 120
121
- ERROR_SEM_TIMEOUT = 121 # timeout from semaphore function
122
- ERROR_INSUFFICIENT_BUFFER = 122
123
-
124
- ERROR_INVALID_NAME = 123 # illegal char or malformed file system name
125
- ERROR_INVALID_LEVEL = 124 # unimplemented level for info retrieval
126
- ERROR_NO_VOLUME_LABEL = 125 # no volume label found
127
- ERROR_MOD_NOT_FOUND = 126 # w_getprocaddr, w_getmodhandle
128
- ERROR_PROC_NOT_FOUND = 127 # w_getprocaddr
129
-
130
- ERROR_WAIT_NO_CHILDREN = 128 # CWait finds to children
131
- ERROR_CHILD_NOT_COMPLETE = 129 # CWait children not dead yet
132
-
133
- ERROR_DIRECT_ACCESS_HANDLE = 130 # invalid for direct disk access
134
- ERROR_NEGATIVE_SEEK = 131 # tried to seek negative offset
135
- ERROR_SEEK_ON_DEVICE = 132 # tried to seek on device or pipe
136
-
137
- ERROR_IS_JOIN_TARGET = 133
138
- ERROR_IS_JOINED = 134
139
- ERROR_IS_SUBSTED = 135
140
- ERROR_NOT_JOINED = 136
141
- ERROR_NOT_SUBSTED = 137
142
- ERROR_JOIN_TO_JOIN = 138
143
- ERROR_SUBST_TO_SUBST = 139
144
- ERROR_JOIN_TO_SUBST = 140
145
- ERROR_SUBST_TO_JOIN = 141
146
- ERROR_BUSY_DRIVE = 142
147
- ERROR_SAME_DRIVE = 143
148
- ERROR_DIR_NOT_ROOT = 144
149
- ERROR_DIR_NOT_EMPTY = 145
150
- ERROR_IS_SUBST_PATH = 146
151
- ERROR_IS_JOIN_PATH = 147
152
- ERROR_PATH_BUSY = 148
153
- ERROR_IS_SUBST_TARGET = 149
154
- ERROR_SYSTEM_TRACE = 150 # system trace error
155
- ERROR_INVALID_EVENT_COUNT = 151 # DosMuxSemWait errors
156
- ERROR_TOO_MANY_MUXWAITERS = 152
157
- ERROR_INVALID_LIST_FORMAT = 153
158
- ERROR_LABEL_TOO_LONG = 154
159
- ERROR_TOO_MANY_TCBS = 155
160
- ERROR_SIGNAL_REFUSED = 156
161
- ERROR_DISCARDED = 157
162
- ERROR_NOT_LOCKED = 158
163
- ERROR_BAD_THREADID_ADDR = 159
164
- ERROR_BAD_ARGUMENTS = 160
165
- ERROR_BAD_PATHNAME = 161
166
- ERROR_SIGNAL_PENDING = 162
167
- ERROR_UNCERTAIN_MEDIA = 163
168
- ERROR_MAX_THRDS_REACHED = 164
169
- ERROR_MONITORS_NOT_SUPPORTED = 165
170
-
171
- ERROR_INVALID_SEGMENT_NUMBER = 180
172
- ERROR_INVALID_CALLGATE = 181
173
- ERROR_INVALID_ORDINAL = 182
174
- ERROR_ALREADY_EXISTS = 183
175
- ERROR_NO_CHILD_PROCESS = 184
176
- ERROR_CHILD_ALIVE_NOWAIT = 185
177
- ERROR_INVALID_FLAG_NUMBER = 186
178
- ERROR_SEM_NOT_FOUND = 187
179
-
180
- ERROR_INVALID_STARTING_CODESEG = 188
181
- ERROR_INVALID_STACKSEG = 189
182
- ERROR_INVALID_MODULETYPE = 190
183
- ERROR_INVALID_EXE_SIGNATURE = 191
184
- ERROR_EXE_MARKED_INVALID = 192
185
- ERROR_BAD_EXE_FORMAT = 193
186
- ERROR_ITERATED_DATA_EXCEEDS_64k = 194
187
- ERROR_INVALID_MINALLOCSIZE = 195
188
- ERROR_DYNLINK_FROM_INVALID_RING = 196
189
- ERROR_IOPL_NOT_ENABLED = 197
190
- ERROR_INVALID_SEGDPL = 198
191
- ERROR_AUTODATASEG_EXCEEDS_64k = 199
192
- ERROR_RING2SEG_MUST_BE_MOVABLE = 200
193
- ERROR_RELOC_CHAIN_XEEDS_SEGLIM = 201
194
- ERROR_INFLOOP_IN_RELOC_CHAIN = 202
195
-
196
- ERROR_ENVVAR_NOT_FOUND = 203
197
- ERROR_NOT_CURRENT_CTRY = 204
198
- ERROR_NO_SIGNAL_SENT = 205
199
- ERROR_FILENAME_EXCED_RANGE = 206 # if filename > 8.3
200
- ERROR_RING2_STACK_IN_USE = 207 # for FAPI
201
- ERROR_META_EXPANSION_TOO_LONG = 208 # if "*a" > 8.3
202
-
203
- ERROR_INVALID_SIGNAL_NUMBER = 209
204
- ERROR_THREAD_1_INACTIVE = 210
205
- ERROR_INFO_NOT_AVAIL = 211 #@@ PTM 5550
206
- ERROR_LOCKED = 212
207
- ERROR_BAD_DYNALINK = 213 #@@ PTM 5760
208
- ERROR_TOO_MANY_MODULES = 214
209
- ERROR_NESTING_NOT_ALLOWED = 215
210
- ERROR_BAD_PIPE = 230
211
- ERROR_PIPE_BUSY = 231
212
- ERROR_NO_DATA = 232
213
- ERROR_PIPE_NOT_CONNECTED = 233
214
- ERROR_MORE_DATA = 234
215
-
216
- ERROR_PIPE_CONNECTED = 535
217
- ERROR_PIPE_LISTENING = 536
218
-
219
- ERROR_OPERATION_ABORTED = 995
220
- ERROR_IO_INCOMPLETE = 996
221
- ERROR_IO_PENDING = 997
222
-
223
- ERROR_USER_DEFINED_BASE = 0xF000
224
-
225
- ERROR_I24_WRITE_PROTECT = 0
226
- ERROR_I24_BAD_UNIT = 1
227
- ERROR_I24_NOT_READY = 2
228
- ERROR_I24_BAD_COMMAND = 3
229
- ERROR_I24_CRC = 4
230
- ERROR_I24_BAD_LENGTH = 5
231
- ERROR_I24_SEEK = 6
232
- ERROR_I24_NOT_DOS_DISK = 7
233
- ERROR_I24_SECTOR_NOT_FOUND = 8
234
- ERROR_I24_OUT_OF_PAPER = 9
235
- ERROR_I24_WRITE_FAULT = 0x0A
236
- ERROR_I24_READ_FAULT = 0x0B
237
- ERROR_I24_GEN_FAILURE = 0x0C
238
- ERROR_I24_DISK_CHANGE = 0x0D
239
- ERROR_I24_WRONG_DISK = 0x0F
240
- ERROR_I24_UNCERTAIN_MEDIA = 0x10
241
- ERROR_I24_CHAR_CALL_INTERRUPTED = 0x11
242
- ERROR_I24_NO_MONITOR_SUPPORT = 0x12
243
- ERROR_I24_INVALID_PARAMETER = 0x13
244
-
245
- APPLICATION_ERROR_MASK = 0x20000000
246
- ERROR_SEVERITY_SUCCESS = 0x00000000
247
- ERROR_SEVERITY_INFORMATIONAL = 0x40000000
248
- ERROR_SEVERITY_WARNING = 0x80000000
249
- ERROR_SEVERITY_ERROR = 0xc0000000
250
-
251
- ALLOWED_FAIL = 0x0001
252
- ALLOWED_ABORT = 0x0002
253
- ALLOWED_RETRY = 0x0004
254
- ALLOWED_IGNORE = 0x0008
255
-
256
- I24_OPERATION = 0x1
257
- I24_AREA = 0x6
258
- I24_CLASS = 0x80
259
-
260
- ERRCLASS_OUTRES = 1 # Out of Resource
261
- ERRCLASS_TEMPSIT = 2 # Temporary Situation
262
- ERRCLASS_AUTH = 3 # Permission problem
263
- ERRCLASS_INTRN = 4 # Internal System Error
264
- ERRCLASS_HRDFAIL = 5 # Hardware Failure
265
- ERRCLASS_SYSFAIL = 6 # System Failure
266
- ERRCLASS_APPERR = 7 # Application Error
267
- ERRCLASS_NOTFND = 8 # Not Found
268
- ERRCLASS_BADFMT = 9 # Bad Format
269
- ERRCLASS_LOCKED = 10 # Locked
270
- ERRCLASS_MEDIA = 11 # Media Failure
271
- ERRCLASS_ALREADY = 12 # Collision with Existing Item
272
- ERRCLASS_UNK = 13 # Unknown/other
273
- ERRCLASS_CANT = 14
274
- ERRCLASS_TIME = 15
275
-
276
- ERRACT_RETRY = 1 # Retry
277
- ERRACT_DLYRET = 2 # Delay Retry, retry after pause
278
- ERRACT_USER = 3 # Ask user to regive info
279
- ERRACT_ABORT = 4 # abort with clean up
280
- ERRACT_PANIC = 5 # abort immediately
281
- ERRACT_IGNORE = 6 # ignore
282
- ERRACT_INTRET = 7 # Retry after User Intervention
283
-
284
- ERRLOC_UNK = 1 # No appropriate value
285
- ERRLOC_DISK = 2 # Random Access Mass Storage
286
- ERRLOC_NET = 3 # Network
287
- ERRLOC_SERDEV = 4 # Serial Device
288
- ERRLOC_MEM = 5 # Memory
289
-
290
- TC_NORMAL = 0
291
- TC_HARDERR = 1
292
- TC_GP_TRAP = 2
293
- TC_SIGNAL = 3
294
-
295
- # From WinError.h
296
-
297
- ERROR_INVALID_FLAGS = 0x1004
298
- ERROR_NO_UNICODE_TRANSLATION = 0x1113
299
-
300
- E_INVALIDARG = 0x80070057
301
- E_NOINTERFACE = 0x80004002
302
- E_NOTIMPL = 0x80004001
303
- E_OUTOFMEMORY = 0x8007000E
304
- E_UNEXPECTED = 0x8000FFFF
305
-
306
- RPC_E_TIMEOUT = 0x8001011F
307
-
308
- CO_E_NOT_SUPPORTED = 0x80004021
309
-
310
- CLASS_E_NOAGGREGATION = 0x80040110
311
-
312
- DISP_E_BADINDEX = 0x8002000B
313
- DISP_E_PARAMNOTFOUND = 0x80020004
314
- DISP_E_EXCEPTION = 0x80020009
315
- DISP_E_MEMBERNOTFOUND = 0x80020003
316
-
317
- # Registry errors
318
-
319
- REGDB_E_CLASSNOTREG = 0x80040154
320
-
321
- # msterr.h
322
-
323
- SCHED_S_TASK_READY = 0x00041300
324
- SCHED_S_TASK_RUNNING = 0x00041301
325
- SCHED_S_TASK_DISABLED = 0x00041302
326
- SCHED_S_TASK_HAS_NOT_RUN = 0x00041303
327
- SCHED_S_TASK_HAS_NO_MORE_RUNS = 0x00041304
328
- SCHED_S_TASK_NOT_SCHEDULED = 0x00041305
329
- SCHED_S_TASK_TERMINATED = 0x00041306
330
- SCHED_S_TASK_NO_VALID_TRIGGERS = 0x00041307
331
- SCHED_S_EVENT_TRIGGER = 0x00041308
332
- SCHED_E_TRIGGER_NOT_FOUND = 0x00041309
333
- SCHED_E_TASK_NOT_READY = 0x0004130A
334
- SCHED_E_TASK_NOT_RUNNING = 0x0004130B
335
- SCHED_E_SERVICE_NOT_INSTALLED = 0x0004130C
336
- SCHED_E_CANNOT_OPEN_TASK = 0x0004130D
337
- SCHED_E_INVALID_TASK = 0x0004130E
338
- SCHED_E_ACCOUNT_INFORMATION_NOT_SET = 0x0004130F
339
- SCHED_E_ACCOUNT_NAME_NOT_FOUND = 0x00041310
340
- SCHED_E_ACCOUNT_DBASE_CORRUPT = 0x00041311
341
- SCHED_E_NO_SECURITY_SERVICES = 0x00041312
342
- SCHED_E_UNKNOWN_OBJECT_VERSION = 0x00041313
343
-
344
- # Socket errors
345
-
346
- WSA_INVALID_HANDLE = 6
347
- WSA_NOT_ENOUGH_MEMORY = 8
348
- WSA_INVALID_PARAMETER = 87
349
- WSA_OPERATION_ABORTED = 995
350
- WSA_IO_INCOMPLETE = 996
351
- WSA_IO_PENDING = 997
352
- WSAEINTR = 10004
353
- WSAEBADF = 10009
354
- WSAEACCESS = 10013
355
- WSAEFAULT = 10014
356
- WSAEINVAL = 10022
357
- WSAEMFILE = 10024
358
- WSAEWOULDBLOCK = 10035
359
- WSAEINPROGRESS = 10036
360
- WSAEALREADY = 10037
361
- WSAENOTSOCK = 10038
362
- WSAEDESTADDRREQ = 10039
363
- WSAEMSGSIZE = 10040
364
- WSAEPROTOTYPE = 10041
365
- WSAENOPROTOOPT = 10042
366
- WSAEPROTONOSUPPORT = 10043
367
- WSAESOCKTNOSUPPORT = 10044
368
- WSAEOPNOTSUPP = 10045
369
- WSAEPFNOSUPPORT = 10046
370
- WSAEAFNOSUPPORT = 10047
371
- WSAEADDRINUSE = 10048
372
- WSAEADDRNOTAVAIL = 10049
373
- WSAENETDOWN = 10050
374
- WSAENETUNREACH = 10051
375
- WSAENETRESET = 10052
376
- WSAECONNABORTED = 10053
377
- WSAECONNRESET = 10054
378
- WSAENOBUFS = 10055
379
- WSAEISCONN = 10056
380
- WSAENOTCONN = 10057
381
- WSAESHUTDOWN = 10058
382
- WSAETOOMANYREFS = 10059
383
- WSATIMEDOUT = 10060
384
- WSAECONNREFUSED = 10061
385
- WSAELOOP = 10062
386
- WSAENAMETOOLONG = 10063
387
- WSAEHOSTDOWN = 10064
388
- WSAEHOSTUNREACH = 10065
389
- WSAENOEMPTY = 10066
390
- WSAEPROCLIM = 10067
391
- WSAEUSERS = 10068
392
- WSAEDQUOT = 10069
393
- WSAESTALE = 10070
394
- WSAEREMOTE = 10071
395
- WSASYSNOTREADY = 10091
396
- WSAVERNOTSUPPORTED = 10092
397
- WSANOTINITIALISED = 10093
398
- WSAEDISCON = 10101
399
- WSAENOMORE = 10102
400
- WSAECANCELLED = 10103
401
- WSAEINVALIDPROCTABLE = 10104
402
- WSAEINVALIDPROVIDER = 10105
403
- WSAEPROVIDERFAILEDINIT = 10106
404
- WSASYSCALLFAILURE = 10107
405
- WSASERVICE_NOT_FOUND = 10108
406
- WSATYPE_NOT_FOUND = 10109
407
- WSA_E_NO_MORE = 10110
408
- WSA_E_CANCELLED = 10111
409
- WSAEREFUSED = 10112
410
- WSAHOST_NOT_FOUND = 11001
411
- WSATRY_AGAIN = 11002
412
- WSANO_RECOVERY = 11003
413
- WSANO_DATA = 11004
414
- WSA_QOS_RECEIVERS = 11005
415
- WSA_QOS_SENDERS = 11006
416
-
417
- API.new('GetLastError', 'V', 'L')
418
- API.new('SetLastError', 'L', 'V')
419
- API.new('SetErrorMode', 'I', 'I')
420
- API.new('FormatMessage', 'LLLLPLP', 'L')
421
-
422
- begin
423
- API.new('SetLastErrorEx', 'LL', 'V', 'user32')
424
- rescue Win32::API::LoadLibraryError
425
- # VC++ 7.0 or later
426
- end
427
-
428
- # Convenience method that wraps FormatMessage with some sane defaults and
429
- # returns a human readable string.
430
- #
431
- def get_last_error(err_num = GetLastError.call)
432
- buf = 0.chr * 260
433
- flags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY
434
- FormatMessageA.call(flags, 0, err_num, 0, buf, buf.size, 0)
435
- buf.strip
436
- end
437
-
438
- # Macros from WinError.h
439
-
440
- def IS_ERROR(status)
441
- status >> 31 == 1
442
- end
443
-
444
- def MAKE_HRESULT(sev, fac, code)
445
- sev << 31 | fac << 16 | code
446
- end
447
-
448
- def MAKE_SCODE(sev, fac, code)
449
- sev << 31 | fac << 16 | code
450
- end
451
-
452
- def HRESULT_CODE(hr)
453
- hr & 0xFFFF
454
- end
455
-
456
- def HRESULT_FACILITY(hr)
457
- (hr >> 16) & 0x1fff
458
- end
459
-
460
- def HRESULT_FROM_NT(x)
461
- x | 0x10000000 # FACILITY_NT_BIT
462
- end
463
-
464
- def HRESULT_FROM_WIN32(x)
465
- if x <= 0
466
- x
467
- else
468
- (x & 0x0000FFFF) | (7 << 16) | 0x80000000
469
- end
470
- end
471
-
472
- def HRESULT_SEVERITY(hr)
473
- (hr >> 31) & 0x1
474
- end
475
-
476
- def FAILED(status)
477
- status < 0
478
- end
479
-
480
- def SUCCEEDED(status)
481
- status >= 0
482
- end
483
- end
484
- end
1
+ ############################################################################
2
+ # error.rb
3
+ #
4
+ # Includes all of the error codes in error.h, msterr.h and some from
5
+ # winerror.h.
6
+ #
7
+ # Adds the following convenience methods:
8
+ #
9
+ # get_last_error - Returns a human readable string for the error returned
10
+ # by the GetLastError() function.
11
+ ############################################################################
12
+ require 'windows/api'
13
+
14
+ module Windows
15
+ module Error
16
+ API.auto_namespace = 'Windows::Error'
17
+ API.auto_method = true
18
+ API.auto_constant = true
19
+ API.auto_unicode = true
20
+
21
+ private
22
+
23
+ FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x00000100
24
+ FORMAT_MESSAGE_IGNORE_INSERTS = 0x00000200
25
+ FORMAT_MESSAGE_FROM_STRING = 0x00000400
26
+ FORMAT_MESSAGE_FROM_HMODULE = 0x00000800
27
+ FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000
28
+ FORMAT_MESSAGE_ARGUMENT_ARRAY = 0x00002000
29
+ FORMAT_MESSAGE_MAX_WIDTH_MASK = 0x000000FF
30
+
31
+ SEM_FAILCRITICALERRORS = 0x0001
32
+ SEM_NOALIGNMENTFAULTEXCEPT = 0x0004
33
+ SEM_NOGPFAULTERRORBOX = 0x0002
34
+ SEM_NOOPENFILEERRORBOX = 0x8000
35
+
36
+ S_OK = 0
37
+ NO_ERROR = 0
38
+ ERROR_SUCCESS = 0
39
+ ERROR_INVALID_FUNCTION = 1
40
+ ERROR_FILE_NOT_FOUND = 2
41
+ ERROR_PATH_NOT_FOUND = 3
42
+ ERROR_TOO_MANY_OPEN_FILES = 4
43
+ ERROR_ACCESS_DENIED = 5
44
+ ERROR_INVALID_HANDLE = 6
45
+ ERROR_ARENA_TRASHED = 7
46
+ ERROR_NOT_ENOUGH_MEMORY = 8
47
+ ERROR_INVALID_BLOCK = 9
48
+ ERROR_BAD_ENVIRONMENT = 10
49
+ ERROR_BAD_FORMAT = 11
50
+ ERROR_INVALID_ACCESS = 12
51
+ ERROR_INVALID_DATA = 13
52
+ ERROR_INVALID_DRIVE = 15
53
+ ERROR_CURRENT_DIRECTORY = 16
54
+ ERROR_NOT_SAME_DEVICE = 17
55
+ ERROR_NO_MORE_FILES = 18
56
+
57
+ ERROR_WRITE_PROTECT = 19
58
+ ERROR_BAD_UNIT = 20
59
+ ERROR_NOT_READY = 21
60
+ ERROR_BAD_COMMAND = 22
61
+ ERROR_CRC = 23
62
+ ERROR_BAD_LENGTH = 24
63
+ ERROR_SEEK = 25
64
+ ERROR_NOT_DOS_DISK = 26
65
+ ERROR_SECTOR_NOT_FOUND = 27
66
+ ERROR_OUT_OF_PAPER = 28
67
+ ERROR_WRITE_FAULT = 29
68
+ ERROR_READ_FAULT = 30
69
+ ERROR_GEN_FAILURE = 31
70
+
71
+ ERROR_SHARING_VIOLATION = 32
72
+ ERROR_LOCK_VIOLATION = 33
73
+ ERROR_WRONG_DISK = 34
74
+ ERROR_FCB_UNAVAILABLE = 35
75
+ ERROR_SHARING_BUFFER_EXCEEDED = 36
76
+ ERROR_HANDLE_EOF = 38
77
+ ERROR_HANDLE_DISK_FULL = 39
78
+
79
+ ERROR_NOT_SUPPORTED = 50
80
+
81
+ ERROR_FILE_EXISTS = 80
82
+ ERROR_DUP_FCB = 81
83
+ ERROR_CANNOT_MAKE = 82
84
+ ERROR_FAIL_I24 = 83
85
+
86
+ ERROR_OUT_OF_STRUCTURES = 84
87
+ ERROR_ALREADY_ASSIGNED = 85
88
+ ERROR_INVALID_PASSWORD = 86
89
+ ERROR_INVALID_PARAMETER = 87
90
+ ERROR_NET_WRITE_FAULT = 88
91
+
92
+ ERROR_NO_PROC_SLOTS = 89 # no process slots available
93
+ ERROR_NOT_FROZEN = 90
94
+ ERR_TSTOVFL = 91 # timer service table overflow
95
+ ERR_TSTDUP = 92 # timer service table duplicate
96
+ ERROR_NO_ITEMS = 93 # There were no items to operate upon
97
+ ERROR_INTERRUPT = 95 # interrupted system call
98
+
99
+ ERROR_TOO_MANY_SEMAPHORES = 100
100
+ ERROR_EXCL_SEM_ALREADY_OWNED = 101
101
+ ERROR_SEM_IS_SET = 102
102
+ ERROR_TOO_MANY_SEM_REQUESTS = 103
103
+ ERROR_INVALID_AT_INTERRUPT_TIME = 104
104
+
105
+ ERROR_SEM_OWNER_DIED = 105 # waitsem found owner died
106
+ ERROR_SEM_USER_LIMIT = 106 # too many procs have this sem
107
+ ERROR_DISK_CHANGE = 107 # insert disk b into drive a
108
+ ERROR_DRIVE_LOCKED = 108 # drive locked by another process
109
+ ERROR_BROKEN_PIPE = 109 # write on pipe with no reader
110
+
111
+ ERROR_OPEN_FAILED = 110 # open/created failed
112
+ ERROR_DISK_FULL = 112 # not enough space
113
+ ERROR_NO_MORE_SEARCH_HANDLES = 113 # can't allocate
114
+ ERROR_INVALID_TARGET_HANDLE = 114 # handle in DOSDUPHANDLE is invalid
115
+ ERROR_PROTECTION_VIOLATION = 115 # bad user virtual address
116
+ ERROR_VIOKBD_REQUEST = 116
117
+ ERROR_INVALID_CATEGORY = 117 # category for DEVIOCTL not defined
118
+ ERROR_INVALID_VERIFY_SWITCH = 118 # invalid value
119
+ ERROR_BAD_DRIVER_LEVEL = 119 # DosDevIOCTL not level four
120
+ ERROR_CALL_NOT_IMPLEMENTED = 120
121
+ ERROR_SEM_TIMEOUT = 121 # timeout from semaphore function
122
+ ERROR_INSUFFICIENT_BUFFER = 122
123
+
124
+ ERROR_INVALID_NAME = 123 # illegal char or malformed file system name
125
+ ERROR_INVALID_LEVEL = 124 # unimplemented level for info retrieval
126
+ ERROR_NO_VOLUME_LABEL = 125 # no volume label found
127
+ ERROR_MOD_NOT_FOUND = 126 # w_getprocaddr, w_getmodhandle
128
+ ERROR_PROC_NOT_FOUND = 127 # w_getprocaddr
129
+
130
+ ERROR_WAIT_NO_CHILDREN = 128 # CWait finds to children
131
+ ERROR_CHILD_NOT_COMPLETE = 129 # CWait children not dead yet
132
+
133
+ ERROR_DIRECT_ACCESS_HANDLE = 130 # invalid for direct disk access
134
+ ERROR_NEGATIVE_SEEK = 131 # tried to seek negative offset
135
+ ERROR_SEEK_ON_DEVICE = 132 # tried to seek on device or pipe
136
+
137
+ ERROR_IS_JOIN_TARGET = 133
138
+ ERROR_IS_JOINED = 134
139
+ ERROR_IS_SUBSTED = 135
140
+ ERROR_NOT_JOINED = 136
141
+ ERROR_NOT_SUBSTED = 137
142
+ ERROR_JOIN_TO_JOIN = 138
143
+ ERROR_SUBST_TO_SUBST = 139
144
+ ERROR_JOIN_TO_SUBST = 140
145
+ ERROR_SUBST_TO_JOIN = 141
146
+ ERROR_BUSY_DRIVE = 142
147
+ ERROR_SAME_DRIVE = 143
148
+ ERROR_DIR_NOT_ROOT = 144
149
+ ERROR_DIR_NOT_EMPTY = 145
150
+ ERROR_IS_SUBST_PATH = 146
151
+ ERROR_IS_JOIN_PATH = 147
152
+ ERROR_PATH_BUSY = 148
153
+ ERROR_IS_SUBST_TARGET = 149
154
+ ERROR_SYSTEM_TRACE = 150 # system trace error
155
+ ERROR_INVALID_EVENT_COUNT = 151 # DosMuxSemWait errors
156
+ ERROR_TOO_MANY_MUXWAITERS = 152
157
+ ERROR_INVALID_LIST_FORMAT = 153
158
+ ERROR_LABEL_TOO_LONG = 154
159
+ ERROR_TOO_MANY_TCBS = 155
160
+ ERROR_SIGNAL_REFUSED = 156
161
+ ERROR_DISCARDED = 157
162
+ ERROR_NOT_LOCKED = 158
163
+ ERROR_BAD_THREADID_ADDR = 159
164
+ ERROR_BAD_ARGUMENTS = 160
165
+ ERROR_BAD_PATHNAME = 161
166
+ ERROR_SIGNAL_PENDING = 162
167
+ ERROR_UNCERTAIN_MEDIA = 163
168
+ ERROR_MAX_THRDS_REACHED = 164
169
+ ERROR_MONITORS_NOT_SUPPORTED = 165
170
+
171
+ ERROR_INVALID_SEGMENT_NUMBER = 180
172
+ ERROR_INVALID_CALLGATE = 181
173
+ ERROR_INVALID_ORDINAL = 182
174
+ ERROR_ALREADY_EXISTS = 183
175
+ ERROR_NO_CHILD_PROCESS = 184
176
+ ERROR_CHILD_ALIVE_NOWAIT = 185
177
+ ERROR_INVALID_FLAG_NUMBER = 186
178
+ ERROR_SEM_NOT_FOUND = 187
179
+
180
+ ERROR_INVALID_STARTING_CODESEG = 188
181
+ ERROR_INVALID_STACKSEG = 189
182
+ ERROR_INVALID_MODULETYPE = 190
183
+ ERROR_INVALID_EXE_SIGNATURE = 191
184
+ ERROR_EXE_MARKED_INVALID = 192
185
+ ERROR_BAD_EXE_FORMAT = 193
186
+ ERROR_ITERATED_DATA_EXCEEDS_64k = 194
187
+ ERROR_INVALID_MINALLOCSIZE = 195
188
+ ERROR_DYNLINK_FROM_INVALID_RING = 196
189
+ ERROR_IOPL_NOT_ENABLED = 197
190
+ ERROR_INVALID_SEGDPL = 198
191
+ ERROR_AUTODATASEG_EXCEEDS_64k = 199
192
+ ERROR_RING2SEG_MUST_BE_MOVABLE = 200
193
+ ERROR_RELOC_CHAIN_XEEDS_SEGLIM = 201
194
+ ERROR_INFLOOP_IN_RELOC_CHAIN = 202
195
+
196
+ ERROR_ENVVAR_NOT_FOUND = 203
197
+ ERROR_NOT_CURRENT_CTRY = 204
198
+ ERROR_NO_SIGNAL_SENT = 205
199
+ ERROR_FILENAME_EXCED_RANGE = 206 # if filename > 8.3
200
+ ERROR_RING2_STACK_IN_USE = 207 # for FAPI
201
+ ERROR_META_EXPANSION_TOO_LONG = 208 # if "*a" > 8.3
202
+
203
+ ERROR_INVALID_SIGNAL_NUMBER = 209
204
+ ERROR_THREAD_1_INACTIVE = 210
205
+ ERROR_INFO_NOT_AVAIL = 211 #@@ PTM 5550
206
+ ERROR_LOCKED = 212
207
+ ERROR_BAD_DYNALINK = 213 #@@ PTM 5760
208
+ ERROR_TOO_MANY_MODULES = 214
209
+ ERROR_NESTING_NOT_ALLOWED = 215
210
+ ERROR_BAD_PIPE = 230
211
+ ERROR_PIPE_BUSY = 231
212
+ ERROR_NO_DATA = 232
213
+ ERROR_PIPE_NOT_CONNECTED = 233
214
+ ERROR_MORE_DATA = 234
215
+
216
+ ERROR_PIPE_CONNECTED = 535
217
+ ERROR_PIPE_LISTENING = 536
218
+
219
+ ERROR_OPERATION_ABORTED = 995
220
+ ERROR_IO_INCOMPLETE = 996
221
+ ERROR_IO_PENDING = 997
222
+
223
+ ERROR_USER_DEFINED_BASE = 0xF000
224
+
225
+ ERROR_I24_WRITE_PROTECT = 0
226
+ ERROR_I24_BAD_UNIT = 1
227
+ ERROR_I24_NOT_READY = 2
228
+ ERROR_I24_BAD_COMMAND = 3
229
+ ERROR_I24_CRC = 4
230
+ ERROR_I24_BAD_LENGTH = 5
231
+ ERROR_I24_SEEK = 6
232
+ ERROR_I24_NOT_DOS_DISK = 7
233
+ ERROR_I24_SECTOR_NOT_FOUND = 8
234
+ ERROR_I24_OUT_OF_PAPER = 9
235
+ ERROR_I24_WRITE_FAULT = 0x0A
236
+ ERROR_I24_READ_FAULT = 0x0B
237
+ ERROR_I24_GEN_FAILURE = 0x0C
238
+ ERROR_I24_DISK_CHANGE = 0x0D
239
+ ERROR_I24_WRONG_DISK = 0x0F
240
+ ERROR_I24_UNCERTAIN_MEDIA = 0x10
241
+ ERROR_I24_CHAR_CALL_INTERRUPTED = 0x11
242
+ ERROR_I24_NO_MONITOR_SUPPORT = 0x12
243
+ ERROR_I24_INVALID_PARAMETER = 0x13
244
+
245
+ APPLICATION_ERROR_MASK = 0x20000000
246
+ ERROR_SEVERITY_SUCCESS = 0x00000000
247
+ ERROR_SEVERITY_INFORMATIONAL = 0x40000000
248
+ ERROR_SEVERITY_WARNING = 0x80000000
249
+ ERROR_SEVERITY_ERROR = 0xc0000000
250
+
251
+ ALLOWED_FAIL = 0x0001
252
+ ALLOWED_ABORT = 0x0002
253
+ ALLOWED_RETRY = 0x0004
254
+ ALLOWED_IGNORE = 0x0008
255
+
256
+ I24_OPERATION = 0x1
257
+ I24_AREA = 0x6
258
+ I24_CLASS = 0x80
259
+
260
+ ERRCLASS_OUTRES = 1 # Out of Resource
261
+ ERRCLASS_TEMPSIT = 2 # Temporary Situation
262
+ ERRCLASS_AUTH = 3 # Permission problem
263
+ ERRCLASS_INTRN = 4 # Internal System Error
264
+ ERRCLASS_HRDFAIL = 5 # Hardware Failure
265
+ ERRCLASS_SYSFAIL = 6 # System Failure
266
+ ERRCLASS_APPERR = 7 # Application Error
267
+ ERRCLASS_NOTFND = 8 # Not Found
268
+ ERRCLASS_BADFMT = 9 # Bad Format
269
+ ERRCLASS_LOCKED = 10 # Locked
270
+ ERRCLASS_MEDIA = 11 # Media Failure
271
+ ERRCLASS_ALREADY = 12 # Collision with Existing Item
272
+ ERRCLASS_UNK = 13 # Unknown/other
273
+ ERRCLASS_CANT = 14
274
+ ERRCLASS_TIME = 15
275
+
276
+ ERRACT_RETRY = 1 # Retry
277
+ ERRACT_DLYRET = 2 # Delay Retry, retry after pause
278
+ ERRACT_USER = 3 # Ask user to regive info
279
+ ERRACT_ABORT = 4 # abort with clean up
280
+ ERRACT_PANIC = 5 # abort immediately
281
+ ERRACT_IGNORE = 6 # ignore
282
+ ERRACT_INTRET = 7 # Retry after User Intervention
283
+
284
+ ERRLOC_UNK = 1 # No appropriate value
285
+ ERRLOC_DISK = 2 # Random Access Mass Storage
286
+ ERRLOC_NET = 3 # Network
287
+ ERRLOC_SERDEV = 4 # Serial Device
288
+ ERRLOC_MEM = 5 # Memory
289
+
290
+ TC_NORMAL = 0
291
+ TC_HARDERR = 1
292
+ TC_GP_TRAP = 2
293
+ TC_SIGNAL = 3
294
+
295
+ # From WinError.h
296
+
297
+ ERROR_INVALID_FLAGS = 0x1004
298
+ ERROR_NO_UNICODE_TRANSLATION = 0x1113
299
+
300
+ E_INVALIDARG = 0x80070057
301
+ E_NOINTERFACE = 0x80004002
302
+ E_NOTIMPL = 0x80004001
303
+ E_OUTOFMEMORY = 0x8007000E
304
+ E_UNEXPECTED = 0x8000FFFF
305
+
306
+ RPC_E_TIMEOUT = 0x8001011F
307
+
308
+ CO_E_NOT_SUPPORTED = 0x80004021
309
+
310
+ CLASS_E_NOAGGREGATION = 0x80040110
311
+
312
+ DISP_E_BADINDEX = 0x8002000B
313
+ DISP_E_PARAMNOTFOUND = 0x80020004
314
+ DISP_E_EXCEPTION = 0x80020009
315
+ DISP_E_MEMBERNOTFOUND = 0x80020003
316
+
317
+ # Registry errors
318
+
319
+ REGDB_E_CLASSNOTREG = 0x80040154
320
+
321
+ # msterr.h
322
+
323
+ SCHED_S_TASK_READY = 0x00041300
324
+ SCHED_S_TASK_RUNNING = 0x00041301
325
+ SCHED_S_TASK_DISABLED = 0x00041302
326
+ SCHED_S_TASK_HAS_NOT_RUN = 0x00041303
327
+ SCHED_S_TASK_HAS_NO_MORE_RUNS = 0x00041304
328
+ SCHED_S_TASK_NOT_SCHEDULED = 0x00041305
329
+ SCHED_S_TASK_TERMINATED = 0x00041306
330
+ SCHED_S_TASK_NO_VALID_TRIGGERS = 0x00041307
331
+ SCHED_S_EVENT_TRIGGER = 0x00041308
332
+ SCHED_E_TRIGGER_NOT_FOUND = 0x00041309
333
+ SCHED_E_TASK_NOT_READY = 0x0004130A
334
+ SCHED_E_TASK_NOT_RUNNING = 0x0004130B
335
+ SCHED_E_SERVICE_NOT_INSTALLED = 0x0004130C
336
+ SCHED_E_CANNOT_OPEN_TASK = 0x0004130D
337
+ SCHED_E_INVALID_TASK = 0x0004130E
338
+ SCHED_E_ACCOUNT_INFORMATION_NOT_SET = 0x0004130F
339
+ SCHED_E_ACCOUNT_NAME_NOT_FOUND = 0x00041310
340
+ SCHED_E_ACCOUNT_DBASE_CORRUPT = 0x00041311
341
+ SCHED_E_NO_SECURITY_SERVICES = 0x00041312
342
+ SCHED_E_UNKNOWN_OBJECT_VERSION = 0x00041313
343
+
344
+ # Socket errors
345
+
346
+ WSA_INVALID_HANDLE = 6
347
+ WSA_NOT_ENOUGH_MEMORY = 8
348
+ WSA_INVALID_PARAMETER = 87
349
+ WSA_OPERATION_ABORTED = 995
350
+ WSA_IO_INCOMPLETE = 996
351
+ WSA_IO_PENDING = 997
352
+ WSAEINTR = 10004
353
+ WSAEBADF = 10009
354
+ WSAEACCESS = 10013
355
+ WSAEFAULT = 10014
356
+ WSAEINVAL = 10022
357
+ WSAEMFILE = 10024
358
+ WSAEWOULDBLOCK = 10035
359
+ WSAEINPROGRESS = 10036
360
+ WSAEALREADY = 10037
361
+ WSAENOTSOCK = 10038
362
+ WSAEDESTADDRREQ = 10039
363
+ WSAEMSGSIZE = 10040
364
+ WSAEPROTOTYPE = 10041
365
+ WSAENOPROTOOPT = 10042
366
+ WSAEPROTONOSUPPORT = 10043
367
+ WSAESOCKTNOSUPPORT = 10044
368
+ WSAEOPNOTSUPP = 10045
369
+ WSAEPFNOSUPPORT = 10046
370
+ WSAEAFNOSUPPORT = 10047
371
+ WSAEADDRINUSE = 10048
372
+ WSAEADDRNOTAVAIL = 10049
373
+ WSAENETDOWN = 10050
374
+ WSAENETUNREACH = 10051
375
+ WSAENETRESET = 10052
376
+ WSAECONNABORTED = 10053
377
+ WSAECONNRESET = 10054
378
+ WSAENOBUFS = 10055
379
+ WSAEISCONN = 10056
380
+ WSAENOTCONN = 10057
381
+ WSAESHUTDOWN = 10058
382
+ WSAETOOMANYREFS = 10059
383
+ WSATIMEDOUT = 10060
384
+ WSAECONNREFUSED = 10061
385
+ WSAELOOP = 10062
386
+ WSAENAMETOOLONG = 10063
387
+ WSAEHOSTDOWN = 10064
388
+ WSAEHOSTUNREACH = 10065
389
+ WSAENOEMPTY = 10066
390
+ WSAEPROCLIM = 10067
391
+ WSAEUSERS = 10068
392
+ WSAEDQUOT = 10069
393
+ WSAESTALE = 10070
394
+ WSAEREMOTE = 10071
395
+ WSASYSNOTREADY = 10091
396
+ WSAVERNOTSUPPORTED = 10092
397
+ WSANOTINITIALISED = 10093
398
+ WSAEDISCON = 10101
399
+ WSAENOMORE = 10102
400
+ WSAECANCELLED = 10103
401
+ WSAEINVALIDPROCTABLE = 10104
402
+ WSAEINVALIDPROVIDER = 10105
403
+ WSAEPROVIDERFAILEDINIT = 10106
404
+ WSASYSCALLFAILURE = 10107
405
+ WSASERVICE_NOT_FOUND = 10108
406
+ WSATYPE_NOT_FOUND = 10109
407
+ WSA_E_NO_MORE = 10110
408
+ WSA_E_CANCELLED = 10111
409
+ WSAEREFUSED = 10112
410
+ WSAHOST_NOT_FOUND = 11001
411
+ WSATRY_AGAIN = 11002
412
+ WSANO_RECOVERY = 11003
413
+ WSANO_DATA = 11004
414
+ WSA_QOS_RECEIVERS = 11005
415
+ WSA_QOS_SENDERS = 11006
416
+
417
+ # Token related
418
+
419
+ ERROR_NO_TOKEN = 1008
420
+ ERROR_NO_IMPERSONATION_TOKEN = 1309
421
+ ERROR_BAD_TOKEN_TYPE = 1349
422
+ ERROR_TOKEN_ALREADY_IN_USE = 1375
423
+ ERROR_SXS_INCORRECT_PUBLIC_KEY_TOKEN = 14095
424
+
425
+ API.new('GetLastError', 'V', 'L')
426
+ API.new('SetLastError', 'L', 'V')
427
+ API.new('SetErrorMode', 'I', 'I')
428
+ API.new('FormatMessage', 'LLLLPLP', 'L')
429
+
430
+ begin
431
+ API.new('GetErrorMode', 'V', 'I')
432
+ rescue Win32::API::LoadLibraryError
433
+ # Vista or later
434
+ end
435
+
436
+ begin
437
+ API.new('SetLastErrorEx', 'LL', 'V', 'user32')
438
+ rescue Win32::API::LoadLibraryError
439
+ # VC++ 7.0 or later
440
+ end
441
+
442
+ # Convenience method that wraps FormatMessage with some sane defaults and
443
+ # returns a human readable string.
444
+ #
445
+ def get_last_error(err_num = GetLastError.call)
446
+ buf = 0.chr * 260
447
+ flags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY
448
+ FormatMessageA.call(flags, 0, err_num, 0, buf, buf.size, 0)
449
+ buf.strip
450
+ end
451
+
452
+ # Macros from WinError.h
453
+
454
+ def IS_ERROR(status)
455
+ status >> 31 == 1
456
+ end
457
+
458
+ def MAKE_HRESULT(sev, fac, code)
459
+ sev << 31 | fac << 16 | code
460
+ end
461
+
462
+ def MAKE_SCODE(sev, fac, code)
463
+ sev << 31 | fac << 16 | code
464
+ end
465
+
466
+ def HRESULT_CODE(hr)
467
+ hr & 0xFFFF
468
+ end
469
+
470
+ def HRESULT_FACILITY(hr)
471
+ (hr >> 16) & 0x1fff
472
+ end
473
+
474
+ def HRESULT_FROM_NT(x)
475
+ x | 0x10000000 # FACILITY_NT_BIT
476
+ end
477
+
478
+ def HRESULT_FROM_WIN32(x)
479
+ if x <= 0
480
+ x
481
+ else
482
+ (x & 0x0000FFFF) | (7 << 16) | 0x80000000
483
+ end
484
+ end
485
+
486
+ def HRESULT_SEVERITY(hr)
487
+ (hr >> 31) & 0x1
488
+ end
489
+
490
+ def FAILED(status)
491
+ status < 0
492
+ end
493
+
494
+ def SUCCEEDED(status)
495
+ status >= 0
496
+ end
497
+ end
498
+ end