win32-api 1.4.7 → 1.4.8
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +6 -0
- data/README +23 -18
- data/Rakefile +44 -17
- data/ext/win32/api.c +6 -6
- data/test/test_win32_api.rb +22 -14
- data/win32-api.gemspec +5 -5
- metadata +8 -8
data/CHANGES
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
== 1.4.8 - 16-Jan-2011
|
2
|
+
* A binary for both 1.8.x and 1.9.x is now shipped as part of the binary
|
3
|
+
build. A stub file is used to dynamically require the correct binary based
|
4
|
+
on your current version of Ruby.
|
5
|
+
* Some updates to the Rakefile to help build multiple binaries.
|
6
|
+
|
1
7
|
== 1.4.7 - 4-Dec-2010
|
2
8
|
* An internal error formatting function now resorts to the default
|
3
9
|
LANGID on error 1815 (ERROR_RESOURCE_LANG_NOT_FOUND). Thanks go to
|
data/README
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
= Description
|
2
2
|
This is a drop-in replacement for the Win32API library currently part of
|
3
3
|
Ruby's standard library.
|
4
|
-
|
4
|
+
|
5
5
|
= Synopsis
|
6
6
|
require 'win32/api'
|
7
7
|
include Win32
|
8
|
-
|
8
|
+
|
9
9
|
# Typical example - Get user name
|
10
10
|
buf = 0.chr * 260
|
11
11
|
len = [buf.length].pack('L')
|
12
|
-
|
12
|
+
|
13
13
|
GetUserName = API.new('GetUserName', 'PP', 'I', 'advapi32')
|
14
14
|
GetUserName.call(buf, len)
|
15
|
-
|
15
|
+
|
16
16
|
puts buf.strip
|
17
|
-
|
17
|
+
|
18
18
|
# Callback example - Enumerate windows
|
19
19
|
EnumWindows = API.new('EnumWindows', 'KP', 'L', 'user32')
|
20
20
|
GetWindowText = API.new('GetWindowText', 'LPI', 'I', 'user32')
|
@@ -24,18 +24,18 @@
|
|
24
24
|
puts buf.strip unless buf.strip.empty?
|
25
25
|
buf.index(param).nil? ? true : false
|
26
26
|
}
|
27
|
-
|
27
|
+
|
28
28
|
EnumWindows.call(EnumWindowsProc, 'UEDIT32')
|
29
|
-
|
29
|
+
|
30
30
|
# Raw function pointer example - System beep
|
31
31
|
LoadLibrary = API.new('LoadLibrary', 'P', 'L')
|
32
32
|
GetProcAddress = API.new('GetProcAddress', 'LP', 'L')
|
33
|
-
|
33
|
+
|
34
34
|
hlib = LoadLibrary.call('user32')
|
35
35
|
addr = GetProcAddress.call(hlib, 'MessageBeep')
|
36
36
|
func = Win32::API::Function.new(addr, 'L', 'L')
|
37
37
|
func.call(0)
|
38
|
-
|
38
|
+
|
39
39
|
= Differences between win32-api and Win32API
|
40
40
|
* This library has callback support
|
41
41
|
* This library supports raw function pointers.
|
@@ -47,50 +47,55 @@
|
|
47
47
|
return type and DLL.
|
48
48
|
* Removed the support for lower case prototype and return types. Always
|
49
49
|
use capital letters.
|
50
|
-
|
50
|
+
|
51
51
|
= Developer's Notes
|
52
52
|
The current Win32API library that ships with the standard library has been
|
53
53
|
slated for removal from Ruby 2.0 and it will not receive any updates in the
|
54
54
|
Ruby 1.8.x branch. I have far too many libraries invested in it to let it
|
55
55
|
die at this point.
|
56
|
-
|
56
|
+
|
57
57
|
In addition, the current Win32API library was written in the bad old Ruby
|
58
58
|
1.6.x days, which means it doesn't use the newer allocation framework.
|
59
59
|
There were several other refactorings that I felt it needed to more closely
|
60
60
|
match how it was actually being used in practice.
|
61
|
-
|
61
|
+
|
62
62
|
The first order of business was changing the order of the arguments. By
|
63
63
|
moving the DLL name from first to last, I was able to provide reasonable
|
64
64
|
default arguments for the prototype, return type and the DLL. Only the
|
65
65
|
function name is required now.
|
66
|
-
|
66
|
+
|
67
67
|
There was a laundry list of other refactorings that were needed: sensical
|
68
68
|
instance variable names with proper accessors, removing support for lower
|
69
69
|
case prototype and return value characters that no one used in practice,
|
70
70
|
better naming conventions, the addition of RDoc ready comments and,
|
71
71
|
especially, callback and raw function pointer support.
|
72
|
-
|
72
|
+
|
73
73
|
Most importantly, we can now add, modify and fix any features that we feel
|
74
74
|
best benefit our end users.
|
75
75
|
|
76
|
+
= Multiple Binaries
|
77
|
+
As of win32-api 1.4.8 a binary gem is shipped that contains binaries for
|
78
|
+
both Ruby 1.8 and Ruby 1.9. The file under lib/win32 dynamically requires
|
79
|
+
the correct binary based on your version of Ruby.
|
80
|
+
|
76
81
|
= Documentation
|
77
82
|
The source file contains inline RDoc documentation. If you installed
|
78
83
|
this file as a gem, then you have the docs. Run "gem server" and point
|
79
84
|
your browser at http://localhost:8808 to see them.
|
80
|
-
|
85
|
+
|
81
86
|
= Warranty
|
82
87
|
This package is provided "as is" and without any express or
|
83
88
|
implied warranties, including, without limitation, the implied
|
84
89
|
warranties of merchantability and fitness for a particular purpose.
|
85
|
-
|
90
|
+
|
86
91
|
= Known Issues
|
87
92
|
Possible callback issues when dealing with multi-threaded applications.
|
88
|
-
|
93
|
+
|
89
94
|
Please submit any bug reports to the project page at
|
90
95
|
http://www.rubyforge.org/projects/win32utils.
|
91
96
|
|
92
97
|
= Copyright
|
93
|
-
(C) 2003-
|
98
|
+
(C) 2003-2011 Daniel J. Berger
|
94
99
|
All Rights Reserved
|
95
100
|
|
96
101
|
= License
|
data/Rakefile
CHANGED
@@ -5,22 +5,28 @@ require 'rbconfig'
|
|
5
5
|
include Config
|
6
6
|
|
7
7
|
CLEAN.include(
|
8
|
-
'lib',
|
9
8
|
'**/*.gem', # Gem files
|
10
9
|
'**/*.rbc', # Rubinius
|
11
10
|
'**/*.o', # C object file
|
12
11
|
'**/*.log', # Ruby extension build log
|
13
12
|
'**/Makefile', # C Makefile
|
14
|
-
'
|
13
|
+
'**/*.def', # Definition files
|
14
|
+
'**/*.exp',
|
15
|
+
'**/*.lib',
|
16
|
+
'**/*.pdb',
|
17
|
+
'**/*.obj',
|
18
|
+
'**/*.stackdump', # Junk that can happen on Windows
|
15
19
|
"**/*.#{CONFIG['DLEXT']}" # C shared object
|
16
20
|
)
|
17
21
|
|
22
|
+
CLOBBER.include('lib') # Generated when building binaries
|
23
|
+
|
18
24
|
make = CONFIG['host_os'] =~ /mingw|cygwin/i ? 'make' : 'nmake'
|
19
25
|
|
20
26
|
desc 'Build the ruby.exe.manifest if it does not already exist'
|
21
27
|
task :build_manifest do
|
22
28
|
version = CONFIG['host_os'].split('_')[1]
|
23
|
-
|
29
|
+
|
24
30
|
if version && version.to_i >= 80
|
25
31
|
unless File.exist?(File.join(CONFIG['bindir'], 'ruby.exe.manifest'))
|
26
32
|
Dir.chdir(CONFIG['bindir']) do
|
@@ -30,33 +36,54 @@ task :build_manifest do
|
|
30
36
|
end
|
31
37
|
end
|
32
38
|
|
33
|
-
desc
|
34
|
-
task :install => [:build] do
|
35
|
-
Dir.chdir('ext'){
|
36
|
-
sh "#{make} install"
|
37
|
-
}
|
38
|
-
end
|
39
|
-
|
40
|
-
desc "Build Win32::API (but don't install it)"
|
39
|
+
desc "Build the win32-api library"
|
41
40
|
task :build => [:clean, :build_manifest] do
|
42
41
|
Dir.chdir('ext') do
|
43
42
|
ruby "extconf.rb"
|
44
43
|
sh make
|
45
|
-
cp
|
44
|
+
cp 'api.so', 'win32' # For testing
|
46
45
|
end
|
47
46
|
end
|
48
47
|
|
49
48
|
namespace 'gem' do
|
50
|
-
desc 'Build
|
51
|
-
task :create => [:clean] do
|
49
|
+
desc 'Build the win32-api gem'
|
50
|
+
task :create => [:clean] do
|
52
51
|
spec = eval(IO.read('win32-api.gemspec'))
|
53
52
|
Gem::Builder.new(spec).build
|
54
53
|
end
|
55
54
|
|
56
55
|
desc 'Build a binary gem'
|
57
|
-
task :binary
|
58
|
-
|
59
|
-
|
56
|
+
task :binary, :ruby18, :ruby19 do |task, args|
|
57
|
+
args.with_defaults(
|
58
|
+
:ruby18 => "c:/ruby/bin/ruby",
|
59
|
+
:ruby19 => "c:/ruby19/bin/ruby"
|
60
|
+
)
|
61
|
+
|
62
|
+
Rake::Task[:clobber].invoke
|
63
|
+
mkdir_p 'lib/win32/ruby18/win32'
|
64
|
+
mkdir_p 'lib/win32/ruby19/win32'
|
65
|
+
|
66
|
+
args.each{ |key, rubyx|
|
67
|
+
Dir.chdir('ext') do
|
68
|
+
sh "make distclean" rescue nil
|
69
|
+
sh "#{rubyx} extconf.rb"
|
70
|
+
sh "make"
|
71
|
+
if key.to_s == 'ruby18'
|
72
|
+
cp 'api.so', '../lib/win32/ruby18/win32/api.so'
|
73
|
+
else
|
74
|
+
cp 'api.so', '../lib/win32/ruby19/win32/api.so'
|
75
|
+
end
|
76
|
+
end
|
77
|
+
}
|
78
|
+
|
79
|
+
# Create a stub file that automatically require's the correct binary
|
80
|
+
File.open('lib/win32/api.rb', 'w'){ |fh|
|
81
|
+
fh.puts "if RUBY_VERSION.to_f >= 1.9"
|
82
|
+
fh.puts " require File.join(File.dirname(__FILE__), 'ruby19/win32/api')"
|
83
|
+
fh.puts "else"
|
84
|
+
fh.puts " require File.join(File.dirname(__FILE__), 'ruby18/win32/api')"
|
85
|
+
fh.puts "end"
|
86
|
+
}
|
60
87
|
|
61
88
|
spec = eval(IO.read('win32-api.gemspec'))
|
62
89
|
spec.platform = Gem::Platform::CURRENT
|
data/ext/win32/api.c
CHANGED
@@ -17,7 +17,7 @@
|
|
17
17
|
#endif
|
18
18
|
|
19
19
|
#define MAX_BUF 1024
|
20
|
-
#define WINDOWS_API_VERSION "1.4.
|
20
|
+
#define WINDOWS_API_VERSION "1.4.8"
|
21
21
|
|
22
22
|
#define _T_VOID 0
|
23
23
|
#define _T_LONG 1
|
@@ -237,8 +237,8 @@ static VALUE api_init(int argc, VALUE* argv, VALUE self)
|
|
237
237
|
FARPROC fProc;
|
238
238
|
Win32API* ptr;
|
239
239
|
int i;
|
240
|
-
char* first = "A";
|
241
|
-
char* second = "W";
|
240
|
+
const char* first = "A";
|
241
|
+
const char* second = "W";
|
242
242
|
VALUE v_proc, v_proto, v_return, v_dll;
|
243
243
|
|
244
244
|
rb_scan_args(argc, argv, "13", &v_proc, &v_proto, &v_return, &v_dll);
|
@@ -257,7 +257,7 @@ static VALUE api_init(int argc, VALUE* argv, VALUE self)
|
|
257
257
|
|
258
258
|
// Set an arbitrary limit of 20 parameters
|
259
259
|
if(20 < RARRAY_LEN(v_proto))
|
260
|
-
rb_raise(rb_eArgError, "too many parameters: %d
|
260
|
+
rb_raise(rb_eArgError, "too many parameters: %d", RARRAY_LEN(v_proto));
|
261
261
|
|
262
262
|
// Set the default dll to 'kernel32'
|
263
263
|
if(NIL_P(v_dll))
|
@@ -763,7 +763,7 @@ static VALUE api_call(int argc, VALUE* argv, VALUE self){
|
|
763
763
|
}
|
764
764
|
else{
|
765
765
|
rb_raise(rb_eArgError,
|
766
|
-
"wrong number of parameters: expected %
|
766
|
+
"wrong number of parameters: expected %li, got %li",
|
767
767
|
RARRAY_LEN(v_proto), RARRAY_LEN(v_args)
|
768
768
|
);
|
769
769
|
}
|
@@ -944,6 +944,6 @@ void Init_api(){
|
|
944
944
|
|
945
945
|
/* Constants */
|
946
946
|
|
947
|
-
/* 1.4.
|
947
|
+
/* 1.4.8: The version of the win32-api library */
|
948
948
|
rb_define_const(cAPI, "VERSION", rb_str_new2(WINDOWS_API_VERSION));
|
949
949
|
}
|
data/test/test_win32_api.rb
CHANGED
@@ -21,7 +21,7 @@ class TC_Win32_API < Test::Unit::TestCase
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def test_version
|
24
|
-
assert_equal('1.4.
|
24
|
+
assert_equal('1.4.8', API::VERSION)
|
25
25
|
end
|
26
26
|
|
27
27
|
def test_constructor_basic
|
@@ -97,22 +97,30 @@ class TC_Win32_API < Test::Unit::TestCase
|
|
97
97
|
assert_raise(API::PrototypeError){ API.new('GetUserName', 'PL', 'X', 'advapi32') }
|
98
98
|
end
|
99
99
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
100
|
+
test "constructor returns expected error message if function not found" do
|
101
|
+
msg = "Unable to load function "
|
102
|
+
assert_raise_message(msg + "'Zap', 'ZapA', or 'ZapW'"){ API.new('Zap') }
|
103
|
+
assert_raise_message(msg + "'strxxx'"){ API.new('strxxx', 'P', 'L', 'msvcrt') }
|
104
|
+
end
|
104
105
|
|
105
|
-
|
106
|
-
|
107
|
-
|
106
|
+
test "constructor returns expected error message if prototype is invalid" do
|
107
|
+
msg = "Illegal prototype 'X'"
|
108
|
+
assert_raise_message(msg){ API.new('GetUserName', 'X', 'I', 'advapi32') }
|
109
|
+
end
|
108
110
|
|
109
|
-
|
110
|
-
|
111
|
-
|
111
|
+
test "constructor returns expected error message if return type is invalid" do
|
112
|
+
msg = "Illegal return type 'Y'"
|
113
|
+
assert_raise_message(msg){ API.new('GetUserName', 'PL', 'Y', 'advapi32') }
|
114
|
+
end
|
112
115
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
+
test "constructor returns expected error message if too many parameters" do
|
117
|
+
msg = "too many parameters: 25"
|
118
|
+
assert_raise_message(msg){ API.new('GetFileAttributes', 'S' * 25, 'L') }
|
119
|
+
end
|
120
|
+
|
121
|
+
test "call method returns expected error message if too many parameters" do
|
122
|
+
msg = "wrong number of parameters: expected 2, got 3"
|
123
|
+
assert_raise_message(msg){ @str.call('test', 'test', 'test') }
|
116
124
|
end
|
117
125
|
|
118
126
|
def test_call_expected_failures
|
data/win32-api.gemspec
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = 'win32-api'
|
5
|
-
spec.version = '1.4.
|
5
|
+
spec.version = '1.4.8'
|
6
6
|
spec.authors = ['Daniel J. Berger', 'Park Heesob']
|
7
7
|
spec.license = 'Artistic 2.0'
|
8
8
|
spec.email = 'djberg96@gmail.com'
|
@@ -13,13 +13,13 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.test_files = Dir['test/test*']
|
14
14
|
spec.extensions = ['ext/extconf.rb']
|
15
15
|
spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
|
16
|
-
|
16
|
+
|
17
17
|
spec.rubyforge_project = 'win32utils'
|
18
18
|
spec.required_ruby_version = '>= 1.8.2'
|
19
19
|
spec.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST', 'ext/win32/api.c']
|
20
|
-
|
21
|
-
spec.add_development_dependency('test-unit', '>= 2.
|
22
|
-
|
20
|
+
|
21
|
+
spec.add_development_dependency('test-unit', '>= 2.1.2')
|
22
|
+
|
23
23
|
spec.description = <<-EOF
|
24
24
|
The Win32::API library is meant as a replacement for the Win32API
|
25
25
|
library that ships as part of the standard library. It contains several
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: win32-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 1.4.
|
9
|
+
- 8
|
10
|
+
version: 1.4.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Daniel J. Berger
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date:
|
19
|
+
date: 2011-01-16 00:00:00 -07:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -27,12 +27,12 @@ dependencies:
|
|
27
27
|
requirements:
|
28
28
|
- - ">="
|
29
29
|
- !ruby/object:Gem::Version
|
30
|
-
hash:
|
30
|
+
hash: 15
|
31
31
|
segments:
|
32
32
|
- 2
|
33
|
-
-
|
34
|
-
-
|
35
|
-
version: 2.
|
33
|
+
- 1
|
34
|
+
- 2
|
35
|
+
version: 2.1.2
|
36
36
|
type: :development
|
37
37
|
version_requirements: *id001
|
38
38
|
description: " The Win32::API library is meant as a replacement for the Win32API\n library that ships as part of the standard library. It contains several\n advantages over Win32API, including callback support, raw function\n pointers, an additional string type, and more.\n"
|