管理具有大量 IDL 接口的 COM 类型库中的定义
我正在创建一个具有一百多个接口的 COM 类型库。在单个库
中定义所有接口和组件类是不合理的...IDL 文件变得有数千行那么长!因此,我尝试将每个接口放入其自己的文件中,并使用 import
来满足其依赖关系。
我可以使用什么策略来管理这么多接口?我试图在任何地方使用 import
指令,但我一直试图将它们包含在 TLB 中。我已经在 library
中尝试过 #include
,但依赖项似乎让事情变得很奇怪。
示例A.idl
import "oaidl.idl", "ocidl.idl";
[ uuid(...) ] interface IExampleA : IDispatch { ... }
示例B.idl
import "oaidl.idl", "ocidl.idl", "IExampleA.idl";
[ uuid(...) ] interface IExampleB : IExampleA { ... }
示例Library.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?
};
I'm creating a COM type library with over one hundred interfaces. Defining all of the interfaces and coclasses in a single library
is unreasonable... the IDL file becomes thousands of lines long! So I'm trying the idea of putting each interface in its own file, and using import
s to satisfy its dependencies.
What strategies can I use to manage this many interfaces? I'm trying to use import
directives everywhere, but I'm stuck trying to get them included in the TLB. I've tried #include
in the library
, but things seem to get funky with dependencies.
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?
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您将接口拆分为多个 tlb 文件的计划很好,但是我不明白为什么您似乎是手动生成文件?
我的建议是将接口拆分为多个类型库,但使用类型库编辑器来创建它们。
每个版本的 Delphi 都附带一个类型库编辑器,但如果您没有这个编辑器,网上应该有一些可用的。
I think your plan to split up the interfaces into multiple tlb files is fine, however I dont understand why you appear to be generating the files by hand?
My suggestion would be to split the interfaces into multiple typelibraries but use a typelibrary editor to create them.
A type library editor comes with every version of Delphi, but if you dont have this there should be a few available on the net.