COM design question
-
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?
-
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?
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. :-)
-
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?
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 :)
-
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?
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.
-
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?
>> 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]
-
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?
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.
-
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?
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
-
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.
You never let go of those damn categories do you? ;) -- Please state the nature of your medical emergency.
-
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?
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