windows-api 0.2.4 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +6 -0
- data/MANIFEST +1 -0
- data/lib/windows/api.rb +4 -12
- data/lib/windows/wide_string.rb +60 -0
- data/test/test_wide_string.rb +53 -0
- data/test/test_windows_api.rb +10 -1
- data/windows-api.gemspec +2 -3
- metadata +9 -8
- data/windows-api.gemspec~ +0 -25
data/CHANGES
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
= 0.3.0 - 1-Feb-2009
|
2
|
+
* No longer explicitly checks for an error in the constructor. It lets the
|
3
|
+
underlying Win32::API library deal with it.
|
4
|
+
* More dynamic handling and setting of the MSVCRT_DLL variable.
|
5
|
+
* Added a WideString implementation. Internal use only.
|
6
|
+
|
1
7
|
= 0.2.4 - 18-Jul-2008
|
2
8
|
* Eliminated unnecessary LoadLibrary() attempts for functions that explicitly
|
3
9
|
end with an 'A' or 'W', and all MSVCRT functions, since they have no 'A'
|
data/MANIFEST
CHANGED
data/lib/windows/api.rb
CHANGED
@@ -12,7 +12,7 @@ module Windows
|
|
12
12
|
if CONFIG['host_os'].split('_')[1].to_i >= 80 &&
|
13
13
|
File.exists?(File.join(CONFIG['bindir'], 'ruby.exe.manifest'))
|
14
14
|
then
|
15
|
-
MSVCRT_DLL = '
|
15
|
+
MSVCRT_DLL = 'msvcr' + CONFIG['host_os'].split('_')[1]
|
16
16
|
else
|
17
17
|
MSVCRT_DLL = 'msvcrt'
|
18
18
|
end
|
@@ -25,11 +25,8 @@ module Windows
|
|
25
25
|
extend Forwardable
|
26
26
|
|
27
27
|
# The version of this library
|
28
|
-
VERSION = '0.
|
28
|
+
VERSION = '0.3.0'
|
29
29
|
|
30
|
-
# Error typically raised if any of the Windows::API methods fail
|
31
|
-
class Error < RuntimeError; end
|
32
|
-
|
33
30
|
# The methods from Win32::API are delegated to the appropriate object
|
34
31
|
def_delegators(:@api, :function_name, :dll_name, :prototype)
|
35
32
|
def_delegators(:@api, :return_type, :effective_function_name)
|
@@ -288,7 +285,6 @@ module Windows
|
|
288
285
|
@auto_unicode = bool
|
289
286
|
end
|
290
287
|
|
291
|
-
|
292
288
|
# call-seq:
|
293
289
|
# API.new(func, proto='V', rtype='L', dll='kernel32')
|
294
290
|
#
|
@@ -334,11 +330,7 @@ module Windows
|
|
334
330
|
@dll_name = dll
|
335
331
|
@boolean = rtype == 'B' ? true : false
|
336
332
|
|
337
|
-
|
338
|
-
@api = Win32::API.new(func, proto, rtype, dll)
|
339
|
-
rescue RuntimeError => err
|
340
|
-
raise Error, err
|
341
|
-
end
|
333
|
+
@api = Win32::API.new(func, proto, rtype, dll)
|
342
334
|
|
343
335
|
api_a = nil
|
344
336
|
api_w = nil
|
@@ -352,7 +344,7 @@ module Windows
|
|
352
344
|
# msvcrt functions never have explicit ANSI or Wide character
|
353
345
|
# versions.
|
354
346
|
#
|
355
|
-
if Windows::API.auto_unicode && dll
|
347
|
+
if Windows::API.auto_unicode && dll !~ /msvcr/i
|
356
348
|
begin
|
357
349
|
unless ['A', 'W'].include?(func[-1].chr)
|
358
350
|
api_a = Win32::API.new("#{func}A", proto, rtype, dll)
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'windows/unicode'
|
2
|
+
require 'windows/msvcrt/string'
|
3
|
+
|
4
|
+
# This is a class that simplifies wide string handling. It is NOT meant
|
5
|
+
# for general consumption, but for internal use by the Win32Utils Team.
|
6
|
+
# Use at your own risk.
|
7
|
+
#
|
8
|
+
class WideString < String
|
9
|
+
include Windows::Unicode
|
10
|
+
include Windows::MSVCRT::String
|
11
|
+
|
12
|
+
ACP = CP_ACP
|
13
|
+
UTF7 = CP_UTF7
|
14
|
+
UTF8 = CP_UTF8
|
15
|
+
|
16
|
+
# Get or set the encoding of the wide string object
|
17
|
+
#
|
18
|
+
attr_accessor :encoding
|
19
|
+
|
20
|
+
# Creates a new wide +string+ with the given +encoding+, or UTF8 if
|
21
|
+
# no encoding is specified.
|
22
|
+
#
|
23
|
+
def initialize(string, encoding = UTF8)
|
24
|
+
super(multi_to_wide(string, encoding))
|
25
|
+
@encoding = encoding
|
26
|
+
end
|
27
|
+
|
28
|
+
# Returns the multibyte version of the wide string.
|
29
|
+
#
|
30
|
+
def to_multi
|
31
|
+
wide_to_multi(self, @encoding)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Replaces the wide string with a multibyte version.
|
35
|
+
#
|
36
|
+
def to_multi!
|
37
|
+
self.replace(wide_to_multi(self, @encoding))
|
38
|
+
end
|
39
|
+
|
40
|
+
alias to_s to_multi
|
41
|
+
alias to_str to_multi
|
42
|
+
alias inspect to_multi
|
43
|
+
|
44
|
+
# Strips the trailing two null characters from the string.
|
45
|
+
#
|
46
|
+
def wstrip
|
47
|
+
self[0..-3] if string[-2..-1] == "\000\000"
|
48
|
+
end
|
49
|
+
|
50
|
+
# The length of the wide string in chars.
|
51
|
+
#
|
52
|
+
def length
|
53
|
+
wcslen(self) * 2
|
54
|
+
end
|
55
|
+
|
56
|
+
# The size of the wide string in bytes.
|
57
|
+
def size
|
58
|
+
wcslen(self)
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'test-unit'
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
require 'windows/wide_string'
|
6
|
+
|
7
|
+
class TC_WideString < Test::Unit::TestCase
|
8
|
+
def setup
|
9
|
+
@str_english = WideString.new('hello')
|
10
|
+
@str_greek = WideString.new('Ελλάσ')
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_length
|
14
|
+
assert_equal(10, @str_english.length)
|
15
|
+
assert_equal(10, @str_greek.length)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_size
|
19
|
+
assert_equal(5, @str_english.size)
|
20
|
+
assert_equal(5, @str_greek.size)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_to_multi
|
24
|
+
assert_respond_to(@str_english, :to_multi)
|
25
|
+
assert_equal('hello', @str_english.to_multi)
|
26
|
+
assert_equal('Ελλάσ', @str_greek.to_multi)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_literal_string_value
|
30
|
+
assert_equal("h\000e\000l\000l\000o\000\000\000", @str_english)
|
31
|
+
assert_equal("\225\003\273\003\273\003\254\003\303\003\000\000", @str_greek)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_alias_to_s
|
35
|
+
assert_respond_to(@str_greek, :to_s)
|
36
|
+
assert_true(@str_greek.method(:to_s) == @str_greek.method(:to_multi))
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_alias_to_str
|
40
|
+
assert_respond_to(@str_greek, :to_str)
|
41
|
+
assert_true(@str_greek.method(:to_str) == @str_greek.method(:to_multi))
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_alias_inspect
|
45
|
+
assert_respond_to(@str_greek, :inspect)
|
46
|
+
assert_true(@str_greek.method(:inspect) == @str_greek.method(:to_multi))
|
47
|
+
end
|
48
|
+
|
49
|
+
def teardown
|
50
|
+
@str_english = nil
|
51
|
+
@str_greek = nil
|
52
|
+
end
|
53
|
+
end
|
data/test/test_windows_api.rb
CHANGED
@@ -55,7 +55,7 @@ class TC_Windows_API < Test::Unit::TestCase
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def test_version
|
58
|
-
assert_equal('0.
|
58
|
+
assert_equal('0.3.0', API::VERSION)
|
59
59
|
end
|
60
60
|
|
61
61
|
def test_full_data_types
|
@@ -148,6 +148,15 @@ class TC_Windows_API < Test::Unit::TestCase
|
|
148
148
|
assert_equal('ReadDirectoryChangesW', $read.effective_function_name)
|
149
149
|
end
|
150
150
|
|
151
|
+
def test_bad_prototype_raises_error
|
152
|
+
assert_raise(Win32::API::PrototypeError){ Windows::API.new('GetCurrentDirectory', 'XL', 'L') }
|
153
|
+
assert_raise(Win32::API::PrototypeError){ Windows::API.new('GetCurrentDirectory', 'PL', 'X') }
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_bad_function_raises_error
|
157
|
+
assert_raise(Win32::API::LoadLibraryError){ Windows::API.new('GetCurrentFooBar', 'LL', 'L') }
|
158
|
+
end
|
159
|
+
|
151
160
|
def teardown
|
152
161
|
@buf = nil
|
153
162
|
end
|
data/windows-api.gemspec
CHANGED
@@ -2,7 +2,7 @@ require "rubygems"
|
|
2
2
|
|
3
3
|
spec = Gem::Specification.new do |gem|
|
4
4
|
gem.name = "windows-api"
|
5
|
-
gem.version = "0.
|
5
|
+
gem.version = "0.3.0"
|
6
6
|
gem.author = "Daniel J. Berger"
|
7
7
|
gem.email = "djberg96@gmail.com"
|
8
8
|
gem.homepage = "http://www.rubyforge.org/projects/win32utils"
|
@@ -16,10 +16,9 @@ spec = Gem::Specification.new do |gem|
|
|
16
16
|
gem.files.reject! { |fn| fn.include? "CVS" }
|
17
17
|
gem.require_path = "lib"
|
18
18
|
gem.extra_rdoc_files = ["README", "CHANGES", "MANIFEST"]
|
19
|
-
gem.add_dependency("win32-api", ">= 1.0
|
19
|
+
gem.add_dependency("win32-api", ">= 1.3.0")
|
20
20
|
end
|
21
21
|
|
22
22
|
if $0 == __FILE__
|
23
|
-
Gem.manage_gems
|
24
23
|
Gem::Builder.new(spec).build
|
25
24
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: windows-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel J. Berger
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-02-01 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 1.0
|
23
|
+
version: 1.3.0
|
24
24
|
version:
|
25
25
|
description: An easier way to create methods using Win32API
|
26
26
|
email: djberg96@gmail.com
|
@@ -34,19 +34,20 @@ extra_rdoc_files:
|
|
34
34
|
- MANIFEST
|
35
35
|
files:
|
36
36
|
- lib/windows/api.rb
|
37
|
-
-
|
37
|
+
- lib/windows/wide_string.rb
|
38
|
+
- test/test_wide_string.rb
|
38
39
|
- test/test_windows_api.rb
|
39
40
|
- CHANGES
|
40
|
-
- CVS
|
41
41
|
- lib
|
42
42
|
- MANIFEST
|
43
43
|
- Rakefile
|
44
44
|
- README
|
45
45
|
- test
|
46
46
|
- windows-api.gemspec
|
47
|
-
- windows-api.gemspec~
|
48
47
|
has_rdoc: true
|
49
48
|
homepage: http://www.rubyforge.org/projects/win32utils
|
49
|
+
licenses: []
|
50
|
+
|
50
51
|
post_install_message:
|
51
52
|
rdoc_options: []
|
52
53
|
|
@@ -67,9 +68,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
68
|
requirements: []
|
68
69
|
|
69
70
|
rubyforge_project: win32utils
|
70
|
-
rubygems_version: 1.
|
71
|
+
rubygems_version: 1.3.1
|
71
72
|
signing_key:
|
72
|
-
specification_version:
|
73
|
+
specification_version: 3
|
73
74
|
summary: An easier way to create methods using Win32API
|
74
75
|
test_files:
|
75
76
|
- test/test_windows_api.rb
|
data/windows-api.gemspec~
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require "rubygems"
|
2
|
-
|
3
|
-
spec = Gem::Specification.new do |gem|
|
4
|
-
gem.name = "windows-api"
|
5
|
-
gem.version = "0.2.4"
|
6
|
-
gem.author = "Daniel J. Berger"
|
7
|
-
gem.email = "djberg96@gmail.com"
|
8
|
-
gem.homepage = "http://www.rubyforge.org/projects/win32utils"
|
9
|
-
gem.rubyforge_project = "win32utils"
|
10
|
-
gem.platform = Gem::Platform::RUBY
|
11
|
-
gem.summary = "An easier way to create methods using Win32API"
|
12
|
-
gem.description = "An easier way to create methods using Win32API"
|
13
|
-
gem.test_file = "test/tc_windows_api.rb"
|
14
|
-
gem.has_rdoc = true
|
15
|
-
gem.files = Dir["lib/windows/*.rb"] + Dir["test/*"] + Dir["[A-Z]*"]
|
16
|
-
gem.files.reject! { |fn| fn.include? "CVS" }
|
17
|
-
gem.require_path = "lib"
|
18
|
-
gem.extra_rdoc_files = ["README", "CHANGES", "MANIFEST"]
|
19
|
-
gem.add_dependency("win32-api", ">= 1.0.5")
|
20
|
-
end
|
21
|
-
|
22
|
-
if $0 == __FILE__
|
23
|
-
Gem.manage_gems
|
24
|
-
Gem::Builder.new(spec).build
|
25
|
-
end
|