windows-api 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +4 -0
- data/README +7 -4
- data/lib/windows/api.rb +32 -13
- data/test/tc_windows_api.rb +28 -2
- data/windows-api.gemspec +1 -1
- metadata +2 -2
data/CHANGES
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
= 0.2.3 - 26-Apr-2008
|
2
|
+
* Improved API.auto_constant and API.auto_method handling for functions that
|
3
|
+
start with a lower case character or an underscore.
|
4
|
+
|
1
5
|
= 0.2.2 - 17-Apr-2008
|
2
6
|
* Added the Windows::MSVCRT_DLL constant so that users can specify MSVCRT_DLL
|
3
7
|
for the DLL name and it will do the right thing, instead of having to worry
|
data/README
CHANGED
@@ -33,6 +33,10 @@
|
|
33
33
|
module Windows
|
34
34
|
module Foo
|
35
35
|
API.auto_namespace = 'Windows::Foo'
|
36
|
+
API.auto_constant = true
|
37
|
+
API.auto_method = true
|
38
|
+
API.auto_unicode = true
|
39
|
+
|
36
40
|
API.new('GetComputerName', 'PP', 'B')
|
37
41
|
end
|
38
42
|
end
|
@@ -41,7 +45,7 @@
|
|
41
45
|
module Windows
|
42
46
|
module Foo
|
43
47
|
GetComputerName = Win32API.new('kernel32', 'GetComputerName', 'PP', 'I')
|
44
|
-
GetComputerNameA = Win32API.new('kernel32', GetComputerNameA', 'PP', 'I')
|
48
|
+
GetComputerNameA = Win32API.new('kernel32', 'GetComputerNameA', 'PP', 'I')
|
45
49
|
GetComputerNameW = Win32API.new('kernel32', 'GetComputerNameW', 'PP', 'I')
|
46
50
|
|
47
51
|
def GetComputerName(p1, p2)
|
@@ -62,9 +66,8 @@
|
|
62
66
|
* Automatic constant generation.
|
63
67
|
* Automatic definition of ANSI and Unicode method wrappers, including
|
64
68
|
special handling for boolean methods.
|
65
|
-
*
|
66
|
-
*
|
67
|
-
and return_type.
|
69
|
+
* Ability to use more familiar Windows data types, e.g. DWORD.
|
70
|
+
* Automatic handling of msvcrt vs msvcrXX via MSVCRT_DLL constant.
|
68
71
|
|
69
72
|
= More documentation
|
70
73
|
See the RDoc documentation, which should have been automatically generated
|
data/lib/windows/api.rb
CHANGED
@@ -18,7 +18,7 @@ module Windows
|
|
18
18
|
end
|
19
19
|
|
20
20
|
class API
|
21
|
-
VERSION = '0.2.
|
21
|
+
VERSION = '0.2.3'
|
22
22
|
|
23
23
|
class Error < RuntimeError; end
|
24
24
|
|
@@ -354,9 +354,12 @@ module Windows
|
|
354
354
|
rescue RuntimeError
|
355
355
|
end
|
356
356
|
end
|
357
|
-
|
357
|
+
|
358
|
+
func_upper = nil
|
359
|
+
|
358
360
|
# Automatically define a constant matching the function name if the
|
359
|
-
# auto_constant option is set.
|
361
|
+
# auto_constant option is set. Lower case method names will have a
|
362
|
+
# capitalized equivalent created, e.g. Memcpy for memcpy, etc.
|
360
363
|
#
|
361
364
|
if Windows::API.auto_constant && Windows::API.auto_namespace
|
362
365
|
if Windows::API.auto_namespace != 'Windows'
|
@@ -364,8 +367,18 @@ module Windows
|
|
364
367
|
else
|
365
368
|
namespace = Windows::API.auto_namespace
|
366
369
|
end
|
367
|
-
|
368
|
-
|
370
|
+
|
371
|
+
# Convert e.g. 'strstr' to 'Strstr' as an equivalent constant
|
372
|
+
if ('A'..'Z').include?(func[0].chr)
|
373
|
+
namespace.const_set(func, @api)
|
374
|
+
else
|
375
|
+
func_upper = func.dup
|
376
|
+
if func_upper[0].chr == '_'
|
377
|
+
func_upper = func_upper[1, func_upper.length]
|
378
|
+
end
|
379
|
+
func_upper[0, 1] = func_upper[0].chr.capitalize
|
380
|
+
namespace.const_set(func_upper, @api)
|
381
|
+
end
|
369
382
|
|
370
383
|
# Automatically define the explicit ANSI and Unicode functions
|
371
384
|
# as constants as well, if appropriate.
|
@@ -398,18 +411,24 @@ module Windows
|
|
398
411
|
end
|
399
412
|
end
|
400
413
|
|
414
|
+
# Use the upper case function equivalent if defined
|
415
|
+
call_func = func_upper || func
|
416
|
+
|
417
|
+
# Remove leading underscores from msvcrt functions
|
418
|
+
func = func[1, func.length] if func[0].chr == '_'
|
419
|
+
|
401
420
|
if @boolean
|
402
421
|
string = <<-EOC
|
403
422
|
module #{Windows::API.auto_namespace}
|
404
423
|
def #{func}(#{proto})
|
405
|
-
#{
|
424
|
+
#{call_func}.call(#{proto}) != 0
|
406
425
|
end
|
407
426
|
EOC
|
408
427
|
|
409
428
|
if api_a
|
410
429
|
string << %Q{
|
411
430
|
def #{func}A(#{proto})
|
412
|
-
#{
|
431
|
+
#{call_func}A.call(#{proto}) != 0
|
413
432
|
end
|
414
433
|
}
|
415
434
|
end
|
@@ -417,7 +436,7 @@ module Windows
|
|
417
436
|
if api_w
|
418
437
|
string << %Q{
|
419
438
|
def #{func}W(#{proto})
|
420
|
-
#{
|
439
|
+
#{call_func}W.call(#{proto}) != 0
|
421
440
|
end
|
422
441
|
}
|
423
442
|
end
|
@@ -425,16 +444,16 @@ module Windows
|
|
425
444
|
string << 'end'
|
426
445
|
else
|
427
446
|
string = <<-EOC
|
428
|
-
module #{Windows::API.auto_namespace}
|
447
|
+
module #{Windows::API.auto_namespace}
|
429
448
|
def #{func}(#{proto})
|
430
|
-
#{
|
449
|
+
#{call_func}.call(#{proto})
|
431
450
|
end
|
432
451
|
EOC
|
433
|
-
|
452
|
+
|
434
453
|
if api_a
|
435
454
|
string << %Q{
|
436
455
|
def #{func}A(#{proto})
|
437
|
-
#{
|
456
|
+
#{call_func}A.call(#{proto})
|
438
457
|
end
|
439
458
|
}
|
440
459
|
end
|
@@ -442,7 +461,7 @@ module Windows
|
|
442
461
|
if api_w
|
443
462
|
string << %Q{
|
444
463
|
def #{func}W(#{proto})
|
445
|
-
#{
|
464
|
+
#{call_func}W.call(#{proto})
|
446
465
|
end
|
447
466
|
}
|
448
467
|
end
|
data/test/tc_windows_api.rb
CHANGED
@@ -31,19 +31,31 @@ module Windows
|
|
31
31
|
API.auto_method = true
|
32
32
|
$bar_method = API.new('GetUserName', 'PP', 'I', 'advapi32')
|
33
33
|
end
|
34
|
+
|
35
|
+
module Baz
|
36
|
+
API.auto_namespace = 'Windows::Baz'
|
37
|
+
API.auto_constant = true
|
38
|
+
API.auto_method = true
|
39
|
+
API.auto_unicode = false
|
40
|
+
|
41
|
+
API.new('strstr', 'PP', 'P', 'msvcrt')
|
42
|
+
API.new('_umask', 'I', 'I', 'msvcrt')
|
43
|
+
API.new('waveOutGetNumDevs', 'V', 'I', 'winmm')
|
44
|
+
end
|
34
45
|
end
|
35
46
|
|
36
47
|
class TC_Windows_API < Test::Unit::TestCase
|
37
48
|
include Windows::Test
|
38
49
|
include Windows::Foo
|
39
50
|
include Windows::Bar
|
51
|
+
include Windows::Baz
|
40
52
|
|
41
53
|
def setup
|
42
54
|
@buf = 0.chr * 256
|
43
55
|
end
|
44
56
|
|
45
57
|
def test_version
|
46
|
-
assert_equal('0.2.
|
58
|
+
assert_equal('0.2.3', API::VERSION)
|
47
59
|
end
|
48
60
|
|
49
61
|
def test_full_data_types
|
@@ -53,7 +65,21 @@ class TC_Windows_API < Test::Unit::TestCase
|
|
53
65
|
end
|
54
66
|
|
55
67
|
def test_msvcrt_constant
|
56
|
-
assert_equal(true, ['msvcrt', 'msvcr80'].include?(Windows::
|
68
|
+
assert_equal(true, ['msvcrt', 'msvcr80'].include?(Windows::MSVCRT_DLL))
|
69
|
+
end
|
70
|
+
|
71
|
+
# Validate that functions like 'strstr' get an uppercase constant like 'Strstr'
|
72
|
+
def test_lower_case_to_capitalized_constant
|
73
|
+
assert_not_nil(Windows::Baz::Strstr)
|
74
|
+
assert_not_nil(Windows::Baz::Umask)
|
75
|
+
assert_not_nil(Windows::Baz::WaveOutGetNumDevs)
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_lower_case_auto_methods
|
79
|
+
assert_respond_to(self, :strstr)
|
80
|
+
assert_respond_to(self, :umask)
|
81
|
+
assert_respond_to(self, :waveOutGetNumDevs)
|
82
|
+
assert_equal('llo', strstr('hello', 'l'))
|
57
83
|
end
|
58
84
|
|
59
85
|
def test_auto_unicode
|
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.3"
|
6
6
|
gem.author = "Daniel J. Berger"
|
7
7
|
gem.email = "djberg96@gmail.com"
|
8
8
|
gem.homepage = "http://www.rubyforge.org/projects/win32utils"
|
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.3
|
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: 2008-04-
|
12
|
+
date: 2008-04-26 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|