如何使用 C# 中的版本化 COM 接口?
如何创建已扩展的 COM 组件的实例并对其进行调用?
然而,这个COM组件已经通过接口继承的方式进行了扩展。以 IDL 表示(使用 OLE/COM 对象查看器 [OleView.Exe]):
interface IXRawfile3 : IXRawfile2 {
.
.
interface IXRawfile2 : IXRawfile {
.
.
interface IXRawfile : IDispatch {
.
.
coclass XRawfile {
[default] interface IXRawfile;
};
完整提取的 XRawFile2.dll 的 IDL 可用(带
的 HTML 页面)。
我想使用新界面 (IXRawfile3) 中可用的函数,
GetMassListRangeFromScanNum()
而不是
GetMassListFromScanNum()
原始界面 (IXRawfile) 中的函数。
我可以轻松创建 XRawFile 实例并调用 GetMassListFromScanNum()。
但我无法让它与 GetMassListRangeFromScanNum() 一起使用。例如,对 XRawFile 实例使用 GetMassListRangeFromScanNum() 会出现以下编译错误:
Error 1 'XRAWFILE2Lib.XRawfile' does not contain a
definition for 'GetMassListRangeFromScanNum' and no
extension method 'GetMassListRangeFromScanNum' accepting a
first argument of type 'XRAWFILE2Lib.XRawfile' could be
found (are you missing a using directive or an assembly
reference?)
试用 C# 源代码也可用。
平台:Windows XP 64 位 SP2。 Visual Studio 2008。XRawFile2.dll 的互操作文件是由 Visual Studio 2008 以正常方式创建的。
How do I make instances of and calls to COM components that have been extended?
I have used a third-party COM component (XRawFile2.dll from Finnigan/ Thermo Scientific) for many years in a mass spectrometry-related application written in .NET (mixed VB.NET and C#) for accessing raw spectrum data. This has worked well.
However, this COM component has been extended by way of interface inheritance. Expressed in IDL (extracted using the OLE/COM Object Viewer [OleView.Exe]):
interface IXRawfile3 : IXRawfile2 {
.
.
interface IXRawfile2 : IXRawfile {
.
.
interface IXRawfile : IDispatch {
.
.
coclass XRawfile {
[default] interface IXRawfile;
};
The full extracted IDL for XRawFile2.dll is available (HTML page with <pre>).
I want to use a function available in the new interface (IXRawfile3),
GetMassListRangeFromScanNum()
instead of
GetMassListFromScanNum()
in the original interface (IXRawfile).
I have no trouble creating an instance of XRawFile and calling GetMassListFromScanNum().
But I can't get it to work with GetMassListRangeFromScanNum(). For instance, using GetMassListRangeFromScanNum() for an instance of XRawFile gives this compile error:
Error 1 'XRAWFILE2Lib.XRawfile' does not contain a
definition for 'GetMassListRangeFromScanNum' and no
extension method 'GetMassListRangeFromScanNum' accepting a
first argument of type 'XRAWFILE2Lib.XRawfile' could be
found (are you missing a using directive or an assembly
reference?)
The tryout C# source code is also available.
Platform: Windows XP 64 bit SP2. Visual Studio 2008. The interop file for XRawFile2.dll was created by Visual Studio 2008 in the normal manner.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将 XRawFile 实例转换为 IXRawfile3
,例如
这应该在 COM 对象上执行一个查询接口,请求它提供 IXRawfile3 接口。 (假设您导入的类型库与 XRawfile 的实现匹配)
Try casting your instance of XRawFile to IXRawfile3
e.g.
This should do a query interface on the COM object, asking it for the IXRawfile3 interface. (Assuming the typelib you have imported does match the implementation of XRawfile)
我建议使用以下语句(对于版本 2.2):
这可能会给您带来强烈的感受。
您可以稍后调用任何方法。
I would suggest to use the following statement (for version 2.2):
This could simply give you an intense.
You may call any of the methods later.