windows-api 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGES CHANGED
@@ -1,3 +1,7 @@
1
+ = 0.2.1 - 10-Feb-2008
2
+ * Added support for long data type names, e.g. 'DWORD' instead of 'L', for
3
+ both the prototype and return type.
4
+
1
5
  = 0.2.0 - 20-Sep-2007
2
6
  * Now requires the win32-api library.
3
7
  * Replaced class variables with class instance variables to prevent conflicts.
data/README CHANGED
@@ -18,6 +18,9 @@
18
18
  # Explicitly state every argument
19
19
  GetComputerNameEx = API.new('GetComputerNameEx', 'PPP', 'I', 'kernel32')
20
20
 
21
+ # Use long data type names
22
+ GetUserName = API.new('GetUserName',['LPTSTR','LPDWORD'],'BOOL','advapi32')
23
+
21
24
  # Attributes for possible inspection
22
25
  puts GetVersion.dll_name # 'kernel32'
23
26
  puts GetVersion.function_name # 'GetVersion'
data/lib/windows/api.rb CHANGED
@@ -2,10 +2,99 @@ require 'win32/api'
2
2
 
3
3
  module Windows
4
4
  class API
5
- VERSION = '0.2.0'
5
+ VERSION = '0.2.1'
6
6
 
7
7
  class Error < RuntimeError; end
8
8
 
9
+ private
10
+
11
+ DATA_TYPES = {
12
+ 'ATOM' => 'I',
13
+ 'BOOL' => 'B',
14
+ 'BOOLEAN' => 'B',
15
+ 'BYTE' => 'I',
16
+ 'CALLBACK' => 'K',
17
+ 'CHAR' => 'I',
18
+ 'COLORREF' => 'L',
19
+ 'DWORD' => 'L',
20
+ 'DWORDLONG' => 'L',
21
+ 'DWORD_PTR' => 'P',
22
+ 'DWORD32' => 'I',
23
+ 'DWORD64' => 'L',
24
+ 'HACCEL' => 'L',
25
+ 'HANDLE' => 'L',
26
+ 'HBITMAP' => 'L',
27
+ 'HBRUSH' => 'L',
28
+ 'HCOLORSPACE' => 'L',
29
+ 'HCONV' => 'L',
30
+ 'HDC' => 'L',
31
+ 'HFILE' => 'I',
32
+ 'HKEY' => 'L',
33
+ 'HFONT' => 'L',
34
+ 'HINSTANCE' => 'L',
35
+ 'HKEY' => 'L',
36
+ 'HLOCAL' => 'L',
37
+ 'HMENU' => 'L',
38
+ 'HMODULE' => 'L',
39
+ 'HRESULT' => 'L',
40
+ 'HWND' => 'L',
41
+ 'INT' => 'I',
42
+ 'INT_PTR' => 'P',
43
+ 'INT32' => 'I',
44
+ 'INT64' => 'L',
45
+ 'LANGID' => 'I',
46
+ 'LCID' => 'L',
47
+ 'LCTYPE' => 'L',
48
+ 'LONG' => 'L',
49
+ 'LONGLONG' => 'L',
50
+ 'LONG_PTR' => 'P',
51
+ 'LONG32' => 'L',
52
+ 'LONG64' => 'L',
53
+ 'LPARAM' => 'P',
54
+ 'LPBOOL' => 'P',
55
+ 'LPBYTE' => 'P',
56
+ 'LPCOLORREF' => 'P',
57
+ 'LPCSTR' => 'P',
58
+ 'LPCTSTR' => 'P',
59
+ 'LPCVOID' => 'L',
60
+ 'LPCWSTR' => 'P',
61
+ 'LPDWORD' => 'P',
62
+ 'LPHANDLE' => 'P',
63
+ 'LPINT' => 'P',
64
+ 'LPLONG' => 'P',
65
+ 'LPSTR' => 'P',
66
+ 'LPTSTR' => 'P',
67
+ 'LPVOID' => 'L',
68
+ 'LPWORD' => 'P',
69
+ 'LPWSTR' => 'P',
70
+ 'LRESULT' => 'P',
71
+ 'PBOOL' => 'P',
72
+ 'PBOOLEAN' => 'P',
73
+ 'PBYTE' => 'P',
74
+ 'PHKEY' => 'P',
75
+ 'SC_HANDLE' => 'L',
76
+ 'SC_LOCK' => 'L',
77
+ 'SERVICE_STATUS_HANDLE' => 'L',
78
+ 'SHORT' => 'I',
79
+ 'SIZE_T' => 'P',
80
+ 'TCHAR' => 'L',
81
+ 'UINT' => 'I',
82
+ 'UINT_PTR' => 'P',
83
+ 'UINT32' => 'I',
84
+ 'UINT64' => 'L',
85
+ 'ULONG' => 'L',
86
+ 'ULONGLONG' => 'L',
87
+ 'ULONG_PTR' => 'P',
88
+ 'ULONG32' => 'L',
89
+ 'ULONG64' => 'L',
90
+ 'USHORT' => 'I',
91
+ 'USN' => 'L',
92
+ 'WINAPI' => 'L',
93
+ 'WORD' => 'I'
94
+ }
95
+
96
+ public
97
+
9
98
  @auto_constant = false
10
99
  @auto_method = false
11
100
  @auto_unicode = false
@@ -200,12 +289,25 @@ module Windows
200
289
  # If the function cannot be found then an API::Error is raised (a subclass
201
290
  # of RuntimeError).
202
291
  #
203
- def initialize(func, proto='V', rtype='L', dll='kernel32')
292
+ def initialize(func, proto='V', rtype='L', dll='kernel32')
293
+ # Convert literal data types to values that win32-api understands
294
+ if proto.is_a?(Array)
295
+ proto.each_with_index{ |pt, index|
296
+ if pt.length > 1
297
+ proto[index].replace(DATA_TYPES[pt])
298
+ end
299
+ }
300
+ end
301
+
302
+ if rtype.length > 1
303
+ rtype.replace(DATA_TYPES[rtype])
304
+ end
305
+
204
306
  @function_name = func
205
307
  @prototype = proto
206
308
  @return_type = rtype == 'B' ? 'I' : rtype
207
309
  @dll_name = dll
208
- @boolean = rtype == 'B' ? true : false
310
+ @boolean = rtype == 'B' ? true : false
209
311
 
210
312
  begin
211
313
  @api = Win32::API.new(func, proto, rtype, dll)
@@ -354,4 +456,4 @@ module Windows
354
456
  result
355
457
  end
356
458
  end
357
- end
459
+ end
@@ -43,7 +43,13 @@ class TC_Windows_API < Test::Unit::TestCase
43
43
  end
44
44
 
45
45
  def test_version
46
- assert_equal('0.2.0', API::VERSION)
46
+ assert_equal('0.2.1', API::VERSION)
47
+ end
48
+
49
+ def test_full_data_types
50
+ assert_nothing_raised{
51
+ API.new('GetUserName', ['LPTSTR', 'LPDWORD'], 'BOOL', 'advapi32')
52
+ }
47
53
  end
48
54
 
49
55
  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.0"
5
+ gem.version = "0.2.1"
6
6
  gem.author = "Daniel J. Berger"
7
7
  gem.email = "djberg96@gmail.com"
8
8
  gem.homepage = "http://www.rubyforge.org/projects/win32utils"
@@ -15,7 +15,7 @@ spec = Gem::Specification.new do |gem|
15
15
  gem.files.reject! { |fn| fn.include? "CVS" }
16
16
  gem.require_path = "lib"
17
17
  gem.extra_rdoc_files = ["README", "CHANGES", "MANIFEST"]
18
- gem.add_dependency("win32-api", ">= 1.0.0")
18
+ gem.add_dependency("win32-api", ">= 1.0.5")
19
19
  end
20
20
 
21
21
  if $0 == __FILE__
metadata CHANGED
@@ -1,33 +1,36 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
4
2
  name: windows-api
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.2.0
7
- date: 2007-09-20 00:00:00 -06:00
8
- summary: An easier way to create methods using Win32API
9
- require_paths:
10
- - lib
11
- email: djberg96@gmail.com
12
- homepage: http://www.rubyforge.org/projects/win32utils
13
- rubyforge_project:
14
- description: An easier way to create methods using 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: 0.0.0
24
- version:
4
+ version: 0.2.1
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: 2008-02-10 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: win32-api
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.0.5
23
+ version:
24
+ description: An easier way to create methods using Win32API
25
+ email: djberg96@gmail.com
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - README
32
+ - CHANGES
33
+ - MANIFEST
31
34
  files:
32
35
  - lib/windows/api.rb
33
36
  - test/CVS
@@ -40,27 +43,31 @@ files:
40
43
  - README
41
44
  - test
42
45
  - windows-api.gemspec
43
- test_files:
44
- - test/tc_windows_api.rb
46
+ has_rdoc: true
47
+ homepage: http://www.rubyforge.org/projects/win32utils
48
+ post_install_message:
45
49
  rdoc_options: []
46
50
 
47
- extra_rdoc_files:
48
- - README
49
- - CHANGES
50
- - MANIFEST
51
- executables: []
52
-
53
- extensions: []
54
-
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
55
65
  requirements: []
56
66
 
57
- dependencies:
58
- - !ruby/object:Gem::Dependency
59
- name: win32-api
60
- version_requirement:
61
- version_requirements: !ruby/object:Gem::Version::Requirement
62
- requirements:
63
- - - ">="
64
- - !ruby/object:Gem::Version
65
- version: 1.0.0
66
- version:
67
+ rubyforge_project:
68
+ rubygems_version: 1.0.1
69
+ signing_key:
70
+ specification_version: 2
71
+ summary: An easier way to create methods using Win32API
72
+ test_files:
73
+ - test/tc_windows_api.rb