11// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET.
22// Licensed under the Apache License, Version 2.0.
33
4- using System ;
5- using System . Runtime . InteropServices ;
6- using System . Text ;
74using ImageMagick ;
85using ImageMagick . Configuration ;
96using Xunit ;
@@ -20,50 +17,13 @@ public void ShouldBeEmbeddedInTheNativeLibrary()
2017 if ( ! Runtime . IsWindows )
2118 Assert . Skip ( "The embedded resources are only available on Windows." ) ;
2219
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-
3220 foreach ( var configurationFile in ConfigurationFiles . Default . All )
3321 {
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 ) ;
4823
49- var data = Encoding . UTF8 . GetString ( bytes ) ;
24+ Assert . NotNull ( data ) ;
5025 Assert . Equal ( configurationFile . Data , data ) ;
5126 }
5227 }
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 ) ;
6828 }
6929}
0 commit comments