Last active
February 3, 2020 14:12
-
-
Save floko84/fd5c5d635b1fc0f9d3e1872e059f160f to your computer and use it in GitHub Desktop.
FreeImage.NET library loader for AnyCPU projects. Attempts to load the platform specific 32-bit/64-bit FreeImage.dll from x86 or x64 subfolders. Compile with https://sourceforge.net/p/freeimage/svn/HEAD/tree/FreeImage/trunk/Wrapper/FreeImage.NET/cs/Library/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Runtime.InteropServices; | |
namespace FreeImageAPI | |
{ | |
public static partial class FreeImage | |
{ | |
private static readonly bool is64BitProcess = (IntPtr.Size == 8); | |
static FreeImage() | |
{ | |
var basePath = Path.GetDirectoryName(new Uri(typeof(FreeImage).Assembly.CodeBase).LocalPath); | |
var platformPath = Path.Combine(basePath, is64BitProcess ? "x64" : "x86"); | |
SetDllDirectory(platformPath); | |
LoadLibrary(Path.Combine(platformPath, FreeImageLibrary)); | |
} | |
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)] | |
private static extern IntPtr LoadLibrary(string lpLibFileName); | |
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)] | |
private static extern bool SetDllDirectory(string lpPathName); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment