开发者

Using and deriving from interfaces defined in another COM library

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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜