Excel RTD COM服务器 - 无法将UpdateEvent(类)强制转换为IRTDUpdateEvent(接口)
此问题与Kenny Kerr关于“Excel RTD Servers:C#Interfaces”的博客文章相关,可以在此处找到,该文章应该允许您构建Excel RTD服务器,而不包括对任何特定Excel类型库的引用;必须包含一个引用使您的RTD服务器Excel版本特定(前向兼容,但不向后兼容,我相信)。对Excel类型库没有任何依赖性简化了RTD到具有不同版本的Excel(XP,2003,2007和2010)的计算机的部署。
现在,没有RTD引用特定的Excel类型库来获取接口IRtdServer和IRTDUpdateEvent是非常好的。但是我有时间让Kenny的建议工作。
这就是我所做的:
1) Added IRtdServer.cs and IRTDUpdateEvent.cs to my RTD project and put the interface definitions from your blog into those files (not changing the GUIDs).
2) Removed any reference to an Excel type library.
3) Build and regasm OK.
我在VBA和VBScript中有一些小测试工具,它通过模拟Excel对RTD的调用来测试我的MyRTD.dll RTD服务器。以下是代码的相关代码段:
第一个VBA:
Const RTDProgID As String = "MyRTD.RTD"
Const UpdateEventProgID As String = "MyRTD.UpdateEvent"
' Create the RTD server object.
Dim rtd As Object
Set rtd = CreateObject(RTDProgID)
' Start the RTD server, passing in a callback object.
Dim callback As Object
Set callback = CreateObject(UpdateEventProgID)
Dim status As Long
status = rtd.ServerStart(callback) <---- Fails here.
此代码在最后一行失败,并显示“无法将MyRTD.UpdateEvent转换为MyRTD.IRTDUpdateEvent”的消息。虽然类UpdateEvent实现了接口IRTDUpdateEvent。
第二个VBScript:
' ProgIDs for COM components.
Const RTDProgID = "MyRTD.RTD"
Const UpdateEventProgID = "MyRTD.UpdateEvent"
' Real-time data (RTD) object
Dim rtd
Set rtd = CreateObject(rtdID)
' Callback object. This is how
' the RTD would notify Excel of
' new data updates.
Dim callback
Set callback = CreateObject(UpdateEventProgID)
' Start the RTD server, passing in
' the callback object.
Dim status
status = rtd.ServerStart(callback) <---- Fails here.
此代码在最后一行失败,消息沿着“无效的过程调用或参数”(我认为回调的结果是错误的类型/接口)。
任何帮助,将不胜感激。
Best regards, Andrew Sheppard
没有找到相关结果
已邀请:
1 个回复
哭木算