使用另一个 COM 库中定义的接口并从中派生
我在 Visual Studio 中有两个 C++ COM 项目。在 ProjectA
中,我在 MIDL 中定义了 InterfaceA
。在 ProjectB
中,我想定义继承于 InterfaceA
的 InterfaceB
。是否可以在不从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论