public static void Load() { Handle = LoadLibrary(fileName); if (Handle == IntPtr.Zero) { Log4Net.WriteLog($"加载DLL失败({Marshal.GetLastWin32Error()})"); } else { try { get_version = Marshal.GetDelegateForFunctionPointer <get_version_t>(GetProcAddress(Handle, nameof(get_version))); auth = Marshal.GetDelegateForFunctionPointer <auth_t>(GetProcAddress(Handle, nameof(auth))); exit_auth = Marshal.GetDelegateForFunctionPointer <auth_t>(GetProcAddress(Handle, nameof(exit_auth))); set_enable_crypt = Marshal.GetDelegateForFunctionPointer <set_enable_crypt_t>(GetProcAddress(Handle, nameof(set_enable_crypt))); set_remote_ip = Marshal.GetDelegateForFunctionPointer <set_str_t>(GetProcAddress(Handle, nameof(set_remote_ip))); set_keep_alive1_flag = Marshal.GetDelegateForFunctionPointer <set_str_t>(GetProcAddress(Handle, nameof(set_keep_alive1_flag))); set_log_file = Marshal.GetDelegateForFunctionPointer <set_str_t>(GetProcAddress(Handle, nameof(set_log_file))); } catch (Exception e) { Log4Net.WriteLog("加载DLL函数失败", e); } } }
public static void Unload() { if (Handle != IntPtr.Zero) { FreeLibrary(Handle); Handle = IntPtr.Zero; get_version = null; auth = null; exit_auth = null; set_enable_crypt = null; set_remote_ip = null; set_keep_alive1_flag = null; set_log_file = null; } }