using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; namespace WindowsFormsApp1 { public struct Result { public string Name; public bool Ok; } public static class Verifier { // 声明 LoadLibrary 函数 [DllImport("kernel32.dll", CharSet = CharSet.Unicode)] public static extern IntPtr LoadLibrary(string lpFileName); // 声明 FreeLibrary 函数 [DllImport("kernel32.dll")] public static extern bool FreeLibrary(IntPtr hModule); public static List Check(List libraries) { return libraries.Select(library => { return new Result { Name = library, Ok = LoadLibraryTest(library), }; }).ToList(); } public static bool LoadLibraryTest(string library) { IntPtr dllHandle = IntPtr.Zero; try { dllHandle = LoadLibrary(library); if (dllHandle == IntPtr.Zero) { return false; } return true; } finally { if (dllHandle != IntPtr.Zero) { FreeLibrary(dllHandle); } } } } }