我在Visual Studio中有两个C ++ COM项目。在ProjectA
中,我在MIDL中定义了InterfaceA
。在ProjectB
我想定义继承自InterfaceB
的{{1}}。如果不从InterfaceA
导入IDL或H文件,可以这样做吗?
以下是代码的布局方式,这可能更清晰。库很大,所以我把东西放在单独的文件中,以便于维护。
ProjectA
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;
};
我有一种感觉,我想做的事情是不可能的。如果MIDL支持库之外的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"
}
等效,那么这不会成为问题!