使用另一个 COM 库中定义的接口并从中派生

发布于 2024-09-15 05:48:45 字数 2096 浏览 2 评论 0原文

我在 Visual Studio 中有两个 C++ COM 项目。在 ProjectA 中,我在 MIDL 中定义了 InterfaceA。在 ProjectB 中,我想定义继承于 InterfaceAInterfaceB 。是否可以在不从 ProjectA 导入 IDL 或 H 文件的情况下完成此操作?

下面是代码的布局,可能更清晰。这些库很大,因此我将内容放在单独的文件中,以便于维护。

项目A

InterfaceA.idl

import "oaidl.idl";
import "ocidl.idl";

[ uuid( ... ) ]
interface InterfaceA : IDispatch { ... }

CoclassA.idl

import "InterfaceA.idl";

[ uuid( ... ) ]
interface CoclassA
{
    [default] interface InterfaceA;
};

ProjectA.idl

import "InterfaceA.idl";

[ uuid( ... ) ]
library ProjectA
{
    interface InterfaceA;
    #include "CoclassA.idl"
}

项目B

InterfaceB.idl

import "oaidl.idl";
import "ocidl.idl";

// If both interfaces were in the same project, I'd just import:
//import "InterfaceA.idl";

// Without the import I get a compilation error, obviously. I don't want to
// add ProjectA as an additional include directory because I don't want ProjectB
// to be dependent on how ProjectA's files are organized. I just want the types
// from ProjectA to be available here.

[ uuid(...) ]
interface InterfaceB: InterfaceA { ... }

CoclassB.idl

import "InterfaceB.idl";

[ uuid( ... ) ]
interface CoclassB
{
    [default] interface InterfaceB;
};

ProjectB.idl

import "InterfaceB.idl";

[ uuid( ... ) ]
library ProjectB
{
    // I wish using importlib would help here, but it won't since InterfaceB is
    // defined and compiled by MIDL separately in InterfaceB.idl.
    //importlib("ProjectA.tlb");

    // I could try to #include "InterfaceB.idl", but then I would lose the
    // automatic dependency analysis that MIDL does. I am also having trouble
    // getting the MIDL compiler to understand #defines.

    interface InterfaceB;
    #include "CoclassB.idl"
}

我有一种感觉,我想做的事情是不可能的。如果 MIDL 支持库之外的 importlib 等效项,那么这将不是问题!

I have two C++ COM projects in Visual Studio. In ProjectA I define InterfaceA in MIDL. In ProjectB I would like to define InterfaceB which inherits from InterfaceA. Is this possible to do without importing IDL or H files from ProjectA?

Here's how the code is laid out, which might be clearer. The libraries are large so I put things in separate files to make it easier to maintain.

Project A

InterfaceA.idl

import "oaidl.idl";
import "ocidl.idl";

[ uuid( ... ) ]
interface InterfaceA : IDispatch { ... }

CoclassA.idl

import "InterfaceA.idl";

[ uuid( ... ) ]
interface CoclassA
{
    [default] interface InterfaceA;
};

ProjectA.idl

import "InterfaceA.idl";

[ uuid( ... ) ]
library ProjectA
{
    interface InterfaceA;
    #include "CoclassA.idl"
}

Project B

InterfaceB.idl

import "oaidl.idl";
import "ocidl.idl";

// If both interfaces were in the same project, I'd just import:
//import "InterfaceA.idl";

// Without the import I get a compilation error, obviously. I don't want to
// add ProjectA as an additional include directory because I don't want ProjectB
// to be dependent on how ProjectA's files are organized. I just want the types
// from ProjectA to be available here.

[ uuid(...) ]
interface InterfaceB: InterfaceA { ... }

CoclassB.idl

import "InterfaceB.idl";

[ uuid( ... ) ]
interface CoclassB
{
    [default] interface InterfaceB;
};

ProjectB.idl

import "InterfaceB.idl";

[ uuid( ... ) ]
library ProjectB
{
    // I wish using importlib would help here, but it won't since InterfaceB is
    // defined and compiled by MIDL separately in InterfaceB.idl.
    //importlib("ProjectA.tlb");

    // I could try to #include "InterfaceB.idl", but then I would lose the
    // automatic dependency analysis that MIDL does. I am also having trouble
    // getting the MIDL compiler to understand #defines.

    interface InterfaceB;
    #include "CoclassB.idl"
}

I have a feeling that what I want to do is not possible. This wouldn't be a problem if MIDL supported an importlib equivalent outside of libraries!

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文