解决方案 »

  1.   

    用委托调用外部DLL,不用声明extern ?
      

  2.   

    是的,动态加载有时会避免DLL的一些缺陷,比如DLL用到一些全局变量,当多线程调用时会冲突,但是动态加载就可以避免这类问题
      

  3.   

    动态加载DLL
    http://wenku.baidu.com/link?url=CQRFDWzWTS4iVjzJvYrX5Jt8FcCyZcaHsk73XVH1ilKMANLbvMTiyIM0p4wC_T1HhNlz42kFzG9c5eZCwXLfCLmCXP2jgAbxKl0vyrctSHC
      

  4.   

    我一直都这么用,给你一段代码:
     public static IPugins LoadDll(string strDllName)
            { 
                if (!Directory.Exists(strPlugin))
                    Directory.CreateDirectory(strPlugin);            string strDllFullName = strDllName;
                if (strDllFullName.Substring(strDllFullName.Length - 4) != ".dll")
                    strDllFullName += ".dll";
                else
                    strDllName = strDllName.Substring(0, strDllName.Length - 4);            byte[] inArray = getAppDll(strDllFullName);
                if (inArray == null || inArray.Length == 0)
                    return null;            AppDomainSetup AppSetup = new AppDomainSetup();
                AppSetup.PrivateBinPath = strPlugin;
                AppDomain _appDomain = AppDomain.CreateDomain(Application.ProductName, null, AppSetup);
                try
                {
                    _appDomain.AssemblyResolve += new ResolveEventHandler(doOnAssemblyResolve);
                    ObjectHandle handle = _appDomain.CreateInstance(Convert.ToBase64String(inArray), strDllName + strNamespace);
                    return (IPugins)handle.Unwrap();
                }
                catch (Exception ex)
                {
                    _appDomain = null;
                    try
                    {
                        AppDomain.Unload(_appDomain);
                    }
                    catch
                    {
                    }
                    _appDomain = null;
                    throw ex;
                }
            }