3

I am trying to load a dll using the following fiddle code: ( If there is a easier way to load a dll and call a function on it that would solve my problem I am happy to hear it )

require 'fiddle' unless defined?(Fiddle)
require 'fiddle/import' unless defined?(Fiddle::Importer)
extend Fiddle::Importer
dlload "Foo.dll"

dlload "C:/Folder/Foo.dll" works like I want. But the problem is that Foo.dll is a c++ dll that requires several other dlls in various locations.

How do I go about just calling dlload "Foo.dll" without a full path. In short how do I add a list of directories to the Ruby dll search path?

I have tried the following:

$LOAD_PATH.unshift("C:/Folder")
ENV['RUBYLIB'] = "C:/Folder"
ENV['LD_LIBRARY_PATH'] = "C:/Folder"

The ruby interpreter is running inside another program (Sketchup), so my environment is restricted.

marsh
  • 2,592
  • 5
  • 29
  • 53
  • 2
    In my experience I haven't been able to get Fiddle to automagically find my DLL files on any system other than MacOS. On Linux, I've used pkg-config in the past, but that's not friendly to non-devs who won't have pkg-config. I then used ldconfig directly. On Windows, I wrote a ruby script that searches for the DLL in the current working directory, then Windows/System32, then the Windows folder itself. That seems to be the search order of most Windows apps. – danini Feb 26 '17 at 08:33

1 Answers1

0

The only solution I got to work was writing a small kernel32.dll library and calling AddDllDirectory from within it.

marsh
  • 2,592
  • 5
  • 29
  • 53