You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.4 KiB
C#
60 lines
1.4 KiB
C#
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<Result> Check(List<string> 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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|