PInvoke一些C++写的dll时,有可能C++的dll还依赖一些相应的dll,通过SetDllDirectory来达到自动的判断
/// <summary>
/// 设置Dlls的搜索路径
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern bool SetDllDirectory(string path);
// ...
var path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
path = Path.Combine(path, Environment.Is64BitProcess ? "dlls64" : "dlls32");
SetDllDirectory(path);
// ...