From: egzumer@... Date: 2021-02-25T19:32:17+00:00 Subject: [ruby-core:102606] [Ruby master Bug#17657] Starting from ruby 2.3.0, LoadLibraryExA called in extension won't use PATH or current directory to find library and/or it's dependencies Issue #17657 has been reported by egzi (Krzysztof Egzmont). ---------------------------------------- Bug #17657: Starting from ruby 2.3.0, LoadLibraryExA called in extension won't use PATH or current directory to find library and/or it's dependencies https://bugs.ruby-lang.org/issues/17657 * Author: egzi (Krzysztof Egzmont) * Status: Open * Priority: Normal * ruby -v: ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x64-mingw32] * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN ---------------------------------------- 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: ``` ruby 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: ``` 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); } ``` -- https://bugs.ruby-lang.org/ Unsubscribe: