예제 #1
0
        private static string findFirstFullPath(string shortFileName, string envVarName = "")
        {
            if (string.IsNullOrEmpty(shortFileName))
            {
                throw new ArgumentNullException("shortFileName");
            }

            string libSearchPathEnvVar = envVarName;

            if (string.IsNullOrEmpty(libSearchPathEnvVar))
            {
                libSearchPathEnvVar = (Environment.OSVersion.Platform == PlatformID.Win32NT ? "PATH" : "LD_LIBRARY_PATH");
            }
            var candidates = PlatformUtility.FindFullPathEnvVar(shortFileName, libSearchPathEnvVar);

            if ((candidates.Length == 0) && (Environment.OSVersion.Platform == PlatformID.Win32NT))
            {
                if (File.Exists(shortFileName))
                {
                    candidates = new string[] { shortFileName }
                }
            }
            ;
            if (candidates.Length == 0)
            {
                throw new DllNotFoundException(string.Format("Could not find native library named '{0}' within the directories specified in the '{1}' environment variable", shortFileName, libSearchPathEnvVar));
            }
            else
            {
                return(candidates[0]);
            }
        }
예제 #2
0
        public SafeHandleUnmanagedDll(string dllName) : base(true)
        {
            IDynamicLibraryLoader libraryLoader = null;

            if (PlatformUtility.IsUnix)
            {
                libraryLoader = new UnixLibraryLoader();
            }
            else if (Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                libraryLoader = new WindowsLibraryLoader();
            }
            else
            {
                throw new NotSupportedException(PlatformUtility.GetPlatformNotSupportedMsg());
            }
            this.libraryLoader = libraryLoader;
            handle             = libraryLoader.LoadLibrary(dllName);
        }