[前][次][番号順一覧][スレッド一覧]

ruby-changes:11124

From: usa <ko1@a...>
Date: Tue, 3 Mar 2009 15:55:37 +0900 (JST)
Subject: [ruby-changes:11124] Ruby:r22724 (trunk): * ext/dl/win32/lib/win32/{registry,resolv}.rb: use dl/import instead

usa	2009-03-03 15:55:26 +0900 (Tue, 03 Mar 2009)

  New Revision: 22724

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=22724

  Log:
    * ext/dl/win32/lib/win32/{registry,resolv}.rb: use dl/import instead
      of Win32API.

  Modified files:
    trunk/ChangeLog
    trunk/ext/dl/win32/lib/win32/registry.rb
    trunk/ext/dl/win32/lib/win32/resolv.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 22723)
+++ ChangeLog	(revision 22724)
@@ -1,3 +1,8 @@
+Tue Mar  3 15:54:11 2009  NAKAMURA Usaku  <usa@r...>
+
+	* ext/dl/win32/lib/win32/{registry,resolv}.rb: use dl/import instead
+	  of Win32API.
+
 Tue Mar  3 15:53:20 2009  NAKAMURA Usaku  <usa@r...>
 
 	* ext/dl/lib/dl/func.rb (DL::Function.name): delegate to @cfunc.
Index: ext/dl/win32/lib/win32/registry.rb
===================================================================
--- ext/dl/win32/lib/win32/registry.rb	(revision 22723)
+++ ext/dl/win32/lib/win32/registry.rb	(revision 22724)
@@ -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 @@
 
 =end
 
-require 'Win32API'
+require 'dl/import'
 
 module Win32
   class Registry
@@ -334,7 +334,11 @@
     # 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 @@
     # 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
Index: ext/dl/win32/lib/win32/resolv.rb
===================================================================
--- ext/dl/win32/lib/win32/resolv.rb	(revision 22723)
+++ ext/dl/win32/lib/win32/resolv.rb	(revision 22724)
@@ -3,6 +3,7 @@
 
 =end
 
+require "dl/import"
 require 'win32/registry'
 
 module Win32
@@ -33,7 +34,11 @@
       [ 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 @@
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]