Skip to content

Commit

Permalink
Cross-platform issues
Browse files Browse the repository at this point in the history
  • Loading branch information
dscheg committed Jul 23, 2017
1 parent a55ec7d commit c337500
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions ZstdNet/ExternMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,26 @@ namespace ZstdNet
internal static class ExternMethods
{
static ExternMethods()
{
if(Environment.OSVersion.Platform == PlatformID.Win32NT)
SetWinDllDirectory();
}

private static void SetWinDllDirectory()
{
var assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
if (assemblyPath == null)
if(assemblyPath == null)
throw new InvalidOperationException("Failed to get assembly directory");
var platform = Environment.Is64BitProcess ? "x64" : "x86";

var ok = SetDllDirectory(Path.Combine(assemblyPath, platform));
if (!ok)
var platform = Environment.Is64BitProcess ? "x64" : "x86";
if(!SetDllDirectory(Path.Combine(assemblyPath, platform)))
throw new InvalidOperationException("Failed to set DLL directory");
}

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

private const string DllName = "libzstd.dll";
private const string DllName = "libzstd";

[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern size_t ZDICT_trainFromBuffer(byte[] dictBuffer, size_t dictBufferCapacity, byte[] samplesBuffer, size_t[] samplesSizes, uint nbSamples);
Expand Down

0 comments on commit c337500

Please sign in to comment.