将Excel RTD库转换为Excel-DNA,同时保留= RTD(接口(64位Excel)。

问题描述 投票:1回答:1

我已经用C#编写了IRTDServer,它工作正常。

我想将代码转换为使用Excel DNA(出于各种原因,但最重要的是,我想在自己的appdomain中分别加载多个插件)。

但是,在短期内,我想保留“旧的”呼叫方式,即= RTD(“ ProgId” ,,“ MyCoolFunction”,“ Arg1”)。

我正在使用此示例项目来开始:

https://github.com/Excel-DNA/Samples/tree/master/RtdClocks/RtdClock-ExcelRtdServer

我正在使用它,以便可以在Excel中使用= dnaRtdClock_ExcelRtdServer(),它每隔几秒钟就会为我提供时间更新。

  1. 是否可以通过= RTD(“ ...]调用它?
  2. 如果是这样,我是否正确,输入Excel的函数应为= RTD(“ RtdClock.ClockServer”,“虚拟/忽略”)。
  3. 然后主要是:
  4. 我需要做什么才能通过= RTD(“ RtdClock.ClockServer” ,,“ dummy / ignored”)

调用同一函数

我想我也应该问第四个问题:

如果我能够通过= RTD(函数调用成功访问IRTDServer,Excel / Excel-DNA会将实现中的DLL加载到FullyTrustedSandbox或DefaultDomain中吗?[毕竟,我执行此转换的全部原因是Excel DNA是要获得AppDomain功能]。

我尝试过的事情:

  1. 我在RTDClockServer项目中添加了GUID。
  2. 我运行了%SystemRoot%\ Microsoft.Net \ Framework64 \ v4.0.30319 \ RegAsm.exe RtdClock-ExcelRtdServer.dll / codebase。最初,它抱怨缺少ExcelDna.Integration。因此,我将该包的引用更改为CopyLocal = True。
  3. 我检查了注册表。它确实具有我希望从注册RTD服务器获得的所有COM注册条目。
  4. 我已经尝试将= RTD(“ RtdClock.ClockServerRTD” ,,)添加为函数调用。我看到它确实加载了我的DLL并遇到了一个断点,但是只有ServerTerminate断点(例如,不是ServerStart)。我还看到在这种情况下,AppDomain是DefaultDomain,而不是“ FullyTrustedSandBox:...”
  5. 我已经尝试针对以下目录中的所有* .xll文件针对DLL运行c:\ windows \ system32 \ regsvr32:[注:我从RtdClock-ExcelRtdServer-AddIn64-packed.xll开始和RtdClock-ExcelRtdServer-AddIn64.xlls,因为它们似乎也是最合逻辑的。]它们始终在命令行中以静默方式失败,但在EventViewer中我看到一个错误:

  6. 应用程序: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
    

enter image description here

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(出于各种原因,但是最重要的是,我想加载多个插件...

excel-dna
1个回答
1
投票

我认为您需要运行RegSvr32.exe RtdClock-ExcelRtdServer-AddIn64-packed.xll或类似的东西,才能将.xll文件注册为服务RTD服务器的COM库。在.dll文件上执行Regasm.exe会造成混乱,导致COM注册与mscorlib相对,后者将在默认AppDomain中托管.dll,如您所见。

© www.soinside.com 2019 - 2024. All rights reserved.