Exemplo n.º 1
0
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="filename">DLL文件路径</param>
        /// <param name="dependencies">依赖DLL</param>
        public LibraryWrapper(string filename, params string[] dependencies)
        {
            if (dependencies != null && dependencies.Length > 0)
            {
                string dirPath = Path.GetDirectoryName(filename);
                foreach (string item in dependencies)
                {
                    string path   = item.Contains(Path.DirectorySeparatorChar) ? item : Path.Combine(dirPath, item);
                    var    handle = LoadLibrary(path);
                    if (handle.IsInvalid)
                    {
                        throw new Exception(string.Format("Failed to load library \"{0}\" failed", path));
                    }
                }
            }
            _handle = LoadLibrary(filename);

            if (_handle.IsInvalid)
            {
                throw new Exception(string.Format("Failed to load library \"{0}\"", filename));
            }
        }
Exemplo n.º 2
0
 public static extern IntPtr GetProcAddress(SafeLibraryHandle handle, string procname);