public static bool LoadUnmanagedModules(String loadDirectory, params String[] unmanagedModules)
{
if (loadDirectory == null)
{
System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
FileInfo file = new FileInfo(asm.Location);
DirectoryInfo directory = file.Directory;
loadDirectory = directory.FullName;
if (Platform.OperationSystem == Emgu.Util.TypeEnum.OS.Windows)
{
if (IntPtr.Size == 8)
{ //64bit process
loadDirectory = Path.Combine(loadDirectory, "x64");
} else
{
loadDirectory = Path.Combine(loadDirectory, "x86");
}
} else if (Platform.OperationSystem == Emgu.Util.TypeEnum.OS.MacOSX)
{
loadDirectory = Path.Combine(loadDirectory, "..");
}
}
if (!Directory.Exists(loadDirectory))
return false;
String oldDir = Environment.CurrentDirectory;
Environment.CurrentDirectory = loadDirectory;
bool success = true;
string prefix = string.Empty;
if (Platform.OperationSystem == Emgu.Util.TypeEnum.OS.MacOSX)
{
prefix = "lib";
}
foreach (String module in unmanagedModules)
{
String fullPath = Path.Combine(loadDirectory, Path.Combine(prefix, module));
success &= (File.Exists(fullPath) && !IntPtr.Zero.Equals(Toolbox.LoadLibrary(fullPath)));
}
Environment.CurrentDirectory = oldDir;
return success;
}