C#在运行时自动引入正确的Dlls

设置程序Dlls的搜索路径

1.导入Native函数

/// <summary>
/// 设置Dlls的搜索路径
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern bool SetDllDirectory(string path);

2.在引入包装类中设置相应的Dlls的搜索路径

var path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
path = Path.Combine(path, Environment.Is64BitProcess ? "x64" : "x86");
SetDllDirectory(path);

C#在运行时自动引入正确的Dlls

上一篇:windows命令行操作


下一篇:C# read file to bytes,File.ReadAllFiles,File.Open(),BinaryReader