我已经用C#编写了IRTDServer,它工作正常。
我想将代码转换为使用Excel DNA(出于各种原因,但最重要的是,我想在自己的appdomain中分别加载多个插件)。
但是,在短期内,我想保留“旧的”呼叫方式,即= RTD(“ ProgId” ,,“ MyCoolFunction”,“ Arg1”)。
我正在使用此示例项目来开始:
https://github.com/Excel-DNA/Samples/tree/master/RtdClocks/RtdClock-ExcelRtdServer
我正在使用它,以便可以在Excel中使用= dnaRtdClock_ExcelRtdServer(),它每隔几秒钟就会为我提供时间更新。
我需要做什么才能通过= RTD(“ RtdClock.ClockServer” ,,“ dummy / ignored”)
我想我也应该问第四个问题:
如果我能够通过= RTD(函数调用成功访问IRTDServer,Excel / Excel-DNA会将实现中的DLL加载到FullyTrustedSandbox或DefaultDomain中吗?[毕竟,我执行此转换的全部原因是Excel DNA是要获得AppDomain功能]。
我尝试过的事情:
我已经尝试针对以下目录中的所有* .xll文件针对DLL运行c:\ windows \ system32 \ regsvr32:[注:我从RtdClock-ExcelRtdServer-AddIn64-packed.xll开始和RtdClock-ExcelRtdServer-AddIn64.xlls,因为它们似乎也是最合逻辑的。]它们始终在命令行中以静默方式失败,但在EventViewer中我看到一个错误:
应用程序:regsvr32.exe框架版本:v4.0.30319说明:由于未处理的异常,进程已终止。异常信息:System.InvalidOperationException在ExcelDna.Integration.RunMacroSynchronization.Register()在ExcelDna.Integration.SynchronizationWindow..ctor()在ExcelDna.Integration.SynchronizationManager.Install()在ExcelDna.Integration.DnaLibrary.Initialize()在ExcelDna.Integration.DnaLibrary.InitializeRootLibrary(System.String)
Directory of C:\Users\xxxx\source\repos\ExcelDna-Samples\RtdClocks\RtdClock-ExcelRtdServer\bin\Debug
02/01/2020 10:38 <DIR> .
02/01/2020 10:38 <DIR> ..
02/01/2020 10:38 629,248 RtdClock-ExcelRtdServer-AddIn-packed.xll
02/01/2020 08:31 939 RtdClock-ExcelRtdServer-AddIn.dna
09/09/2015 22:49 751,104 RtdClock-ExcelRtdServer-AddIn.xll
02/01/2020 10:38 539,136 RtdClock-ExcelRtdServer-AddIn64-packed.xll
02/01/2020 08:31 939 RtdClock-ExcelRtdServer-AddIn64.dna
09/09/2015 22:49 660,992 RtdClock-ExcelRtdServer-AddIn64.xll
02/01/2020 10:38 6,144 RtdClock-ExcelRtdServer.dll
02/01/2020 10:38 17,920 RtdClock-ExcelRtdServer.pdb
namespace RtdClock_ExcelRtdServer { [Guid("2838E6F0-B2CA-4FC9-A9AF-7F834CBC595C")] [ComVisible(true)] // Required since the default template puts [assembly:ComVisible(false)] in the AssemblyInfo.cs [ProgId(RtdClockServer.ServerProgId)] // If ProgId is not specified, change the XlCall.RTD call in the wrapper to use namespace + type name (the default ProgId) public class RtdClockServer : ExcelRtdServer { public const string ServerProgId = "RtdClock.ClockServer"; // Using a System.Threading.Time which invokes the callback on a ThreadPool thread // (normally that would be dangerous for an RTD server, but ExcelRtdServer is thread-safe) Timer _timer; List<Topic> _topics; protected override bool ServerStart() { _timer = new Timer(timer_tick, null, 0, 1000); _topics = new List<Topic>(); return true; }
注意:操作系统名称Microsoft Windows 10 Pro版本10.0.18362内部版本18362Microsoft Excel for Office 365版本1911内部版本12228.20364即点即用每月频道
我已经用C#编写了IRTDServer,它工作正常。我想将代码转换为使用Excel DNA(出于各种原因,但是最重要的是,我想加载多个插件...
我认为您需要运行RegSvr32.exe RtdClock-ExcelRtdServer-AddIn64-packed.xll
或类似的东西,才能将.xll文件注册为服务RTD服务器的COM库。在.dll文件上执行Regasm.exe
会造成混乱,导致COM注册与mscorlib相对,后者将在默认AppDomain中托管.dll,如您所见。