# This file is loaded only on LoadError. class OCI8 module Util case RUBY_PLATFORM when /mswin32|cygwin|mingw32|bccwin32/ require 'fiddle/import' require 'fiddle/types' extend Fiddle::Importer dlload 'kernel32.dll' include Fiddle::BasicTypes include Fiddle::Win32Types typealias "HANDLE", "void*" typealias "HMODULE", "void*" extern "DWORD GetModuleFileNameA(HMODULE, LPSTR, DWORD)" extern "UINT GetSystemDirectoryA(LPCSTR, UINT)" extern "UINT GetWindowsDirectoryA(LPCSTR, UINT)" extern "HMODULE LoadLibraryExA(LPCSTR, HANDLE, DWORD)" extern "BOOL FreeLibrary(HMODULE)" MAX_PATH = 260 DONT_RESOLVE_DLL_REFERENCES = 0x00000001 def self.check_os_specific_load_error(exc) case exc.message when /^OCI\.DLL: 193\(/, /^193: / # "OCI.DLL: 193(%1 is not a valid Win32 application.)" in English check_win32_pe_arch(exc.message.split(' - ')[1], "ruby-oci8") dll_load_path_list.each do |path| check_win32_pe_arch(File.join(path, '\OCI.DLL'), "Oracle client") end when /^OCI.DLL: 126\(/, /^126: / # "OCI.DLL: 126(The specified module could not be found.)" in English oci_dll_files = dll_load_path_list.inject([]) do |files, path| file = File.join(path, '\OCI.DLL') files << file if File.exist?(file) files end if oci_dll_files.empty? raise LoadError, "Cannot find OCI.DLL in PATH." end if oci_dll_files.none? {|file| open(file, 'rb') {true} rescue false} raise LoadError, "OCI.DLL in PATH isn't readable." end first_error = nil oci_dll_files.each do |file| begin check_win32_pe_arch(file, "Oracle client") valid_arch = true rescue LoadError first_error ||= $! valid_arch = false end if valid_arch handle = LoadLibraryExA(file, nil, DONT_RESOLVE_DLL_REFERENCES) unless handle.null? FreeLibrary(handle) raise LoadError, <