Bug #17657
closedStarting from ruby 2.3.0, LoadLibraryExA called in extension won't use PATH or current directory to find library and/or it's dependencies
Description
I'm on windows 10 pro. The sample code runs successfully on ruby up to 2.2.5.
On newer versions I get "cannot load such file". The fallowing documentation lists PATH environment variable as one of the search paths, that are used to locate DLL modules, but it gets ignored.
https://docs.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order#standard-search-order-for-desktop-applications
I suspect some permission issues but I read LoadLibraryExA and I can't see why this might be happening. I tried changing dwFlags, doesn't help. If I missed something obvious then I'm sorry.
I tried to boil down the problem to minimal sample code. It needs those two files and a lib directory with any DLL that would be loaded with load_lib global function.
I know that passing absolute path will make it work, but there is still problem when the library has some dependencies that are located in a different directory, those can't be find neither.
test.rb:
require 'devkit'
require 'mkmf'
create_makefile 'foobar'
`make`
require_relative 'foobar'
ENV['PATH'] = (Dir.pwd + '\lib;').gsub('/', '\\') + ENV['PATH']
load_lib('bz2.dll')
foobar.c:
#include "ruby.h"
VALUE rb_load_lib(VALUE self, VALUE path)
{
HMODULE mod;
printf("%s\n\n", getenv("PATH"));
mod = LoadLibraryExA(RSTRING_PTR(path), NULL, 0);
printf("LoadLibraryExA: %s\n", mod != 0 ? "SUCCESS" : "FAIL");
return Qnil;
}
void Init_foobar()
{
rb_define_global_function("load_lib", rb_load_lib, 1);
}