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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. dual interface

dual interface

Scheduled Pinned Locked Moved C / C++ / MFC
questioncom
63 Posts 7 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.
  • G George_George

    Thanks Sandip, 1. I am still confused. Dual interface means two ways to invoke methods of my class. One of them is through IDispatch.Invoke, the other way is? 2. Confused about what do you mean -- "Implement the vtable part of the interface in your class." If my class have virtual methods, it should have vtable, what do you mean implement the vtable part? regards, George

    CPalliniC Offline
    CPalliniC Offline
    CPallini
    wrote on last edited by
    #8

    George_George wrote:

    1. I am still confused. Dual interface means two ways to invoke methods of my class. One of them is through IDispatch.Invoke, the other way is?

    Via another interface's VTABLE.

    George_George wrote:

    2. Confused about what do you mean -- "Implement the vtable part of the interface in your class."

    Suppose you have (only) a method (say Add) you can use via IDispatch::Invoke. Implement the VTABLE part of the interface means: provide an interface, say IOperation exposing the Add method (since such method is not directly exposed by IDispatch). Possibly the final COM component interface inherits both from IDispatch and IOperation, as Sandip I don't remember the technical details and, as usual: "this in going on my arrogant assumptions..." :)

    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
    [My articles]

    In testa che avete, signor di Ceprano?

    G S 2 Replies Last reply
    0
    • CPalliniC CPallini

      George_George wrote:

      1. I am still confused. Dual interface means two ways to invoke methods of my class. One of them is through IDispatch.Invoke, the other way is?

      Via another interface's VTABLE.

      George_George wrote:

      2. Confused about what do you mean -- "Implement the vtable part of the interface in your class."

      Suppose you have (only) a method (say Add) you can use via IDispatch::Invoke. Implement the VTABLE part of the interface means: provide an interface, say IOperation exposing the Add method (since such method is not directly exposed by IDispatch). Possibly the final COM component interface inherits both from IDispatch and IOperation, as Sandip I don't remember the technical details and, as usual: "this in going on my arrogant assumptions..." :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      G Offline
      G Offline
      George_George
      wrote on last edited by
      #9

      Thanks CPallini, I have did more study and I want to share my points here. Could you help to review whether my points are correct please? :-) 1. If a component implements IDispatch directly, we can only invoke its member methods through IDispatch.Invoke -- only one way, so it is not dual interface; 2. If a component implements IUnknown directly, we can only use AddRef/Release/QueryInterface, it is useless since we can only use the 3 methods; 3. If a component implements a customized interface, then the customized interface implements IUnknown, then we could invoke the component's member methods through QueryInterface to get the customized interface, and using the vtable in the customized interface to invoke member methods. But still one way, so it is not dual interface; 4. If a component implements a customized interface, then the customized interface implements IDispatch, then we could invoke the component's member methods through QueryInterface to get the customized interface, and using the vtable in the customized interface to invoke member methods, and also we could invoke through IDispatch.Invoke. Two ways to invoke it, so called dual interface. All of my understandings are correct? Anything missing? :-) regards, George

      CPalliniC L 2 Replies Last reply
      0
      • G George_George

        Thanks CPallini, I have did more study and I want to share my points here. Could you help to review whether my points are correct please? :-) 1. If a component implements IDispatch directly, we can only invoke its member methods through IDispatch.Invoke -- only one way, so it is not dual interface; 2. If a component implements IUnknown directly, we can only use AddRef/Release/QueryInterface, it is useless since we can only use the 3 methods; 3. If a component implements a customized interface, then the customized interface implements IUnknown, then we could invoke the component's member methods through QueryInterface to get the customized interface, and using the vtable in the customized interface to invoke member methods. But still one way, so it is not dual interface; 4. If a component implements a customized interface, then the customized interface implements IDispatch, then we could invoke the component's member methods through QueryInterface to get the customized interface, and using the vtable in the customized interface to invoke member methods, and also we could invoke through IDispatch.Invoke. Two ways to invoke it, so called dual interface. All of my understandings are correct? Anything missing? :-) regards, George

        CPalliniC Offline
        CPalliniC Offline
        CPallini
        wrote on last edited by
        #10

        IMHO your understandings are correct. Point (2), as it stands, IMHO is misleading: since IUnknown implementation is mandatory, I will say: if a component implements only IDispatch... But such a point is obvious. Also, as you know well, IDispatch, like any other COM interface must provide IUnknown, then saying: "implementing only IDispatch" it is equivalent to say: "implementing a IUnknown whose QueryInterface method may return only IDispatch". :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        In testa che avete, signor di Ceprano?

        G 1 Reply Last reply
        0
        • CPalliniC CPallini

          George_George wrote:

          1. I am still confused. Dual interface means two ways to invoke methods of my class. One of them is through IDispatch.Invoke, the other way is?

          Via another interface's VTABLE.

          George_George wrote:

          2. Confused about what do you mean -- "Implement the vtable part of the interface in your class."

          Suppose you have (only) a method (say Add) you can use via IDispatch::Invoke. Implement the VTABLE part of the interface means: provide an interface, say IOperation exposing the Add method (since such method is not directly exposed by IDispatch). Possibly the final COM component interface inherits both from IDispatch and IOperation, as Sandip I don't remember the technical details and, as usual: "this in going on my arrogant assumptions..." :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          S Offline
          S Offline
          SandipG
          wrote on last edited by
          #11

          Hi CPallini, I am not sure that we require an extra Interface. Check this Link Dual Interfaces[^] I could not find some good sample for this do you have one which will explain step by step procedure.. I am asking for this because i have never implemented this ..

          CPallini wrote:

          Sandip I don't remember the technical details and, as usual: "this in going on my arrogant assumptions..." Smile

          :laugh:

          Regards, Sandip.

          modified on Friday, September 12, 2008 4:31 AM

          CPalliniC G 2 Replies Last reply
          0
          • S SandipG

            Hi CPallini, I am not sure that we require an extra Interface. Check this Link Dual Interfaces[^] I could not find some good sample for this do you have one which will explain step by step procedure.. I am asking for this because i have never implemented this ..

            CPallini wrote:

            Sandip I don't remember the technical details and, as usual: "this in going on my arrogant assumptions..." Smile

            :laugh:

            Regards, Sandip.

            modified on Friday, September 12, 2008 4:31 AM

            CPalliniC Offline
            CPalliniC Offline
            CPallini
            wrote on last edited by
            #12

            I think you're right, since you may simply do something like:

            class IMyDualInterface : public IDispatch

            with a VTABLE arranged the following way:

            • QueryInterface methods
            • IDispatch methods
            • 'Add' method here.

            :)

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
            [My articles]

            In testa che avete, signor di Ceprano?

            G 1 Reply Last reply
            0
            • G George_George

              Thanks CPallini, I have did more study and I want to share my points here. Could you help to review whether my points are correct please? :-) 1. If a component implements IDispatch directly, we can only invoke its member methods through IDispatch.Invoke -- only one way, so it is not dual interface; 2. If a component implements IUnknown directly, we can only use AddRef/Release/QueryInterface, it is useless since we can only use the 3 methods; 3. If a component implements a customized interface, then the customized interface implements IUnknown, then we could invoke the component's member methods through QueryInterface to get the customized interface, and using the vtable in the customized interface to invoke member methods. But still one way, so it is not dual interface; 4. If a component implements a customized interface, then the customized interface implements IDispatch, then we could invoke the component's member methods through QueryInterface to get the customized interface, and using the vtable in the customized interface to invoke member methods, and also we could invoke through IDispatch.Invoke. Two ways to invoke it, so called dual interface. All of my understandings are correct? Anything missing? :-) regards, George

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #13

              When you say a component implements IDispatch or IUnknown im assuming that you have an interface IX that is derived from either of those interfaces (IDispatch or IUnknown)and you are implementing those intrefaces in a coclass. 1. Any COM interface has to be derived from IUnknown. So when you implement IDispatch you also have to implement IUnknown, because IDispatch is also derived from IUnknown. Any interface,say IX, that is derived from IDispatch is a dual interface. Because IX methods can be invoked through IDispatch methods as well as vtable. 2. You can also derive your interface IX from IUnknown and invoke its methods through vtable. 3,4. Don't know what you mean by customized interface. May i suggest that you go through "Inside COM" by Dale Rogerson. It is a very good book it will help you in understanding COM much better.

              G 1 Reply Last reply
              0
              • S SandipG

                Hi CPallini, I am not sure that we require an extra Interface. Check this Link Dual Interfaces[^] I could not find some good sample for this do you have one which will explain step by step procedure.. I am asking for this because i have never implemented this ..

                CPallini wrote:

                Sandip I don't remember the technical details and, as usual: "this in going on my arrogant assumptions..." Smile

                :laugh:

                Regards, Sandip.

                modified on Friday, September 12, 2008 4:31 AM

                G Offline
                G Offline
                George_George
                wrote on last edited by
                #14

                Thanks Sandip, I am a little losting the context you are talking about. Do you mean in order to implement a dual interface, - we need an additional customized interface, which implements IDispatch? - or we need implement both an additional customized interface (and the customized interface inherits from IUnknown) and also implement IDispatch? - or both the above two ways are fine? regards, George

                1 Reply Last reply
                0
                • CPalliniC CPallini

                  I think you're right, since you may simply do something like:

                  class IMyDualInterface : public IDispatch

                  with a VTABLE arranged the following way:

                  • QueryInterface methods
                  • IDispatch methods
                  • 'Add' method here.

                  :)

                  If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                  This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                  [My articles]

                  G Offline
                  G Offline
                  George_George
                  wrote on last edited by
                  #15

                  Thanks CPallini, I am a little losing the context and my English is not very good. Do you guys mean in order to implement a dual interface, - we need an additional customized interface, which implements IDispatch? - or we need implement both an additional customized interface (and the customized interface inherits from IUnknown) and also implement IDispatch? - or both the above two ways are fine? regards, George

                  CPalliniC 1 Reply Last reply
                  0
                  • CPalliniC CPallini

                    IMHO your understandings are correct. Point (2), as it stands, IMHO is misleading: since IUnknown implementation is mandatory, I will say: if a component implements only IDispatch... But such a point is obvious. Also, as you know well, IDispatch, like any other COM interface must provide IUnknown, then saying: "implementing only IDispatch" it is equivalent to say: "implementing a IUnknown whose QueryInterface method may return only IDispatch". :)

                    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                    [My articles]

                    G Offline
                    G Offline
                    George_George
                    wrote on last edited by
                    #16

                    Thanks CPallini! http://www.codeproject.com/script/Forums/View.aspx?fid=1647&msg=2720744[^] Your reply is very clear. I post my further question here. Do you have any ideas? :-) regards, George

                    1 Reply Last reply
                    0
                    • G George_George

                      Thanks CPallini, I am a little losing the context and my English is not very good. Do you guys mean in order to implement a dual interface, - we need an additional customized interface, which implements IDispatch? - or we need implement both an additional customized interface (and the customized interface inherits from IUnknown) and also implement IDispatch? - or both the above two ways are fine? regards, George

                      CPalliniC Offline
                      CPalliniC Offline
                      CPallini
                      wrote on last edited by
                      #17

                      We need a customized interface that implements (also) IDispatch (Usually it inherits from IDispatch, that in turn, inherits from IUnknown). :)

                      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                      [My articles]

                      In testa che avete, signor di Ceprano?

                      S G 2 Replies Last reply
                      0
                      • L Lost User

                        When you say a component implements IDispatch or IUnknown im assuming that you have an interface IX that is derived from either of those interfaces (IDispatch or IUnknown)and you are implementing those intrefaces in a coclass. 1. Any COM interface has to be derived from IUnknown. So when you implement IDispatch you also have to implement IUnknown, because IDispatch is also derived from IUnknown. Any interface,say IX, that is derived from IDispatch is a dual interface. Because IX methods can be invoked through IDispatch methods as well as vtable. 2. You can also derive your interface IX from IUnknown and invoke its methods through vtable. 3,4. Don't know what you mean by customized interface. May i suggest that you go through "Inside COM" by Dale Rogerson. It is a very good book it will help you in understanding COM much better.

                        G Offline
                        G Offline
                        George_George
                        wrote on last edited by
                        #18

                        Thanks sw@thi, 1. You mentioned twice about "invoke its methods through vtable". My confusion is what exactly mean "through vtable". I think you mean QueryInterface for interface IX for the coclass object, and invoke the exposed methods in IX is through vtable of coclass object for interface IX. Correct? 2.

                        sw@thi wrote:

                        3,4. Don't know what you mean by customized interface.

                        Customized interface I mean any C++ eligible interface which is not IDispatch and IUnknown, and in 3 the customized interface inherits IUnknown and in 4 the customized interface inherits IDispatch. From my description, do you think my points for 3 and 4 are both correct? regards, George

                        1 Reply Last reply
                        0
                        • CPalliniC CPallini

                          We need a customized interface that implements (also) IDispatch (Usually it inherits from IDispatch, that in turn, inherits from IUnknown). :)

                          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                          [My articles]

                          S Offline
                          S Offline
                          SandipG
                          wrote on last edited by
                          #19

                          Hi CPallini, I didn't find any simple article or example to do this on CP, which will explain steps. Do you know any? If not i think George can write one side by side as he implements Dual Interface :)

                          Regards, Sandip.

                          G CPalliniC 2 Replies Last reply
                          0
                          • CPalliniC CPallini

                            We need a customized interface that implements (also) IDispatch (Usually it inherits from IDispatch, that in turn, inherits from IUnknown). :)

                            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                            [My articles]

                            G Offline
                            G Offline
                            George_George
                            wrote on last edited by
                            #20

                            Thanks CPallini, I have one more comment, at first I agree with what you mean above. I think there is another way to implement dual interface, which is we need implement both an additional customized interface (and the customized interface inherits from IUnknown) and also implement IDispatch (in IDispatch's Invoke implementation we can call the methods from the customized interface methods' implementation)? Is that also dual interface? regards, George

                            CPalliniC 1 Reply Last reply
                            0
                            • S SandipG

                              Hi CPallini, I didn't find any simple article or example to do this on CP, which will explain steps. Do you know any? If not i think George can write one side by side as he implements Dual Interface :)

                              Regards, Sandip.

                              G Offline
                              G Offline
                              George_George
                              wrote on last edited by
                              #21

                              I am also asking for this, about various ways to implement dual interface. regards, George

                              1 Reply Last reply
                              0
                              • S SandipG

                                Hi CPallini, I didn't find any simple article or example to do this on CP, which will explain steps. Do you know any? If not i think George can write one side by side as he implements Dual Interface :)

                                Regards, Sandip.

                                CPalliniC Offline
                                CPalliniC Offline
                                CPallini
                                wrote on last edited by
                                #22

                                SandipG wrote:

                                Do you know any?

                                Unfortunately, no. :sigh:

                                SandipG wrote:

                                If not i think George can write one side by side as he implements Dual Interface

                                Oh, he's writing the George's COM Bible! :-D

                                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                                This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                                [My articles]

                                modified on Friday, September 12, 2008 5:39 AM

                                In testa che avete, signor di Ceprano?

                                1 Reply Last reply
                                0
                                • G George_George

                                  Thanks CPallini, I have one more comment, at first I agree with what you mean above. I think there is another way to implement dual interface, which is we need implement both an additional customized interface (and the customized interface inherits from IUnknown) and also implement IDispatch (in IDispatch's Invoke implementation we can call the methods from the customized interface methods' implementation)? Is that also dual interface? regards, George

                                  CPalliniC Offline
                                  CPalliniC Offline
                                  CPallini
                                  wrote on last edited by
                                  #23

                                  I think the standard way is just inheriting from IDispatch (since IDispatch in turn inherits from IUnknown) this way does not prevent IDispatch::Invoke to call the methods of the customized interface. :)

                                  If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                                  This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                                  [My articles]

                                  In testa che avete, signor di Ceprano?

                                  G 2 Replies Last reply
                                  0
                                  • CPalliniC CPallini

                                    I think the standard way is just inheriting from IDispatch (since IDispatch in turn inherits from IUnknown) this way does not prevent IDispatch::Invoke to call the methods of the customized interface. :)

                                    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                                    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                                    [My articles]

                                    G Offline
                                    G Offline
                                    George_George
                                    wrote on last edited by
                                    #24

                                    I agree, but my implementation above is wrong and not dual interface, CPallini? regards, George

                                    CPalliniC S 2 Replies Last reply
                                    0
                                    • CPalliniC CPallini

                                      I think the standard way is just inheriting from IDispatch (since IDispatch in turn inherits from IUnknown) this way does not prevent IDispatch::Invoke to call the methods of the customized interface. :)

                                      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                                      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                                      [My articles]

                                      G Offline
                                      G Offline
                                      George_George
                                      wrote on last edited by
                                      #25

                                      Just think of one more point to clarify -- we always mentioned of the dual interface access methods is -- invoke its methods through vtable. My confusion is what exactly mean "through vtable". I think it means using QueryInterface for customized interface for the coclass object, and invoke the exposed methods in the customized interface is through vtable of coclass object for the customized interface. Correct? regards, George

                                      CPalliniC 1 Reply Last reply
                                      0
                                      • G George_George

                                        I agree, but my implementation above is wrong and not dual interface, CPallini? regards, George

                                        CPalliniC Offline
                                        CPalliniC Offline
                                        CPallini
                                        wrote on last edited by
                                        #26

                                        Well, it depends on how do you implement the IDispatch interface (for instance, if your customized interface inherits both from IUnknown and IDispatch the you've a undesirable diamond inehritance path). :)

                                        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                                        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                                        [My articles]

                                        In testa che avete, signor di Ceprano?

                                        G 1 Reply Last reply
                                        0
                                        • G George_George

                                          Just think of one more point to clarify -- we always mentioned of the dual interface access methods is -- invoke its methods through vtable. My confusion is what exactly mean "through vtable". I think it means using QueryInterface for customized interface for the coclass object, and invoke the exposed methods in the customized interface is through vtable of coclass object for the customized interface. Correct? regards, George

                                          CPalliniC Offline
                                          CPalliniC Offline
                                          CPallini
                                          wrote on last edited by
                                          #27

                                          Yes, it means (1) get the IUnknown pointer (2) get the ICustomized pointer via IUnknown->QueryInterface (3) call ICustomized->WhateverMethod() (eventually perform cleanup...) on the other hand, access via IDispatch is quite different. :)

                                          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                                          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                                          [My articles]

                                          In testa che avete, signor di Ceprano?

                                          G 2 Replies 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