using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using static System.Net.Mime.MediaTypeNames; namespace SuperDogTest { /// /// 超级狗辅助类 /// public static class SuperDogHelper { /// /// 加载dll /// /// /// [DllImport("kernel32.dll")] public extern static IntPtr LoadLibrary(string DllName); /// /// 释放dll /// /// /// [DllImport("kernel32")] public extern static bool FreeLibrary(IntPtr hModule); /// /// 获取dll中的方法句柄 /// /// /// /// [DllImport("kernel32.dll")] public extern static IntPtr GetProcAddress(IntPtr hModule, string ProcName); /// /// 查找加密狗委托 /// /// /// [UnmanagedFunctionPointer(CallingConvention.StdCall)] public delegate int VikeyFindType(ref int Count); /// /// 读取加密狗数据委托 /// /// /// /// /// /// [UnmanagedFunctionPointer(CallingConvention.StdCall)] public delegate int VikeyReadDataType(int Index, int Addr, int Length, StringBuilder buffer); /// /// 管理员登录加密狗委托 /// /// /// /// [UnmanagedFunctionPointer(CallingConvention.StdCall)] public delegate int VikeyAdminLoginType(int Index, string AdminPassword); /// /// 加密狗句柄 /// private static IntPtr VikeyHandle; /// /// 查找加密狗 /// public static VikeyFindType VikeyFind { get; private set; } /// /// 加密狗管理员登录 /// public static VikeyAdminLoginType VikeyAdminLogin { get; private set; } /// /// 加密狗读取数据 /// public static VikeyReadDataType VikeyReadData { get; private set; } static SuperDogHelper() { if (IntPtr.Size == 4) { VikeyHandle = LoadLibrary("ViKey32.dll"); } else if (IntPtr.Size == 8) { VikeyHandle = LoadLibrary("ViKey64.dll"); } else return; VikeyFind = Marshal.GetDelegateForFunctionPointer(GetProcAddress(VikeyHandle, "VikeyFind")); VikeyAdminLogin = Marshal.GetDelegateForFunctionPointer(GetProcAddress(VikeyHandle, "VikeyAdminLogin")); VikeyReadData = Marshal.GetDelegateForFunctionPointer(GetProcAddress(VikeyHandle, "VikeyReadData")); } } }