When PInvoke some dlls written in C ++, it is possible that C ++ dlls also depend on some corresponding dlls, and automatic judgment can be achieved through 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);
// ...