|
1 | 1 | using System;
|
2 | 2 | using System.ComponentModel;
|
| 3 | +using System.IO; |
3 | 4 | using System.Runtime.InteropServices;
|
4 | 5 |
|
5 | 6 | namespace Python.Runtime.Platform
|
6 | 7 | {
|
7 | 8 | interface ILibraryLoader
|
8 | 9 | {
|
9 |
| - IntPtr Load(string dllToLoad); |
| 10 | + IntPtr Load(string dllToLoad, string directory = ""); |
10 | 11 |
|
11 | 12 | IntPtr GetFunction(IntPtr hModule, string procedureName);
|
12 | 13 |
|
@@ -47,9 +48,9 @@ class LinuxLoader : ILibraryLoader
|
47 | 48 | private static IntPtr RTLD_DEFAULT = IntPtr.Zero;
|
48 | 49 | private const string NativeDll = "libdl.so";
|
49 | 50 |
|
50 |
| - public IntPtr Load(string dllToLoad) |
| 51 | + public IntPtr Load(string dllToLoad, string directory = "") |
51 | 52 | {
|
52 |
| - var filename = $"lib{dllToLoad}.so"; |
| 53 | + var filename = $"{directory}lib{dllToLoad}.so"; |
53 | 54 | ClearError();
|
54 | 55 | var res = dlopen(filename, RTLD_NOW | RTLD_GLOBAL);
|
55 | 56 | if (res == IntPtr.Zero)
|
@@ -118,9 +119,9 @@ class DarwinLoader : ILibraryLoader
|
118 | 119 | private const string NativeDll = "/usr/lib/libSystem.dylib";
|
119 | 120 | private static IntPtr RTLD_DEFAULT = new IntPtr(-2);
|
120 | 121 |
|
121 |
| - public IntPtr Load(string dllToLoad) |
| 122 | + public IntPtr Load(string dllToLoad, string directory = "") |
122 | 123 | {
|
123 |
| - var filename = $"lib{dllToLoad}.dylib"; |
| 124 | + var filename = $"{directory}lib{dllToLoad}.dylib"; |
124 | 125 | ClearError();
|
125 | 126 | var res = dlopen(filename, RTLD_NOW | RTLD_GLOBAL);
|
126 | 127 | if (res == IntPtr.Zero)
|
@@ -187,8 +188,9 @@ class WindowsLoader : ILibraryLoader
|
187 | 188 | private const string NativeDll = "kernel32.dll";
|
188 | 189 |
|
189 | 190 |
|
190 |
| - public IntPtr Load(string dllToLoad) |
| 191 | + public IntPtr Load(string dllToLoad, string directory = "") |
191 | 192 | {
|
| 193 | + dllToLoad = Path.GetFullPath($"{directory}{dllToLoad}.dll"); |
192 | 194 | var res = WindowsLoader.LoadLibrary(dllToLoad);
|
193 | 195 | if (res == IntPtr.Zero)
|
194 | 196 | throw new DllNotFoundException($"Could not load {dllToLoad}", new Win32Exception());
|
|
0 commit comments