diff options
author | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-03-03 06:55:26 +0000 |
---|---|---|
committer | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-03-03 06:55:26 +0000 |
commit | 2a89c088a25ef0ff7b148a211160bc4894d7a9b2 (patch) | |
tree | 3b7005bc5ce3249212e59b2029a0bdc51dcf3742 /ext | |
parent | 95189045d06ab1ff40b023dfb69552f20957e3a0 (diff) |
* ext/dl/win32/lib/win32/{registry,resolv}.rb: use dl/import instead
of Win32API.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22724 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r-- | ext/dl/win32/lib/win32/registry.rb | 37 | ||||
-rw-r--r-- | ext/dl/win32/lib/win32/resolv.rb | 15 |
2 files changed, 34 insertions, 18 deletions
diff --git a/ext/dl/win32/lib/win32/registry.rb b/ext/dl/win32/lib/win32/registry.rb index ccdd721818..175b34cede 100644 --- a/ext/dl/win32/lib/win32/registry.rb +++ b/ext/dl/win32/lib/win32/registry.rb @@ -1,7 +1,7 @@ =begin = Win32 Registry I/F win32/registry is registry accessor library for Win32 platform. -It uses Win32API to call Win32 Registry APIs. +It uses dl/import to call Win32 Registry APIs. == example Win32::Registry::HKEY_CURRENT_USER.open('SOFTWARE\foo') do |reg| @@ -261,7 +261,7 @@ For detail, see ((<MSDN Library|URL:http://msdn.microsoft.com/library/en-us/sysi =end -require 'Win32API' +require 'dl/import' module Win32 class Registry @@ -334,7 +334,11 @@ module Win32 # Error # class Error < ::StandardError - FormatMessageA = Win32API.new('kernel32.dll', 'FormatMessageA', 'LPLLPLP', 'L') + module Kernel32 + extend DL::Importer + dlload "kernel32.dll" + end + FormatMessageA = Kernel32.extern "int FormatMessageA(int, void *, int, int, void *, int, void *)", :stdcall def initialize(code) @code = code msg = "\0".force_encoding(Encoding::ASCII_8BIT) * 1024 @@ -376,20 +380,23 @@ module Win32 # Win32 APIs # module API + extend DL::Importer + dlload "advapi32.dll" [ - %w/RegOpenKeyExA LPLLP L/, - %w/RegCreateKeyExA LPLLLLPPP L/, - %w/RegEnumValueA LLPPPPPP L/, - %w/RegEnumKeyExA LLPPLLLP L/, - %w/RegQueryValueExA LPLPPP L/, - %w/RegSetValueExA LPLLPL L/, - %w/RegDeleteValue LP L/, - %w/RegDeleteKey LP L/, - %w/RegFlushKey L L/, - %w/RegCloseKey L L/, - %w/RegQueryInfoKey LPPPPPPPPPPP L/, + "long RegOpenKeyExA(void *, void *, long, long, void *)", + "long RegCreateKeyExA(void *, void *, long, long, long, long, void *, void *)", + "long RegEnumValueA(void *, long, void *, void *, void *, void *, void *, void *)", + "long RegEnumKeyExA(void *, long, void *, void *, void *, void *, void *, void *)", + "long RegQueryValueExA(void *, void *, void *, void *, void *, void *)", + "long RegSetValueExA(void *, void *, long, long, void *, long)", + "long RegDeleteValue(void *, void *)", + "long RegDeleteKey(void *, void *)", + "long RegFlushKey(void *)", + "long RegCloseKey(void *)", + "long RegQueryInfoKey(void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *)", ].each do |fn| - const_set fn[0].intern, Win32API.new('advapi32.dll', *fn) + cfunc = extern fn, :stdcall + const_set cfunc.name.intern, cfunc end module_function diff --git a/ext/dl/win32/lib/win32/resolv.rb b/ext/dl/win32/lib/win32/resolv.rb index 4e69f58085..cefec61caa 100644 --- a/ext/dl/win32/lib/win32/resolv.rb +++ b/ext/dl/win32/lib/win32/resolv.rb @@ -3,6 +3,7 @@ =end +require "dl/import" require 'win32/registry' module Win32 @@ -33,7 +34,11 @@ module Win32 [ search, nameserver ] end -getv = Win32API.new('kernel32.dll', 'GetVersionExA', 'P', 'L') +module Kernel32 + extend DL::Importer + dlload "kernel32" +end +getv = Kernel32.extern "int GetVersionExA(void *)", :stdcall info = [ 148, 0, 0, 0, 0 ].pack('V5') + "\0" * 128 getv.call(info) if info.unpack('V5')[4] == 2 # VER_PLATFORM_WIN32_NT @@ -255,8 +260,12 @@ else end module WsControl - WsControl = Win32API.new('wsock32.dll', 'WsControl', 'LLPPPP', 'L') - WSAGetLastError = Win32API.new('wsock32.dll', 'WSAGetLastError', 'V', 'L') + module WSock32 + extend DL::Importer + dlload "wsock32.dll" + end + WsControl = WSock32.extern "int WsControl(int, int, void *, void *, void *, void *", :stdcall + WSAGetLastError = WSock32.extern "int WSAGetLastError(void)", :stdcall MAX_TDI_ENTITIES = 512 IPPROTO_TCP = 6 |