1
1
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET.
2
2
// Licensed under the Apache License, Version 2.0.
3
3
4
- using System ;
5
- using System . Runtime . InteropServices ;
6
- using System . Text ;
7
4
using ImageMagick ;
8
5
using ImageMagick . Configuration ;
9
6
using Xunit ;
@@ -20,50 +17,13 @@ public void ShouldBeEmbeddedInTheNativeLibrary()
20
17
if ( ! Runtime . IsWindows )
21
18
Assert . Skip ( "The embedded resources are only available on Windows." ) ;
22
19
23
- #if PLATFORM_x64 || PLATFORM_AnyCPU
24
- var module = GetModuleHandle ( ImageMagick . NativeLibrary . X64Name ) ;
25
- #elif PLATFORM_arm64
26
- var module = GetModuleHandle ( ImageMagick . NativeLibrary . Arm64Name ) ;
27
- #else
28
- var module = GetModuleHandle ( ImageMagick . NativeLibrary . X86Name ) ;
29
- #endif
30
- Assert . NotEqual ( IntPtr . Zero , module ) ;
31
-
32
20
foreach ( var configurationFile in ConfigurationFiles . Default . All )
33
21
{
34
- var resource = FindResource ( module , configurationFile . FileName , "IMAGEMAGICK" ) ;
35
- Assert . NotEqual ( IntPtr . Zero , resource ) ;
36
-
37
- var resourceData = LoadResource ( module , resource ) ;
38
- Assert . NotEqual ( IntPtr . Zero , resourceData ) ;
39
-
40
- var resourcePointer = LockResource ( resourceData ) ;
41
- Assert . NotEqual ( IntPtr . Zero , resourcePointer ) ;
42
-
43
- var size = SizeofResource ( module , resource ) ;
44
- Assert . NotEqual ( 0U , size ) ;
45
-
46
- var bytes = new byte [ size ] ;
47
- Marshal . Copy ( resourcePointer , bytes , 0 , ( int ) size ) ;
22
+ var data = MagickNET . GetWindowsResource ( configurationFile . FileName ) ;
48
23
49
- var data = Encoding . UTF8 . GetString ( bytes ) ;
24
+ Assert . NotNull ( data ) ;
50
25
Assert . Equal ( configurationFile . Data , data ) ;
51
26
}
52
27
}
53
-
54
- [ DllImport ( "kernel32.dll" , SetLastError = true ) ]
55
- private static extern IntPtr FindResource ( IntPtr hModule , string lpName , string lpType ) ;
56
-
57
- [ DllImport ( "kernel32.dll" , SetLastError = true ) ]
58
- private static extern IntPtr GetModuleHandle ( string lpModuleName ) ;
59
-
60
- [ DllImport ( "kernel32.dll" , SetLastError = true ) ]
61
- private static extern IntPtr LoadResource ( IntPtr hModule , IntPtr hResInfo ) ;
62
-
63
- [ DllImport ( "kernel32.dll" , SetLastError = true ) ]
64
- private static extern IntPtr LockResource ( IntPtr hResData ) ;
65
-
66
- [ DllImport ( "kernel32.dll" , SetLastError = true ) ]
67
- private static extern uint SizeofResource ( IntPtr hModule , IntPtr hResInfo ) ;
68
28
}
69
29
}
0 commit comments