@@ -78,18 +78,30 @@ private static class NativeMethods
78
78
[ DllImport ( LIBDL ) ]
79
79
public static extern SafeLibraryHandle dlopen ( string fileName , int flags ) ;
80
80
81
+
82
+ [ DllImport ( LIBDL , SetLastError = true ) ]
83
+ [ return : MarshalAs ( UnmanagedType . Bool ) ]
84
+ public static extern int dlclose ( IntPtr hModule ) ;
85
+
81
86
#if __MonoCS__
82
87
83
88
public static SafeLibraryHandle LoadPlatformLibrary ( string fileName )
84
89
{
85
90
return dlopen ( fileName , 1 ) ;
86
91
}
92
+ public static bool FreePlatformLibrary ( IntPtr hModule ) { return dlclose ( hModule ) == 0 ; }
93
+
87
94
#else
88
95
const string KERNEL = "kernel32" ;
89
96
90
97
[ DllImport ( KERNEL , CharSet = CharSet . Auto , BestFitMapping = false , SetLastError = true ) ]
91
98
public static extern SafeLibraryHandle LoadLibrary ( string fileName ) ;
92
99
100
+ [ ReliabilityContract ( Consistency . WillNotCorruptState , Cer . Success ) ]
101
+ [ DllImport ( KERNEL , SetLastError = true ) ]
102
+ [ return : MarshalAs ( UnmanagedType . Bool ) ]
103
+ public static extern bool FreeLibrary ( IntPtr hModule ) ;
104
+
93
105
public static SafeLibraryHandle LoadPlatformLibrary ( string fileName )
94
106
{
95
107
if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
@@ -98,6 +110,15 @@ public static SafeLibraryHandle LoadPlatformLibrary(string fileName)
98
110
}
99
111
return dlopen ( fileName , 1 ) ;
100
112
}
113
+
114
+ public static bool FreePlatformLibrary ( IntPtr hModule )
115
+ {
116
+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
117
+ {
118
+ return FreeLibrary ( hModule ) ;
119
+ }
120
+ return return dlclose ( hModule ) == 0 ;
121
+ }
101
122
#endif
102
123
}
103
124
0 commit comments