【发布时间】: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 时遇到编译错误”这样的描述并不是很有帮助,你知道,除非你真的不在乎结果。
-
他们是类重定义错误——我更新了评论。