Skip to content

Commit

Permalink
GDAL: fix dll load
Browse files Browse the repository at this point in the history
  • Loading branch information
meee1 committed Aug 22, 2023
1 parent ffa71e5 commit fdb080e
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions ExtLibs/GDAL/GDAL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,30 @@ public class GDAL: IGDAL

static List<GeoBitmap> _cache = new List<GeoBitmap>();

[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern bool SetDllDirectory(string lpPathName);

static GDAL()
{
log.InfoFormat("GDAL static ctor");
try
{
string executingAssemblyFile = new Uri(Assembly.GetExecutingAssembly().GetName().CodeBase).LocalPath;
string executingDirectory = Path.GetDirectoryName(executingAssemblyFile);
string gdalPath = Path.Combine(executingDirectory, "gdal");
string nativePath = "";
if (Environment.Is64BitProcess)
nativePath = Path.Combine(gdalPath, "x64");
else
nativePath = Path.Combine(gdalPath, "x86");

SetDllDirectory(nativePath);
}
catch(Exception ex)
{
log.Error(ex);
}

try
{
GdalConfiguration.ConfigureGdal();
Expand Down

0 comments on commit fdb080e

Please sign in to comment.