using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Text; namespace POSV.Payment.Abmcs { public delegate int Abmcs(string strIn, StringBuilder strOut); public class DLLMsdi { [DllImport("kernel32.dll")] private extern static IntPtr LoadLibrary(string path); [DllImport("kernel32.dll")] private extern static IntPtr GetProcAddress(IntPtr lib, string funcName); [DllImport("kernel32.dll")] private extern static bool FreeLibrary(IntPtr lib); private IntPtr hLib; public DLLMsdi(String DLLPath) { hLib = LoadLibrary(DLLPath); } public void UnLoad() { FreeLibrary(hLib); } //将要执行的函数转换为委托 public Delegate Invoke(string APIName, Type t) { IntPtr api = GetProcAddress(hLib, APIName); return (Delegate)Marshal.GetDelegateForFunctionPointer(api, t); } } }