【发布时间】:2014-06-01 08:02:21
【问题描述】:
我正在使用 VSTO for Excel 2007 并使用 IConnectionPointContainer 管理 Excel 应用程序事件,而不是直接订阅它们。现在在 Office 2013 之前,我没有使用 VSTO,而是实现了 IExtensibility2 接口。我以前直接获取excel应用程序对象,管理excel事件如下:
IConnectionPoint _eventSourceConnectionPoint;
ComObjLifetimeManager _eventSourceConnectionPointLifeManager;
var _eventSource = excelApplication as IConnectionPointContainer;
_eventSource.FindConnectionPoint(ref _xlAppEventsIID, out _eventSourceConnectionPoint);
_eventSourceConnectionPointLifeManager = new ComObjLifetimeManager(_eventSourceConnectionPoint);
_eventSourceConnectionPoint.Advise(this, out _connectionCookie);
这在以前可以正常工作。现在我正在使用 VSTO,我在调用 _eventSource.FindConnectionPoint() 方法时遇到了 TargetInvocationException 异常。
"接口不支持后期绑定调用,因为它不是从 IDispatch 派生的"
除了我现在从“this.Application”获取 excel 应用程序对象,而不是通过 IExtensibility2 接口免费获取之外,其他所有内容都与之前相同。
【问题讨论】:
标签: excel com vsto excel-addins