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

使用和派生另一个COM库中定义的接口,com,dll,dependencies,atl,Com,Dll,Dependencies,Atl,我在VisualStudio中有两个C++ COM项目。在ProjectA中,我用MIDL定义InterfaceA。在ProjectB中,我想定义从InterfaceA继承的InterfaceB。这是否可以在不从ProjectA导入IDL或H文件的情况下实现 下面是代码的布局,这可能更清楚。这些库很大,所以我将它们放在单独的文件中,以便于维护 项目A 接口a.idl CoclassA.idl 项目a.idl 项目B 接口b.idl CoclassB.idl 项目b.idl 我觉得我想做的是不可能

我在VisualStudio中有两个C++ COM项目。在ProjectA中,我用MIDL定义InterfaceA。在ProjectB中,我想定义从InterfaceA继承的InterfaceB。这是否可以在不从ProjectA导入IDL或H文件的情况下实现

下面是代码的布局,这可能更清楚。这些库很大,所以我将它们放在单独的文件中,以便于维护

项目A 接口a.idl CoclassA.idl 项目a.idl 项目B 接口b.idl CoclassB.idl 项目b.idl 我觉得我想做的是不可能的。如果MIDL在库之外支持importlib等价物,这就不会成为问题

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

[ uuid( ... ) ]
interface InterfaceA : IDispatch { ... }
import "InterfaceA.idl";

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

[ uuid( ... ) ]
library ProjectA
{
    interface InterfaceA;
    #include "CoclassA.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 { ... }
import "InterfaceB.idl";

[ uuid( ... ) ]
interface CoclassB
{
    [default] interface InterfaceB;
};
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"
}