windows-api 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +12 -1
- data/MANIFEST +1 -1
- data/Rakefile +0 -2
- data/lib/windows/api.rb +26 -13
- data/test/{tc_windows_api.rb → test_windows_api.rb} +21 -7
- data/windows-api.gemspec +2 -2
- data/windows-api.gemspec~ +25 -0
- metadata +7 -5
data/CHANGES
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
= 0.2.4 - 18-Jul-2008
|
2
|
+
* Eliminated unnecessary LoadLibrary() attempts for functions that explicitly
|
3
|
+
end with an 'A' or 'W', and all MSVCRT functions, since they have no 'A'
|
4
|
+
or 'W' equivalent.
|
5
|
+
* Replaced all of the attr_reader's with a delegation scheme using Forwardable.
|
6
|
+
All Win32::API functions now delegate to the internally stored Win32::API
|
7
|
+
object instead of reimplementing them. This change also fixed a bug where
|
8
|
+
the effective_function_name method did not work properly.
|
9
|
+
* Added more tests, and fixed one assertion that was wrong (the prototype).
|
10
|
+
* Some documentation additions.
|
11
|
+
|
1
12
|
= 0.2.3 - 26-Apr-2008
|
2
13
|
* Improved API.auto_constant and API.auto_method handling for functions that
|
3
14
|
start with a lower case character or an underscore.
|
@@ -19,4 +30,4 @@
|
|
19
30
|
* Fixed a void parameter bug.
|
20
31
|
|
21
32
|
= 0.1.0 - 24-May-2007
|
22
|
-
* Initial release
|
33
|
+
* Initial release
|
data/MANIFEST
CHANGED
data/Rakefile
CHANGED
data/lib/windows/api.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
require 'win32/api'
|
2
2
|
require 'rbconfig'
|
3
|
+
require 'forwardable'
|
3
4
|
include Config
|
4
5
|
|
6
|
+
# The Windows module serves as a namespace only
|
5
7
|
module Windows
|
8
|
+
|
6
9
|
# With Microsoft Visual C++ 8 and later users should use the associated
|
7
10
|
# DLL instead of msvcrt directly, if possible.
|
8
11
|
if CONFIG['host_os'].split('_')[1]
|
@@ -17,13 +20,23 @@ module Windows
|
|
17
20
|
MSVCRT_DLL = 'msvcrt'
|
18
21
|
end
|
19
22
|
|
23
|
+
# Wrapper around the Win32::API class
|
20
24
|
class API
|
21
|
-
|
25
|
+
extend Forwardable
|
26
|
+
|
27
|
+
# The version of this library
|
28
|
+
VERSION = '0.2.4'
|
22
29
|
|
30
|
+
# Error typically raised if any of the Windows::API methods fail
|
23
31
|
class Error < RuntimeError; end
|
32
|
+
|
33
|
+
# The methods from Win32::API are delegated to the appropriate object
|
34
|
+
def_delegators(:@api, :function_name, :dll_name, :prototype)
|
35
|
+
def_delegators(:@api, :return_type, :effective_function_name)
|
24
36
|
|
25
37
|
private
|
26
38
|
|
39
|
+
# Verbose data types that can be used instead of single letters
|
27
40
|
DATA_TYPES = {
|
28
41
|
'ATOM' => 'I',
|
29
42
|
'BOOL' => 'B',
|
@@ -275,11 +288,7 @@ module Windows
|
|
275
288
|
@auto_unicode = bool
|
276
289
|
end
|
277
290
|
|
278
|
-
|
279
|
-
attr_reader :dll_name
|
280
|
-
attr_reader :prototype
|
281
|
-
attr_reader :return_type
|
282
|
-
|
291
|
+
|
283
292
|
# call-seq:
|
284
293
|
# API.new(func, proto='V', rtype='L', dll='kernel32')
|
285
294
|
#
|
@@ -335,20 +344,24 @@ module Windows
|
|
335
344
|
api_w = nil
|
336
345
|
|
337
346
|
# If the auto_unicode option is set, and the func is not already
|
338
|
-
# an explicit ANSI or
|
347
|
+
# an explicit ANSI or Wide function name, generate Win32::API
|
339
348
|
# objects for those functions as well. Ignore errors because not
|
340
|
-
# all functions have explicit ANSI or
|
349
|
+
# all functions have explicit ANSI or Wide character implementations.
|
350
|
+
#
|
351
|
+
# This entire bit of logic is skipped if the DLL is msvcrt, since
|
352
|
+
# msvcrt functions never have explicit ANSI or Wide character
|
353
|
+
# versions.
|
341
354
|
#
|
342
|
-
if Windows::API.auto_unicode
|
355
|
+
if Windows::API.auto_unicode && dll.downcase != 'msvcrt'
|
343
356
|
begin
|
344
|
-
|
357
|
+
unless ['A', 'W'].include?(func[-1].chr)
|
345
358
|
api_a = Win32::API.new("#{func}A", proto, rtype, dll)
|
346
359
|
end
|
347
360
|
rescue RuntimeError
|
348
361
|
end
|
349
|
-
|
362
|
+
|
350
363
|
begin
|
351
|
-
|
364
|
+
unless ['W', 'A'].include?(func[-1].chr)
|
352
365
|
api_w = Win32::API.new("#{func}W", proto, rtype, dll)
|
353
366
|
end
|
354
367
|
rescue RuntimeError
|
@@ -478,7 +491,7 @@ module Windows
|
|
478
491
|
def call(*args)
|
479
492
|
@api.call(*args)
|
480
493
|
end
|
481
|
-
|
494
|
+
|
482
495
|
private
|
483
496
|
|
484
497
|
# Get a module's namespace. This is basically the equivalent of
|
@@ -1,5 +1,5 @@
|
|
1
1
|
############################################################################
|
2
|
-
#
|
2
|
+
# test_windows_api.rb
|
3
3
|
#
|
4
4
|
# Test case for the Windows::API class. You should run this as Rake task,
|
5
5
|
# i.e. 'rake test', instead of running it directly.
|
@@ -36,11 +36,11 @@ module Windows
|
|
36
36
|
API.auto_namespace = 'Windows::Baz'
|
37
37
|
API.auto_constant = true
|
38
38
|
API.auto_method = true
|
39
|
-
API.auto_unicode = false
|
40
39
|
|
41
|
-
API.new('strstr', 'PP', 'P', 'msvcrt')
|
42
|
-
API.new('_umask', 'I', 'I', 'msvcrt')
|
43
|
-
API.new('waveOutGetNumDevs', 'V', 'I', 'winmm')
|
40
|
+
$strstr = API.new('strstr', 'PP', 'P', 'msvcrt')
|
41
|
+
$umask = API.new('_umask', 'I', 'I', 'msvcrt')
|
42
|
+
$wave = API.new('waveOutGetNumDevs', 'V', 'I', 'winmm')
|
43
|
+
$read = API.new('ReadDirectoryChangesW', 'LPLILPPP', 'B') # No ANSI equivalent
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -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.2.
|
58
|
+
assert_equal('0.2.4', API::VERSION)
|
59
59
|
end
|
60
60
|
|
61
61
|
def test_full_data_types
|
@@ -75,6 +75,12 @@ class TC_Windows_API < Test::Unit::TestCase
|
|
75
75
|
assert_not_nil(Windows::Baz::WaveOutGetNumDevs)
|
76
76
|
end
|
77
77
|
|
78
|
+
def test_explicit_wide_function_only
|
79
|
+
assert_not_nil(Windows::Baz::ReadDirectoryChangesW)
|
80
|
+
assert_equal(false, Windows::Baz.constants.include?('ReadDirectoryChanges'))
|
81
|
+
assert_equal(false, Windows::Baz.constants.include?('ReadDirectoryChangesA'))
|
82
|
+
end
|
83
|
+
|
78
84
|
def test_lower_case_auto_methods
|
79
85
|
assert_respond_to(self, :strstr)
|
80
86
|
assert_respond_to(self, :umask)
|
@@ -126,13 +132,21 @@ class TC_Windows_API < Test::Unit::TestCase
|
|
126
132
|
|
127
133
|
def test_prototype
|
128
134
|
assert_respond_to($test_method, :prototype)
|
129
|
-
assert_equal('
|
135
|
+
assert_equal(['P', 'P'], $test_method.prototype)
|
130
136
|
end
|
131
137
|
|
132
138
|
def test_return_type
|
133
139
|
assert_respond_to($test_method, :return_type)
|
134
140
|
assert_equal('L', $test_method.return_type)
|
135
141
|
end
|
142
|
+
|
143
|
+
def test_effective_function_name
|
144
|
+
assert_respond_to($test_method, :effective_function_name)
|
145
|
+
assert_equal('GetCurrentDirectoryA', $test_method.effective_function_name)
|
146
|
+
assert_equal('strstr', $strstr.effective_function_name)
|
147
|
+
assert_equal('waveOutGetNumDevs', $wave.effective_function_name)
|
148
|
+
assert_equal('ReadDirectoryChangesW', $read.effective_function_name)
|
149
|
+
end
|
136
150
|
|
137
151
|
def teardown
|
138
152
|
@buf = nil
|
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.2.
|
5
|
+
gem.version = "0.2.4"
|
6
6
|
gem.author = "Daniel J. Berger"
|
7
7
|
gem.email = "djberg96@gmail.com"
|
8
8
|
gem.homepage = "http://www.rubyforge.org/projects/win32utils"
|
@@ -10,7 +10,7 @@ spec = Gem::Specification.new do |gem|
|
|
10
10
|
gem.platform = Gem::Platform::RUBY
|
11
11
|
gem.summary = "An easier way to create methods using Win32API"
|
12
12
|
gem.description = "An easier way to create methods using Win32API"
|
13
|
-
gem.test_file = "test/
|
13
|
+
gem.test_file = "test/test_windows_api.rb"
|
14
14
|
gem.has_rdoc = true
|
15
15
|
gem.files = Dir["lib/windows/*.rb"] + Dir["test/*"] + Dir["[A-Z]*"]
|
16
16
|
gem.files.reject! { |fn| fn.include? "CVS" }
|
@@ -0,0 +1,25 @@
|
|
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
|
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.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel J. Berger
|
@@ -9,11 +9,12 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-07-19 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: win32-api
|
17
|
+
type: :runtime
|
17
18
|
version_requirement:
|
18
19
|
version_requirements: !ruby/object:Gem::Requirement
|
19
20
|
requirements:
|
@@ -34,7 +35,7 @@ extra_rdoc_files:
|
|
34
35
|
files:
|
35
36
|
- lib/windows/api.rb
|
36
37
|
- test/CVS
|
37
|
-
- test/
|
38
|
+
- test/test_windows_api.rb
|
38
39
|
- CHANGES
|
39
40
|
- CVS
|
40
41
|
- lib
|
@@ -43,6 +44,7 @@ files:
|
|
43
44
|
- README
|
44
45
|
- test
|
45
46
|
- windows-api.gemspec
|
47
|
+
- windows-api.gemspec~
|
46
48
|
has_rdoc: true
|
47
49
|
homepage: http://www.rubyforge.org/projects/win32utils
|
48
50
|
post_install_message:
|
@@ -65,9 +67,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
67
|
requirements: []
|
66
68
|
|
67
69
|
rubyforge_project: win32utils
|
68
|
-
rubygems_version: 1.
|
70
|
+
rubygems_version: 1.2.0
|
69
71
|
signing_key:
|
70
72
|
specification_version: 2
|
71
73
|
summary: An easier way to create methods using Win32API
|
72
74
|
test_files:
|
73
|
-
- test/
|
75
|
+
- test/test_windows_api.rb
|