正确扩展 COM 接口 (IDL)

发布于 2024-08-13 21:01:34 字数 557 浏览 2 评论 0原文

我正在使用一些遗留的 C++ 代码,并且需要扩展一个接口。目前的接口例如:

[
  object,
  uuid(guid),
  version(1.0),
  dual,
  nonextensible,
  oleautomation
]
interface IInfo : ITask {
   // Methods here
}

[
  object,
  uuid(guid),
  version(1.0),
  dual,
  nonextensible,
  oleautomation
]
interface IExtendedInfoTask : IInfo {
   // Methods here
}

我想扩展的是IInfo接口。现在,根据我的理解,执行此操作的正确方法是创建一个继承 IInfo 接口的 IInfo2 接口,但是我需要我的 IExtendedInfoTask 继承此 IInfo2。更改其当前的继承会破坏现有的接口,不是吗?

执行此操作的正确方法是创建一个扩展 IInfo2 的 IExtendedInfoTask 并复制 IExtendedInfoTask 的方法吗?

I am working with some legacy c++ code and I need to extend an interface. The current interfaces are for example:

[
  object,
  uuid(guid),
  version(1.0),
  dual,
  nonextensible,
  oleautomation
]
interface IInfo : ITask {
   // Methods here
}

[
  object,
  uuid(guid),
  version(1.0),
  dual,
  nonextensible,
  oleautomation
]
interface IExtendedInfoTask : IInfo {
   // Methods here
}

What I would like to extend is the IInfo interface. Now from my understanding the proper way to do this would be to create an IInfo2 interface that inherits the IInfo interface, however I need my IExtendedInfoTask to inherit from this IInfo2. Changing its current inheritance would break the existing interface would it not?

Would the proper way to do this be creating a IExtendedInfoTask that extends the IInfo2 and duplicate the methods of the IExtendedInfoTask?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请爱~陌生人 2024-08-20 21:01:34

执行此操作的正确方法是创建一个扩展新 IInfo2 接口的 IExtendedInfoTask2。 COM 要求接口一旦定义,就是不可变的。

您可以让同一个类同时实现 IExtendedInfoTask 和 IExtendedInfoTask2,以便调用者可以使用任一版本。这只是 vtable 的区别——您不必单独实现这些方法。

The proper way to do this is to create an IExtendedInfoTask2 that extends the new IInfo2 interface. COM requires that an interface, once defined, is immutable.

You can have the same class implement both IExtendedInfoTask and IExtendedInfoTask2, so the caller can use either version. It's only a vtable difference -- you don't have to implement the methods separately.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文