win32-api 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +6 -1
- data/MANIFEST +8 -8
- data/README +84 -71
- data/ext/win32/api.c +14 -6
- data/test/tc_win32_api.rb +1 -1
- metadata +45 -38
data/CHANGES
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
= 1.0.5 - 20-Nov-2007
|
2
|
+
* The API.new method now defaults to "W" (wide character functions) before "A"
|
3
|
+
(ANSI functions) if the $KCODE global variable is set to 'u' (UTF8).
|
4
|
+
* Minor improvements to the Rakefile.
|
5
|
+
|
1
6
|
= 1.0.4 - 26-Oct-2007
|
2
7
|
* Fixed a bug where methods that returned pointers ('P') could choke if the
|
3
8
|
resulting pointer was 0 or NULL. In this case, nil is now returned instead.
|
@@ -21,4 +26,4 @@
|
|
21
26
|
* Fixed the gemspec for the native build.
|
22
27
|
|
23
28
|
= 1.0.0 - 14-Sep-2007
|
24
|
-
* Initial release
|
29
|
+
* Initial release
|
data/MANIFEST
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
* CHANGES
|
2
|
-
* MANIFEST
|
3
|
-
* README
|
4
|
-
* Rakefile
|
5
|
-
* win32-api.gemspec
|
6
|
-
* ext/extconf.rb
|
7
|
-
* ext/win32/api.c
|
8
|
-
* test/tc_win32_api_callback.rb
|
1
|
+
* CHANGES
|
2
|
+
* MANIFEST
|
3
|
+
* README
|
4
|
+
* Rakefile
|
5
|
+
* win32-api.gemspec
|
6
|
+
* ext/extconf.rb
|
7
|
+
* ext/win32/api.c
|
8
|
+
* test/tc_win32_api_callback.rb
|
9
9
|
* test/tc_win32_api.rb
|
data/README
CHANGED
@@ -1,72 +1,85 @@
|
|
1
|
-
= Description
|
2
|
-
This is a drop-in replacement for the Win32API library currently part of
|
3
|
-
Ruby's standard library.
|
4
|
-
|
5
|
-
= Synopsis
|
6
|
-
require 'win32/api'
|
7
|
-
include Win32
|
8
|
-
|
9
|
-
buf = 0.chr * 260
|
10
|
-
len = [@buf.length].pack('L')
|
11
|
-
|
12
|
-
GetUserName = API.new('GetUserName', 'PP', 'I', 'advapi32')
|
13
|
-
GetUserName.call(buf, len)
|
14
|
-
|
15
|
-
puts buf.strip
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
=
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
=
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
1
|
+
= Description
|
2
|
+
This is a drop-in replacement for the Win32API library currently part of
|
3
|
+
Ruby's standard library.
|
4
|
+
|
5
|
+
= Synopsis
|
6
|
+
require 'win32/api'
|
7
|
+
include Win32
|
8
|
+
|
9
|
+
buf = 0.chr * 260
|
10
|
+
len = [@buf.length].pack('L')
|
11
|
+
|
12
|
+
GetUserName = API.new('GetUserName', 'PP', 'I', 'advapi32')
|
13
|
+
GetUserName.call(buf, len)
|
14
|
+
|
15
|
+
puts buf.strip
|
16
|
+
|
17
|
+
# Callback example
|
18
|
+
EnumWindows = API.new('EnumWindows', 'KP', 'L', 'user32')
|
19
|
+
GetWindowText = API.new('GetWindowText', 'LPI', 'I', 'user32')
|
20
|
+
EnumWindowsProc = API::Callback.new('LP', 'I'){ |handle, param|
|
21
|
+
buf = "\0" * 200
|
22
|
+
GetWindowText.call(handle, buf, 200);
|
23
|
+
puts buf.strip
|
24
|
+
buf.index(param).nil? ? true : false
|
25
|
+
}
|
26
|
+
|
27
|
+
= Differences between win32-api and Win32API
|
28
|
+
* This library has callback support!
|
29
|
+
* Argument order change. The DLL name is now last, not first.
|
30
|
+
* Removed the 'N' and 'n'. Always use 'L' for longs now.
|
31
|
+
* Sensible default arguments for the prototype, return type and DLL name.
|
32
|
+
* Reader methods for the function name, prototype, return type and DLL.
|
33
|
+
* Removed the support for lower case prototype and return types. Always
|
34
|
+
use capital letters.
|
35
|
+
* Resorts to wide character functions (where possible) when $KCODE is set
|
36
|
+
to UTF8.
|
37
|
+
|
38
|
+
= Developer's Notes
|
39
|
+
The current Win32API library that ships with the standard library has been
|
40
|
+
slated for removal from Ruby 2.0 and it will not receive any updates in the
|
41
|
+
Ruby 1.8.x branch. I have far too many libraries invested in it to let it
|
42
|
+
die at this point.
|
43
|
+
|
44
|
+
In addition, the current Win32API library was written in the bad old Ruby
|
45
|
+
1.6.x days, which means it doesn't use the newer allocation framework.
|
46
|
+
There were several other refactorings that I felt it needed to more closely
|
47
|
+
match how it was actually being used in practice.
|
48
|
+
|
49
|
+
The first order of business was changing the order of the arguments. By
|
50
|
+
moving the DLL name from first to last, I was able to provide reasonable
|
51
|
+
default arguments for the prototype, return type and the DLL. Only the
|
52
|
+
function name is required now.
|
53
|
+
|
54
|
+
There was a laundry list of other refactorings that were needed: sensical
|
55
|
+
instance variable names with proper accessors, removing support for lower
|
56
|
+
case prototype and return value characters that no one used in practice,
|
57
|
+
better naming conventions, the addition of RDoc ready comments and,
|
58
|
+
especially, callback support.
|
59
|
+
|
60
|
+
Most importantly, we can now add, modify and fix any features that we feel
|
61
|
+
best benefit our end users.
|
62
|
+
|
63
|
+
= Documentation
|
64
|
+
The source file contains inline RDoc documentation. If you installed
|
65
|
+
this file as a gem, then you have the docs.
|
66
|
+
|
67
|
+
= Warranty
|
68
|
+
This package is provided "as is" and without any express or
|
69
|
+
implied warranties, including, without limitation, the implied
|
70
|
+
warranties of merchantability and fitness for a particular purpose.
|
71
|
+
|
72
|
+
= Known Bugs
|
73
|
+
None that I'm aware of. Please submit any bug reports to the project page
|
74
|
+
at http://www.rubyforge.org/projects/win32utils.
|
75
|
+
|
76
|
+
= Copyright
|
77
|
+
(C) 2003-2007 Daniel J. Berger
|
78
|
+
All Rights Reserved
|
79
|
+
|
80
|
+
= License
|
81
|
+
Ruby's
|
82
|
+
|
83
|
+
= Authors
|
84
|
+
Daniel J. Berger
|
72
85
|
Park Heesob
|
data/ext/win32/api.c
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
#include <windows.h>
|
3
3
|
|
4
4
|
#define MAX_BUF 1024
|
5
|
-
#define WINDOWS_API_VERSION "1.0.
|
5
|
+
#define WINDOWS_API_VERSION "1.0.5"
|
6
6
|
|
7
7
|
#define _T_VOID 0
|
8
8
|
#define _T_LONG 1
|
@@ -146,6 +146,8 @@ static VALUE api_init(int argc, VALUE* argv, VALUE self)
|
|
146
146
|
FARPROC fProc;
|
147
147
|
Win32API* ptr;
|
148
148
|
int i;
|
149
|
+
char* first = "A";
|
150
|
+
char* second = "W";
|
149
151
|
VALUE v_proc, v_proto, v_return, v_dll, v_bool, v_name;
|
150
152
|
|
151
153
|
rb_scan_args(argc, argv, "13", &v_proc, &v_proto, &v_return, &v_dll);
|
@@ -190,19 +192,25 @@ static VALUE api_init(int argc, VALUE* argv, VALUE self)
|
|
190
192
|
ptr->library = hLibrary;
|
191
193
|
|
192
194
|
/* Attempt to get the function. If it fails, try again with an 'A'
|
193
|
-
* appended. If that fails, try again with a 'W' appended.
|
195
|
+
* appended. If that fails, try again with a 'W' appended. If that
|
194
196
|
* still fails, raise an API::Error.
|
195
197
|
*/
|
196
198
|
fProc = GetProcAddress(hLibrary, TEXT(RSTRING(v_proc)->ptr));
|
197
199
|
|
200
|
+
/* The order of 'A' and 'W' is reversed if $KCODE is set to 'UTF8'. */
|
201
|
+
if(!_tcscmp(rb_get_kcode(), "UTF8")){
|
202
|
+
first = "W";
|
203
|
+
second = "A";
|
204
|
+
}
|
205
|
+
|
198
206
|
if(!fProc){
|
199
207
|
VALUE v_ascii = rb_str_new3(v_proc);
|
200
|
-
v_ascii = rb_str_cat(v_ascii,
|
208
|
+
v_ascii = rb_str_cat(v_ascii, first, 1);
|
201
209
|
fProc = GetProcAddress(hLibrary, TEXT(RSTRING(v_ascii)->ptr));
|
202
210
|
|
203
211
|
if(!fProc){
|
204
212
|
VALUE v_unicode = rb_str_new3(v_proc);
|
205
|
-
v_unicode = rb_str_cat(v_unicode,
|
213
|
+
v_unicode = rb_str_cat(v_unicode, second, 1);
|
206
214
|
fProc = GetProcAddress(hLibrary, TEXT(RSTRING(v_unicode)->ptr));
|
207
215
|
|
208
216
|
if(!fProc){
|
@@ -342,7 +350,7 @@ DWORD CallbackFunction(PARAM param)
|
|
342
350
|
if(NIL_P(v_retval)){
|
343
351
|
return 0;
|
344
352
|
}
|
345
|
-
else if
|
353
|
+
else if(FIXNUM_P(v_retval)){
|
346
354
|
return NUM2ULONG(v_retval);
|
347
355
|
}
|
348
356
|
else{
|
@@ -519,6 +527,6 @@ void Init_api(){
|
|
519
527
|
|
520
528
|
/* Constants */
|
521
529
|
|
522
|
-
/* 1.
|
530
|
+
/* 1.1.0: The version of this library, returned as a String */
|
523
531
|
rb_define_const(cAPI, "VERSION", rb_str_new2(WINDOWS_API_VERSION));
|
524
532
|
}
|
data/test/tc_win32_api.rb
CHANGED
metadata
CHANGED
@@ -1,33 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.4
|
3
|
-
specification_version: 1
|
4
2
|
name: win32-api
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.0.
|
7
|
-
date: 2007-10-29 00:00:00 -07:00
|
8
|
-
summary: A superior replacement for Win32API
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email: djberg96@gmail.com
|
12
|
-
homepage: http://www.rubyforge.org/projects/win32utils
|
13
|
-
rubyforge_project: win32utils
|
14
|
-
description: A superior replacement for Win32API
|
15
|
-
autorequire:
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: true
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 1.8.0
|
24
|
-
version:
|
4
|
+
version: 1.0.5
|
25
5
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
6
|
authors:
|
30
7
|
- Daniel J. Berger
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2007-11-20 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: A superior replacement for Win32API
|
17
|
+
email: djberg96@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions:
|
21
|
+
- ext/extconf.rb
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README
|
24
|
+
- CHANGES
|
25
|
+
- MANIFEST
|
26
|
+
- ext/win32/api.c
|
31
27
|
files:
|
32
28
|
- ext/extconf.rb
|
33
29
|
- ext/win32
|
@@ -37,21 +33,32 @@ files:
|
|
37
33
|
- README
|
38
34
|
- CHANGES
|
39
35
|
- MANIFEST
|
40
|
-
|
41
|
-
|
42
|
-
|
36
|
+
has_rdoc: true
|
37
|
+
homepage: http://www.rubyforge.org/projects/win32utils
|
38
|
+
post_install_message:
|
43
39
|
rdoc_options: []
|
44
40
|
|
45
|
-
|
46
|
-
-
|
47
|
-
|
48
|
-
|
49
|
-
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.8.0
|
48
|
+
version:
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
54
55
|
requirements: []
|
55
56
|
|
56
|
-
|
57
|
-
|
57
|
+
rubyforge_project: win32utils
|
58
|
+
rubygems_version: 0.9.5
|
59
|
+
signing_key:
|
60
|
+
specification_version: 2
|
61
|
+
summary: A superior replacement for Win32API
|
62
|
+
test_files:
|
63
|
+
- test/tc_win32_api.rb
|
64
|
+
- test/tc_win32_api_callback.rb
|