@@ -113,6 +113,10 @@ static int loader_impl_dependencies_self_find(loader_impl impl, const char *key_
113113
114114static int loader_impl_dependencies_load (loader_impl impl , const char * key_str , value * paths_array , size_t paths_size );
115115
116+ #if defined(WIN32 ) || defined(_WIN32 )
117+ static void loader_impl_dependencies_search_paths (loader_impl impl , const loader_tag tag );
118+ #endif
119+
116120static configuration loader_impl_initialize_configuration (const loader_tag tag );
117121
118122static int loader_impl_initialize_registered (plugin_manager manager , plugin p );
@@ -370,6 +374,39 @@ int loader_impl_dependencies_load(loader_impl impl, const char *key_str, value *
370374 return 1 ;
371375}
372376
377+ #if defined(WIN32 ) || defined(_WIN32 )
378+ void loader_impl_dependencies_search_paths (loader_impl impl , const loader_tag tag )
379+ {
380+ /* Search paths have the following format and are only implemented for Windows:
381+ {
382+ "search_paths": ["C:\Program Files\ruby\bin\ruby_builtin_dlls"]
383+ }
384+ */
385+ value search_paths_value = configuration_value_type (impl -> config , "search_paths" , TYPE_ARRAY );
386+
387+ /* Check if the loader has search paths and initialize them */
388+ if (search_paths_value != NULL )
389+ {
390+ size_t size = value_type_count (search_paths_value );
391+ value * search_paths_array = value_to_array (search_paths_value );
392+ size_t iterator ;
393+
394+ for (iterator = 0 ; iterator < size ; ++ iterator )
395+ {
396+ if (value_type_id (search_paths_array [iterator ]) == TYPE_STRING )
397+ {
398+ const char * key_str = value_to_string (search_paths_array [iterator ]);
399+
400+ if (SetDllDirectoryA (key_str ) == FALSE)
401+ {
402+ log_write ("metacall" , LOG_LEVEL_ERROR , "Failed to register the DLL directory %s in loader '%s'; dependencies with other dependant DLLs may fail to load" , key_str , tag );
403+ }
404+ }
405+ }
406+ }
407+ }
408+ #endif
409+
373410int loader_impl_dependencies (loader_impl impl , detour d , const loader_tag tag )
374411{
375412 /* Dependencies have the following format:
@@ -412,6 +449,10 @@ int loader_impl_dependencies(loader_impl impl, detour d, const loader_tag tag)
412449 /* Initialize the loader detour */
413450 impl -> d = d ;
414451
452+ #if defined(WIN32 ) || defined(_WIN32 )
453+ loader_impl_dependencies_search_paths (impl , tag );
454+ #endif
455+
415456 /* Check if the loader has dependencies and load them */
416457 if (dependencies_value != NULL )
417458 {
0 commit comments