【问题标题】:Managing definitions in a COM type library with a lot of IDL interfaces使用大量 IDL 接口管理 COM 类型库中的定义
【发布时间】:2011-03-17 02:21:09
【问题描述】:

我正在创建一个包含一百多个接口的 COM 类型库。在单个 library 中定义所有接口和 coclass 是不合理的……IDL 文件变成了数千行!所以我尝试将每个接口放在自己的文件中,并使用imports 来满足其依赖关系。

我可以使用哪些策略来管理这么多接口?我试图在任何地方使用import 指令,但我一直试图将它们包含在 TLB 中。我在library 中尝试过#include,但依赖项似乎变得很奇怪。

ExampleA.idl

import "oaidl.idl", "ocidl.idl";
[ uuid(...) ] interface IExampleA : IDispatch { ... }

ExampleB.idl

import "oaidl.idl", "ocidl.idl", "IExampleA.idl";
[ uuid(...) ] interface IExampleB : IExampleA { ... }

ExampleLibrary.idl

// Should I put some imports here? They won't be included in the library.
import "IExampleA.idl";
import "IExampleB.idl";

[ uuid(...) ]
library InfrastructureLib
{
    // This? Imports in a library don't actually include the types
    import "IExampleA.idl";
    import "IExampleB.idl";

    // Or this? I get class redefinition errors trying #include 
    #include "IExampleA.idl"
    #include "IExampleB.idl"

    // Is there another way?
};

【问题讨论】:

  • 只是出于好奇,您正在编写什么样的库,需要 100 多个接口?我想如果我尝试使用它,我的大脑会爆炸。如果是我,我会尝试按某种逻辑顺序对它们进行分组,然后将它们分成不同的库。
  • ^_^ 我们有很多基础设施(日志记录、文件 I/O 等),然后是通信类(一堆代表不同消息的类)。我想我可以将它们放入单独的库中......然后 importlib 会让我将它们全部分组到一个主库中吗?嗯……
  • 诸如“我在尝试#include 时遇到编译错误”这样的描述并不是很有帮助,你知道,除非你真的不在乎结果。
  • 他们是类重定义错误——我更新了评论。

标签: com atl idl midl typelib


【解决方案1】:

我认为您将接口拆分为多个 tlb 文件的计划很好,但是我不明白您为什么似乎是手动生成文件?

我的建议是将接口拆分为多个类型库,但使用类型库编辑器来创建它们。

每个版本的 Delphi 都附带一个类型库编辑器,但如果你没有这个,网上应该有一些可用的。

【讨论】:

  • 我不知道存在这样的东西...... Visual Studio 中包含一个吗?我正在使用 ATL 创建 COM 对象和接口。
猜你喜欢
  • 2014-12-09
  • 1970-01-01
  • 2011-03-18
  • 2019-07-15
  • 2010-12-24
  • 2013-09-22
  • 1970-01-01
  • 2011-04-10
  • 2011-08-23
相关资源
最近更新 更多