此問題與肯尼克爾關於「Excel RTD服務器:C#接口」的博客文章相關,該文章可以找到here,它應該允許您構建Excel RTD服務器而不包含對任何特定Excel類型庫的引用;必須包含一個引用使RTD服務器的Excel版本特定(向前兼容,但不向後兼容,我相信)。不依賴於Excel類型庫可簡化RTD到具有不同版本的Excel(XP,2003,2007和2010)的計算機的部署。Excel RTD COM服務器 - 無法將UpdateEvent(類)轉換爲IRTDUpdateEvent(接口)
現在,沒有RTD引用特定的Excel類型庫來獲取接口IRtdServer和IRTDUpdateEvent是非常好的。但我有一段時間讓魔鬼的建議工作的惡魔。
這裏是我做了什麼:
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