From: "Isabelle L." Date: 2012-10-15T21:19:28+09:00 Subject: Problems calling a DLL from Ruby Hello everyone, I'm trying to call a third-party DLL from a Ruby script. I have no control over this DLL. The examples I have for calling this DLL's functions are all in Visual Basic. I have registered the DLL using regsvr32. I've successfully used the DLL in a small VBA project, but I can't make it work in Ruby. I think the problem may be in part because I have to instantiate an object to call the DLL's functions. Here's what I've done in VB : --------- Function Main() Dim AnOPCServer As OPCServer Dim AllOPCServers As Variant Set AnOPCServer = New OPCServer AllOPCServers = AnOPCServer.GetOPCServers End Function --------- Here's one try in Ruby using Win32Ole : Code : --------- require './TestDNP.rb' require 'win32ole' test = WIN32OLE.new('C:\Windows\System32\gbda_aut.dll') servers = test.GetOPCServers --------- Error I get : --------- C:\Ruby192\bin\ruby.exe -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) C:/RubyWorkspaces/testEnv/test_DNP_Comm.rb C:/RubyWorkspaces/testEnv/test_DNP_Comm.rb:5:in `initialize': unknown OLE server: `C:\Windows\System32\gbda_aut.dll' (WIN32OLERuntimeError) HRESULT error code:0x800401f3 Chaine de classe incorrecte from C:/RubyWorkspaces/testEnv/test_DNP_Comm.rb:5:in `new' from C:/RubyWorkspaces/testEnv/test_DNP_Comm.rb:5:in `' from -e:1:in `load' from -e:1:in `
' Process finished with exit code 1 --------- Here's another try using Win32API. The problem here is that I don't know how to instantiate an object using Win32API. I don't know what to pass as the function's arguments and return value, since there are none. Code : --------- require "Win32API" OPCserver = Win32API.new('C:\Windows\System32\gbda_aut.dll','OPCServer', ['0'], '0') --------- Error I get : --------- C:\Ruby192\bin\ruby.exe -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) C:/RubyWorkspaces/testEnv/test_DNP_Comm.rb C:/Ruby192/lib/ruby/1.9.1/Win32API.rb:14:in `[]': unknown symbol "OPCServer" (LoadError) from C:/Ruby192/lib/ruby/1.9.1/Win32API.rb:14:in `initialize' from C:/RubyWorkspaces/testEnv/test_DNP_Comm.rb:11:in `new' from C:/RubyWorkspaces/testEnv/test_DNP_Comm.rb:11:in `' from -e:1:in `load' from -e:1:in `
' Process finished with exit code 1 --------- Any help to successfully create an object from this DLL and call its functions would be greatly appreciated. Isabelle LaRoche Junior Engineer Gentec Quebec, Canada -- Posted via http://www.ruby-forum.com/.