8
8
using System . Reflection ;
9
9
using System . Runtime . InteropServices ;
10
10
using System . Text ;
11
- using System . Web ;
12
11
13
12
namespace OpenCvSharp
14
13
{
@@ -28,7 +27,7 @@ public sealed class WindowsLibraryLoader
28
27
public static WindowsLibraryLoader Instance { get { return instance ; } }
29
28
30
29
#endregion
31
-
30
+
32
31
/// <summary>
33
32
/// The default base directory name to copy the assemblies too.
34
33
/// </summary>
@@ -53,7 +52,7 @@ public sealed class WindowsLibraryLoader
53
52
/// <summary>
54
53
/// Used as a sanity check for the returned processor architecture to double check the returned value.
55
54
/// </summary>
56
- private readonly Dictionary < string , int > processorArchitectureAddressWidthPlatforms =
55
+ private readonly Dictionary < string , int > processorArchitectureAddressWidthPlatforms =
57
56
new Dictionary < string , int > ( StringComparer . OrdinalIgnoreCase )
58
57
{
59
58
{ "x86" , 4 } ,
@@ -65,8 +64,8 @@ public sealed class WindowsLibraryLoader
65
64
/// <summary>
66
65
/// Additional user-defined DLL paths
67
66
/// </summary>
68
- public List < string > AdditionalPaths { get ; private set ; }
69
-
67
+ public List < string > AdditionalPaths { get ; private set ; }
68
+
70
69
private readonly object syncLock = new object ( ) ;
71
70
72
71
/// <summary>
@@ -114,7 +113,7 @@ public void LoadLibrary(string dllName, IEnumerable<string> additionalPaths = nu
114
113
115
114
if ( additionalPaths == null )
116
115
additionalPaths = new string [ 0 ] ;
117
-
116
+
118
117
try
119
118
{
120
119
lock ( syncLock )
@@ -131,8 +130,8 @@ public void LoadLibrary(string dllName, IEnumerable<string> additionalPaths = nu
131
130
// Try loading from user-defined paths
132
131
foreach ( string path in additionalPaths )
133
132
{
134
- baseDirectory = Path . GetDirectoryName ( path ) ;
135
- dllHandle = LoadLibraryInternal ( dllName , baseDirectory , processArch ) ;
133
+ // baseDirectory = Path.GetFullPath (path);
134
+ dllHandle = LoadLibraryRaw ( dllName , path ) ;
136
135
if ( dllHandle != IntPtr . Zero ) return ;
137
136
}
138
137
@@ -170,10 +169,10 @@ public void LoadLibrary(string dllName, IEnumerable<string> additionalPaths = nu
170
169
// include process detection warnings
171
170
errorMessage . AppendFormat ( "\r \n Warnings: \r \n {0}" , processArch . WarningText ( ) ) ;
172
171
}
173
- throw new LoadLibraryException ( errorMessage . ToString ( ) ) ;
172
+ throw new Exception ( errorMessage . ToString ( ) ) ;
174
173
}
175
174
}
176
- catch ( LoadLibraryException e )
175
+ catch ( Exception e )
177
176
{
178
177
Trace . TraceError ( e . Message ) ;
179
178
}
@@ -222,11 +221,19 @@ private ProcessArchitectureInfo GetProcessArchitecture()
222
221
223
222
private IntPtr LoadLibraryInternal ( string dllName , string baseDirectory , ProcessArchitectureInfo processArchInfo )
224
223
{
225
- IntPtr libraryHandle = IntPtr . Zero ;
224
+ // IntPtr libraryHandle = IntPtr.Zero;
226
225
var platformName = GetPlatformName ( processArchInfo . Architecture ) ;
227
226
var expectedDllDirectory = Path . Combine (
228
227
Path . Combine ( baseDirectory , DllDirectory ) , platformName ) ;
229
- var fileName = FixUpDllFileName ( Path . Combine ( expectedDllDirectory , dllName ) ) ;
228
+ //var fileName = FixUpDllFileName(Path.Combine(expectedDllDirectory, dllName));
229
+
230
+ return LoadLibraryRaw ( dllName , expectedDllDirectory ) ;
231
+ }
232
+
233
+ private IntPtr LoadLibraryRaw ( string dllName , string baseDirectory )
234
+ {
235
+ IntPtr libraryHandle = IntPtr . Zero ;
236
+ var fileName = FixUpDllFileName ( Path . Combine ( baseDirectory , dllName ) ) ;
230
237
231
238
if ( File . Exists ( fileName ) )
232
239
{
@@ -250,15 +257,15 @@ private IntPtr LoadLibraryInternal(string dllName, string baseDirectory, Process
250
257
else
251
258
{
252
259
Trace . TraceError (
253
- "Failed to load native library \" {0}\" .\r \n Check windows event log." ,
260
+ "Failed to load native library \" {0}\" .\r \n Check windows event log." ,
254
261
fileName ) ;
255
262
}
256
263
}
257
264
catch ( Exception e )
258
265
{
259
266
var lastError = Marshal . GetLastWin32Error ( ) ;
260
267
Trace . TraceError (
261
- "Failed to load native library \" {0}\" .\r \n Last Error:{1}\r \n Check inner exception and\\ or windows event log.\r \n Inner Exception: {2}" ,
268
+ "Failed to load native library \" {0}\" .\r \n Last Error:{1}\r \n Check inner exception and\\ or windows event log.\r \n Inner Exception: {2}" ,
262
269
fileName , lastError , e ) ;
263
270
}
264
271
}
0 commit comments