My situation is described as below:
1. Define an interface in "CommonInterface.idl":
interface Interface1 : IUnknown {
[, helpstring("method Add")] HRESULT Add([in] int a1, [in] int a2, [out] int *sum);
};
Compile it to generate corresponding .h, _i.c, _i.p files; (I do not know how to compile a sole .idl file, so I create a ATL project, write the definition of interface in .idl flieand compile it)
2. Create two COM component by ATL project, both use the Interface1:
"SampleCOM1.idl":
library SampleCOM1Lib
{
import "CommonInterface.idl"; // import idl file defined Interface1
importlib("stdole2.tlb");
[
uuid(EBBD4C25-4C46-4355-B0DA-586945ACD464),
helpstring("Sample1 Class")
]
coclass Sample1
{
[default] interface ISample1;
interface Interface1; // coclass Sample1 implements Interface1
};
};
"SampleCOM2.idl":
library SampleCOM2Lib
{
import "CommonInterface.idl"; // import idl file defined Interface1
importlib("stdole2.tlb");
[
uuid(37262053-20FF-4ECC-96F3-C530D7E078C3),
helpstring("Sample2 Class")
]
coclass Sample2
{
[default] interface ISample2;
interface Interface1; // coclass Sample2 implements Interface1
};
};
3. Build the two ATL projects and get "SampleCOM1.dll" and "SampleCOM2.dll"
4. Add the two COMs into a C# console project's references and generate:
Interop.SampleCOM1Lib,
Interop.SampleCOM2Lib,
both contain the interface Interface1, namely there're two Interface1:
SampleCOM1Lib.Interface1 and SampleCOM2Lib.Interface1, so ambiguity arises.
In my opioion, there should be only one Interface1 as a common interface, and class Sample1 and Sample2 contains the different implementation towards Interface2. How to make it come true
In SampleCOM1.idl (or SampleCOM2.idl), there's no definition of Interface1, just the coclass implements it, why In SampleCOM1Lib (or SampleCOM2 ) there's the Interface1 But where the Interface1 should be