网站注册时,希望同时在另一个验证服务器上注册。验证服务器为VC++写的程序。现在在网站上写了一VC的DLL作为接口,一个页面连续操作100次没有问题,可多个页面操作时就报错。
 public class AuthenSOC
    {
 private const string sDllPath = "E:/ZB/WebManage_d.dll";  
        //断开验证服务器
        //void WINAPI DisConnectAuthen()
        private delegate void FDis();        
        private delegate bool FAdd(string lUserName, string lPwd, string sBarName, int iCount, int iType, string lEndTime,  ref int iRet);        
        //添加用户 返回值表示连接验证服务器是否成功
        //pUserName 用户名 pPwd 密码 pBarName 名称 nMachineCount 数 nAccountType 类型 
        //nVipEndTime 到期时间 格式为 2009-05-06 pRet 返回值
        //bool AddBarUser(const char *pUserName,const char *pPwd,const char *pBarName,int nMachineCount,int nAccountType,const char *nVipEndTime,int *pRet)
        public int AddLogin(string sName, string sPwd,string sBarName, int iCount, int iType, string sEndTime)
        {
            try
            {
                //ACCOUNT_IS_EXIST,//账号不存在
                //ACCOUNT_DONT_EXIST,//账号已存在
                //OPER_FAIL,//操作失败
                //OPER_SUCCESS,//操作成功
                int iDll = DllBase.LoadLibrary(sDllPath);
                FAdd foo = (FAdd)DllBase.GetFunctionAddress(iDll, "AddBarUser", typeof(FAdd));
                FDis fo1 = (FDis)DllBase.GetFunctionAddress(iDll, "DisConnectAuthen", typeof(FDis));
                int i = 99;
                bool ss = false;
                ss = foo(sName, sPwd,sBarName,iCount,iType,sEndTime, ref i);
                System.Threading.Thread.Sleep(500);//等 i赋值
                fo1();
                System.Threading.Thread.Sleep(200);
                DllBase.FreeLibrary(iDll);
                return i;
            }
            catch
            {
                throw;
            }
        }
DllBase代码
 public class DllBase
    {
        public DllBase()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }
        [DllImport("Kernel32")]
        public static extern int LoadLibrary(String funcname);        ///<summary> 
        /// API GetProcAddress 
        ///</summary> 
        [DllImport("Kernel32")]
        public static extern int GetProcAddress(int handle, String funcname);        ///<summary> 
        /// API FreeLibrary 
        ///</summary> 
        [DllImport("Kernel32")]
        public static extern int FreeLibrary(int handle);        ///<summary> 
        ///通过非托管函数名转换为对应的委托, by jingzhongrong 
        ///</summary> 
        ///<param name="dllModule">通过LoadLibrary获得的DLL句柄</param> 
        ///<param name="functionName">非托管函数名</param> 
        ///<param name="t">对应的委托类型</param> 
        ///<returns>委托实例,可强制转换为适当的委托类型</returns> 
        public static Delegate GetFunctionAddress(int dllModule, string functionName, Type t)
        {
            int address = GetProcAddress(dllModule, functionName);
            if (address == 0)
                return null;
            else
                return Marshal.GetDelegateForFunctionPointer(new IntPtr(address), t);
        }
        ///<summary> 
        ///将表示函数地址的IntPtr实例转换成对应的委托, by jingzhongrong 
        ///</summary> 
        public static Delegate GetDelegateFromIntPtr(IntPtr address, Type t)
        {
            if (address == IntPtr.Zero)
                return null;
            else
                return Marshal.GetDelegateForFunctionPointer(address, t);
        }        ///<summary> 
        ///将表示函数地址的int转换成对应的委托,by jingzhongrong 
        ///</summary> 
        public static Delegate GetDelegateFromIntPtr(int address, Type t)
        {
            if (address == 0)
                return null;
            else
                return Marshal.GetDelegateForFunctionPointer(new IntPtr(address), t);
        }