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. COM
  4. COM design question

COM design question

Scheduled Pinned Locked Moved COM
questionc++comdesignhelp
9 Posts 9 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.
  • J Offline
    J Offline
    Jeremy Pullicino
    wrote on last edited by
    #1

    Hi guys, I have a COM question which has more to do with design than with actual code. I have a object A and object B. Both objects have exactly the same interface, however, underneath their interface, they have different implementations. I also have object C which needs to use the interface that both A and B expose. However, depending on some other criteria, object C needs to either use object A's implementation or use object B's implementation. I have the following questions: * How do I have object A and B both installed and registered on the same machine (same interfaces but different implementation). Is it OK to have a different GUID, but the same interfaces(methods, properties)? * What is the most transparent way of making object C load a different implementation (A or B) depedning on which one it needs? Could anyone help me with the above? Any pointers, advice, thoughts or questions will be greatly appreciated. Jeremy. Jeremy Pullicino Professional C++ Developer Done any hacking lately?

    R M S P S 7 Replies Last reply
    0
    • J Jeremy Pullicino

      Hi guys, I have a COM question which has more to do with design than with actual code. I have a object A and object B. Both objects have exactly the same interface, however, underneath their interface, they have different implementations. I also have object C which needs to use the interface that both A and B expose. However, depending on some other criteria, object C needs to either use object A's implementation or use object B's implementation. I have the following questions: * How do I have object A and B both installed and registered on the same machine (same interfaces but different implementation). Is it OK to have a different GUID, but the same interfaces(methods, properties)? * What is the most transparent way of making object C load a different implementation (A or B) depedning on which one it needs? Could anyone help me with the above? Any pointers, advice, thoughts or questions will be greatly appreciated. Jeremy. Jeremy Pullicino Professional C++ Developer Done any hacking lately?

      R Offline
      R Offline
      Ranjan Banerji
      wrote on last edited by
      #2

      Oh boy!... you just cannot ask a simple question can you.... :-) Well, first of all there is no ptoblem at all with two objects with exactly the same interface. But that is really not the main issue behind your design requirements. Now the part of object C creating an instance of A or B, can be handled in several ways. I don't think either Containment or Aggregation will help. (COM gurus will be able to answer that better). So you can have a switch in your object C that either creates A or B. But that just does not look too elegant. You could consider creating a single COM object D. D provides the COM interface to a base class Z. From Z you derive A and B which provide the different implementations for the interfaces. Now somewhere in your COM D object you will have Z = new A or Z = new B and then you use Z->Interface(). So you have a single COM object not two. But inside the COM object you use standard OO polymorphism to handle to different implementations of A and B. I think I may be rambling now. But you may want to think along this path. Hope this helped. :-)

      1 Reply Last reply
      0
      • J Jeremy Pullicino

        Hi guys, I have a COM question which has more to do with design than with actual code. I have a object A and object B. Both objects have exactly the same interface, however, underneath their interface, they have different implementations. I also have object C which needs to use the interface that both A and B expose. However, depending on some other criteria, object C needs to either use object A's implementation or use object B's implementation. I have the following questions: * How do I have object A and B both installed and registered on the same machine (same interfaces but different implementation). Is it OK to have a different GUID, but the same interfaces(methods, properties)? * What is the most transparent way of making object C load a different implementation (A or B) depedning on which one it needs? Could anyone help me with the above? Any pointers, advice, thoughts or questions will be greatly appreciated. Jeremy. Jeremy Pullicino Professional C++ Developer Done any hacking lately?

        M Offline
        M Offline
        Mike Player
        wrote on last edited by
        #3

        If the two objects are seperate COM objects then it simply a case of each having a different Class ID (CLSID) and both supporting the same Interface ID (IID). Your outer program can create an instance of the either object by selecting the relavent Class ID in the CoCreateInstance call :)

        1 Reply Last reply
        0
        • J Jeremy Pullicino

          Hi guys, I have a COM question which has more to do with design than with actual code. I have a object A and object B. Both objects have exactly the same interface, however, underneath their interface, they have different implementations. I also have object C which needs to use the interface that both A and B expose. However, depending on some other criteria, object C needs to either use object A's implementation or use object B's implementation. I have the following questions: * How do I have object A and B both installed and registered on the same machine (same interfaces but different implementation). Is it OK to have a different GUID, but the same interfaces(methods, properties)? * What is the most transparent way of making object C load a different implementation (A or B) depedning on which one it needs? Could anyone help me with the above? Any pointers, advice, thoughts or questions will be greatly appreciated. Jeremy. Jeremy Pullicino Professional C++ Developer Done any hacking lately?

          S Offline
          S Offline
          Stefan Pedersen
          wrote on last edited by
          #4

          The previous post answers your question. To make it even more configurable you might want to implement a CATID system and let the objects themself decide if they are matching the critera.

          J 1 Reply Last reply
          0
          • J Jeremy Pullicino

            Hi guys, I have a COM question which has more to do with design than with actual code. I have a object A and object B. Both objects have exactly the same interface, however, underneath their interface, they have different implementations. I also have object C which needs to use the interface that both A and B expose. However, depending on some other criteria, object C needs to either use object A's implementation or use object B's implementation. I have the following questions: * How do I have object A and B both installed and registered on the same machine (same interfaces but different implementation). Is it OK to have a different GUID, but the same interfaces(methods, properties)? * What is the most transparent way of making object C load a different implementation (A or B) depedning on which one it needs? Could anyone help me with the above? Any pointers, advice, thoughts or questions will be greatly appreciated. Jeremy. Jeremy Pullicino Professional C++ Developer Done any hacking lately?

            P Offline
            P Offline
            peterchen
            wrote on last edited by
            #5

            >> Is it OK to have a different GUID, but the same interfaces(methods, properties)? yes, that's a "key intention" of COM. >> What is the most transparent way of making object C load a different implementation (A or B) depedning on which one it needs? using a CLSID or ProgID of the component to load. The "perfect COM way" would be to create your own COM Category (the UUID for this one is called CATID), and register "all possible" COM servers under this category. This way C could enumerate the components it has available to work with on the current machine.


            Auch den Schatten will ich lieben weil ich manchmal lieber frier'  Rosenstolz   [sighist]

            1 Reply Last reply
            0
            • J Jeremy Pullicino

              Hi guys, I have a COM question which has more to do with design than with actual code. I have a object A and object B. Both objects have exactly the same interface, however, underneath their interface, they have different implementations. I also have object C which needs to use the interface that both A and B expose. However, depending on some other criteria, object C needs to either use object A's implementation or use object B's implementation. I have the following questions: * How do I have object A and B both installed and registered on the same machine (same interfaces but different implementation). Is it OK to have a different GUID, but the same interfaces(methods, properties)? * What is the most transparent way of making object C load a different implementation (A or B) depedning on which one it needs? Could anyone help me with the above? Any pointers, advice, thoughts or questions will be greatly appreciated. Jeremy. Jeremy Pullicino Professional C++ Developer Done any hacking lately?

              S Offline
              S Offline
              Steve Hopkins
              wrote on last edited by
              #6

              We do it via progid. When the user chosses which integration module to use via the settings UI, the progID of that component is stored in the registry. When it comes the time to create A or B ( or up to F in our cases) the progid is read, and the component is instantiated using it.

              1 Reply Last reply
              0
              • J Jeremy Pullicino

                Hi guys, I have a COM question which has more to do with design than with actual code. I have a object A and object B. Both objects have exactly the same interface, however, underneath their interface, they have different implementations. I also have object C which needs to use the interface that both A and B expose. However, depending on some other criteria, object C needs to either use object A's implementation or use object B's implementation. I have the following questions: * How do I have object A and B both installed and registered on the same machine (same interfaces but different implementation). Is it OK to have a different GUID, but the same interfaces(methods, properties)? * What is the most transparent way of making object C load a different implementation (A or B) depedning on which one it needs? Could anyone help me with the above? Any pointers, advice, thoughts or questions will be greatly appreciated. Jeremy. Jeremy Pullicino Professional C++ Developer Done any hacking lately?

                V Offline
                V Offline
                Vi2
                wrote on last edited by
                #7

                I think that it depends on when your object C would know about some criteria. The best solution is a Moniker like "C:A" or "C:B" or "C:criteria". When this Moniker will be bound, he is possible to return the appropriate object A or B. On VB-client: Set o = GetObject("C:xxx"), on C-client: CoGetObject("C:xxx",IID_Ix, &px); But there is no any real C object. If you wish to have the real C object, then you can derived objectC-class from your known interface Ix and realize all of his methods to delegate simply these calls to some A_or_B object. For example

                class objectC : public Ix ...
                {
                CComPtr m_A_or_B;
                ...
                STDMETHODIMP IxMethod(...params...)
                {
                if( m_A_or_B )
                return m_A_or_B->IxMethod(...params...);
                return E_UNEXPECTED;
                }
                };

                m_A_or_B object can be created by COM common way through the criteria. With best wishes, Vita

                1 Reply Last reply
                0
                • S Stefan Pedersen

                  The previous post answers your question. To make it even more configurable you might want to implement a CATID system and let the objects themself decide if they are matching the critera.

                  J Offline
                  J Offline
                  Jorgen Sigvardsson
                  wrote on last edited by
                  #8

                  You never let go of those damn categories do you? ;) -- Please state the nature of your medical emergency.

                  1 Reply Last reply
                  0
                  • J Jeremy Pullicino

                    Hi guys, I have a COM question which has more to do with design than with actual code. I have a object A and object B. Both objects have exactly the same interface, however, underneath their interface, they have different implementations. I also have object C which needs to use the interface that both A and B expose. However, depending on some other criteria, object C needs to either use object A's implementation or use object B's implementation. I have the following questions: * How do I have object A and B both installed and registered on the same machine (same interfaces but different implementation). Is it OK to have a different GUID, but the same interfaces(methods, properties)? * What is the most transparent way of making object C load a different implementation (A or B) depedning on which one it needs? Could anyone help me with the above? Any pointers, advice, thoughts or questions will be greatly appreciated. Jeremy. Jeremy Pullicino Professional C++ Developer Done any hacking lately?

                    Z Offline
                    Z Offline
                    ZBUILDER
                    wrote on last edited by
                    #9

                    Hi,I donot think it is a question. First ,you should know some concepts. Interface means the assembly of a bunch of functions.It is not an object.One Interface has one UUID called as IID_XXX. CoClass stands for object which implements some interfaces.One CoClass has one UUID called as CLSID_XXX Library looks like a DLL or EXE file.One library can contains and exporses one or more CoClass. So the solutions of your question can be like the followings: No.1 You create a library "La",which contains two coclasss coA and coB,which both implements the interface Interace0.In your application you can create object coA or coB then query their's interface0 to execute some method. No.2 You can create two library "La" and "Lb",which contains coA and accordingly.the following steps is same to No1 SORRY My poor words.:-D SIMPLE IS BEAUTY

                    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