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.
Files changed (6) hide show
  1. data/CHANGES +6 -1
  2. data/MANIFEST +8 -8
  3. data/README +84 -71
  4. data/ext/win32/api.c +14 -6
  5. data/test/tc_win32_api.rb +1 -1
  6. 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
- = Differences between win32-api and Win32API
18
- * Argument order change. The DLL name is now last, not first.
19
- * Removed the 'N' and 'n'. Always use 'L' for longs now.
20
- * Sensible default arguments for the prototype, return type and DLL name.
21
- * Reader methods for the function name, prototype, return type and DLL.
22
- * Removed the support for lower case prototype and return types. Always
23
- use capital letters.
24
-
25
- = Developer's Notes
26
- The current Win32API library that ships with the standard library has been
27
- slated for removal from Ruby 2.0 and it will not receive any updates in the
28
- Ruby 1.8.x branch. I have far too many libraries invested in it to let it
29
- die at this point.
30
-
31
- In addition, the current Win32API library was written in the bad old Ruby
32
- 1.6.x days, which means it doesn't use the newer allocation framework.
33
- There were several other refactorings that I felt it needed to more closely
34
- match how it was actually being used in practice.
35
-
36
- The first order of business was changing the order of the arguments. By
37
- moving the DLL name from first to last, I was able to provide reasonable
38
- default arguments for the prototype, return type and the DLL. Only the
39
- function name is required now.
40
-
41
- There was a laundry list of other refactorings that were needed: sensical
42
- instance variable names with proper accessors, removing support for lower
43
- case prototype and return value characters that no one used in practice,
44
- better naming conventions, the addition of RDoc ready comments and,
45
- especially, callback support.
46
-
47
- Most importantly, we can now add, modify and fix any features that we feel
48
- best benefit our end users.
49
-
50
- = Documentation
51
- The source file contains inline RDoc documentation. If you installed
52
- this file as a gem, then you have the docs.
53
-
54
- = Warranty
55
- This package is provided "as is" and without any express or
56
- implied warranties, including, without limitation, the implied
57
- warranties of merchantability and fitness for a particular purpose.
58
-
59
- = Known Bugs
60
- None that I'm aware of. Please submit any bug reports to the project page
61
- at http://www.rubyforge.org/projects/win32utils.
62
-
63
- = Copyright
64
- (C) 2003-2007 Daniel J. Berger
65
- All Rights Reserved
66
-
67
- = License
68
- Ruby's
69
-
70
- = Authors
71
- Daniel J. Berger
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
@@ -2,7 +2,7 @@
2
2
  #include <windows.h>
3
3
 
4
4
  #define MAX_BUF 1024
5
- #define WINDOWS_API_VERSION "1.0.4"
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. If that
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, "A", 1);
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, "W", 1);
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 (FIXNUM_P(v_retval)){
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.0.0: The version of this library, returned as a String */
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
  }
@@ -16,7 +16,7 @@ class TC_Win32_API < Test::Unit::TestCase
16
16
  end
17
17
 
18
18
  def test_version
19
- assert_equal('1.0.4', API::VERSION)
19
+ assert_equal('1.0.5', API::VERSION)
20
20
  end
21
21
 
22
22
  def test_call
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.4
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
- test_files:
41
- - test/tc_win32_api.rb
42
- - test/tc_win32_api_callback.rb
36
+ has_rdoc: true
37
+ homepage: http://www.rubyforge.org/projects/win32utils
38
+ post_install_message:
43
39
  rdoc_options: []
44
40
 
45
- extra_rdoc_files:
46
- - README
47
- - CHANGES
48
- - MANIFEST
49
- - ext/win32/api.c
50
- executables: []
51
-
52
- extensions:
53
- - ext/extconf.rb
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
- dependencies: []
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