多个dll分文件夹存放,保证程序能正常加载

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[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 ? "x64" : "x86");
SetDllDirectory(path);
//遍历子文件夹
DirectoryInfo modulePath = new DirectoryInfo(path);
DirectoryInfo[] dirSub=modulePath.GetDirectories();
foreach (DirectoryInfo directoryInfo in dirSub) {
var temp = Path.Combine(path, directoryInfo.ToString());
SetDllDirectory(temp);
}