1
1
//! Shared library/module access for Windows.
2
- use crate :: { core:: optional:: NSTDOptional , NSTDAny , NSTDAnyMut , NSTDChar , NSTDInt } ;
3
- use windows_sys:: Win32 :: System :: LibraryLoader :: { FreeLibrary , GetProcAddress , LoadLibraryA } ;
2
+ use crate :: {
3
+ core:: { def:: NSTDErrorCode , optional:: NSTDOptional } ,
4
+ NSTDAny , NSTDAnyMut , NSTDChar , NSTDInt ,
5
+ } ;
6
+ use windows_sys:: Win32 :: System :: LibraryLoader :: {
7
+ FreeLibrary , GetProcAddress , LoadLibraryA , SetDllDirectoryA ,
8
+ } ;
4
9
5
10
/// A handle to a loaded library.
6
11
#[ repr( C ) ]
@@ -20,6 +25,28 @@ impl Drop for NSTDWindowsSharedLib {
20
25
/// An optional (possibly null) shared Windows library handle.
21
26
pub type NSTDWindowsOptionalSharedLib = NSTDOptional < NSTDWindowsSharedLib > ;
22
27
28
+ /// Adds a directory to the system's search path used to load shared libraries.
29
+ ///
30
+ /// # Parameters:
31
+ ///
32
+ /// - `const NSTDChar *path` - A path to a directory to search when looking for DLLs. Pass null to
33
+ /// restore the default search order.
34
+ ///
35
+ /// # Returns
36
+ ///
37
+ /// `NSTDErrorCode errc` - Nonzero on error.
38
+ ///
39
+ /// # Safety
40
+ ///
41
+ /// See <https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setdlldirectorya>.
42
+ #[ inline]
43
+ #[ cfg_attr( feature = "clib" , no_mangle) ]
44
+ pub unsafe extern "C" fn nstd_os_windows_shared_lib_add_dir (
45
+ path : * const NSTDChar ,
46
+ ) -> NSTDErrorCode {
47
+ ( SetDllDirectoryA ( path. cast ( ) ) == 0 ) . into ( )
48
+ }
49
+
23
50
/// Loads a shared library/module by name.
24
51
///
25
52
/// # Parameters:
0 commit comments