Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. How to implement drived Interface using ATL?

How to implement drived Interface using ATL?

Scheduled Pinned Locked Moved ATL / WTL / STL
c++visual-studiohelptutorialquestion
11 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K kcynic

    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?

    _ Offline
    _ Offline
    _Superman_
    wrote on last edited by
    #2

    If you derive IB from IA, you have to re-implement whatever you did in CA. You could however derive IB from CA and implement only the methods of IB in CB.

    «_Superman_» I love work. It gives me something to do between weekends.
    Microsoft MVP (Visual C++)

    K 1 Reply Last reply
    0
    • _ _Superman_

      If you derive IB from IA, you have to re-implement whatever you did in CA. You could however derive IB from CA and implement only the methods of IB in CB.

      «_Superman_» I love work. It gives me something to do between weekends.
      Microsoft MVP (Visual C++)

      K Offline
      K Offline
      kcynic
      wrote on last edited by
      #3

      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.

      L 1 Reply Last reply
      0
      • K kcynic

        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.

        L Offline
        L Offline
        Lim Bio Liong
        wrote on last edited by
        #4

        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.

        K 1 Reply Last reply
        0
        • L Lim Bio Liong

          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.

          K Offline
          K Offline
          kcynic
          wrote on last edited by
          #5

          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.

          L 1 Reply Last reply
          0
          • K kcynic

            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.

            L Offline
            L Offline
            Lim Bio Liong
            wrote on last edited by
            #6

            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.

            K 1 Reply Last reply
            0
            • L Lim Bio Liong

              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.

              K Offline
              K Offline
              kcynic
              wrote on last edited by
              #7

              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.

              L 1 Reply Last reply
              0
              • K kcynic

                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.

                L Offline
                L Offline
                Lim Bio Liong
                wrote on last edited by
                #8

                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.

                K 1 Reply Last reply
                0
                • L Lim Bio Liong

                  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.

                  K Offline
                  K Offline
                  kcynic
                  wrote on last edited by
                  #9

                  Book Name: ATL Internals: Working with ATL 8 Book Authors: Christopher Tavares Kirk Fertitta Brent Rector Chris Sells maybe yours is the first edition

                  L 1 Reply Last reply
                  0
                  • K kcynic

                    Book Name: ATL Internals: Working with ATL 8 Book Authors: Christopher Tavares Kirk Fertitta Brent Rector Chris Sells maybe yours is the first edition

                    L Offline
                    L Offline
                    Lim Bio Liong
                    wrote on last edited by
                    #10

                    Yes, I think I have the book at home. Would be most glad to help if you need any explanation. - Bio.

                    K 1 Reply Last reply
                    0
                    • L Lim Bio Liong

                      Yes, I think I have the book at home. Would be most glad to help if you need any explanation. - Bio.

                      K Offline
                      K Offline
                      kcynic
                      wrote on last edited by
                      #11

                      OK. Its very kind of you.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups