Hi Aleksandr,
Thanks for your reply. Since you said I was not clear, I am explaining here with the example.
This is the present situation in my code. (This code is a part of COM component but not exposed to any other components).
class B {
public:
virtual void func();
virtual void func1();
virtual void func2();
}
class D1 : public B {
void func3();
void func4();
void func2() { //do something...};
}
class D2 : public B {
void func5();
void func6();
void func1() { //do something...};
}
int main() {
B* b;
//Based on the requirement, I need to create the specific object. Here, I create an object for D1.
b = new D1;
b->func3(); //OK. Should call D1's func3().
b->func4(); //OK. Should call D1's func4().
b->func2(); //OK. Should call D1's func2() since overridden.
b->func1(); //OK. Should call B's func1()
b->func(); //OK. Should call B's func()
b->func5(); //Error. Should not work.
b->func6(); //Error. Should not work.
}
So, here, I was able to call func3, func4, func1 and most importantly the correct func2().
Now, coming to the situation after I change these to interfaces and exposing to other components.
interace IB: public IUnknown
{
public:
void func();
void func1();
void func2();
};
interface ID1: public IUnknown
{
public:
void func3();
void func4();
};
interface ID2: public IUnknown
{
public:
void func5();
void func6();
};
Suppose that all these interfaces are supported by my coclass(CA).
And I write this code from some client component.
ID1* d1;
CreateObject(__uuid(D1), &d1);
d1->func3(); //OK. Should be fine. It should call the func3() of the implementation class for ID1 interface.
d1->func4(); //OK. Should be fine. It should call the func4() of the implementation class for ID1 interface.
d1->func2(); //Error. It will not work since func2 is not overridden in ID1's implementation class.
d1->func1(); //Error. func1() is only implemented in IB's implementation class. Since it is not implemented in ID1's implementation class, this will not work. This is my main requirement.
d1->func(); //Error. func1() is only implemented in IB's implementation class. Since it is not implemented in ID1's implementation class, this will not work. This is my main requirement.
So, if you can see clearly, I am able to call func2, func1 also with the same pointer variable in my present implentation. But, if I make them separate interfaces, I am not able to create an object which is able to call func2, func1 and func.
As you suggested to go by interface inheritance, the situation can improve to this extent.
ID1* d1;
CreateObject(__uuid(D1), &d1);
d1->func3(); //OK. Should be fine. It should call the func3() of the implementation class for ID1 interface.
d1->func4(); //OK. Should be fine. It should call the func4() of the implementation class for ID1 interface.
d1->func2(); //OK. Should be fine. It should call the func2() of the implementation class for IB interface.
d1->func1(); //OK. Should be fine. It should call the func1() of the implementation class for IB interface.
d1->func(); //OK. Should be fine. It should call the func() of the implementation class for IB interface.
But, here again, my actual purpose is not yet done. In my present implementation, I have virtual function func2() of class B which was overridden in D1. And whenever I create an object of D1, I was able to call this function with a pointer to B.
I want to know if this support is there in COM. I doubt it is not possible.
Suppose the name of coclass which is supporting these interfaces in CA. And my implementation class(CAImpl) should be derived from this CA. So, even though I can declare func2() in IB, ID1 and ID2, the implementation of func2() will be in CAImpl and can be only one implementation.
I am not sure if this can work if I use three different coclasses to support my three interfaces IB, ID1 and ID2. But, this can be tedious and requires generation of many implementation classes as well.
Kindly, let me know if this is possible in COM.
If I am still not clear, please let me know and I will try my best to be clear.
Thanks and Regards,
krishna