How to Expose two COM interfaces
-
Hello, I have an ActiveX Control which is embedded in another application which works fine. The only problem is that some peers want to test the control in the application before we ship the product. From my point of view: Automated Tests = COM, so I came up with the idea to make a second COM interface and register it in the ROT (Running Obect table). This Interface gives full access to my ActiveX control. I have not done this before so I would like get some opinions how this could be done in the best object oriented way. Can I use the same .ODL file for my ActiveX project and insert there the second interface ? What must I do to implement a second COM interface by myself ? Yours, Alois Kraus
-
Hello, I have an ActiveX Control which is embedded in another application which works fine. The only problem is that some peers want to test the control in the application before we ship the product. From my point of view: Automated Tests = COM, so I came up with the idea to make a second COM interface and register it in the ROT (Running Obect table). This Interface gives full access to my ActiveX control. I have not done this before so I would like get some opinions how this could be done in the best object oriented way. Can I use the same .ODL file for my ActiveX project and insert there the second interface ? What must I do to implement a second COM interface by myself ? Yours, Alois Kraus
There are two basic ways to expose a secondary interface: a) local classes (MFC does that, including some dirty tricks to make this effective) b) multile inheritance (ATL does that) b) is IMO much cleaner, only you can get into problems with method name clashes Some pseudocode for the latter:
class CCoImpl : public IFun, public ITest
{
HRESULT QueryInterface()
{
if (iid == IUnknown) { // always return the same pointer when specifically asked for IUnk; which one doesn't matter
addref, return static_cast(this);
}
if (iid == IFun) {
addref, return static_cast(this);
}
if (iid == ITest) {
addref, return static_cast(this);
}
return E_NOINTERFACE;
}
// IFun methods:
HRESULT GoShopping() { ... }
HRESULT GoRocking() { ... }// ITest Methods
HRESULT TestCountShoes(....) { ... }
};you get the idea... Neither way you can expose two dispatch (or dual) interfaces - you can only have obe dispatch-based interface per object.
If I could find a souvenir / just to prove the world was here [sighist]