How to implement drived Interface using ATL?
-
First, i have a Interface name IA, i implement it in class CA. Second, i want to use a Interface IB driving from IA. So, I want to implement IB in class CB. Since IB drove from IB, I don't want to copy methods implemented by CA to CB. I use ATL wizard to add a new simple ATL object (IB) to the project, and modify the IB's base Interface from IUnkown to IA. But when i compile the project, VS would give me an error says there are some abstract methods had not been implemented in CB otherwise i copy all the implemented methods of CA to CB. If no atl, i think i can do it correctly. but i have no idea in atl. What should i do?
If you derive
IB
fromIA
, you have to re-implement whatever you did inCA
. You could however deriveIB
fromCA
and implement only the methods ofIB
inCB
.«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) -
If you derive
IB
fromIA
, you have to re-implement whatever you did inCA
. You could however deriveIB
fromCA
and implement only the methods ofIB
inCB
.«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) -
What a pity! You know, if IA already was a big interface, that is, CA had a plenty of code, i would have to copy the same code from CA to CB.
Err, hold on a second, kcynic. You do not absolutely need to copy the code from CA to CB. Here are some alternatives : 1. You could simply have only the CA object and have it implement IB. To do this : 1.1 Derive CA from IB, e.g. class ATL_NO_VTABLE CA : public ... public IB... 1.2 Then in your COM map, declare that CA implements IB : BEGIN_COM_MAP(CA) ... // COM_INTERFACE_ENTRY(IA) // Make sure this is commented out. COM_INTERFACE_ENTRY(IB) COM_INTERFACE_ENTRY2(IA, IB) // Indicates that IA interface is gotten through IB. ... END_COM_MAP() 1.3 You then implement methods of IB in CA. Essentially, CA is derived from both IA and IB. 2. If you absolutely need to have 2 objects, CA and CB, then you could simply contain the whole of CA's implementation inside CB. You do this via COM techniques of containment or aggregation. You can read these up in MSDN. This way, you can avoid making a duplicate of CA's implementation which is problematic for maintenance. - Bio.
-
Err, hold on a second, kcynic. You do not absolutely need to copy the code from CA to CB. Here are some alternatives : 1. You could simply have only the CA object and have it implement IB. To do this : 1.1 Derive CA from IB, e.g. class ATL_NO_VTABLE CA : public ... public IB... 1.2 Then in your COM map, declare that CA implements IB : BEGIN_COM_MAP(CA) ... // COM_INTERFACE_ENTRY(IA) // Make sure this is commented out. COM_INTERFACE_ENTRY(IB) COM_INTERFACE_ENTRY2(IA, IB) // Indicates that IA interface is gotten through IB. ... END_COM_MAP() 1.3 You then implement methods of IB in CA. Essentially, CA is derived from both IA and IB. 2. If you absolutely need to have 2 objects, CA and CB, then you could simply contain the whole of CA's implementation inside CB. You do this via COM techniques of containment or aggregation. You can read these up in MSDN. This way, you can avoid making a duplicate of CA's implementation which is problematic for maintenance. - Bio.
Cool. This is really the perfect solution! I have read the concept on the book but couldn't take them into practice. I remember your idea. And, btw, are you usually working with ATL/WTL/COM? Im a beginner of COM programming and only know the basic knowledge of com, atl/wtl too. Im reading the book 'ATLs Internals Second Edition Working with ATL8'. Regards.
-
Cool. This is really the perfect solution! I have read the concept on the book but couldn't take them into practice. I remember your idea. And, btw, are you usually working with ATL/WTL/COM? Im a beginner of COM programming and only know the basic knowledge of com, atl/wtl too. Im reading the book 'ATLs Internals Second Edition Working with ATL8'. Regards.
Yes, I've worked with COM with ATL for a number of years now. I have not tried WTL yet, though. Please have a look at some of my COM articles : http://www.codeproject.com/script/Articles/MemberArticles.aspx?amid=24366[^] Bio.
-
Yes, I've worked with COM with ATL for a number of years now. I have not tried WTL yet, though. Please have a look at some of my COM articles : http://www.codeproject.com/script/Articles/MemberArticles.aspx?amid=24366[^] Bio.
-
Thanks, I will. im learning WTL too. because, its independent with MFC. I think wtl(atl too) as perfect practice of C++ concepts. And have you read the book i said before, if so, i hope i can ask you some puzzling questions about that book.
I have a book titled "ATL Internals" but I'm not sure if it is the same one you have. What is/are the name/s of the author/s ? Bio.
-
I have a book titled "ATL Internals" but I'm not sure if it is the same one you have. What is/are the name/s of the author/s ? Bio.
-
Book Name: ATL Internals: Working with ATL 8 Book Authors: Christopher Tavares Kirk Fertitta Brent Rector Chris Sells maybe yours is the first edition
Yes, I think I have the book at home. Would be most glad to help if you need any explanation. - Bio.
-
Yes, I think I have the book at home. Would be most glad to help if you need any explanation. - Bio.