管理具有大量 IDL 接口的 COM 类型库中的定义

发布于 2024-09-10 09:06:19 字数 1060 浏览 8 评论 0原文

我正在创建一个具有一百多个接口的 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 imports 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 技术交流群。

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

发布评论

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

评论(1

妄司 2024-09-17 09:06:19

我认为您将接口拆分为多个 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.

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