Call SetDllDirectory with your additional DLL paths before you SetDllDirectory imported function for the first time.
P / Invoke Signature:
[DllImport("kernel32.dll", SetLastError = true)] static extern bool SetDllDirectory(string lpPathName);
To specify more than one additional DLL search path, modify the PATH environment, for example:
static void AddEnvironmentPaths(string[] paths) { string path = Environment.GetEnvironmentVariable("PATH") ?? string.Empty; path += ";" + string.Join(";", paths); Environment.SetEnvironmentVariable("PATH", path); }
There is more information about the DLL search order here on MSDN .
Updated 2013/07/30:
Updated version above using Path.PathSeparator :
static void AddEnvironmentPaths(IEnumerable<string> paths) { var path = new[] { Environment.GetEnvironmentVariable("PATH") ?? string.Empty }; string newPath = string.Join(Path.PathSeparator.ToString(), path.Concat(paths)); Environment.SetEnvironmentVariable("PATH", newPath); }
Chris Schmich May 19 '10 at 10:39 a.m. 2010-05-19 10:39
source share