windows-pr 1.2.2 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGES +444 -438
- data/MANIFEST +68 -65
- data/README +154 -153
- data/Rakefile +42 -37
- data/doc/conversion_guide.txt +37 -37
- data/lib/windows/clipboard.rb +61 -61
- data/lib/windows/com.rb +192 -192
- data/lib/windows/com/accessibility.rb +16 -16
- data/lib/windows/com/automation.rb +149 -149
- data/lib/windows/com/variant.rb +24 -24
- data/lib/windows/console.rb +114 -114
- data/lib/windows/debug.rb +35 -35
- data/lib/windows/device_io.rb +248 -248
- data/lib/windows/directory.rb +27 -27
- data/lib/windows/error.rb +504 -498
- data/lib/windows/eventlog.rb +80 -80
- data/lib/windows/file.rb +264 -264
- data/lib/windows/file_mapping.rb +25 -25
- data/lib/windows/filesystem.rb +15 -15
- data/lib/windows/gdi/bitmap.rb +65 -65
- data/lib/windows/gdi/device_context.rb +46 -46
- data/lib/windows/gdi/metafile.rb +40 -40
- data/lib/windows/gdi/painting_drawing.rb +115 -115
- data/lib/windows/handle.rb +23 -23
- data/lib/windows/library.rb +44 -44
- data/lib/windows/limits.rb +34 -34
- data/lib/windows/mailslot.rb +24 -24
- data/lib/windows/memory.rb +128 -128
- data/lib/windows/msvcrt/buffer.rb +75 -75
- data/lib/windows/msvcrt/directory.rb +31 -31
- data/lib/windows/msvcrt/file.rb +47 -47
- data/lib/windows/msvcrt/io.rb +73 -73
- data/lib/windows/msvcrt/string.rb +182 -182
- data/lib/windows/msvcrt/time.rb +169 -169
- data/lib/windows/national.rb +580 -580
- data/lib/windows/network/management.rb +525 -525
- data/lib/windows/network/snmp.rb +92 -92
- data/lib/windows/network/winsock.rb +128 -128
- data/lib/windows/nio.rb +50 -50
- data/lib/windows/ntfs/winternl.rb +117 -117
- data/lib/windows/path.rb +143 -143
- data/lib/windows/pipe.rb +42 -42
- data/lib/windows/process.rb +176 -176
- data/lib/windows/registry.rb +171 -171
- data/lib/windows/security.rb +479 -479
- data/lib/windows/security/authentication.rb +32 -32
- data/lib/windows/security/sspi.rb +153 -0
- data/lib/windows/service.rb +142 -142
- data/lib/windows/shell.rb +171 -171
- data/lib/windows/socket.rb +86 -86
- data/lib/windows/sound.rb +39 -39
- data/lib/windows/synchronize.rb +133 -133
- data/lib/windows/system_info.rb +229 -229
- data/lib/windows/thread.rb +64 -64
- data/lib/windows/time.rb +48 -48
- data/lib/windows/tool_helper.rb +36 -36
- data/lib/windows/unicode.rb +155 -155
- data/lib/windows/volume.rb +61 -61
- data/lib/windows/window.rb +81 -81
- data/lib/windows/window/classes.rb +59 -59
- data/lib/windows/window/dialog.rb +91 -91
- data/lib/windows/window/menu.rb +102 -102
- data/lib/windows/window/message.rb +297 -297
- data/lib/windows/window/properties.rb +20 -20
- data/lib/windows/window/timer.rb +19 -19
- data/lib/windows/wsa.rb +102 -102
- data/test/tc_clipboard.rb +41 -41
- data/test/tc_com.rb +32 -32
- data/test/tc_com_automation.rb +15 -15
- data/test/tc_console.rb +108 -108
- data/test/tc_debug.rb +48 -48
- data/test/tc_device_io.rb +29 -29
- data/test/tc_directory.rb +25 -25
- data/test/tc_error.rb +38 -38
- data/test/tc_eventlog.rb +58 -58
- data/test/tc_file.rb +67 -67
- data/test/tc_file_mapping.rb +38 -38
- data/test/tc_filesystem.rb +27 -27
- data/test/tc_gdi_bitmap.rb +25 -25
- data/test/tc_gdi_metafile.rb +23 -23
- data/test/tc_handle.rb +36 -36
- data/test/tc_library.rb +37 -37
- data/test/tc_limits.rb +34 -34
- data/test/tc_mailslot.rb +22 -22
- data/test/tc_memory.rb +44 -44
- data/test/tc_msvcrt_buffer.rb +63 -63
- data/test/tc_msvcrt_directory.rb +96 -96
- data/test/tc_msvcrt_file.rb +80 -80
- data/test/tc_msvcrt_io.rb +48 -48
- data/test/tc_msvcrt_string.rb +94 -94
- data/test/tc_msvcrt_time.rb +19 -19
- data/test/tc_national.rb +38 -38
- data/test/tc_network_management.rb +32 -32
- data/test/tc_network_snmp.rb +31 -31
- data/test/tc_network_winsock.rb +34 -34
- data/test/tc_nio.rb +32 -32
- data/test/tc_ntfs_winternl.rb +48 -48
- data/test/tc_path.rb +90 -90
- data/test/tc_pipe.rb +53 -53
- data/test/tc_process.rb +24 -24
- data/test/tc_registry.rb +29 -29
- data/test/tc_security.rb +104 -104
- data/test/tc_security_authentication.rb +34 -34
- data/test/tc_security_sspi.rb +23 -0
- data/test/tc_service.rb +57 -57
- data/test/tc_shell.rb +34 -34
- data/test/tc_socket.rb +20 -20
- data/test/tc_sound.rb +37 -37
- data/test/tc_synchronize.rb +75 -75
- data/test/tc_system_info.rb +33 -33
- data/test/tc_thread.rb +29 -29
- data/test/tc_time.rb +32 -32
- data/test/tc_tool_helper.rb +29 -29
- data/test/tc_unicode.rb +83 -83
- data/test/tc_volume.rb +47 -47
- data/test/tc_window.rb +45 -45
- data/test/tc_window_classes.rb +33 -33
- data/test/tc_window_dialog.rb +33 -33
- data/test/tc_window_menu.rb +29 -29
- data/test/tc_window_message.rb +33 -33
- data/test/tc_window_properties.rb +29 -29
- data/test/tc_window_timer.rb +29 -29
- data/test/tc_wsa.rb +19 -19
- data/windows-pr.gemspec +33 -34
- metadata +31 -32
data/lib/windows/thread.rb
CHANGED
@@ -1,64 +1,64 @@
|
|
1
|
-
require 'windows/api'
|
2
|
-
|
3
|
-
module Windows
|
4
|
-
module Thread
|
5
|
-
API.auto_namespace = 'Windows::Thread'
|
6
|
-
API.auto_constant = true
|
7
|
-
API.auto_method = true
|
8
|
-
API.auto_unicode = true
|
9
|
-
|
10
|
-
private
|
11
|
-
|
12
|
-
SYNCHRONIZE = 0x00100000
|
13
|
-
THREAD_ALL_ACCESS = 0x1F03FF
|
14
|
-
THREAD_DIRECT_IMPERSONATION = 0x0200
|
15
|
-
THREAD_GET_CONTEXT = 0x0008
|
16
|
-
THREAD_IMPERSONATE = 0x0100
|
17
|
-
THREAD_QUERY_INFORMATION = 0x0040
|
18
|
-
THREAD_SET_CONTEXT = 0x0010
|
19
|
-
THREAD_SET_INFORMATION = 0x0020
|
20
|
-
THREAD_SET_THREAD_TOKEN = 0x0080
|
21
|
-
THREAD_SUSPEND_RESUME = 0x0002
|
22
|
-
THREAD_TERMINATE = 0x0001
|
23
|
-
|
24
|
-
THREAD_PRIORITY_ABOVE_NORMAL = 1
|
25
|
-
THREAD_PRIORITY_BELOW_NORMAL = -1
|
26
|
-
THREAD_PRIORITY_HIGHEST = 2
|
27
|
-
THREAD_PRIORITY_IDLE = -15
|
28
|
-
THREAD_PRIORITY_LOWEST = -2
|
29
|
-
THREAD_PRIORITY_NORMAL = 0
|
30
|
-
THREAD_PRIORITY_TIME_CRITICAL = 15
|
31
|
-
|
32
|
-
API.new('CreateRemoteThread', 'LPLLPLP', 'L')
|
33
|
-
API.new('CreateThread', 'PLKPLP', 'L')
|
34
|
-
API.new('ExitThread', 'L', 'V')
|
35
|
-
API.new('GetCurrentThread', 'V', 'L')
|
36
|
-
API.new('GetCurrentThreadId', 'V', 'L')
|
37
|
-
API.new('GetExitCodeThread', 'LP', 'B')
|
38
|
-
API.new('GetThreadPriority', 'L', 'I')
|
39
|
-
API.new('GetThreadPriorityBoost', 'LP', 'B')
|
40
|
-
API.new('GetThreadTimes', 'LPPPP', 'B')
|
41
|
-
API.new('OpenThread', 'LIL', 'L')
|
42
|
-
API.new('ResumeThread', 'L', 'L')
|
43
|
-
API.new('SetThreadAffinityMask', 'LP', 'P')
|
44
|
-
API.new('SetThreadIdealProcessor', 'LL', 'L')
|
45
|
-
API.new('SetThreadPriority', 'LI', 'B')
|
46
|
-
API.new('SetThreadPriorityBoost', 'LI', 'B')
|
47
|
-
API.new('Sleep', 'L', 'V')
|
48
|
-
API.new('SleepEx', 'LI', 'L')
|
49
|
-
API.new('SuspendThread', 'L', 'L')
|
50
|
-
API.new('SwitchToThread', 'V', 'B')
|
51
|
-
API.new('TerminateThread', 'LL', 'B')
|
52
|
-
API.new('TlsAlloc', 'V', 'L')
|
53
|
-
API.new('TlsFree', 'L', 'B')
|
54
|
-
API.new('TlsGetValue', 'L', 'L')
|
55
|
-
API.new('TlsSetValue', 'LL', 'B')
|
56
|
-
|
57
|
-
begin
|
58
|
-
API.new('AttachThreadInput', 'LLI', 'B', 'user32')
|
59
|
-
API.new('GetThreadIOPendingFlag', 'LP', 'B')
|
60
|
-
rescue Win32::API::LoadLibraryError
|
61
|
-
# Windows XP or later
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
1
|
+
require 'windows/api'
|
2
|
+
|
3
|
+
module Windows
|
4
|
+
module Thread
|
5
|
+
API.auto_namespace = 'Windows::Thread'
|
6
|
+
API.auto_constant = true
|
7
|
+
API.auto_method = true
|
8
|
+
API.auto_unicode = true
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
SYNCHRONIZE = 0x00100000
|
13
|
+
THREAD_ALL_ACCESS = 0x1F03FF
|
14
|
+
THREAD_DIRECT_IMPERSONATION = 0x0200
|
15
|
+
THREAD_GET_CONTEXT = 0x0008
|
16
|
+
THREAD_IMPERSONATE = 0x0100
|
17
|
+
THREAD_QUERY_INFORMATION = 0x0040
|
18
|
+
THREAD_SET_CONTEXT = 0x0010
|
19
|
+
THREAD_SET_INFORMATION = 0x0020
|
20
|
+
THREAD_SET_THREAD_TOKEN = 0x0080
|
21
|
+
THREAD_SUSPEND_RESUME = 0x0002
|
22
|
+
THREAD_TERMINATE = 0x0001
|
23
|
+
|
24
|
+
THREAD_PRIORITY_ABOVE_NORMAL = 1
|
25
|
+
THREAD_PRIORITY_BELOW_NORMAL = -1
|
26
|
+
THREAD_PRIORITY_HIGHEST = 2
|
27
|
+
THREAD_PRIORITY_IDLE = -15
|
28
|
+
THREAD_PRIORITY_LOWEST = -2
|
29
|
+
THREAD_PRIORITY_NORMAL = 0
|
30
|
+
THREAD_PRIORITY_TIME_CRITICAL = 15
|
31
|
+
|
32
|
+
API.new('CreateRemoteThread', 'LPLLPLP', 'L')
|
33
|
+
API.new('CreateThread', 'PLKPLP', 'L')
|
34
|
+
API.new('ExitThread', 'L', 'V')
|
35
|
+
API.new('GetCurrentThread', 'V', 'L')
|
36
|
+
API.new('GetCurrentThreadId', 'V', 'L')
|
37
|
+
API.new('GetExitCodeThread', 'LP', 'B')
|
38
|
+
API.new('GetThreadPriority', 'L', 'I')
|
39
|
+
API.new('GetThreadPriorityBoost', 'LP', 'B')
|
40
|
+
API.new('GetThreadTimes', 'LPPPP', 'B')
|
41
|
+
API.new('OpenThread', 'LIL', 'L')
|
42
|
+
API.new('ResumeThread', 'L', 'L')
|
43
|
+
API.new('SetThreadAffinityMask', 'LP', 'P')
|
44
|
+
API.new('SetThreadIdealProcessor', 'LL', 'L')
|
45
|
+
API.new('SetThreadPriority', 'LI', 'B')
|
46
|
+
API.new('SetThreadPriorityBoost', 'LI', 'B')
|
47
|
+
API.new('Sleep', 'L', 'V')
|
48
|
+
API.new('SleepEx', 'LI', 'L')
|
49
|
+
API.new('SuspendThread', 'L', 'L')
|
50
|
+
API.new('SwitchToThread', 'V', 'B')
|
51
|
+
API.new('TerminateThread', 'LL', 'B')
|
52
|
+
API.new('TlsAlloc', 'V', 'L')
|
53
|
+
API.new('TlsFree', 'L', 'B')
|
54
|
+
API.new('TlsGetValue', 'L', 'L')
|
55
|
+
API.new('TlsSetValue', 'LL', 'B')
|
56
|
+
|
57
|
+
begin
|
58
|
+
API.new('AttachThreadInput', 'LLI', 'B', 'user32')
|
59
|
+
API.new('GetThreadIOPendingFlag', 'LP', 'B')
|
60
|
+
rescue Win32::API::LoadLibraryError
|
61
|
+
# Windows XP or later
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/lib/windows/time.rb
CHANGED
@@ -1,48 +1,48 @@
|
|
1
|
-
require 'windows/api'
|
2
|
-
|
3
|
-
# In general you will want to use this module with Windows::National because
|
4
|
-
# it contains the various LOCALE and TIME constants.
|
5
|
-
|
6
|
-
module Windows
|
7
|
-
module Time
|
8
|
-
API.auto_namespace = 'Windows::Time'
|
9
|
-
API.auto_constant = true
|
10
|
-
API.auto_method = true
|
11
|
-
API.auto_unicode = true
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
TIME_ZONE_ID_UNKNOWN = 0
|
16
|
-
TIME_ZONE_ID_STANDARD = 1
|
17
|
-
TIME_ZONE_ID_DAYLIGHT = 2
|
18
|
-
|
19
|
-
API.new('CompareFileTime', 'PP', 'L')
|
20
|
-
API.new('DosDateTimeToFileTime', 'IIP', 'B')
|
21
|
-
API.new('FileTimeToDosDateTime', 'PPP', 'B')
|
22
|
-
API.new('FileTimeToLocalFileTime', 'PP', 'B')
|
23
|
-
API.new('FileTimeToSystemTime', 'PP', 'B')
|
24
|
-
API.new('GetFileTime', 'LPPP', 'B')
|
25
|
-
API.new('GetLocalTime', 'P')
|
26
|
-
API.new('GetSystemTime', 'P')
|
27
|
-
API.new('GetSystemTimeAdjustment', 'PPP', 'B')
|
28
|
-
API.new('GetSystemTimeAsFileTime', 'P')
|
29
|
-
API.new('GetTickCount')
|
30
|
-
API.new('GetTimeFormat', 'ILPPPI', 'I')
|
31
|
-
API.new('GetTimeZoneInformation', 'P', 'L')
|
32
|
-
API.new('LocalFileTimeToFileTime', 'PP', 'B')
|
33
|
-
API.new('SetFileTime', 'LPPP', 'B')
|
34
|
-
API.new('SetLocalTime', 'P', 'B')
|
35
|
-
API.new('SetSystemTime', 'P', 'B')
|
36
|
-
API.new('SetTimeZoneInformation', 'P', 'B')
|
37
|
-
API.new('SetSystemTimeAdjustment', 'LI', 'B')
|
38
|
-
API.new('SystemTimeToFileTime', 'PP', 'B')
|
39
|
-
API.new('SystemTimeToTzSpecificLocalTime', 'PPP', 'B')
|
40
|
-
|
41
|
-
begin
|
42
|
-
API.new('GetSystemTimes', 'PPP', 'B')
|
43
|
-
API.new('TzSpecificLocalTimeToSystemTime', 'PPP', 'B')
|
44
|
-
rescue Win32::API::LoadLibraryError
|
45
|
-
# Windows XP or later
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
1
|
+
require 'windows/api'
|
2
|
+
|
3
|
+
# In general you will want to use this module with Windows::National because
|
4
|
+
# it contains the various LOCALE and TIME constants.
|
5
|
+
|
6
|
+
module Windows
|
7
|
+
module Time
|
8
|
+
API.auto_namespace = 'Windows::Time'
|
9
|
+
API.auto_constant = true
|
10
|
+
API.auto_method = true
|
11
|
+
API.auto_unicode = true
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
TIME_ZONE_ID_UNKNOWN = 0
|
16
|
+
TIME_ZONE_ID_STANDARD = 1
|
17
|
+
TIME_ZONE_ID_DAYLIGHT = 2
|
18
|
+
|
19
|
+
API.new('CompareFileTime', 'PP', 'L')
|
20
|
+
API.new('DosDateTimeToFileTime', 'IIP', 'B')
|
21
|
+
API.new('FileTimeToDosDateTime', 'PPP', 'B')
|
22
|
+
API.new('FileTimeToLocalFileTime', 'PP', 'B')
|
23
|
+
API.new('FileTimeToSystemTime', 'PP', 'B')
|
24
|
+
API.new('GetFileTime', 'LPPP', 'B')
|
25
|
+
API.new('GetLocalTime', 'P')
|
26
|
+
API.new('GetSystemTime', 'P')
|
27
|
+
API.new('GetSystemTimeAdjustment', 'PPP', 'B')
|
28
|
+
API.new('GetSystemTimeAsFileTime', 'P')
|
29
|
+
API.new('GetTickCount')
|
30
|
+
API.new('GetTimeFormat', 'ILPPPI', 'I')
|
31
|
+
API.new('GetTimeZoneInformation', 'P', 'L')
|
32
|
+
API.new('LocalFileTimeToFileTime', 'PP', 'B')
|
33
|
+
API.new('SetFileTime', 'LPPP', 'B')
|
34
|
+
API.new('SetLocalTime', 'P', 'B')
|
35
|
+
API.new('SetSystemTime', 'P', 'B')
|
36
|
+
API.new('SetTimeZoneInformation', 'P', 'B')
|
37
|
+
API.new('SetSystemTimeAdjustment', 'LI', 'B')
|
38
|
+
API.new('SystemTimeToFileTime', 'PP', 'B')
|
39
|
+
API.new('SystemTimeToTzSpecificLocalTime', 'PPP', 'B')
|
40
|
+
|
41
|
+
begin
|
42
|
+
API.new('GetSystemTimes', 'PPP', 'B')
|
43
|
+
API.new('TzSpecificLocalTimeToSystemTime', 'PPP', 'B')
|
44
|
+
rescue Win32::API::LoadLibraryError
|
45
|
+
# Windows XP or later
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/windows/tool_helper.rb
CHANGED
@@ -1,36 +1,36 @@
|
|
1
|
-
require 'windows/api'
|
2
|
-
|
3
|
-
# Functions and constants from tlhelp32.h
|
4
|
-
|
5
|
-
module Windows
|
6
|
-
module ToolHelper
|
7
|
-
API.auto_namespace = 'Windows::ToolHelper'
|
8
|
-
API.auto_constant = true
|
9
|
-
API.auto_method = true
|
10
|
-
API.auto_unicode = true
|
11
|
-
|
12
|
-
private
|
13
|
-
|
14
|
-
TH32CS_SNAPHEAPLIST = 0x00000001
|
15
|
-
TH32CS_SNAPPROCESS = 0x00000002
|
16
|
-
TH32CS_SNAPTHREAD = 0x00000004
|
17
|
-
TH32CS_SNAPMODULE = 0x00000008
|
18
|
-
TH32CS_SNAPMODULE32 = 0x00000010
|
19
|
-
TH32CS_INHERIT = 0x80000000
|
20
|
-
TH32CS_SNAPALL = TH32CS_SNAPHEAPLIST | TH32CS_SNAPMODULE |
|
21
|
-
TH32CS_SNAPPROCESS | TH32CS_SNAPTHREAD
|
22
|
-
|
23
|
-
API.new('CreateToolhelp32Snapshot', 'LL', 'L')
|
24
|
-
API.new('Heap32First', 'PLL', 'B')
|
25
|
-
API.new('Heap32ListFirst', 'LP', 'B')
|
26
|
-
API.new('Heap32ListNext', 'LP', 'B')
|
27
|
-
API.new('Heap32Next', 'P', 'B')
|
28
|
-
API.new('Module32First', 'LP', 'B')
|
29
|
-
API.new('Module32Next', 'LP', 'B')
|
30
|
-
API.new('Process32First', 'LP', 'B')
|
31
|
-
API.new('Process32Next', 'LP', 'B')
|
32
|
-
API.new('Thread32First', 'LP', 'B')
|
33
|
-
API.new('Thread32Next', 'LP', 'B')
|
34
|
-
API.new('Toolhelp32ReadProcessMemory', 'LLPLL', 'B')
|
35
|
-
end
|
36
|
-
end
|
1
|
+
require 'windows/api'
|
2
|
+
|
3
|
+
# Functions and constants from tlhelp32.h
|
4
|
+
|
5
|
+
module Windows
|
6
|
+
module ToolHelper
|
7
|
+
API.auto_namespace = 'Windows::ToolHelper'
|
8
|
+
API.auto_constant = true
|
9
|
+
API.auto_method = true
|
10
|
+
API.auto_unicode = true
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
TH32CS_SNAPHEAPLIST = 0x00000001
|
15
|
+
TH32CS_SNAPPROCESS = 0x00000002
|
16
|
+
TH32CS_SNAPTHREAD = 0x00000004
|
17
|
+
TH32CS_SNAPMODULE = 0x00000008
|
18
|
+
TH32CS_SNAPMODULE32 = 0x00000010
|
19
|
+
TH32CS_INHERIT = 0x80000000
|
20
|
+
TH32CS_SNAPALL = TH32CS_SNAPHEAPLIST | TH32CS_SNAPMODULE |
|
21
|
+
TH32CS_SNAPPROCESS | TH32CS_SNAPTHREAD
|
22
|
+
|
23
|
+
API.new('CreateToolhelp32Snapshot', 'LL', 'L')
|
24
|
+
API.new('Heap32First', 'PLL', 'B')
|
25
|
+
API.new('Heap32ListFirst', 'LP', 'B')
|
26
|
+
API.new('Heap32ListNext', 'LP', 'B')
|
27
|
+
API.new('Heap32Next', 'P', 'B')
|
28
|
+
API.new('Module32First', 'LP', 'B')
|
29
|
+
API.new('Module32Next', 'LP', 'B')
|
30
|
+
API.new('Process32First', 'LP', 'B')
|
31
|
+
API.new('Process32Next', 'LP', 'B')
|
32
|
+
API.new('Thread32First', 'LP', 'B')
|
33
|
+
API.new('Thread32Next', 'LP', 'B')
|
34
|
+
API.new('Toolhelp32ReadProcessMemory', 'LLPLL', 'B')
|
35
|
+
end
|
36
|
+
end
|
data/lib/windows/unicode.rb
CHANGED
@@ -1,155 +1,155 @@
|
|
1
|
-
# encoding: ascii-8bit
|
2
|
-
require 'windows/api'
|
3
|
-
require 'windows/msvcrt/string'
|
4
|
-
require 'windows/error'
|
5
|
-
|
6
|
-
module Windows
|
7
|
-
module Unicode
|
8
|
-
include Windows::MSVCRT::String
|
9
|
-
include Windows::Error
|
10
|
-
|
11
|
-
private
|
12
|
-
|
13
|
-
API.auto_namespace = 'Windows::Unicode'
|
14
|
-
API.auto_constant = true
|
15
|
-
API.auto_method = true
|
16
|
-
API.auto_unicode = false
|
17
|
-
|
18
|
-
CP_ACP = 0
|
19
|
-
CP_OEMCP = 1
|
20
|
-
CP_MACCP = 2
|
21
|
-
CP_THREAD_ACP = 3
|
22
|
-
CP_SYMBOL = 42
|
23
|
-
CP_UTF7 = 65000
|
24
|
-
CP_UTF8 = 65001
|
25
|
-
|
26
|
-
MB_PRECOMPOSED = 0x00000001
|
27
|
-
MB_COMPOSITE = 0x00000002
|
28
|
-
MB_USEGLYPHCHARS = 0x00000004
|
29
|
-
MB_ERR_INVALID_CHARS = 0x00000008
|
30
|
-
|
31
|
-
WC_COMPOSITECHECK = 0x00000200
|
32
|
-
WC_DISCARDNS = 0x00000010
|
33
|
-
WC_SEPCHARS = 0x00000020
|
34
|
-
WC_DEFAULTCHAR = 0x00000040
|
35
|
-
WC_NO_BEST_FIT_CHARS = 0x00000400
|
36
|
-
|
37
|
-
ANSI_CHARSET = 0
|
38
|
-
DEFAULT_CHARSET = 1
|
39
|
-
SYMBOL_CHARSET = 2
|
40
|
-
SHIFTJIS_CHARSET = 128
|
41
|
-
HANGEUL_CHARSET = 129
|
42
|
-
HANGUL_CHARSET = 129
|
43
|
-
GB2312_CHARSET = 134
|
44
|
-
CHINESEBIG5_CHARSET = 136
|
45
|
-
OEM_CHARSET = 255
|
46
|
-
JOHAB_CHARSET = 130
|
47
|
-
HEBREW_CHARSET = 177
|
48
|
-
ARABIC_CHARSET = 178
|
49
|
-
GREEK_CHARSET = 161
|
50
|
-
TURKISH_CHARSET = 162
|
51
|
-
VIETNAMESE_CHARSET = 163
|
52
|
-
THAI_CHARSET = 222
|
53
|
-
EASTEUROPE_CHARSET = 238
|
54
|
-
RUSSIAN_CHARSET = 204
|
55
|
-
|
56
|
-
IS_TEXT_UNICODE_ASCII16 = 0x0001
|
57
|
-
IS_TEXT_UNICODE_REVERSE_ASCII16 = 0x0010
|
58
|
-
IS_TEXT_UNICODE_STATISTICS = 0x0002
|
59
|
-
IS_TEXT_UNICODE_REVERSE_STATISTICS = 0x0020
|
60
|
-
IS_TEXT_UNICODE_CONTROLS = 0x0004
|
61
|
-
IS_TEXT_UNICODE_REVERSE_CONTROLS = 0x0040
|
62
|
-
IS_TEXT_UNICODE_SIGNATURE = 0x0008
|
63
|
-
IS_TEXT_UNICODE_REVERSE_SIGNATURE = 0x0080
|
64
|
-
IS_TEXT_UNICODE_ILLEGAL_CHARS = 0x0100
|
65
|
-
IS_TEXT_UNICODE_ODD_LENGTH = 0x0200
|
66
|
-
IS_TEXT_UNICODE_DBCS_LEADBYTE = 0x0400
|
67
|
-
IS_TEXT_UNICODE_NULL_BYTES = 0x1000
|
68
|
-
IS_TEXT_UNICODE_UNICODE_MASK = 0x000F
|
69
|
-
IS_TEXT_UNICODE_REVERSE_MASK = 0x00F0
|
70
|
-
IS_TEXT_UNICODE_NOT_UNICODE_MASK = 0x0F00
|
71
|
-
IS_TEXT_UNICODE_NOT_ASCII_MASK = 0xF000
|
72
|
-
|
73
|
-
TCI_SRCCHARSET = 1
|
74
|
-
TCI_SRCCODEPAGE = 2
|
75
|
-
TCI_SRCFONTSIG = 3
|
76
|
-
TCI_SRCLOCALE = 0x100
|
77
|
-
|
78
|
-
API.new('GetTextCharset', 'L', 'I', 'gdi32')
|
79
|
-
API.new('GetTextCharsetInfo', 'LPL', 'I', 'gdi32')
|
80
|
-
API.new('IsDBCSLeadByte', 'P', 'B')
|
81
|
-
API.new('IsDBCSLeadByteEx', 'IP', 'B')
|
82
|
-
API.new('IsTextUnicode', 'SIP', 'B', 'advapi32')
|
83
|
-
API.new('MultiByteToWideChar', 'ILSIPI', 'I')
|
84
|
-
API.new('TranslateCharsetInfo', 'PPL', 'B', 'gdi32')
|
85
|
-
API.new('WideCharToMultiByte', 'ILSIPIPP', 'I')
|
86
|
-
|
87
|
-
# Convenient wrapper methods
|
88
|
-
|
89
|
-
# Maps a character string to a UTF-16 (wide) character string using the
|
90
|
-
# specified +encoding+. If no encoding is specified, then CP_UTF8
|
91
|
-
# is used if $KCODE (or the encoding name in Ruby 1.9.x) is set to UTF8.
|
92
|
-
# Otherwise, CP_ACP is used.
|
93
|
-
#
|
94
|
-
# If the function fails it simply returns the string as-is.
|
95
|
-
#
|
96
|
-
def multi_to_wide(string, encoding=nil)
|
97
|
-
return nil unless string
|
98
|
-
raise TypeError unless string.is_a?(String)
|
99
|
-
return string if IsTextUnicode(string, string.size, nil)
|
100
|
-
|
101
|
-
unless encoding
|
102
|
-
if RUBY_VERSION.to_f >= 1.9
|
103
|
-
encoding = (string.encoding.name == 'UTF-8') ? CP_UTF8 : CP_ACP
|
104
|
-
else
|
105
|
-
encoding = ($KCODE == 'UTF8') ? CP_UTF8 : CP_ACP
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
int = MultiByteToWideChar(encoding, 0, string, -1, nil, 0)
|
110
|
-
|
111
|
-
# Trailing nulls are retained
|
112
|
-
if int > 0
|
113
|
-
buf = ' ' * int * 2
|
114
|
-
MultiByteToWideChar(encoding, 0, string, -1, buf, int)
|
115
|
-
buf
|
116
|
-
else
|
117
|
-
raise ArgumentError, get_last_error
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
# Maps a wide character string to a new character string using the
|
122
|
-
# specified +encoding+. If no encoding is specified, then CP_UTF8
|
123
|
-
# is used if $KCODE (or the encoding name in Ruby 1.9.x) is set to UTF8.
|
124
|
-
# Otherwise, CP_ACP is used.
|
125
|
-
#
|
126
|
-
# If the function fails it simply returns the string as-is.
|
127
|
-
#
|
128
|
-
def wide_to_multi(wstring, encoding=nil)
|
129
|
-
return nil unless wstring
|
130
|
-
raise TypeError unless wstring.is_a?(String)
|
131
|
-
|
132
|
-
unless encoding
|
133
|
-
if RUBY_VERSION.to_f >= 1.9
|
134
|
-
encoding = (wstring.encoding.name == 'UTF-8') ? CP_UTF8 : CP_ACP
|
135
|
-
else
|
136
|
-
encoding = ($KCODE == 'UTF8') ? CP_UTF8 : CP_ACP
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
# Add a trailing double null if necessary
|
141
|
-
wstring << "\000\000" if wstring[-1].chr != "\000"
|
142
|
-
|
143
|
-
int = WideCharToMultiByte(encoding, 0, wstring, -1, 0, 0, nil, nil)
|
144
|
-
|
145
|
-
# Trailing nulls are stripped
|
146
|
-
if int > 0
|
147
|
-
buf = ' ' * int
|
148
|
-
WideCharToMultiByte(encoding, 0, wstring, -1, buf, strlen(buf), nil, nil)
|
149
|
-
buf[ /^[^\0]*/ ]
|
150
|
-
else
|
151
|
-
raise ArgumentError, get_last_error
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end
|
1
|
+
# encoding: ascii-8bit
|
2
|
+
require 'windows/api'
|
3
|
+
require 'windows/msvcrt/string'
|
4
|
+
require 'windows/error'
|
5
|
+
|
6
|
+
module Windows
|
7
|
+
module Unicode
|
8
|
+
include Windows::MSVCRT::String
|
9
|
+
include Windows::Error
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
API.auto_namespace = 'Windows::Unicode'
|
14
|
+
API.auto_constant = true
|
15
|
+
API.auto_method = true
|
16
|
+
API.auto_unicode = false
|
17
|
+
|
18
|
+
CP_ACP = 0
|
19
|
+
CP_OEMCP = 1
|
20
|
+
CP_MACCP = 2
|
21
|
+
CP_THREAD_ACP = 3
|
22
|
+
CP_SYMBOL = 42
|
23
|
+
CP_UTF7 = 65000
|
24
|
+
CP_UTF8 = 65001
|
25
|
+
|
26
|
+
MB_PRECOMPOSED = 0x00000001
|
27
|
+
MB_COMPOSITE = 0x00000002
|
28
|
+
MB_USEGLYPHCHARS = 0x00000004
|
29
|
+
MB_ERR_INVALID_CHARS = 0x00000008
|
30
|
+
|
31
|
+
WC_COMPOSITECHECK = 0x00000200
|
32
|
+
WC_DISCARDNS = 0x00000010
|
33
|
+
WC_SEPCHARS = 0x00000020
|
34
|
+
WC_DEFAULTCHAR = 0x00000040
|
35
|
+
WC_NO_BEST_FIT_CHARS = 0x00000400
|
36
|
+
|
37
|
+
ANSI_CHARSET = 0
|
38
|
+
DEFAULT_CHARSET = 1
|
39
|
+
SYMBOL_CHARSET = 2
|
40
|
+
SHIFTJIS_CHARSET = 128
|
41
|
+
HANGEUL_CHARSET = 129
|
42
|
+
HANGUL_CHARSET = 129
|
43
|
+
GB2312_CHARSET = 134
|
44
|
+
CHINESEBIG5_CHARSET = 136
|
45
|
+
OEM_CHARSET = 255
|
46
|
+
JOHAB_CHARSET = 130
|
47
|
+
HEBREW_CHARSET = 177
|
48
|
+
ARABIC_CHARSET = 178
|
49
|
+
GREEK_CHARSET = 161
|
50
|
+
TURKISH_CHARSET = 162
|
51
|
+
VIETNAMESE_CHARSET = 163
|
52
|
+
THAI_CHARSET = 222
|
53
|
+
EASTEUROPE_CHARSET = 238
|
54
|
+
RUSSIAN_CHARSET = 204
|
55
|
+
|
56
|
+
IS_TEXT_UNICODE_ASCII16 = 0x0001
|
57
|
+
IS_TEXT_UNICODE_REVERSE_ASCII16 = 0x0010
|
58
|
+
IS_TEXT_UNICODE_STATISTICS = 0x0002
|
59
|
+
IS_TEXT_UNICODE_REVERSE_STATISTICS = 0x0020
|
60
|
+
IS_TEXT_UNICODE_CONTROLS = 0x0004
|
61
|
+
IS_TEXT_UNICODE_REVERSE_CONTROLS = 0x0040
|
62
|
+
IS_TEXT_UNICODE_SIGNATURE = 0x0008
|
63
|
+
IS_TEXT_UNICODE_REVERSE_SIGNATURE = 0x0080
|
64
|
+
IS_TEXT_UNICODE_ILLEGAL_CHARS = 0x0100
|
65
|
+
IS_TEXT_UNICODE_ODD_LENGTH = 0x0200
|
66
|
+
IS_TEXT_UNICODE_DBCS_LEADBYTE = 0x0400
|
67
|
+
IS_TEXT_UNICODE_NULL_BYTES = 0x1000
|
68
|
+
IS_TEXT_UNICODE_UNICODE_MASK = 0x000F
|
69
|
+
IS_TEXT_UNICODE_REVERSE_MASK = 0x00F0
|
70
|
+
IS_TEXT_UNICODE_NOT_UNICODE_MASK = 0x0F00
|
71
|
+
IS_TEXT_UNICODE_NOT_ASCII_MASK = 0xF000
|
72
|
+
|
73
|
+
TCI_SRCCHARSET = 1
|
74
|
+
TCI_SRCCODEPAGE = 2
|
75
|
+
TCI_SRCFONTSIG = 3
|
76
|
+
TCI_SRCLOCALE = 0x100
|
77
|
+
|
78
|
+
API.new('GetTextCharset', 'L', 'I', 'gdi32')
|
79
|
+
API.new('GetTextCharsetInfo', 'LPL', 'I', 'gdi32')
|
80
|
+
API.new('IsDBCSLeadByte', 'P', 'B')
|
81
|
+
API.new('IsDBCSLeadByteEx', 'IP', 'B')
|
82
|
+
API.new('IsTextUnicode', 'SIP', 'B', 'advapi32')
|
83
|
+
API.new('MultiByteToWideChar', 'ILSIPI', 'I')
|
84
|
+
API.new('TranslateCharsetInfo', 'PPL', 'B', 'gdi32')
|
85
|
+
API.new('WideCharToMultiByte', 'ILSIPIPP', 'I')
|
86
|
+
|
87
|
+
# Convenient wrapper methods
|
88
|
+
|
89
|
+
# Maps a character string to a UTF-16 (wide) character string using the
|
90
|
+
# specified +encoding+. If no encoding is specified, then CP_UTF8
|
91
|
+
# is used if $KCODE (or the encoding name in Ruby 1.9.x) is set to UTF8.
|
92
|
+
# Otherwise, CP_ACP is used.
|
93
|
+
#
|
94
|
+
# If the function fails it simply returns the string as-is.
|
95
|
+
#
|
96
|
+
def multi_to_wide(string, encoding=nil)
|
97
|
+
return nil unless string
|
98
|
+
raise TypeError unless string.is_a?(String)
|
99
|
+
return string if IsTextUnicode(string, string.size, nil)
|
100
|
+
|
101
|
+
unless encoding
|
102
|
+
if RUBY_VERSION.to_f >= 1.9
|
103
|
+
encoding = (string.encoding.name == 'UTF-8') ? CP_UTF8 : CP_ACP
|
104
|
+
else
|
105
|
+
encoding = ($KCODE == 'UTF8') ? CP_UTF8 : CP_ACP
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
int = MultiByteToWideChar(encoding, 0, string, -1, nil, 0)
|
110
|
+
|
111
|
+
# Trailing nulls are retained
|
112
|
+
if int > 0
|
113
|
+
buf = ' ' * int * 2
|
114
|
+
MultiByteToWideChar(encoding, 0, string, -1, buf, int)
|
115
|
+
buf
|
116
|
+
else
|
117
|
+
raise ArgumentError, get_last_error
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
# Maps a wide character string to a new character string using the
|
122
|
+
# specified +encoding+. If no encoding is specified, then CP_UTF8
|
123
|
+
# is used if $KCODE (or the encoding name in Ruby 1.9.x) is set to UTF8.
|
124
|
+
# Otherwise, CP_ACP is used.
|
125
|
+
#
|
126
|
+
# If the function fails it simply returns the string as-is.
|
127
|
+
#
|
128
|
+
def wide_to_multi(wstring, encoding=nil)
|
129
|
+
return nil unless wstring
|
130
|
+
raise TypeError unless wstring.is_a?(String)
|
131
|
+
|
132
|
+
unless encoding
|
133
|
+
if RUBY_VERSION.to_f >= 1.9
|
134
|
+
encoding = (wstring.encoding.name == 'UTF-8') ? CP_UTF8 : CP_ACP
|
135
|
+
else
|
136
|
+
encoding = ($KCODE == 'UTF8') ? CP_UTF8 : CP_ACP
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
# Add a trailing double null if necessary
|
141
|
+
wstring << "\000\000" if wstring[-1].chr != "\000"
|
142
|
+
|
143
|
+
int = WideCharToMultiByte(encoding, 0, wstring, -1, 0, 0, nil, nil)
|
144
|
+
|
145
|
+
# Trailing nulls are stripped
|
146
|
+
if int > 0
|
147
|
+
buf = ' ' * int
|
148
|
+
WideCharToMultiByte(encoding, 0, wstring, -1, buf, strlen(buf), nil, nil)
|
149
|
+
buf[ /^[^\0]*/ ]
|
150
|
+
else
|
151
|
+
raise ArgumentError, get_last_error
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|