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);

猜你喜欢

转载自www.cnblogs.com/linxmouse/p/12009946.html